Skip to content
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

Merged
merged 11 commits into from
Jan 28, 2024

Conversation

Qbeom0925
Copy link
Member

작업 내용

이 머지 리퀘스트에서는 새로운 기능으로 사용자가 주변 식당에 대한 리뷰를 생성할 수 있도록 하는 작업을 수행했습니다.
주요 변경사항은 다음과 같습니다

ReviewController에 createReviewByStore 메서드 추가
ReviewCreateReq DTO 클래스에 새로운 필드 추가
ReviewService 인터페이스 및 구현체에 createReviewByStore 메서드 추가
Store 엔티티에 addGrade 메서드 추가
MyBatis XML 매퍼 파일에 새로운 쿼리 추가
테스트 코드 작성 및 실행

관련 이슈

#83

작업 확인 방법

새로운 API를 확인하려면 아래의 방법을 사용하세요:

createReviewByStore API에 적절한 요청을 전송하여 리뷰를 생성합니다.
생성된 리뷰는 해당 식당의 평점에 반영되어야 합니다.

@Qbeom0925 Qbeom0925 added Feature 기능 개발 Test 테스트 관련 labels Jan 27, 2024
@Qbeom0925 Qbeom0925 self-assigned this Jan 27, 2024
Copy link
Member Author

@Qbeom0925 Qbeom0925 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 -44 to +50
summary = "식당 리뷰 작성",
summary = "학식 리뷰 작성",
description = """
식당 리뷰 작성을 진행합니다. <br>
학식 리뷰 작성을 진행합니다. <br>
로그인이 필요한 기능입니다.
""")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "리뷰 등록 성공"),
@ApiResponse(responseCode = "200", description = "학식 리뷰 등록 성공"),
Copy link
Member Author

Choose a reason for hiding this comment

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

@dldmsql
식당 -> 학식으로 변경했습니다!!

Copy link
Member

Choose a reason for hiding this comment

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

엇!! 감사합니다

