Conversation
rdd9223
left a comment
There was a problem hiding this comment.
전반적으로 잘 작성해주셨지만, 중간중간 아쉬운 점이 보입니다. 특히 service는 service디렉토리 하위에서 컨트롤 할 수 있도록 수정해주세요.
| console.log(`서버가 ${PORT}번에서 실행중입니다.`); | ||
| }); | ||
|
|
||
| export default prisma; |
There was a problem hiding this comment.
레포지토리/미들웨어가 사용하는 prisma를 여기서 export 하면 안됩니다. 항상 의존(import)하는 건 단방향이어야 해요. repository > service > controller > route(middleware) > index가 되도록 해주세요. 현재는 index > repository > service > controller > route(middleware) > index 여서 순환참조가 일어나고 있어요. 전용 모듈로 별도로 분리하는 것이 좋습니다.
| constructor(productService: ProductService) { | ||
| this.productService = productService; | ||
| const commentRepository = new CommentRepository(); | ||
| this.commentService = new CommentService(commentRepository); | ||
| const likeRepository = new LikeRepository(); | ||
| this.likeService = new LikeService(likeRepository); | ||
| } |
There was a problem hiding this comment.
해당 ProductsController를 여러 route에서 사용하게 된다면 여러 생성자들이 추가로 생성하게 될 수 있어요. 의존성 주입 일관성을 위해서 라우터 조립부에서 생성해서 컨트롤러 생성자에 주입하는 것이 좋습니다.
| constructor(productService: ProductService) { | |
| this.productService = productService; | |
| const commentRepository = new CommentRepository(); | |
| this.commentService = new CommentService(commentRepository); | |
| const likeRepository = new LikeRepository(); | |
| this.likeService = new LikeService(likeRepository); | |
| } | |
| constructor(productService: ProductService, commendService: CommentService, likeService: LikeService) { | |
| this.productService = productService; | |
| this.commentRepository = commentService | |
| this.likeRepository = likeRepository | |
| } |
| router.delete('/products/comments/:commentId', authMiddleware, productsController.deleteComment); | ||
|
|
||
| // 상품 좋아요 API | ||
| router.post('/:productId/like', authMiddleware, productsController.toggleLike); |
There was a problem hiding this comment.
/:productId/like가/:articleId/like와 경로가 겹칩니다. /1234/like로 요청한다면 어떤 경로로 들어갈지 생각해보세요. /product/:productid/like 같이 표현하는 것이 좋아요.
| router | ||
| .route('/products/:productId') | ||
| .get(optionalAuthMiddleware, productsController.getProductById) | ||
| .patch(validateProduct, authMiddleware, productsController.updateProduct) |
There was a problem hiding this comment.
이 경로로 보면 인증검증 로직보다 입력값 검증 로직이 더 빨라요. 일반적으로는 인증로직이 우선이에요.
| router | ||
| .route('/articles/:articleId') | ||
| .get(optionalAuthMiddleware, articlesController.getArticleById) | ||
| .patch(authMiddleware, validateArticle, articlesController.updateArticle) |
| @@ -0,0 +1,50 @@ | |||
| import { Product as PrismaProduct, Prisma } from '@prisma/client'; | |||
There was a problem hiding this comment.
바로 사용하지 말고 repository를 사용하도록 해주세요.
| "main": "index.js", | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "dev": "ts-node-dev --respawn --transpile-only src/index.ts", |
There was a problem hiding this comment.
--transpile-only은 타입에러를 런타임까지 가져갈 수 있어요. 타입스크립트의 장점을 살리기 위해 제거해주세요!
| return res.status(403).json({ message: '상품 수정 권한이 없습니다.' }); | ||
| } | ||
|
|
||
| const updatedProduct = await this.productService.updateProduct(parseInt(productId), { |
There was a problem hiding this comment.
이런 비즈니스 로직은 Service에서 구현해주세요! Controller는 얇게 유지하는 것이 좋습니다.
| @@ -0,0 +1,20 @@ | |||
| { | |||
There was a problem hiding this comment.
프로젝트 전반적으로 상대경로가 많습니다. baseUrl, paths옵션을 이용해서 절대 경로로 사용할 수 있도록 구성해보세요.
There was a problem hiding this comment.
dist 하위의 빌드 파일은 커밋할 필요 없습니다. .gitignore에 해당 디렉토리를 추가해주세요.
|
@Jerang2 target branch 가 잘못된 것 같네요. 개인 브랜치로 변경해주세요. |
기본
개발 환경 설정
심화
-> 구현에 또 에러가 생겨서 해결중입니다.. ㅠㅠ