Skip to content

Commit

Permalink
Merge pull request #63 from AndLetgo/feature/61-find-review
Browse files Browse the repository at this point in the history
✨ [FEAT]: Review 조회 API 개발
  • Loading branch information
gyehwan24 authored Jan 10, 2024
2 parents 71a4814 + a363ef7 commit 656b01f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private Double calculateRate(Exhibition exhibition) {
return sum / ratingList.size();
}

private Rating validateRatingByUserIdAndExhibitionId(Long userId, Long exhibitionId) {
public Rating validateRatingByUserIdAndExhibitionId(Long userId, Long exhibitionId) {
Optional<Rating> rating = ratingRepository.findByUserIdAndExhibitionId(userId, exhibitionId);
DefaultAssert.isTrue(rating.isPresent(), "해당하는 별점이 없습니다.");
return rating.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@

import depth.jeonsilog.domain.alarm.application.AlarmService;
import depth.jeonsilog.domain.common.Status;
import depth.jeonsilog.domain.exhibition.application.ExhibitionService;
import depth.jeonsilog.domain.exhibition.converter.ExhibitionConverter;
import depth.jeonsilog.domain.exhibition.domain.Exhibition;
import depth.jeonsilog.domain.exhibition.domain.repository.ExhibitionRepository;
import depth.jeonsilog.domain.exhibition.dto.ExhibitionResponseDto;
import depth.jeonsilog.domain.place.converter.PlaceConverter;
import depth.jeonsilog.domain.place.domain.Place;
import depth.jeonsilog.domain.place.dto.PlaceResponseDto;
import depth.jeonsilog.domain.rating.application.RatingService;
import depth.jeonsilog.domain.rating.domain.Rating;
import depth.jeonsilog.domain.rating.domain.repository.RatingRepository;
import depth.jeonsilog.domain.reply.domain.Reply;
import depth.jeonsilog.domain.reply.domain.repository.ReplyRepository;
Expand All @@ -14,8 +22,10 @@
import depth.jeonsilog.domain.review.dto.ReviewRequestDto;
import depth.jeonsilog.domain.review.dto.ReviewResponseDto;
import depth.jeonsilog.domain.user.application.UserService;
import depth.jeonsilog.domain.user.converter.UserConverter;
import depth.jeonsilog.domain.user.domain.Role;
import depth.jeonsilog.domain.user.domain.User;
import depth.jeonsilog.domain.user.dto.UserResponseDto;
import depth.jeonsilog.global.DefaultAssert;
import depth.jeonsilog.global.config.security.token.UserPrincipal;
import depth.jeonsilog.global.payload.ApiResponse;
Expand Down Expand Up @@ -43,7 +53,9 @@ public class ReviewService {
private final ReplyRepository replyRepository;

private final UserService userService;
private final ExhibitionService exhibitionService;
private final AlarmService alarmService;
private final RatingService ratingService;

// 감상평 작성
@Transactional
Expand Down Expand Up @@ -156,9 +168,26 @@ public ResponseEntity<?> checkIsWrite(UserPrincipal userPrincipal, Long exhibiti
return ResponseEntity.ok(apiResponse);
}

// Description : Review Id로 review 조회
public ResponseEntity<?> getReview(Long reviewId) {

Review review = validateReviewById(reviewId);
User user = review.getUser();
Exhibition exhibition = review.getExhibition();
Rating rating = ratingService.validateRatingByUserIdAndExhibitionId(user.getId(), exhibition.getId());
Double rate = rating.getRate();

UserResponseDto.SearchUsersRes userRes = UserConverter.toSearchUserRes(user);
ReviewResponseDto.ReviewListRes reviewRes = ReviewConverter.toReviewListRes(review, userRes, rate);

ApiResponse apiResponse = ApiResponse.toApiResponse(reviewRes);
return ResponseEntity.ok(apiResponse);
}

public Review validateReviewById(Long reviewId) {
Optional<Review> review = reviewRepository.findById(reviewId);
DefaultAssert.isTrue(review.isPresent(), "감상평 정보가 올바르지 않습니다.");
return review.get();
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package depth.jeonsilog.domain.review.converter;

import depth.jeonsilog.domain.exhibition.domain.Exhibition;
import depth.jeonsilog.domain.exhibition.dto.ExhibitionResponseDto;
import depth.jeonsilog.domain.rating.domain.Rating;
import depth.jeonsilog.domain.rating.domain.repository.RatingRepository;
import depth.jeonsilog.domain.review.domain.Review;
import depth.jeonsilog.domain.review.dto.ReviewResponseDto;
import depth.jeonsilog.domain.user.domain.User;
import depth.jeonsilog.domain.user.dto.UserResponseDto;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -74,4 +76,17 @@ public static ReviewResponseDto.ReviewListResList toReviewListResList(boolean ha
.data(reviewListRes)
.build();
}

public static ReviewResponseDto.ReviewListRes toReviewListRes(Review review, UserResponseDto.SearchUsersRes userRes, Double rate) {
return ReviewResponseDto.ReviewListRes.builder()
.reviewId(review.getId())
.userId(userRes.getUserId())
.imgUrl(userRes.getProfileImgUrl())
.nickname(userRes.getNickname())
.contents(review.getContents())
.rate(rate)
.numReply(review.getNumReply())
.createdDate(review.getCreatedDate())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package depth.jeonsilog.domain.review.dto;

import depth.jeonsilog.domain.exhibition.dto.ExhibitionResponseDto;
import depth.jeonsilog.domain.user.dto.UserResponseDto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -91,4 +93,5 @@ public static class CheckIsWriteRes {
@Schema(type = "boolean", example = "true", description = "해당 전시회 - 감상평 작성 여부를 출력합니다.")
private Boolean isWrite;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,16 @@ public ResponseEntity<?> getUserReviewList(
) {
return reviewService.checkIsWrite(userPrincipal, exhibitionId);
}

@Operation(summary = "감상평 조회", description = "감상평 id를 이용하여 감상평을 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "조회 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ReviewResponseDto.ReviewListRes.class))}),
@ApiResponse(responseCode = "400", description = "조회 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@GetMapping("/review/{reviewId}")
public ResponseEntity<?> getReview(
@Parameter(description = "감상평 id를 입력해주세요.", required = true) @PathVariable(value = "reviewId") Long reviewId
) {
return reviewService.getReview(reviewId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,13 @@ public static UserResponseDto.IsOpenRes toIsOpenRes(User user) {
.isOpen(user.getIsOpen())
.build();
}

// Review에서 사용
public static UserResponseDto.SearchUsersRes toSearchUserRes (User user) {
return UserResponseDto.SearchUsersRes.builder()
.userId(user.getId())
.nickname(user.getNickname())
.profileImgUrl(user.getProfileImg())
.build();
}
}

0 comments on commit 656b01f

Please sign in to comment.