From 47863236ea477563f8619b7afc23d3735de125ef Mon Sep 17 00:00:00 2001 From: Dayeon-Hong Date: Sun, 12 May 2024 18:38:51 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=A3=BC=EC=84=9D=20=ED=95=B4=EC=A0=9C=20=EB=B0=8F?= =?UTF-8?q?=20=ED=95=A8=EC=88=98=20=EC=A0=95=EB=A6=AC=20#40?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ScheduleController.java | 42 +++++++++-------- .../domain/schedule/entity/Schedule.java | 3 -- .../repository/ScheduleRepository.java | 1 - .../schedule/service/ScheduleServiceImpl.java | 47 +++++++++---------- 4 files changed, 46 insertions(+), 47 deletions(-) diff --git a/backend/src/main/java/com/isp/backend/domain/schedule/controller/ScheduleController.java b/backend/src/main/java/com/isp/backend/domain/schedule/controller/ScheduleController.java index d8998ef4..07380887 100644 --- a/backend/src/main/java/com/isp/backend/domain/schedule/controller/ScheduleController.java +++ b/backend/src/main/java/com/isp/backend/domain/schedule/controller/ScheduleController.java @@ -18,14 +18,6 @@ public class ScheduleController { private final ScheduleServiceImpl scheduleServiceImpl; - /** 여행 일정 목록 조회 API **/ - @GetMapping() - public ResponseEntity> getScheduleList(@AuthenticationPrincipal CustomUserDetails userDetails) { - String uid = userDetails.getUsername(); - List scheduleList = scheduleServiceImpl.getScheduleList(uid); - return ResponseEntity.ok(scheduleList); - } - /** 여행 일정 저장 API **/ @PostMapping() public ResponseEntity saveSchedule(@AuthenticationPrincipal CustomUserDetails customUserDetails, @@ -34,24 +26,25 @@ public ResponseEntity saveSchedule(@AuthenticationPrincipal CustomUserDeta return ResponseEntity.ok().build(); } + + /** 여행 일정 목록 조회 API **/ + @GetMapping() + public ResponseEntity> getScheduleList(@AuthenticationPrincipal CustomUserDetails userDetails) { + String memberUid = userDetails.getUsername(); + List scheduleList = scheduleServiceImpl.getScheduleList(memberUid); + return ResponseEntity.ok(scheduleList); + } + + /** 여행 일정 상세 조회 API **/ @GetMapping("/details/{scheduleId}") public ResponseEntity getScheduleDetail(@AuthenticationPrincipal CustomUserDetails userDetails, @PathVariable Long scheduleId) { - String uid = userDetails.getUsername(); - ScheduleSaveRequest scheduleDetail = scheduleServiceImpl.getScheduleDetail(uid, scheduleId); + String memberUid = userDetails.getUsername(); + ScheduleSaveRequest scheduleDetail = scheduleServiceImpl.getScheduleDetail(memberUid, scheduleId); return ResponseEntity.ok(scheduleDetail); } - /** 여행 일정 삭제 API **/ - @DeleteMapping("/{scheduleId}") - public ResponseEntity deleteSchedule(@AuthenticationPrincipal CustomUserDetails userDetails, - @PathVariable Long scheduleId) { - String uid = userDetails.getUsername(); - scheduleServiceImpl.deleteSchedule(uid, scheduleId); - return ResponseEntity.ok().build(); - } - /** 여행 일정 수정 API **/ @PutMapping("/{scheduleId}") @@ -62,4 +55,15 @@ public ResponseEntity updateSchedule(@AuthenticationPrincip return ResponseEntity.ok(updatedSchedule); } + + /** 여행 일정 삭제 API **/ + @DeleteMapping("/{scheduleId}") + public ResponseEntity deleteSchedule(@AuthenticationPrincipal CustomUserDetails userDetails, + @PathVariable Long scheduleId) { + String memberUid = userDetails.getUsername(); + scheduleServiceImpl.deleteSchedule(memberUid, scheduleId); + return ResponseEntity.ok().build(); + } + + } \ No newline at end of file diff --git a/backend/src/main/java/com/isp/backend/domain/schedule/entity/Schedule.java b/backend/src/main/java/com/isp/backend/domain/schedule/entity/Schedule.java index e05a00dc..2bd92bc8 100644 --- a/backend/src/main/java/com/isp/backend/domain/schedule/entity/Schedule.java +++ b/backend/src/main/java/com/isp/backend/domain/schedule/entity/Schedule.java @@ -39,9 +39,6 @@ public class Schedule extends BaseEntity { @OneToMany(mappedBy = "schedule", cascade = CascadeType.ALL) private List scheduleDetails = new ArrayList<>(); - // FK 연결 필요 - private String bookingId; - private String startDate; private String endDate; diff --git a/backend/src/main/java/com/isp/backend/domain/schedule/repository/ScheduleRepository.java b/backend/src/main/java/com/isp/backend/domain/schedule/repository/ScheduleRepository.java index ba2b7167..350bd950 100644 --- a/backend/src/main/java/com/isp/backend/domain/schedule/repository/ScheduleRepository.java +++ b/backend/src/main/java/com/isp/backend/domain/schedule/repository/ScheduleRepository.java @@ -15,5 +15,4 @@ public interface ScheduleRepository extends JpaRepository { @Query("SELECT s FROM Schedule s WHERE s.member = :member AND s.activated = true ORDER BY s.updatedAt DESC") List findSchedulesByMember(@Param("member") Member member); - } diff --git a/backend/src/main/java/com/isp/backend/domain/schedule/service/ScheduleServiceImpl.java b/backend/src/main/java/com/isp/backend/domain/schedule/service/ScheduleServiceImpl.java index 301a659e..cff485cd 100644 --- a/backend/src/main/java/com/isp/backend/domain/schedule/service/ScheduleServiceImpl.java +++ b/backend/src/main/java/com/isp/backend/domain/schedule/service/ScheduleServiceImpl.java @@ -37,7 +37,7 @@ public class ScheduleServiceImpl implements ScheduleService { private final ScheduleMapper scheduleMapper; - /** 여행 일정 저장 API **/ + /** 여행 일정 저장 **/ @Transactional @Override public void saveSchedule(String uid, ScheduleSaveRequest scheduleSaveRequest) { @@ -52,7 +52,7 @@ public void saveSchedule(String uid, ScheduleSaveRequest scheduleSaveRequest) { } - /** 여행 일정 목록 조회 API **/ + /** 여행 일정 목록 조회 **/ @Override public List getScheduleList(String uid) { Member findMember = validateUserCheck(uid); @@ -65,7 +65,7 @@ public List getScheduleList(String uid) { } - /** 여행 일정 상세 조회 API **/ + /** 여행 일정 상세 조회 **/ @Override public ScheduleSaveRequest getScheduleDetail(String uid, Long scheduleId) { Member findMember = validateUserCheck(uid); @@ -75,27 +75,7 @@ public ScheduleSaveRequest getScheduleDetail(String uid, Long scheduleId) { } - /** 여행 일정 삭제 API **/ - @Transactional - @Override - public void deleteSchedule(String uid, Long scheduleId) { - Member findMember = validateUserCheck(uid); - Schedule findSchedule = validateSchedule(scheduleId); - - // 자신의 여행 일정인지 확인 - if (!findSchedule.getMember().equals(findMember)) { - throw new NotYourScheduleException(); - } - - // ScheduleDetail 테이블 데이터 삭제 - scheduleDetailRepository.deleteBySchedule(findSchedule); - findSchedule.setActivated(false); - - scheduleRepository.save(findSchedule); - } - - - /** 여행 일정 수정 API **/ + /** 여행 일정 수정 **/ @Transactional @Override public ScheduleSaveRequest updateSchedule(String uid, Long scheduleId, ScheduleSaveRequest updateRequestDTO) { @@ -129,6 +109,25 @@ public ScheduleSaveRequest updateSchedule(String uid, Long scheduleId, ScheduleS } + /** 여행 일정 삭제 **/ + @Transactional + @Override + public void deleteSchedule(String uid, Long scheduleId) { + Member findMember = validateUserCheck(uid); + Schedule findSchedule = validateSchedule(scheduleId); + // 자신의 여행 일정인지 확인 + if (!findSchedule.getMember().equals(findMember)) { + throw new NotYourScheduleException(); + } + + // ScheduleDetail 테이블 데이터 삭제 + scheduleDetailRepository.deleteBySchedule(findSchedule); + findSchedule.setActivated(false); + + scheduleRepository.save(findSchedule); + } + + /** 여행 일정 총 경비 계산 **/ @Override public void calculateTotalPrice(Schedule schedule) {