Skip to content

Commit

Permalink
Merge pull request #13 from 9oormthon-univ/feature/#11
Browse files Browse the repository at this point in the history
[FEAT] 기업 리뷰 조회 API 구현
  • Loading branch information
haeun1107 authored Nov 18, 2024
2 parents 1fab671 + a9dfee0 commit b2a865d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
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());
}
}

0 comments on commit b2a865d

Please sign in to comment.