Skip to content

Commit

Permalink
#11 [Fix] 리뷰 DTO 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 15, 2022
1 parent e3f7e2d commit 24efe68
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mpnp.baechelin.review.domain.Review;
import com.mpnp.baechelin.store.domain.Store;
import com.mpnp.baechelin.user.domain.User;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -24,8 +25,11 @@ public class ReviewMainResponseDto {
private double point; //별점
private List<ReviewImageResponseDto> reviewImageUrlList; //리뷰 이미지 사진
private List<ReviewResponseDto.TagResponseDto> tagList;
public ReviewMainResponseDto(Review review) {
// this.storeId = store.getId();
public ReviewMainResponseDto(Review review, Store store, User user) {
this.storeId = store.getId();
this.userId = user.getId();
this.storeName = store.getName();
this.userName = user.getName();
this.content = review.getContent();
this.point = review.getPoint();
this.reviewImageUrlList = review.getReviewImageList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ public ReviewQueryRepository(JPAQueryFactory queryFactory) {
}

public List<Review> findRecentReviews(BigDecimal lat,
BigDecimal lng,
int limit) {
BigDecimal[] location = QuerydslLocation.getRange(lat, lng, 20);
BooleanBuilder builder = QuerydslLocation.locationBuilder(location[0], location[1], location[2], location[3]);
BigDecimal lng,
int limit) {
BooleanBuilder builder = new BooleanBuilder();
if (lat != null && lng != null) {
BigDecimal[] location = QuerydslLocation.getRange(lat, lng, 20);
builder = QuerydslLocation.locationBuilder(location[0], location[1], location[2], location[3]);
}
// 위도 경도에 해당하는 가게를 찾음 -> 해당 댓글을 다 가져옴 -> 내림차순 정렬 -> limit
// TODO 쿼리문 개선하기
return queryFactory.selectFrom(review)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Slf4j
Expand Down Expand Up @@ -77,21 +76,20 @@ public List<ReviewResponseDto> getReview(int storeId) {
}

public void reviewUpdate(ReviewRequestDto reviewRequestDto, String socialId, int reviewId) throws IOException {
int storeId = reviewRequestDto.getStoreId();
User user = userRepository.findBySocialId(socialId);
Store store = storeRepository.findById(storeId).orElseThrow(() -> new IllegalArgumentException("해당하는 업장이 존재하지 않습니다."));
int storeId = reviewRequestDto.getStoreId();
User user = userRepository.findBySocialId(socialId);
Store store = storeRepository.findById(storeId).orElseThrow(() -> new IllegalArgumentException("해당하는 업장이 존재하지 않습니다."));

// 리뷰이미지 변환
List<ReviewImage> reviewImageUrlList = new ArrayList<>();
List<MultipartFile> imageFileList = reviewRequestDto.getImageFile();
List<ReviewImage> reviewImageUrlList = new ArrayList<>();
List<MultipartFile> imageFileList = reviewRequestDto.getImageFile();
// awsS3Manager.deleteFile();

for (MultipartFile reviewImage : imageFileList) {
reviewImageUrlList.add(ReviewImage.builder().reviewImageUrl(awsS3Manager.uploadFile(reviewImage)).build());
}


Review review = reviewRepository.findById(reviewId).orElseThrow(() -> new IllegalArgumentException("해당하는 리뷰가 없습니다."));
Review review = reviewRepository.findById(reviewId).orElseThrow(() -> new IllegalArgumentException("해당하는 리뷰가 없습니다."));
List<String> tagList = reviewRequestDto.getTagList();

review.update(reviewRequestDto);
Expand All @@ -108,7 +106,7 @@ public void reviewUpdate(ReviewRequestDto reviewRequestDto, String socialId, int
public List<ReviewMainResponseDto> getRecentReview(BigDecimal lat, BigDecimal lng, int limit) {
return reviewQueryRepository
.findRecentReviews(lat, lng, limit)
.parallelStream().map(ReviewMainResponseDto::new).collect(Collectors.toList());
.parallelStream().map(review -> new ReviewMainResponseDto(review, review.getStoreId(), review.getUserId())).collect(Collectors.toList());
}

}

0 comments on commit 24efe68

Please sign in to comment.