Comment on lines 76 to 84
@AfterEach
void tearDown() {
reviewMarkRepository.deleteAllInBatch();
reviewRepository.deleteAllInBatch();
mealRepository.deleteAllInBatch();
storeRepository.deleteAllInBatch();
restaurantRepository.deleteAllInBatch();
userRepository.deleteAllInBatch();
universityRepository.deleteAllInBatch();
Copy link
Member Author

Choose a reason for hiding this comment

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

@dldmsql 이 부분 삭제 순서가 엄청 중요하더라구요...!

Copy link
Member

Choose a reason for hiding this comment

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

ㅎㅎ.. 맞아요 관계가 많다보니 ㅠ

Comment on lines +184 to +210
// (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();
Copy link
Member Author

Choose a reason for hiding this comment

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

@dldmsql 은비님이 만들어주신 로직... 너무 잘 사용했습니다.

Copy link
Member

Choose a reason for hiding this comment

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

ㅎ.ㅎ 도움이 되었다니 다행이에요

@Qbeom0925
Copy link
Member Author

@dldmsql
은비님... "오늘 먹었어요. 리뷰 조회" 가 에러가 계속 발생하더라구요..!

혹시 은비님이 의도하신 Query가 아래의 쿼리가 맞을까요?? (Local 테스트는 통과를 하더라구요!!)
이전에도 같은 문제가 있었는데 이번에야말로 잡겠습니다.

   SELECT r.idx as 'reviewIdx',
               r.content as 'content'
        FROM reviews r
               JOIN restaurant r2 ON r.restaurant_idx = r2.idx AND r2.idx = 15
        WHERE DATE(r.created_at) = DATE('2024-01-27')
          AND r.is_today_review = 1
          OR r.idx = (
          SELECT rm.review_idx
          FROM review_marks rm
          JOIN reviews r ON rm.review_idx = r.idx
          WHERE DATE(r.created_at) = DATE('2024-01-27')
          GROUP BY rm.review_idx
          ORDER BY COUNT(rm.review_idx) DESC
          LIMIT 1
          );

Copy link

sonarcloud bot commented Jan 28, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

4 New issues
0 Security Hotspots
84.6% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@Qbeom0925
Copy link
Member Author

Qbeom0925 commented Jan 28, 2024

@dldmsql 은비님... "오늘 먹었어요. 리뷰 조회" 가 되어서 발생했어요..!

혹시 은비님이 의도하신 Query가 아래의 쿼리가 맞을까요?? (Local 테스트는 통과를 하더라구요!!) 이전에도 같은 문제가 있었는데 이번에야말로 잡겠습니다.

   SELECT r.idx as 'reviewIdx',
               r.content as 'content'
        FROM reviews r
               JOIN restaurant r2 ON r.restaurant_idx = r2.idx AND r2.idx = 15
        WHERE DATE(r.created_at) = DATE('2024-01-27')
          AND r.is_today_review = 1
          OR r.idx = (
          SELECT rm.review_idx
          FROM review_marks rm
          JOIN reviews r ON rm.review_idx = r.idx
          WHERE DATE(r.created_at) = DATE('2024-01-27')
          GROUP BY rm.review_idx
          ORDER BY COUNT(rm.review_idx) DESC
          LIMIT 1
          );

이 부분이 이것 저것 만져보았는데 또 되네요...
이렇게 간헐적으로 발생하는 것으로 보아 뭔가 JPA로 저장하고 mybatis로 조회를 작업할때 hibernate가 영속성에 넣어둔 정보를 mybatis가 못읽는 것이 아닐까 싶습니다.
크게 변경한 부분은 없는데 일단은 피알은 반영해두고 다음에 같은 문제가 발생할 경우, EntityManger로 클리어 작업 이후에 테스트 해보고 다시 한번 해결해보도록 하겠습니다.

@Qbeom0925 Qbeom0925 merged commit fbc44c8 into develop Jan 28, 2024
2 checks passed
Copy link
Member

@dldmsql dldmsql left a 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;
Copy link
Member

Choose a reason for hiding this comment

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

여기서 StoreRepository를 통하는 진입점을 별도의 서비스로 만들어서 하는 건 어떨까요?
StoreCommServiceImpl 클래스에서만 repository 접근이 가능하도록!!
일종의 파사드 패턴?처럼 작성하면 확장성에도 좋을 거 같아요.

Comment on lines +184 to +210
// (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();
Copy link
Member

Choose a reason for hiding this comment

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

ㅎ.ㅎ 도움이 되었다니 다행이에요

@dldmsql
Copy link
Member

dldmsql commented Jan 28, 2024

@dldmsql 은비님... "오늘 먹었어요. 리뷰 조회" 가 되어서 발생했어요..!
혹시 은비님이 의도하신 Query가 아래의 쿼리가 맞을까요?? (Local 테스트는 통과를 하더라구요!!) 이전에도 같은 문제가 있었는데 이번에야말로 잡겠습니다.

   SELECT r.idx as 'reviewIdx',
               r.content as 'content'
        FROM reviews r
               JOIN restaurant r2 ON r.restaurant_idx = r2.idx AND r2.idx = 15
        WHERE DATE(r.created_at) = DATE('2024-01-27')
          AND r.is_today_review = 1
          OR r.idx = (
          SELECT rm.review_idx
          FROM review_marks rm
          JOIN reviews r ON rm.review_idx = r.idx
          WHERE DATE(r.created_at) = DATE('2024-01-27')
          GROUP BY rm.review_idx
          ORDER BY COUNT(rm.review_idx) DESC
          LIMIT 1
          );

이 부분이 이것 저것 만져보았는데 또 되네요... 이렇게 간헐적으로 발생하는 것으로 보아 뭔가 JPA로 저장하고 mybatis로 조회를 작업할때 hibernate가 영속성에 넣어둔 정보를 mybatis가 못읽는 것이 아닐까 싶습니다. 크게 변경한 부분은 없는데 일단은 피알은 반영해두고 다음에 같은 문제가 발생할 경우, EntityManger로 클리어 작업 이후에 테스트 해보고 다시 한번 해결해보도록 하겠습니다.

그쵸ㅠㅠ 이게 로컬에선 이상이 없는데, 액션으로 올라가면 이상해요..ㅠㅠ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature 기능 개발 Test 테스트 관련
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants