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

[FEAT] 기업 리뷰 조회 API 구현 #13

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -57,4 +57,13 @@ public ApiResponse<String> 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<List<GetEnterpriseReviewResponse>> getEnterpriseReviews(@PathVariable Long enterpriseId, Authentication authentication) {
List<GetEnterpriseReviewResponse> response = reviewService.getEnterpriseReviews(enterpriseId, authentication.getName());
return ApiResponse.onSuccess(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,4 +64,19 @@ public static GetMyReviewResponse toMyReviewsResponse(Review review, List<TagLis
.tagNumbers(tagNumbers)
.build();
}

public static GetEnterpriseReviewResponse toEnterpriseReviewResponse(Review review, List<TagList> tagList) {
List<Integer> 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();
}
}
11 changes: 11 additions & 0 deletions src/main/java/danpoong/soenter/domain/review/dto/ReviewDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,16 @@ public static class MyReviewsWrapperResponse {
private Integer totalReviewCount;
private List<GetMyReviewResponse> reviews;
}

@Getter
@Builder
public static class GetEnterpriseReviewResponse {
private Long reviewId;
private String userName;
private String content;
private LocalDate createAt;
private Integer tagCount;
private List<Integer> tagNumbers;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,4 +11,5 @@
@Repository
public interface ReviewRepository extends JpaRepository<Review, Long> {
List<Review> findByUser(User user);
List<Review> findByEnterprise(Enterprise enterprise);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<GetEnterpriseReviewResponse> getEnterpriseReviews(Long enterpriseId, String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,4 +125,19 @@ public String deleteReview(Long reviewId, String userId) {
reviewRepository.delete(review); // 리뷰 삭제
return "성공!";
}

@Transactional(readOnly = true)
public List<GetEnterpriseReviewResponse> getEnterpriseReviews(Long enterpriseId, String userId) {
User user = userRepository.findById(Long.valueOf(userId))
.orElseThrow(() -> new RuntimeException("존재하지 않는 사용자입니다."));

Enterprise enterprise = enterpriseRepository.findById(enterpriseId)
.orElseThrow(() -> new RuntimeException("존재하지 않는 기업입니다."));

List<Review> reviews = reviewRepository.findByEnterprise(enterprise);

return reviews.stream()
.map(review -> ReviewConverter.toEnterpriseReviewResponse(review, tagListRepository.findByReview(review)))
.collect(Collectors.toList());
}
}
Loading