Skip to content

Commit

Permalink
[#56] feat: 여행지 리뷰 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mmihye committed Jun 10, 2024
1 parent e8dba59 commit 9dd3c27
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ApiResponse<PlaceDetailRes> getPlaceDetail(@AuthenticationPrincipal Princ
@PostMapping("/review/{placeId}")
public ApiResponse<?> createReivew(@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestPart(required = false) List<MultipartFile> images,
@RequestBody PlaceReviewReq placeReviewReq,
@RequestPart PlaceReviewReq placeReviewReq,
@PathVariable Long placeId) {
images = (images == null) ? new ArrayList<>() : images;
placeService.createReview(principalDetails.getMember(), images,placeReviewReq, placeId);
Expand Down Expand Up @@ -82,13 +82,11 @@ public ApiResponse<MyReview> getPlaceMyReview(
@PatchMapping("/review/my/{reviewId}")
public ApiResponse<?> updatePlaceMyReview(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestBody UpdateReviewDto updateReviewDto,
@RequestParam(required = false) List<String> deleteImages,
@RequestParam(required = false) List<MultipartFile> addImages,
@RequestPart(required = false) UpdateReviewDto updateReviewDto,
@RequestPart(required = false) List<MultipartFile> addImages,
@PathVariable Long reviewId) {
deleteImages = (deleteImages == null) ? new ArrayList<>() : deleteImages;
addImages = (addImages == null) ? new ArrayList<>() : addImages;
placeService.updateMyPlaceReview(principalDetails.getMember(),updateReviewDto,deleteImages,addImages,reviewId);
placeService.updateMyPlaceReview(principalDetails.getMember(),updateReviewDto,addImages,reviewId);
return ApiResponse.success(Success.UPDATE_MY_PLACE_REVIEW_SUCCESS);
}
@GetMapping("/search/list")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package Journey.Together.domain.place.dto.request;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.annotation.Nullable;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

public record UpdateReviewDto(
@Nullable
@JsonFormat(pattern = "yyyy-MM-dd")
Float grade,
@Nullable
LocalDate date,
@Nullable
String content
String content,
@Nullable
List<String> deleteImgUrls

) {
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package Journey.Together.domain.place.repository;

import Journey.Together.domain.member.entity.Member;
import Journey.Together.domain.place.dto.request.UpdateReviewDto;
import Journey.Together.domain.place.dto.response.PlaceRes;
import Journey.Together.domain.place.dto.response.SearchPlace;
import Journey.Together.domain.place.dto.response.SearchPlaceRes;

import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

public interface PlaceRepositoryCustom {
SearchPlace search(String category, String query, List<Long> disabilityType, List<Long> detailFilter, String areacode, String sigungucode, String arrange, Pageable pageable,
Double minX, Double maxX, Double minY, Double maxY);

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package Journey.Together.domain.place.repository;

import Journey.Together.domain.bookbark.entity.QPlaceBookmark;
import Journey.Together.domain.member.entity.Member;
import Journey.Together.domain.member.repository.MemberRepository;
import Journey.Together.domain.place.dto.request.UpdateReviewDto;
import Journey.Together.domain.place.dto.response.PlaceRes;
import Journey.Together.domain.place.dto.response.SearchPlace;
import Journey.Together.domain.place.dto.response.SearchPlaceRes;
Expand All @@ -24,6 +26,7 @@
import jakarta.persistence.EntityManager;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -73,6 +76,7 @@ public SearchPlace search(String category, String query, List<Long> disabilityTy

return new SearchPlace(places,total);
}

private BooleanExpression categoryEq(String category) {
List<String> categoryList = new ArrayList<>(Arrays.asList("A01", "A02", "A03", "A04", "B01", "C01"));

Expand Down Expand Up @@ -183,4 +187,5 @@ private OrderSpecifier<?> arg(String arrange) {
return place.createdAt.desc(); // default = 최신순
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public interface PlaceReviewImgRepository extends JpaRepository<PlaceReviewImg,L

void deleteByPlaceReview(PlaceReview placeReview);

void deleteByImgUrl(String imgUrl);


}
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,47 @@ private MyPlaceReviewDto getMyPlaceReview(PlaceReview placeReview ){

}


public UpdateReviewDto updateMyPlaceReview(Member member, UpdateReviewDto updateReviewDto, List<String> deleteImages, List<MultipartFile> addImages, Long reviewId) {
@Transactional
public void updateMyPlaceReview(Member member, UpdateReviewDto updateReviewDto, List<MultipartFile> addImages, Long reviewId) {
PlaceReview placeReview = placeReviewRepository.findById(reviewId).orElseThrow(
() -> new ApplicationException(ErrorCode.NOT_FOUND_PLACE_REVIEW_EXCEPTION));

if(placeReview.getMember() != member){
if(placeReview.getMember().getMemberId() != member.getMemberId()){
throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION);
}

if (addImages != null) {
try {
for(MultipartFile file : addImages) {
String uuid = UUID.randomUUID().toString();
final String imageUrl = s3Client.upload(file, POST_IMAGE_FOLDER_NAME+member.getMemberId(), uuid);
PlaceReviewImg placeReviewImg = PlaceReviewImg.builder().placeReview(placeReview).imgUrl(imageUrl).build();
placeReviewImgRepository.save(placeReviewImg);
}
} catch (RuntimeException e) {
throw new RuntimeException(e.getMessage());
}
}

if (updateReviewDto != null) {
if (updateReviewDto.content() != null) {
placeReview.setContent(updateReviewDto.content());
}if (updateReviewDto.date() != null) {
placeReview.setDate(updateReviewDto.date());
}if (updateReviewDto.grade() != null) {
placeReview.setGrade(updateReviewDto.grade());
}
if (updateReviewDto.deleteImgUrls() != null) {
updateReviewDto.deleteImgUrls().forEach(
deleteImg -> {
placeReviewImgRepository.deleteByImgUrl(deleteImg);
s3Client.delete(StringUtils.substringAfter(deleteImg, partToFind));
}
);
}
}

placeReviewRepository.save(placeReview);

}
}

0 comments on commit 9dd3c27

Please sign in to comment.