Skip to content

Express 임경민 미션 6#2

Merged
devbini merged 36 commits intocodeit-sprint-fullstack:express-임경민from
play-ancora-gyungmin:express-임경민
Sep 30, 2025

Hidden character warning

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

Express 임경민 미션 6#2
devbini merged 36 commits intocodeit-sprint-fullstack:express-임경민from
play-ancora-gyungmin:express-임경민

Conversation

@play-ancora-gyungmin
Copy link
Collaborator

미션 6 요구사항

기본 요구사항

공통

  • Github에 스프린트 미션 PR을 만들어 주세요.
  • React, Express를 사용해 진행합니다.

백엔드 구현 요구사항

중고마켓

  • Product 스키마를 작성해 주세요.
    • idnamedescriptionpricetagscreatedAtupdatedAt필드를 가집니다.
    • 필요한 필드가 있다면 자유롭게 추가해 주세요.
  • 상품 등록 API를 만들어 주세요.
    • namedescriptionpricetags를 입력하여 상품을 등록합니다.
  • 상품 상세 조회 API를 만들어 주세요.
    • idnamedescriptionpricetagscreatedAt를 조회합니다.
  • 상품 수정 API를 만들어 주세요.
    • PATCH 메서드를 사용해 주세요.
  • 상품 삭제 API를 만들어 주세요.
  • 상품 목록 조회 API를 만들어 주세요.
    • idnamepricecreatedAt를 조회합니다.
    • offset 방식의 페이지네이션 기능을 포함해 주세요.
    • 최신순(recent)으로 정렬할 수 있습니다.
    • namedescription에 포함된 단어로 검색할 수 있습니다.
  • 각 API에 적절한 에러 처리를 해 주세요.
  • 각 API 응답에 적절한 상태 코드를 리턴하도록 해 주세요.
  • . env 파일에 환경 변수를 설정해 주세요.
  • CORS를 설정해 주세요.
  • [render.com](https://render.com/)로 배포해 주세요.
  • MongoDB를 활용해 주세요.

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.

🎉 고생하셨습니다!

전체적으로 깔끔하고 좋습니다!
HttpException로부터 상속받아 Exception들을 자식으로 만들어 관리하는 건 너무나 좋은 습관이라 생각해요.
미들웨어 구분도 잘 되어 있어서, 차후 누군가 코드를 딱 봤을 때 한번에 이해하기도 좋네요.

로직 부분도 크게 수정할 건 없고, mongoose 사용에 일부 미숙해보이는 부분만 잡아봤어요.
하지만.. 직접적으로 배우고자 하는 건 postgresql이니, 이건 그냥 토막 상식으로 알고 넘어가는 수준이면 될 것 같아요ㅎㅎ

첫 BE PR인데, 고생하셨습니다! 😊


const productSchema = new Schema(
{
id: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thinking

지금 보니, id 컬럼을 별도 생성하고 있는 것 같네요.
최신 monggo Driver를 통해 개발을 하고 있다면 이 방법이 유효하지만..
mongoose를 사용하고 있다면, _id 컬럼이 자동 생성되기 때문에, 중복된 id 컬럼이 생성될 수 있어요.

아래 문서를 한번 읽어보면 좋을 것 같아요. _id 컬럼 생성을 막는 방법도 있으니까요 😁

https://mongoosejs.com/docs/guide.html#_id

물론, 해당 id 컬럼에 특별히 다른 의미가 있다면 상관없겠죠! 👏

}

if (!price || isNaN(price)) {
throw new BadRequestException('상품명은 존재해야하며, 숫자여야 합니다.');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thinking

조건은 price(상품 가격)인데, 에러 메시지는 상품명으로 표시되고 있는 것 같아요 🤣

},
);

productSchema.pre('save', function (next) {
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

음.. findByIdAndUpdate 메서드가 호출될 때 해당 훅이 인터셉트해서 동작하길 기대한 것 같아요.
제가 알기로는 .pre('save')는 새로운 Document를 신규 생성할 때 동작하고, 그 외 다른 메서드에선 동작하지 않는 것으로 압니다.
아마 훅 중에... pre('update', ...)를 사용하면, 원하는 대로 기능을 구현할 수 있을 것 같아요.

https://mongoosejs.com/docs/middleware.html

또는!
productSchema를 생성할 때 timestamps 옵션을 추가하는 것도 방법이랍니다.
그러면 자동으로 mongoose가 save/update될 때 자동으로 관리 해 주는 부분도 있어요 😊

https://mongoosejs.com/docs/timestamps.html

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

Choose a reason for hiding this comment

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

Thinking

멘토링때도 말씀 드렸지만, 이 역시 별도 환경변수로 관리 해 주는 게 좋겠죠? 😊

@devbini devbini merged commit d1039d4 into codeit-sprint-fullstack:express-임경민 Sep 30, 2025
1 check passed
devbini pushed a commit that referenced this pull request Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants