-
Notifications
You must be signed in to change notification settings - Fork 22
[이태빈] Sprint10 #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[이태빈] Sprint10 #40
The head ref may contain hidden characters: "express-\uC774\uD0DC\uBE48-sprint10"
Conversation
reach0908
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다.
트랜잭션이 데이터베이스에서 필요한 이유야 ACID 원칙, 잠금 수준과 같은 기본적인 부분들에 대하여 더 공부해보고 정말 트랜잭션이 필요한 행위인가를 사용자 플로우 관점에서 고민하는 방법을 공부하면 좋을 것 같습니다.
| const productsWithImages = products.map((product) => ({ | ||
| ...product, | ||
| productImages: undefined, | ||
| images: product.productImages.map((img) => `${baseUrl}/${img.imageUrl}`), | ||
| })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1]
저는 이 로직도 서비스 로직에 들어가야한다고 생각합니다.
productService.getProdutsWithImages 와 같은 함수가 있어야하고 내부적으로 다시 getProducts를 사용하는 방향으로 개선해보는 것은 어떨까요?
| const [articles, totalCount] = await articleRepository.findAll(query); | ||
|
|
||
| if (!articles || articles.length === 0) { | ||
| const error = new Error("게시글이 없습니다."); | ||
| error.code = 404; | ||
|
|
||
| throw error; | ||
| } | ||
|
|
||
| const articletWithLikeCount = await Promise.all( | ||
| articles.map(async (article) => { | ||
| const likeCount = await articleRepository.findArticleLikeCountById( | ||
| article.id | ||
| ); | ||
|
|
||
| return { ...article, likeCount }; | ||
| }) | ||
| ); | ||
|
|
||
| return [articletWithLikeCount, totalCount]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P0]
대표적인 데이터베이스의 N+1 문제가 발생하는 것 같습니다.
SQL 쿼리를 통해 해결하는 방법과 좋아요에서 트랜잭션 처리와함께 항상 article 문서에도 likeCount 등을 업데이트해주는 방법이 있을 수 있습니다.
항상 함께 다닌다면 후자도 괜찮을 것 같아요
| // 상품 상세조회 | ||
| const getProduct = async (userId, productId) => { | ||
| return await prisma.$transaction(async (tx) => { | ||
| const [product, images, likeCount, isLiked] = | ||
| await productRepository.findByIdWithTx(tx, userId, productId); | ||
|
|
||
| if (!product) { | ||
| const error = new Error("존재하지 않는 상품입니다."); | ||
| error.code = 404; | ||
|
|
||
| throw error; | ||
| } | ||
|
|
||
| const productTags = await productRepository.findProductTagByIdWithTx( | ||
| tx, | ||
| productId | ||
| ); | ||
|
|
||
| const tags = productTags.map((tag) => tag.tag.name); | ||
| const imageUrls = images.map((image) => image.imageUrl); | ||
|
|
||
| return { | ||
| ...product, | ||
| tags, | ||
| images: imageUrls, | ||
| likeCount, | ||
| isLiked: !!isLiked, | ||
| }; | ||
| }); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P0]
조회 작업에 꼭 트랜잭션이 필요한 이유가 있을지 고민해보면 좋을 것 같습니다.
| const { tags } = body; | ||
|
|
||
| return await prisma.$transaction(async (tx) => { | ||
| const newProduct = await productRepository.createWithTx(tx, userId, body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const newProduct = await productRepository.createWithTx({userId, body}, tx);
위와 같이 관리하면 추후 create를 위한 Input DTO와 tx 변수들의 타입을 쉽게 관리할 수 있습니다. 변수 순서를 헷갈리거나 하는 부분도 해소할 수 잇을 것 같아요
1691c8c
into
codeit-sprint-fullstack:express-이태빈
🐼 판다마켓 : https://been-panda.vercel.app
요구사항
기본 요구사항
공통
프론트엔드 구현 요구사항
중고마켓 페이지
상품 등록하기 페이지
백엔드 구현 요구사항
상품 등록
multer미들웨어를 사용하여 이미지 업로드 API를 구현해 주세요.상품 상세
좋아요 기능
$transaction을 사용해 주세요.$transaction을 사용해 주세요.isLiked필드를 응답 객체에 포함시켜 반환해 주세요.에러 처리
라우트 중복 제거
/users에 대한get및post요청)를app.route()로 통합해 중복을 제거합니다.express.Router()를 활용하여 중고마켓/자유게시판 관련 라우트를 별도의 모듈로 구분합니다.인증
id,email,nickname,image,encryptedPassword,createdAt,updatedAt필드를 가집니다.email,nickname,password를 입력하여 회원가입을 진행합니다.password는 해싱해 저장합니다.상품 기능 인가
게시글 기능 인가
댓글 기능 인가
심화 요구사항
상태코드 (웹 API 관련)
인증
OAuth를 활용한 인증
프로젝트 구조 변경
(생략 가능) 자유게시판 게시물 등록
multer미들웨어를 사용하여 이미지 업로드 API를 구현해 주세요.주요 변경사항
멘토에게
스크린샷
로그인
PC






회원가입
PC





상품 상세 페이지 + 수정 페이지
PC


