From 7a524beba4a949e90997bc8b1556f4f246c0b5a7 Mon Sep 17 00:00:00 2001 From: yang Date: Thu, 11 Jan 2024 00:39:36 +0900 Subject: [PATCH] =?UTF-8?q?RAC-277=20feat=20:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=82=AD=EC=A0=9C=20=EA=B5=AC=ED=98=84(=EA=B2=B0?= =?UTF-8?q?=EC=A0=9C=20=EC=8B=A4=ED=8C=A8=EC=8B=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/MentoringApplyUseCase.java | 5 +++-- .../usecase/MentoringManageUseCase.java | 7 +++++++ .../domain/service/MentoringDeleteService.java | 16 ++++++++++++++++ .../presentation/MentoringController.java | 14 +++++++++++--- .../constant/MentoringResponseMessage.java | 1 + 5 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringDeleteService.java diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyUseCase.java index d65c7d9c..fcc2281c 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyUseCase.java @@ -19,12 +19,13 @@ public class MentoringApplyUseCase { private final MentoringSaveService mentoringSaveService; private final SeniorGetService seniorGetService; - public void applyMentoring(User user, MentoringApplyRequest request) { + public Long applyMentoring(User user, MentoringApplyRequest request) { String[] dates = request.date().split(","); if (dates.length != 3) throw new MentoringDateException(); Senior senior = seniorGetService.bySeniorId(request.seniorId()); Mentoring mentoring = MentoringMapper.mapToMentoring(user, senior, request); - mentoringSaveService.save(mentoring); + Mentoring save = mentoringSaveService.save(mentoring); + return save.getMentoringId(); } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java index 224099f7..1d1e75c7 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java @@ -4,6 +4,7 @@ import com.postgraduate.domain.account.domain.service.AccountGetService; import com.postgraduate.domain.mentoring.application.dto.req.MentoringDateRequest; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; +import com.postgraduate.domain.mentoring.domain.service.MentoringDeleteService; import com.postgraduate.domain.mentoring.domain.service.MentoringGetService; import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService; import com.postgraduate.domain.mentoring.exception.MentoringNotExpectedException; @@ -36,6 +37,7 @@ public class MentoringManageUseCase { private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase; private final MentoringUpdateService mentoringUpdateService; private final MentoringGetService mentoringGetService; + private final MentoringDeleteService mentoringDeleteService; private final RefuseSaveService refuseSaveService; private final AccountGetService accountGetService; private final SeniorGetService seniorGetService; @@ -79,6 +81,11 @@ public Boolean updateExpected(User user, Long mentoringId, MentoringDateRequest return account.isPresent(); } + public void delete(User user, Long mentoringId) { + Mentoring mentoring = checkIsMyMentoringUseCase.byUser(user, mentoringId); + mentoringDeleteService.deleteMentoring(mentoring); + } + @Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul") public void updateAutoCancel() { LocalDateTime now = LocalDateTime.now() diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringDeleteService.java b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringDeleteService.java new file mode 100644 index 00000000..edb24dd3 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringDeleteService.java @@ -0,0 +1,16 @@ +package com.postgraduate.domain.mentoring.domain.service; + +import com.postgraduate.domain.mentoring.domain.entity.Mentoring; +import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class MentoringDeleteService { + private final MentoringRepository mentoringRepository; + + public void deleteMentoring(Mentoring mentoring) { + mentoringRepository.deleteById(mentoring.getMentoringId()); + } +} diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java index 2ded304a..f4b1928d 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java @@ -59,12 +59,20 @@ public ResponseDto getMentoringDetail(@Authentic return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_DETAIL_INFO.getMessage(), mentoringDetail); } + @DeleteMapping("/me/{mentoringId}") + @Operation(summary = "[대학생] 결제 오류/취소시 멘토링 삭제", description = "대학생이 신청한 멘토링을 삭제합니다. (취소/거절 아닌 삭제)") + public ResponseDto deleteMentoring(@AuthenticationPrincipal User user, + @PathVariable Long mentoringId) { + manageUseCase.delete(user, mentoringId); + return ResponseDto.create(MENTORING_DELETE.getCode(), DELETE_MENTORING.getMessage()); + } + @PostMapping("/applying") @Operation(summary = "[대학생] 멘토링 신청", description = "대학생이 멘토링을 신청합니다.") - public ResponseDto applyMentoring(@AuthenticationPrincipal User user, + public ResponseDto applyMentoring(@AuthenticationPrincipal User user, @RequestBody @Valid MentoringApplyRequest request) { - applyUseCase.applyMentoring(user, request); - return ResponseDto.create(MENTORING_CREATE.getCode(), CREATE_MENTORING.getMessage()); + Long mentoringId = applyUseCase.applyMentoring(user, request); + return ResponseDto.create(MENTORING_CREATE.getCode(), CREATE_MENTORING.getMessage(), mentoringId); } @PatchMapping("/me/{mentoringId}/done") diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java index 72fd8686..e208f907 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java @@ -10,6 +10,7 @@ public enum MentoringResponseMessage { GET_MENTORING_DETAIL_INFO("멘토링 상세 조회에 성공하였습니다."), CREATE_MENTORING("멘토링 신청에 성공하였습니다."), UPDATE_MENTORING("멘토링 상태 갱신에 성공하였습니다."), + DELETE_MENTORING("멘토링 삭제에 성공하였습니다."), NOT_FOUND_MENTORING("멘토링이 존재하지 않습니다."), NOT_FOUND_DETAIL("볼 수 없는 신청서 입니다."),