diff --git a/src/main/java/Journey/Together/domain/dairy/controller/PlanController.java b/src/main/java/Journey/Together/domain/dairy/controller/PlanController.java index 41cd2b2..a26509f 100644 --- a/src/main/java/Journey/Together/domain/dairy/controller/PlanController.java +++ b/src/main/java/Journey/Together/domain/dairy/controller/PlanController.java @@ -67,6 +67,12 @@ public ApiResponse findPlanReview(@AuthenticationPrincipal Princi return ApiResponse.success(Success.GET_REVIEW_SUCCESS,planService.findPlanReview(principalDetails.getMember(),planId)); } + @DeleteMapping("/review/{review_id}") + public ApiResponse deletePlanReview(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("review_id")Long reviewId){ + planService.deletePlanReview(principalDetails.getMember(),reviewId); + return ApiResponse.success(Success.DELETE_PLAN_REVIEW_SUCCESS); + } + @GetMapping("/guest/review/{plan_id}") public ApiResponse findPlanReviewGuest(@PathVariable("plan_id")Long planId){ return ApiResponse.success(Success.GET_REVIEW_SUCCESS,planService.findPlanReview(null,planId)); diff --git a/src/main/java/Journey/Together/domain/dairy/entity/PlanReviewImage.java b/src/main/java/Journey/Together/domain/dairy/entity/PlanReviewImage.java index adc98ae..7398f61 100644 --- a/src/main/java/Journey/Together/domain/dairy/entity/PlanReviewImage.java +++ b/src/main/java/Journey/Together/domain/dairy/entity/PlanReviewImage.java @@ -1,5 +1,6 @@ package Journey.Together.domain.dairy.entity; +import Journey.Together.global.common.BaseTimeEntity; import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import lombok.*; @@ -10,7 +11,7 @@ @Table(name = "palnReviewImage") @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor -public class PlanReviewImage { +public class PlanReviewImage extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "planReviewImage_id") diff --git a/src/main/java/Journey/Together/domain/dairy/repository/PlanReviewImageRepository.java b/src/main/java/Journey/Together/domain/dairy/repository/PlanReviewImageRepository.java index af62f01..5a9484f 100644 --- a/src/main/java/Journey/Together/domain/dairy/repository/PlanReviewImageRepository.java +++ b/src/main/java/Journey/Together/domain/dairy/repository/PlanReviewImageRepository.java @@ -7,5 +7,6 @@ import java.util.List; public interface PlanReviewImageRepository extends JpaRepository { - List findAllByPlanReview(PlanReview planReview); + List findAllByPlanReviewAndDeletedAtIsNull(PlanReview planReview); + void deletePlanReviewImageByPlanReviewImageId(Long planReviewImageId); } diff --git a/src/main/java/Journey/Together/domain/dairy/repository/PlanReviewRepository.java b/src/main/java/Journey/Together/domain/dairy/repository/PlanReviewRepository.java index a378767..6d29fe1 100644 --- a/src/main/java/Journey/Together/domain/dairy/repository/PlanReviewRepository.java +++ b/src/main/java/Journey/Together/domain/dairy/repository/PlanReviewRepository.java @@ -8,4 +8,6 @@ public interface PlanReviewRepository extends JpaRepository { boolean existsAllByPlan(Plan plan); PlanReview findPlanReviewByPlan(Plan plan); + PlanReview findPlanReviewByPlanReviewIdAndDeletedAtIsNull(Long reviewId); + void deletePlanReviewByPlanReviewId(Long planReviewId); } diff --git a/src/main/java/Journey/Together/domain/dairy/service/PlanService.java b/src/main/java/Journey/Together/domain/dairy/service/PlanService.java index 1880467..453029a 100644 --- a/src/main/java/Journey/Together/domain/dairy/service/PlanService.java +++ b/src/main/java/Journey/Together/domain/dairy/service/PlanService.java @@ -135,7 +135,7 @@ public PlanDetailRes findPlanDetail(Member member, Long planId){ } }else { PlanReview planReview = planReviewRepository.findPlanReviewByPlan(plan); - List planReviewImageList = planReviewImageRepository.findAllByPlanReview(planReview); + List planReviewImageList = planReviewImageRepository.findAllByPlanReviewAndDeletedAtIsNull(planReview); if(planReviewImageList == null){ //imageUrl : 장소사진 for(Day day : dayList){ @@ -244,6 +244,25 @@ public PlanReviewRes findPlanReview(Member member,long planId){ } + @Transactional + public void deletePlanReview(Member member,Long reviewId){ + PlanReview planReview = planReviewRepository.findPlanReviewByPlanReviewIdAndDeletedAtIsNull(reviewId); + if(planReview.getPlan().getMember().getMemberId()!=member.getMemberId()){ + throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION); + } + List planReviewImageList = planReviewImageRepository.findAllByPlanReviewAndDeletedAtIsNull(planReview); + if(planReviewImageList!=null){ + for(PlanReviewImage planReviewImage : planReviewImageList){ + String filename = planReviewImage.getImageUrl().replace(s3Client.baseUrl(), ""); + System.out.println(filename); + s3Client.delete(filename); + planReviewImageRepository.deletePlanReviewImageByPlanReviewImageId(planReviewImage.getPlanReviewImageId()); + } + } + System.out.println("test4"); + planReviewRepository.deletePlanReviewByPlanReviewId(planReview.getPlanReviewId()); + } + @Transactional public List findMyPlans(Member member) { //Vaildation @@ -339,7 +358,7 @@ public String getPlanImageUrl(Member member,Plan plan){ //후기가 있을 경우 else { //후기가 있지만 후기 사진이 없을 경우 -> 첫번째날 첫번째 장소 사진(1장) - List planReviewImageList = planReviewImageRepository.findAllByPlanReview(planReview); + List planReviewImageList = planReviewImageRepository.findAllByPlanReviewAndDeletedAtIsNull(planReview); if(planReviewImageList == null){ return getPlaceFirstImage(member,plan); } diff --git a/src/main/java/Journey/Together/global/exception/Success.java b/src/main/java/Journey/Together/global/exception/Success.java index cf8ede9..c6b3d3d 100644 --- a/src/main/java/Journey/Together/global/exception/Success.java +++ b/src/main/java/Journey/Together/global/exception/Success.java @@ -48,6 +48,7 @@ public enum Success { DELETE_PLAN_SUCCESS(HttpStatus.OK, "일정 삭제 성공"), DELETE_CATEGORY_SUCCESS(HttpStatus.OK, "카테고리 삭제 성공"), DELETE_MY_PLACE_REVIEW_SUCCESS(HttpStatus.OK, "나의 여행지 후기 삭제 성공"), + DELETE_PLAN_REVIEW_SUCCESS(HttpStatus.OK, "나의 일정 후기 삭제 성공"), SEARCH_SUCCESS(HttpStatus.OK, "검색 성공"), PARSING_OG_SUCCESS(HttpStatus.OK, "og 데이터 파싱 결과입니다. 크롤링을 막은 페이지는 기본이미지가 나옵니다."), UPDATE_PUSH_ALLOWED_SUCCESS(HttpStatus.OK, "푸시알림 수정 성공"), diff --git a/src/main/java/Journey/Together/global/util/S3Client.java b/src/main/java/Journey/Together/global/util/S3Client.java index 01523c2..31e3be2 100644 --- a/src/main/java/Journey/Together/global/util/S3Client.java +++ b/src/main/java/Journey/Together/global/util/S3Client.java @@ -91,6 +91,7 @@ public String getUrl(){ } public void delete(String fileName) { + System.out.println("delete : "+bucket+fileName); // Validation if(!amazonS3Client.doesObjectExist(bucket, fileName)) { throw new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION);