Skip to content

Commit

Permalink
Merge pull request #61 from Journey-Together/feature/31
Browse files Browse the repository at this point in the history
#31 feat : 일정 후기 삭제 api
  • Loading branch information
sycuuui authored Jun 9, 2024
2 parents 88748ae + 5c1c629 commit d6a2dbd
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public ApiResponse<PlanReviewRes> 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<PlanReviewRes> findPlanReviewGuest(@PathVariable("plan_id")Long planId){
return ApiResponse.success(Success.GET_REVIEW_SUCCESS,planService.findPlanReview(null,planId));
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
import java.util.List;

public interface PlanReviewImageRepository extends JpaRepository<PlanReviewImage,Long> {
List<PlanReviewImage> findAllByPlanReview(PlanReview planReview);
List<PlanReviewImage> findAllByPlanReviewAndDeletedAtIsNull(PlanReview planReview);
void deletePlanReviewImageByPlanReviewImageId(Long planReviewImageId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
public interface PlanReviewRepository extends JpaRepository<PlanReview,Long> {
boolean existsAllByPlan(Plan plan);
PlanReview findPlanReviewByPlan(Plan plan);
PlanReview findPlanReviewByPlanReviewIdAndDeletedAtIsNull(Long reviewId);
void deletePlanReviewByPlanReviewId(Long planReviewId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public PlanDetailRes findPlanDetail(Member member, Long planId){
}
}else {
PlanReview planReview = planReviewRepository.findPlanReviewByPlan(plan);
List<PlanReviewImage> planReviewImageList = planReviewImageRepository.findAllByPlanReview(planReview);
List<PlanReviewImage> planReviewImageList = planReviewImageRepository.findAllByPlanReviewAndDeletedAtIsNull(planReview);
if(planReviewImageList == null){
//imageUrl : 장소사진
for(Day day : dayList){
Expand Down Expand Up @@ -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<PlanReviewImage> 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<MyPlanRes> findMyPlans(Member member) {
//Vaildation
Expand Down Expand Up @@ -339,7 +358,7 @@ public String getPlanImageUrl(Member member,Plan plan){
//후기가 있을 경우
else {
//후기가 있지만 후기 사진이 없을 경우 -> 첫번째날 첫번째 장소 사진(1장)
List<PlanReviewImage> planReviewImageList = planReviewImageRepository.findAllByPlanReview(planReview);
List<PlanReviewImage> planReviewImageList = planReviewImageRepository.findAllByPlanReviewAndDeletedAtIsNull(planReview);
if(planReviewImageList == null){
return getPlaceFirstImage(member,plan);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "푸시알림 수정 성공"),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Journey/Together/global/util/S3Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d6a2dbd

Please sign in to comment.