Skip to content

Commit

Permalink
#11 [Add, Fix] 리뷰 이미지 조회 기능 추가, 오류 수정
Browse files Browse the repository at this point in the history
리뷰 이미지 조회 기능을 수정하였으며, save시 store_id가 null로 표시되는 오류를 수정
  • Loading branch information
JSoi committed Jul 14, 2022
1 parent 5592aa3 commit 154585f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
8 changes: 0 additions & 8 deletions src/main/java/com/mpnp/baechelin/review/domain/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,5 @@ public Review(ReviewRequestDto reviewRequestDto, Store store, User user) throws
this.userId = user;
}

public void setImage(List<ReviewImage> reviewImageList){
this.reviewImageList = reviewImageList;
}
public void addSingleTag(Tag tag){
tag.setReview(this);
this.tagList.add(tag);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public class ReviewImage extends TimeStamped {
@JoinColumn(name = "REVIEW_ID", nullable = false)
private Review reviewId;

public void addReview(Review review, String reviewImageUrl){
this.reviewId = review;
this.reviewImageUrl = reviewImageUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public ReviewResponseDto(Review review) {
this.userId = review.getUserId().getId();
this.point = review.getPoint();
this.content = review.getContent();
this.createdAt = review.getCreatedAt();
this.modifiedAt = review.getModifiedAt();
this.reviewImageUrlList = review.getReviewImageList()
.stream().map(ReviewImageResponseDto::new).collect(Collectors.toList());
this.tagList = review.getTagList().stream().map(TagResponseDto::new).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mpnp.baechelin.review.repository;

import com.mpnp.baechelin.review.domain.ReviewImage;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ReviewImageRepository extends JpaRepository<ReviewImage, Integer> {
}
23 changes: 15 additions & 8 deletions src/main/java/com/mpnp/baechelin/review/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mpnp.baechelin.review.domain.ReviewImage;
import com.mpnp.baechelin.review.dto.ReviewRequestDto;
import com.mpnp.baechelin.review.dto.ReviewResponseDto;
import com.mpnp.baechelin.review.repository.ReviewImageRepository;
import com.mpnp.baechelin.review.repository.ReviewRepository;
import com.mpnp.baechelin.store.domain.Store;
import com.mpnp.baechelin.store.repository.StoreRepository;
Expand Down Expand Up @@ -32,6 +33,7 @@ public class ReviewService {
private final UserRepository userRepository;
private final StoreRepository storeRepository;
private final TagRepository tagRepository;
private final ReviewImageRepository reviewImageRepository;
private final AwsS3Manager awsS3Manager;

/**
Expand All @@ -43,18 +45,23 @@ public void review(ReviewRequestDto reviewRequestDto, String socialId) throws IO
Store store = storeRepository.findById(storeId).orElseThrow(() -> new IllegalArgumentException("해당하는 업장이 존재하지 않습니다."));
User user = userRepository.findBySocialId(socialId);

Review review = new Review(reviewRequestDto, store, user);

List<Tag> tagList = new ArrayList<>();
for (String s : reviewRequestDto.getTagList()) {
tagList.add(new Tag(s, review));
} // 태그 -> 엔티티 변환

List<ReviewImage> reviewImageUrlList = new ArrayList<>();
for (MultipartFile reviewImage : reviewRequestDto.getImageFile()) {
reviewImageUrlList.add(ReviewImage.builder().reviewImageUrl(awsS3Manager.uploadFile(reviewImage)).build());
} // 리뷰이미지 변환
reviewImageUrlList.add(ReviewImage.builder().reviewId(review).reviewImageUrl(awsS3Manager.uploadFile(reviewImage)).build());
} // 리뷰이미지 -> url -> 엔티티 변환

tagRepository.saveAll(tagList);
reviewImageRepository.saveAll(reviewImageUrlList);

Review review = new Review(reviewRequestDto, store, user);
for (String s : reviewRequestDto.getTagList()) {
Tag tag = new Tag(s, review);
review.addSingleTag(tag);
tagRepository.save(tag);
}
reviewRepository.save(review);

storeRepository.save(store.updatePointAvg(reviewRequestDto.getPoint()));
}

Expand Down

0 comments on commit 154585f

Please sign in to comment.