Skip to content

Express 임경민 미션 7#4

Merged
devbini merged 21 commits intocodeit-sprint-fullstack:express-임경민from
play-ancora-gyungmin:express-임경민
Oct 14, 2025

Hidden character warning

The head ref may contain hidden characters: "express-\uc784\uacbd\ubbfc"
Merged

Express 임경민 미션 7#4
devbini merged 21 commits intocodeit-sprint-fullstack:express-임경민from
play-ancora-gyungmin:express-임경민

Conversation

@play-ancora-gyungmin
Copy link
Collaborator

미션 7 요구사항

기본 요구사항

중고마켓

  • mongoDB에서 PostgreSQL을 사용하도록 코드를 마이그레이션 해주세요.

공통

  • PostgreSQL를 이용해 주세요.
  • 데이터 모델 간의 관계를 고려하여 onDelete를 설정해 주세요.
  • 데이터베이스 시딩 코드를 작성해 주세요.
  • 각 API에 적절한 에러 처리를 해 주세요.
  • 각 API 응답에 적절한 상태 코드를 리턴하도록 해 주세요.

자유게시판

  • Article 스키마를 작성해 주세요.
  • id, title, content, createdAt, updatedAt 필드를 가집니다.
  • 게시글 등록 API를 만들어 주세요.
  • title, content를 입력해 게시글을 등록합니다.
  • 게시글 조회 API를 만들어 주세요.
  • id, title, content, createdAt를 조회합니다.
  • 게시글 수정 API를 만들어 주세요.
  • 게시글 삭제 API를 만들어 주세요.
  • 게시글 목록 조회 API를 만들어 주세요.
  • id, title, content, createdAt를 조회합니다.
  • offset 방식의 페이지네이션 기능을 포함해 주세요.
  • 최신순(recent)으로 정렬할 수 있습니다.
  • title, content에 포함된 단어로 검색할 수 있습니다.

댓글

  • 댓글 등록 API를 만들어 주세요.
  • content를 입력하여 댓글을 등록합니다.
  • 중고마켓, 자유게시판 댓글 등록 API를 따로 만들어 주세요.
  • 댓글 수정 API를 만들어 주세요.
  • PATCH 메서드를 사용해 주세요.
  • 댓글 삭제 API를 만들어 주세요.
  • 댓글 목록 조회 API를 만들어 주세요.
  • id, content, createdAt 를 조회합니다.
  • cursor 방식의 페이지네이션 기능을 포함해 주세요.
  • 중고마켓, 자유게시판 댓글 목록 조회 API를 따로 만들어 주세요.

Copy link
Collaborator

@devbini devbini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 고생하셨습니다!

저번부터 좋은 퀄리티의 코드를 보여주고 계셔서 기대가 되네요.
이번엔 Repository 패턴을 이용한 게 사실 마음에 듭니다. 은근히 이런 기본적인 분리를 전혀 신경쓰지 않는 분들이 많아서 조금 슬퍼하고 있었단 말이죠...
트랜잭션 설정이나 스키마 구조 모델링도 깔끔하네요. 제약조건 설정까지...

이제는 일부 prism 문법이나 origin/host/referer 일부분만 더 익숙해지면
정말 제가 더 터치할 게 없을 정도의 코드가 되지 않을까 기대 해 봅니다.

정말 고생하셨어요! 🎉😊

async function findCommentsInArticle() {
return await prisma.$transaction([
prisma.comment.count({ where: { parent: String('Article') } }),
prisma.comment.findMany(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪛 Fix Point

정상적으로 동작을 안 할텐데, 제가 잘못 알고있는 걸 수도 있지만
Prisma ORM 기준 상 제가 썼던 방법과 다른 부분이 있어 코멘트 남겨봐요.

findMany 뿐 만 아니라 다른 메서드들도 매개변수는 하나만 받도록 되어있습니다.

prisma.x.findMany( { } );

이렇게 작성 해 주어야 하는데, 지금은

prisma.x.findMany( { }, { } );

위처럼 매개 값이 두 개가 들어있어서 이게 동작하나? 하고 의문스러워서요.

정석적으로 사용한다고 하면 아래와 같이 수정이 필요합니다.

prisma.comment.findMany({
  where: { parent: 'Article' },
  orderBy: { createdAt: 'desc' },
})

관련 공식 문서를 첨부 드리니, 한번 확인 해 보면 좋을 것 같아요 :D

https://www.prisma.io/docs/orm/prisma-client/queries/filtering-and-sorting

return await prisma.$transaction([
prisma.comment.count({ where: { articleId: String(articleId) } }),
prisma.comment.findMany(
{ where: { parent: String('Article') } },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪛 Fix Point

누락이 된 것 같은데, ArticleId 조건이 빠져있는 것 같아요~!


export const cors = (req, res, next) => {
const origin =
req.headers.origin || req.headers.host || req.headers.referer || '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking

사실 음... origin만 넣어줘도 충분하지 않을까 싶어요.
referer는 오히려 null이 될 수도 있고, 전체 URI를 가지는거라 화이트리스트의 origin과 동일한 경우도 사실상 없는 수준이라 생각이 되어서... 거기에 hostorigin에 거의 종속되어 있으니, 특별한 이유가 없다면 origin만 써도 괜찮지 않을까 하는 생각입니다.

@devbini devbini merged commit 60982e6 into codeit-sprint-fullstack:express-임경민 Oct 14, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants