diff --git a/src/main/java/danpoong/soenter/domain/review/controller/ReviewController.java b/src/main/java/danpoong/soenter/domain/review/controller/ReviewController.java index bdd028d..c7565cc 100644 --- a/src/main/java/danpoong/soenter/domain/review/controller/ReviewController.java +++ b/src/main/java/danpoong/soenter/domain/review/controller/ReviewController.java @@ -1,8 +1,8 @@ package danpoong.soenter.domain.review.controller; import danpoong.soenter.base.ApiResponse; +import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.GetEnterpriseReviewResponse; import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.MyReviewsWrapperResponse; -import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.GetMyReviewResponse; import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.PostReviewResponse; import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewRequest.PostReviewRequest; import danpoong.soenter.domain.review.service.ReviewService; @@ -57,4 +57,13 @@ public ApiResponse deleteReview(@PathVariable Long reviewId, Authenticat reviewService.deleteReview(reviewId, authentication.getName()); return ApiResponse.onSuccess(null); } + + @GetMapping("/{enterpriseId}/enterprises") + @Operation(summary = "기업 리뷰 조회 API", description = "특정 기업에 대한 모든 리뷰를 조회합니다.") + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공") + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "잘못된 요청입니다.") + public ApiResponse> getEnterpriseReviews(@PathVariable Long enterpriseId, Authentication authentication) { + List response = reviewService.getEnterpriseReviews(enterpriseId, authentication.getName()); + return ApiResponse.onSuccess(response); + } } \ No newline at end of file diff --git a/src/main/java/danpoong/soenter/domain/review/converter/ReviewConverter.java b/src/main/java/danpoong/soenter/domain/review/converter/ReviewConverter.java index ddb3ea1..782c178 100644 --- a/src/main/java/danpoong/soenter/domain/review/converter/ReviewConverter.java +++ b/src/main/java/danpoong/soenter/domain/review/converter/ReviewConverter.java @@ -2,6 +2,7 @@ import danpoong.soenter.domain.enterprise.entity.Enterprise; import danpoong.soenter.domain.enterprise.entity.Visit; +import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.GetEnterpriseReviewResponse; import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.GetMyReviewResponse; import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.PostReviewResponse; import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewRequest.PostReviewRequest; @@ -63,4 +64,19 @@ public static GetMyReviewResponse toMyReviewsResponse(Review review, List tagList) { + List tagNumbers = tagList.stream() + .map(TagList::getTagNum) + .collect(Collectors.toList()); + + return GetEnterpriseReviewResponse.builder() + .reviewId(review.getReviewId()) + .userName(review.getUser().getName()) + .content(review.getContent()) + .createAt(review.getCreateAt()) + .tagCount(tagList.size()) + .tagNumbers(tagNumbers) + .build(); + } } diff --git a/src/main/java/danpoong/soenter/domain/review/dto/ReviewDTO.java b/src/main/java/danpoong/soenter/domain/review/dto/ReviewDTO.java index 68d1766..23b5002 100644 --- a/src/main/java/danpoong/soenter/domain/review/dto/ReviewDTO.java +++ b/src/main/java/danpoong/soenter/domain/review/dto/ReviewDTO.java @@ -56,5 +56,16 @@ public static class MyReviewsWrapperResponse { private Integer totalReviewCount; private List reviews; } + + @Getter + @Builder + public static class GetEnterpriseReviewResponse { + private Long reviewId; + private String userName; + private String content; + private LocalDate createAt; + private Integer tagCount; + private List tagNumbers; + } } } diff --git a/src/main/java/danpoong/soenter/domain/review/repository/ReviewRepository.java b/src/main/java/danpoong/soenter/domain/review/repository/ReviewRepository.java index fb4cc88..00f906b 100644 --- a/src/main/java/danpoong/soenter/domain/review/repository/ReviewRepository.java +++ b/src/main/java/danpoong/soenter/domain/review/repository/ReviewRepository.java @@ -1,5 +1,6 @@ package danpoong.soenter.domain.review.repository; +import danpoong.soenter.domain.enterprise.entity.Enterprise; import danpoong.soenter.domain.review.entity.Review; import danpoong.soenter.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; @@ -10,4 +11,5 @@ @Repository public interface ReviewRepository extends JpaRepository { List findByUser(User user); + List findByEnterprise(Enterprise enterprise); } \ No newline at end of file diff --git a/src/main/java/danpoong/soenter/domain/review/service/ReviewService.java b/src/main/java/danpoong/soenter/domain/review/service/ReviewService.java index d58200c..0ad5ee9 100644 --- a/src/main/java/danpoong/soenter/domain/review/service/ReviewService.java +++ b/src/main/java/danpoong/soenter/domain/review/service/ReviewService.java @@ -1,4 +1,5 @@ package danpoong.soenter.domain.review.service; +import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.GetEnterpriseReviewResponse; import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.MyReviewsWrapperResponse; import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewRequest.PostReviewRequest; import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.PostReviewResponse; @@ -10,4 +11,5 @@ public interface ReviewService { public MyReviewsWrapperResponse getMyReviews(String userId); public PostReviewResponse updateReview(Long reviewId, PostReviewRequest postReviewRequest, String userId); String deleteReview(Long reviewId, String userId); + List getEnterpriseReviews(Long enterpriseId, String userId); } diff --git a/src/main/java/danpoong/soenter/domain/review/service/ReviewServiceImpl.java b/src/main/java/danpoong/soenter/domain/review/service/ReviewServiceImpl.java index 967253e..e264516 100644 --- a/src/main/java/danpoong/soenter/domain/review/service/ReviewServiceImpl.java +++ b/src/main/java/danpoong/soenter/domain/review/service/ReviewServiceImpl.java @@ -5,6 +5,7 @@ import danpoong.soenter.domain.enterprise.repository.EnterpriseRepository; import danpoong.soenter.domain.enterprise.repository.VisitRepository; import danpoong.soenter.domain.review.converter.ReviewConverter; +import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.GetEnterpriseReviewResponse; import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.MyReviewsWrapperResponse; import danpoong.soenter.domain.review.dto.ReviewDTO.ReviewResponse.GetMyReviewResponse; import danpoong.soenter.domain.review.entity.Review; @@ -124,4 +125,19 @@ public String deleteReview(Long reviewId, String userId) { reviewRepository.delete(review); // 리뷰 삭제 return "성공!"; } + + @Transactional(readOnly = true) + public List getEnterpriseReviews(Long enterpriseId, String userId) { + User user = userRepository.findById(Long.valueOf(userId)) + .orElseThrow(() -> new RuntimeException("존재하지 않는 사용자입니다.")); + + Enterprise enterprise = enterpriseRepository.findById(enterpriseId) + .orElseThrow(() -> new RuntimeException("존재하지 않는 기업입니다.")); + + List reviews = reviewRepository.findByEnterprise(enterprise); + + return reviews.stream() + .map(review -> ReviewConverter.toEnterpriseReviewResponse(review, tagListRepository.findByReview(review))) + .collect(Collectors.toList()); + } }