Skip to content

[이유진]스프린트 미션 6#2

Draft
nijuuy wants to merge 10 commits intocodeit-sprint-fullstack:express-이유진from
nijuuy:feat/products-api
Draft

[이유진]스프린트 미션 6#2
nijuuy wants to merge 10 commits intocodeit-sprint-fullstack:express-이유진from
nijuuy:feat/products-api

Conversation

@nijuuy
Copy link
Collaborator

@nijuuy nijuuy commented Jun 9, 2025

요구사항

기본

백엔드 구현 요구사항
중고마켓

[x] Product 스키마를 작성해 주세요.

[x] id, name, description, price, tags, createdAt, updatedAt필드를 가집니다.
[x] 필요한 필드가 있다면 자유롭게 추가해 주세요.
[x] 상품 등록 API를 만들어 주세요.

[x] name, description, price, tags를 입력하여 상품을 등록합니다.
[x] 상품 상세 조회 API를 만들어 주세요.

[x] id, name, description, price, tags, createdAt를 조회합니다.
[x] 상품 수정 API를 만들어 주세요.

[x] PATCH 메서드를 사용해 주세요.
[x] 상품 삭제 API를 만들어 주세요.

[x] 상품 목록 조회 API를 만들어 주세요.

[x] id, name, price, createdAt를 조회합니다.
[x] offset 방식의 페이지네이션 기능을 포함해 주세요.
[x] 최신순(recent)으로 정렬할 수 있습니다.
[x] name, description에 포함된 단어로 검색할 수 있습니다.
[x] 각 API에 적절한 에러 처리를 해 주세요.

[x] 각 API 응답에 적절한 상태 코드를 리턴하도록 해 주세요.

[x] . env 파일에 환경 변수를 설정해 주세요.

[x] CORS를 설정해 주세요.

[ ] render.com로 배포해 주세요.

[x] MongoDB를 활용해 주세요.

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

@nijuuy nijuuy marked this pull request as draft June 9, 2025 13:57
@nijuuy nijuuy self-assigned this Jun 9, 2025
@nijuuy nijuuy requested a review from changchanghwang June 9, 2025 13:58
@nijuuy nijuuy changed the base branch from main to express-이유진 June 10, 2025 11:02
Copy link

@changchanghwang changchanghwang left a comment

Choose a reason for hiding this comment

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

전체적으로 깔끔한 구조를 가지고 있는 것 같습니다. 다만 조금 더 주석의 필요성에 대해서 고민해보시고 각 레이어의 책임을 한번 더 생각해보시면 좋을 것 같습니다.

Comment on lines +4 to +7
productService;
constructor(productService) {
this.productService = productService;
}

Choose a reason for hiding this comment

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

이런식으로 Dependency Injection을 통해 주입하는것은 좋은패턴입니다 :)
실제로 많은 프레임워크들에서 채택하고있는 방식이에요 ( spring, nest 등)

Comment on lines +73 to +74
const offset = Number(req.query.offset) || 0;
const limit = Number(req.query.limit) || 10;

Choose a reason for hiding this comment

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

offset, limit이 숫자가 아닌게 온다면 에러를 던져야하고 undefined or null로 왔을때 default로 해줘야되지 않을까요?
validation + non null assertion을 사용하는것을 추천드립니다.

const offset = Number(req.query.offset) || 0;
const limit = Number(req.query.limit) || 10;
const orderBy = req.query.orderBy || "recent";
const search = req.query.search || "";

Choose a reason for hiding this comment

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

Suggested change
const search = req.query.search || "";
const search = req.query.search ?? "";

import Product from "../../model/product.model.js";

class ProductRepository {
// 상품 생성

Choose a reason for hiding this comment

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

create라는 메서드명이 생성을 뜻하고있어서 필요없는 주석으로 생각됩니다.

Comment on lines +10 to +11
// 모든 요청에 대해 CORS 허용
app.use(cors());

Choose a reason for hiding this comment

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

이건 나중에 배포를 하게되면 해당 사이트에서 오는 요청만 받아줄 수 있도록 cors origin을 설정해주어야합니다.

Comment on lines +12 to +13
//터미널에 로그를 찍어주는 미들웨어
app.use(morgan("dev"));

Choose a reason for hiding this comment

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

request log를 찍기위한거겠죠?

// 요청 body가 JSON일 경우 파싱해서 req.body에 넣어줌
app.use(express.json());

const PORT = 3000; // 서버가 사용할 포트 번호

Choose a reason for hiding this comment

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

port의 경우 환경변수로 지정하고 경우에따라 다르게 사용하는 방법이 있습니다.

일반적으로 배포할때는 known port의 경우 봇의 접근이나 이런 악성코드의 접근이 자동으로 돌아가기때문에 지양하는 것이 좋습니다.

@@ -0,0 +1,34 @@
import Product from "../../model/product.model.js";

class ProductRepository {

Choose a reason for hiding this comment

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

repository의 경우 혹시나 디비를 바꾼다면 interface로 선언하는것도 좋습니다.

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.

3 participants