From 70696fdc54500dcf314a7085a543fcaa9552f32a Mon Sep 17 00:00:00 2001 From: cseongbo Date: Wed, 27 Sep 2023 13:29:29 +0900 Subject: [PATCH] trip delete --- .../controller/TripController.java | 22 +++++++++++++++---- .../TripPlannerZ/dto/trip/TripDelete.java | 14 ++++++++++++ .../TripPlannerZ/service/MemberService.java | 12 +++++----- .../TripPlannerZ/service/TripService.java | 6 +++++ 4 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 src/main/java/GraduationProject/TripPlannerZ/dto/trip/TripDelete.java diff --git a/src/main/java/GraduationProject/TripPlannerZ/controller/TripController.java b/src/main/java/GraduationProject/TripPlannerZ/controller/TripController.java index 590880f8..49584aee 100644 --- a/src/main/java/GraduationProject/TripPlannerZ/controller/TripController.java +++ b/src/main/java/GraduationProject/TripPlannerZ/controller/TripController.java @@ -13,13 +13,11 @@ import GraduationProject.TripPlannerZ.dto.member.MemberInfo; import GraduationProject.TripPlannerZ.dto.member.MemberTrip; import GraduationProject.TripPlannerZ.dto.trip.TripCreate; +import GraduationProject.TripPlannerZ.dto.trip.TripDelete; import GraduationProject.TripPlannerZ.dto.trip.TripDetail; import GraduationProject.TripPlannerZ.repository.MemberPartyRepository; import GraduationProject.TripPlannerZ.repository.TripImageRepository; -import GraduationProject.TripPlannerZ.service.LocationService; -import GraduationProject.TripPlannerZ.service.MemberService; -import GraduationProject.TripPlannerZ.service.PartyService; -import GraduationProject.TripPlannerZ.service.TripService; +import GraduationProject.TripPlannerZ.service.*; import GraduationProject.TripPlannerZ.sseEmitter.SseEmitterService; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -56,6 +54,7 @@ public class TripController { private final LocationService locationService; private final CommentService commentService; private final SseEmitterService sseEmitterService; + private final LoginService loginService; @PostMapping("/trip/create") @@ -210,4 +209,19 @@ public void responseAccompany(@RequestBody CommentResponse commentResponse) { memberPartyRepository.save(mp); } + + @PostMapping("/trip/delete") + public ResponseEntity deleteTrip(@RequestBody TripDelete tripDelete) { + Member member = loginService.getLoggedInMember(); + Trip trip = tripService.findByUUID(tripDelete.getTripUUID()).get(); + Member creater = memberService.findByEmail(trip.getCreater().getEmail()).get(); + + if (member != creater) { + return ResponseEntity.ok().body("not allowed"); + } + + tripService.deleteTrip(trip); + + return ResponseEntity.ok().body("deleted"); + } } \ No newline at end of file diff --git a/src/main/java/GraduationProject/TripPlannerZ/dto/trip/TripDelete.java b/src/main/java/GraduationProject/TripPlannerZ/dto/trip/TripDelete.java new file mode 100644 index 00000000..c63d8cfe --- /dev/null +++ b/src/main/java/GraduationProject/TripPlannerZ/dto/trip/TripDelete.java @@ -0,0 +1,14 @@ +package GraduationProject.TripPlannerZ.dto.trip; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TripDelete { + + private String tripUUID; + +} diff --git a/src/main/java/GraduationProject/TripPlannerZ/service/MemberService.java b/src/main/java/GraduationProject/TripPlannerZ/service/MemberService.java index fbfff98a..d5f8df60 100644 --- a/src/main/java/GraduationProject/TripPlannerZ/service/MemberService.java +++ b/src/main/java/GraduationProject/TripPlannerZ/service/MemberService.java @@ -78,13 +78,13 @@ public Page findTrip(Member member, String sortType, Pageable pageab // 회원 탈퇴 @Transactional public void exit(Member member) { - member.exit(); +// member.exit(); memberRepository.delete(member); - List list = partyRepository.noMemberParty(); - - for (Long id : list) { - partyRepository.deleteById(id); - } +// List list = partyRepository.noMemberParty(); +// +// for (Long id : list) { +// partyRepository.deleteById(id); +// } } // 비밀 번호 변경 diff --git a/src/main/java/GraduationProject/TripPlannerZ/service/TripService.java b/src/main/java/GraduationProject/TripPlannerZ/service/TripService.java index ed168d6d..e6065176 100644 --- a/src/main/java/GraduationProject/TripPlannerZ/service/TripService.java +++ b/src/main/java/GraduationProject/TripPlannerZ/service/TripService.java @@ -20,6 +20,12 @@ public Long createTrip(Trip trip){ return trip.getId(); } + @Transactional + public Long deleteTrip(Trip trip) { + tripRepository.delete(trip); + return trip.getId(); + } + public Optional findByUUID(String id){ return tripRepository.findByUUID(id); }