Skip to content

Commit

Permalink
RAC-277 feat : 멘토링 삭제 구현(결제 실패시)
Browse files Browse the repository at this point in the history
  • Loading branch information
ywj9811 committed Jan 10, 2024
1 parent e880eb3 commit 7a524be
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,20 @@ public ResponseDto<AppliedMentoringDetailResponse> getMentoringDetail(@Authentic
return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_DETAIL_INFO.getMessage(), mentoringDetail);
}

@DeleteMapping("/me/{mentoringId}")
@Operation(summary = "[대학생] 결제 오류/취소시 멘토링 삭제", description = "대학생이 신청한 멘토링을 삭제합니다. (취소/거절 아닌 삭제)")
public ResponseDto<AppliedMentoringDetailResponse> 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<Long> 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum MentoringResponseMessage {
GET_MENTORING_DETAIL_INFO("멘토링 상세 조회에 성공하였습니다."),
CREATE_MENTORING("멘토링 신청에 성공하였습니다."),
UPDATE_MENTORING("멘토링 상태 갱신에 성공하였습니다."),
DELETE_MENTORING("멘토링 삭제에 성공하였습니다."),

NOT_FOUND_MENTORING("멘토링이 존재하지 않습니다."),
NOT_FOUND_DETAIL("볼 수 없는 신청서 입니다."),
Expand Down

0 comments on commit 7a524be

Please sign in to comment.