-
Notifications
You must be signed in to change notification settings - Fork 0
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
[feature/store-post-review] 식당 리뷰 생성 API #84
Conversation
- 기존 리뷰 작성 API에서 식당 -> 학식으로 표기
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.
뷰 포인트들 잡아두었습니다!
summary = "식당 리뷰 작성", | ||
summary = "학식 리뷰 작성", | ||
description = """ | ||
식당 리뷰 작성을 진행합니다. <br> | ||
학식 리뷰 작성을 진행합니다. <br> | ||
로그인이 필요한 기능입니다. | ||
""") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", description = "리뷰 등록 성공"), | ||
@ApiResponse(responseCode = "200", description = "학식 리뷰 등록 성공"), |
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.
@dldmsql
식당 -> 학식으로 변경했습니다!!
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.
엇!! 감사합니다
@AfterEach | ||
void tearDown() { | ||
reviewMarkRepository.deleteAllInBatch(); | ||
reviewRepository.deleteAllInBatch(); | ||
mealRepository.deleteAllInBatch(); | ||
storeRepository.deleteAllInBatch(); | ||
restaurantRepository.deleteAllInBatch(); | ||
userRepository.deleteAllInBatch(); | ||
universityRepository.deleteAllInBatch(); |
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.
@dldmsql 이 부분 삭제 순서가 엄청 중요하더라구요...!
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.
ㅎㅎ.. 맞아요 관계가 많다보니 ㅠ
// (1) restaurant 객체 조회 | ||
Store store = | ||
storeRepository | ||
.findById(request.idx()) | ||
.orElseThrow(() -> new ApplicationException(STORE_NOT_FOUND)); | ||
|
||
// (2) 이미지 주소 <> 이미지 객체 치환 | ||
List<Image> imageList = getImageFromString(request.imageList()); | ||
User user = userCommServiceImpl.getUserEntity(userIdx); | ||
|
||
// (3) Entity 생성 ( 사진리뷰인지 분기 처리 ) | ||
Review review = | ||
(request.content() == null && request.grade() == 0) | ||
? Review.builder().images(imageList).store(store).user(user).build() | ||
: Review.builder() | ||
.content(request.content()) | ||
.images(imageList) | ||
.store(store) | ||
.grade(request.grade()) | ||
.user(user) | ||
.build(); | ||
|
||
// (4) 저장 | ||
Review savedReview = reviewCommServiceImpl.save(review); | ||
|
||
store.addGrade(request.grade()); | ||
return savedReview.getIdx(); |
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.
@dldmsql 은비님이 만들어주신 로직... 너무 잘 사용했습니다.
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.
ㅎ.ㅎ 도움이 되었다니 다행이에요
@dldmsql 혹시 은비님이 의도하신 Query가 아래의 쿼리가 맞을까요?? (Local 테스트는 통과를 하더라구요!!)
|
Quality Gate passedThe SonarCloud Quality Gate passed, but some issues were introduced. 4 New issues |
이 부분이 이것 저것 만져보았는데 또 되네요... |
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.
수고하셨습니다.!!
@@ -31,13 +34,13 @@ public class ReviewServiceImpl implements ReviewService { | |||
private final RestaurantCommServiceImpl restaurantCommServiceImpl; | |||
private final UserCommServiceImpl userCommServiceImpl; | |||
private final ReviewCommServiceImpl reviewCommServiceImpl; | |||
private final StoreRepository storeRepository; |
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.
여기서 StoreRepository를 통하는 진입점을 별도의 서비스로 만들어서 하는 건 어떨까요?
StoreCommServiceImpl 클래스에서만 repository 접근이 가능하도록!!
일종의 파사드 패턴?처럼 작성하면 확장성에도 좋을 거 같아요.
// (1) restaurant 객체 조회 | ||
Store store = | ||
storeRepository | ||
.findById(request.idx()) | ||
.orElseThrow(() -> new ApplicationException(STORE_NOT_FOUND)); | ||
|
||
// (2) 이미지 주소 <> 이미지 객체 치환 | ||
List<Image> imageList = getImageFromString(request.imageList()); | ||
User user = userCommServiceImpl.getUserEntity(userIdx); | ||
|
||
// (3) Entity 생성 ( 사진리뷰인지 분기 처리 ) | ||
Review review = | ||
(request.content() == null && request.grade() == 0) | ||
? Review.builder().images(imageList).store(store).user(user).build() | ||
: Review.builder() | ||
.content(request.content()) | ||
.images(imageList) | ||
.store(store) | ||
.grade(request.grade()) | ||
.user(user) | ||
.build(); | ||
|
||
// (4) 저장 | ||
Review savedReview = reviewCommServiceImpl.save(review); | ||
|
||
store.addGrade(request.grade()); | ||
return savedReview.getIdx(); |
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.
ㅎ.ㅎ 도움이 되었다니 다행이에요
그쵸ㅠㅠ 이게 로컬에선 이상이 없는데, 액션으로 올라가면 이상해요..ㅠㅠ |
작업 내용
이 머지 리퀘스트에서는 새로운 기능으로 사용자가 주변 식당에 대한 리뷰를 생성할 수 있도록 하는 작업을 수행했습니다.
주요 변경사항은 다음과 같습니다
ReviewController에 createReviewByStore 메서드 추가
ReviewCreateReq DTO 클래스에 새로운 필드 추가
ReviewService 인터페이스 및 구현체에 createReviewByStore 메서드 추가
Store 엔티티에 addGrade 메서드 추가
MyBatis XML 매퍼 파일에 새로운 쿼리 추가
테스트 코드 작성 및 실행
관련 이슈
#83
작업 확인 방법
새로운 API를 확인하려면 아래의 방법을 사용하세요:
createReviewByStore API에 적절한 요청을 전송하여 리뷰를 생성합니다.
생성된 리뷰는 해당 식당의 평점에 반영되어야 합니다.