Skip to content

[황채원] Sprint 7#9

Closed
chaewon127 wants to merge 16 commits intocodeit-sprint-fullstack:node-황채원from
chaewon127:node-황채원-sprint7

Hidden character warning

The head ref may contain hidden characters: "node-\ud669\ucc44\uc6d0-sprint7"
Closed

[황채원] Sprint 7#9
chaewon127 wants to merge 16 commits intocodeit-sprint-fullstack:node-황채원from
chaewon127:node-황채원-sprint7

Conversation

@chaewon127
Copy link
Collaborator

@chaewon127 chaewon127 commented Aug 31, 2025

요구사항

기본 요구사항

중고마켓

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

공통

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

자유게시판

  • [ x 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를 따로 만들어 주세요.

주요 변경사항

스크린샷

image

멘토에게

  • 셀프 코드 리뷰를 통해 질문 이어가겠습니다.

@chaewon127 chaewon127 marked this pull request as ready for review August 31, 2025 14:52
@chaewon127 chaewon127 requested a review from keepoki August 31, 2025 14:52
@chaewon127 chaewon127 changed the title [황채] Sprint 7 [황채원] Sprint 7 Aug 31, 2025
Copy link
Collaborator

@keepoki keepoki left a comment

Choose a reason for hiding this comment

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

node_modules 폴더를 없애고 다시 commit 해주시거나, PR을 다시 올려주시면 감사하겠습니다.
node_modules 폴더는 용량도 크고 파일도 많아서 .gitignore 파일에 추가해주시면 되겠습니다!.

이 PR은 지우지 마셔요!! 리뷰의 흔적도 지워지니까요~
https://sangumi.tistory.com/54

개선하면 좋은 점

prisma/schema.prisma 데이터 모델을 정의 할 때 관계 설정을 하면 더 좋을 것 같습니다.

https://velog.io/@dnjsdn96/Prisma-Schema-%EB%AA%A8%EB%8D%B8%EB%A7%81-Relation-%EA%B4%80%EA%B3%84-%EC%84%A4%EC%A0%95%ED%95%98%EA%B8%B0

app.js에서 /articles get 라우트와 /comments get 라우트 코드가 중복되고 있는데, 중복되는 부분은 하나로 합쳐서 관리하는 것이 좋아 보입니다~!

댓글 목록 조회 API의 요구사항은 cursor 방식의 페이지네이션 이었는데, offset 방식으로 되어 있습니다~
offset 방식은 페이지 뒤로 갈수록 데이터베이스가 건너뛰어야 할 행이 많아져 성능이 저하될 수 있습니다.
특히 실시간으로 데이터가 추가/삭제되는 댓글과 같은 기능에는 cursor 방식이 더 안정적이고 효율적입니다.

https://cactuslog.tistory.com/22

Comment on lines +10 to +30
function asyncHandler(handler) {
return async function (req, res) {
try {
await handler(req, res);
} catch (e) {
if (
e.name === "StructError" ||
e instanceof Prisma.PrismaClientValidationError
) {
res.status(400).send({ message: e.message });
} else if (
e instanceof Prisma.PrismaClientKnownRequestError &&
e.code === "P2025"
) {
res.status(400).send({ message: "Cannot find given id" });
} else {
res.status(500).send({ message: e.message });
}
}
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

에러 헨들러를 만들어 중앙에서 관리할 수 있도록 한 것은 잘 하셨습니다! 훌륭하네요~

여기서 조금 개선하자면, 따로 미들웨어로 분류해서 모듈로서 관리하는 것입니다.

https://inpa.tistory.com/entry/EXPRESS-%F0%9F%93%9A-%EB%AF%B8%EB%93%A4%EC%9B%A8%EC%96%B4-%F0%9F%92%AF-%EC%9D%B4%ED%95%B4-%EC%A0%95%EB%A6%AC

@@ -0,0 +1,2 @@
export const DATABASE_URL =
Copy link
Collaborator

Choose a reason for hiding this comment

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

.env 파일 관리에 대해 알아두면 좋은 정보를 남깁니다.
그리고 env파일은 .gitignore에 추가하여 저장소에 올리지 않아야 합니다. (보안 정보 노출)

https://www.daleseo.com/js-dotenv/
https://wikidocs.net/277237

Comment on lines +1 to +30
GET http://localhost:5432/mockArticles

###

GET http://localhost:5432/mockArticles?sort=newestcount=5

###

GET http://localhost:5432/mockArticles/1

###

POST http://localhost:5432/mockArticles
Content-Type: application/json

{
"title": "New Article",
"content": "This is the content of the new article.",
}

###
PATCH http://localhost:5432/mockArticles
Content-Type: application/json

{
"title": "New New",
}

###
DELETE http://localhost:5432/mockArticles/1 No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

테스트 코드 잘 작성하셨네요!~ 저도 간단하게 사용할 때는 이거 씁니다 ㅎㅎ

@keepoki keepoki closed this Sep 6, 2025
keepoki pushed a commit that referenced this pull request Oct 27, 2025
feat: add sorting by likes in ArticleRoutes
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