diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringStatusRequest.java b/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringDateRequest.java similarity index 65% rename from src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringStatusRequest.java rename to src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringDateRequest.java index a2c6e5d3..ae67820c 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringStatusRequest.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringDateRequest.java @@ -1,15 +1,14 @@ package com.postgraduate.domain.mentoring.application.dto.req; -import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @Getter -@AllArgsConstructor @NoArgsConstructor -public class MentoringStatusRequest { +@AllArgsConstructor +public class MentoringDateRequest { @NotNull - private Status status; + private String date; } diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringRefuseRequest.java b/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringRefuseRequest.java new file mode 100644 index 00000000..677989b3 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringRefuseRequest.java @@ -0,0 +1,14 @@ +package com.postgraduate.domain.mentoring.application.dto.req; + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class MentoringRefuseRequest { + @NotNull + private String refuse; +} diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/dto/res/SeniorMentoringDetailResponse.java b/src/main/java/com/postgraduate/domain/mentoring/application/dto/res/SeniorMentoringDetailResponse.java new file mode 100644 index 00000000..26297d93 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/application/dto/res/SeniorMentoringDetailResponse.java @@ -0,0 +1,15 @@ +package com.postgraduate.domain.mentoring.application.dto.res; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Builder +@AllArgsConstructor +@Getter +public class SeniorMentoringDetailResponse { + private String nickName; + private String topic; + private String question; + private String[] dates; +} diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/dto/res/SeniorMentoringResponse.java b/src/main/java/com/postgraduate/domain/mentoring/application/dto/res/SeniorMentoringResponse.java new file mode 100644 index 00000000..cf79f7d1 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/application/dto/res/SeniorMentoringResponse.java @@ -0,0 +1,15 @@ +package com.postgraduate.domain.mentoring.application.dto.res; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Builder +@AllArgsConstructor +@Getter +public class SeniorMentoringResponse { + private Long mentoringId; + private String nickname; + private String[] dates; + private int term; +} diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java b/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java index dfd688d5..745971dd 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java @@ -3,6 +3,8 @@ import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo; import com.postgraduate.domain.mentoring.application.dto.req.MentoringApplyRequest; import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse; +import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringDetailResponse; +import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringResponse; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; @@ -63,4 +65,24 @@ public static Mentoring mapToMentoring(User user, Senior senior, MentoringApplyR .date(request.getDate()) .build(); } + + public static SeniorMentoringResponse mapToSeniorMentoring(Mentoring mentoring) { + String[] dates = mentoring.getDate().split(","); + return SeniorMentoringResponse.builder() + .mentoringId(mentoring.getMentoringId()) + .nickname(mentoring.getUser().getNickName()) + .dates(dates) + .term(mentoring.getSenior().getTerm()) + .build(); + } + + public static SeniorMentoringDetailResponse mapToSeniorMentoringDetail(Mentoring mentoring) { + String[] dates = mentoring.getDate().split(","); + return SeniorMentoringDetailResponse.builder() + .nickName(mentoring.getUser().getNickName()) + .topic(mentoring.getTopic()) + .question(mentoring.getQuestion()) + .dates(dates) + .build(); + } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java index 671c8729..31e7f310 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java @@ -4,7 +4,10 @@ import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.service.MentoringGetService; import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.global.auth.AuthDetails; +import com.postgraduate.global.config.security.util.SecurityUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -13,8 +16,12 @@ @Transactional @RequiredArgsConstructor public class CheckIsMyMentoringUseCase { + private final SecurityUtils securityUtils; + private final SeniorGetService seniorGetService; private final MentoringGetService mentoringGetService; - public Mentoring checkByRole(User user, Long mentoringId) { + + public Mentoring byUser(AuthDetails authDetails, Long mentoringId) { + User user = securityUtils.getLoggedInUser(authDetails); Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId); if (mentoring.getUser() != user) { throw new PermissionDeniedException(); @@ -22,7 +29,9 @@ public Mentoring checkByRole(User user, Long mentoringId) { return mentoring; } - public Mentoring checkByRole(Senior senior, Long mentoringId) { + public Mentoring bySenior(AuthDetails authDetails, Long mentoringId) { + User user = securityUtils.getLoggedInUser(authDetails); + Senior senior = seniorGetService.byUser(user); Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId); if (mentoring.getSenior() != senior) { throw new PermissionDeniedException(); diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java index 9d0e457d..36ca1c35 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java @@ -1,12 +1,18 @@ package com.postgraduate.domain.mentoring.application.usecase; +import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo; import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse; import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringResponse; -import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo; +import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringDetailResponse; +import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringResponse; import com.postgraduate.domain.mentoring.application.mapper.MentoringMapper; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.service.MentoringGetService; +import com.postgraduate.domain.mentoring.exception.MentoringDoneException; +import com.postgraduate.domain.mentoring.exception.MentoringNotWaitingException; +import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.global.auth.AuthDetails; import com.postgraduate.global.config.security.util.SecurityUtils; @@ -16,6 +22,10 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; + +import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.DONE; +import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.WAITING; @Service @Transactional @@ -23,6 +33,7 @@ public class MentoringInfoUseCase { private final MentoringGetService mentoringGetService; private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase; + private final SeniorGetService seniorGetService; private final SecurityUtils securityUtils; /** * securityUtils 이후 수정 @@ -35,6 +46,14 @@ public AppliedMentoringResponse getMentorings(Status status, AuthDetails authDet return getCategories(status, mentorings); } + public List getSeniorMentorings(Status status, AuthDetails authDetails) { + User user = securityUtils.getLoggedInUser(authDetails); + Senior senior = seniorGetService.byUser(user); + + List mentorings = mentoringGetService.mentoringBySenior(senior, status); + return mentorings.stream().map(MentoringMapper::mapToSeniorMentoring).collect(Collectors.toList()); + } + private AppliedMentoringResponse getCategories(Status status, List mentorings) { List appliedMentoringInfos = new ArrayList<>(); @@ -56,8 +75,18 @@ private AppliedMentoringResponse getCategories(Status status, List me } public AppliedMentoringDetailResponse getMentoringDetail(AuthDetails authDetails, Long mentoringId) { - User user = securityUtils.getLoggedInUser(authDetails); - Mentoring mentoring = checkIsMyMentoringUseCase.checkByRole(user, mentoringId); + Mentoring mentoring = checkIsMyMentoringUseCase.byUser(authDetails, mentoringId); + if (mentoring.getStatus() != WAITING) { + throw new MentoringNotWaitingException(); + } return MentoringMapper.mapToAppliedDetailInfo(mentoring); } + + public SeniorMentoringDetailResponse getSeniorMentoringDetail(AuthDetails authDetails, Long mentoringId) { + Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(authDetails, mentoringId); + if (mentoring.getStatus() == DONE) { + throw new MentoringDoneException(); + } + return MentoringMapper.mapToSeniorMentoringDetail(mentoring); + } } 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 ac2383ec..7859f66c 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 @@ -1,26 +1,46 @@ package com.postgraduate.domain.mentoring.application.usecase; -import com.postgraduate.domain.mentoring.application.dto.req.MentoringStatusRequest; +import com.postgraduate.domain.mentoring.application.dto.req.MentoringDateRequest; +import com.postgraduate.domain.mentoring.application.dto.req.MentoringRefuseRequest; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; +import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService; -import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.domain.mentoring.exception.MentoringNotWaitingException; import com.postgraduate.global.auth.AuthDetails; -import com.postgraduate.global.config.security.util.SecurityUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.WAITING; + @Service @Transactional @RequiredArgsConstructor public class MentoringManageUseCase { - private final SecurityUtils securityUtils; - private final MentoringUpdateService mentoringUpdateService; private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase; + private final MentoringUpdateService mentoringUpdateService; + + public void updateStatus(AuthDetails authDetails, Long mentoringId, Status status) { + Mentoring mentoring = checkIsMyMentoringUseCase.byUser(authDetails, mentoringId); + mentoringUpdateService.updateStatus(mentoring, status); + } + + public void updateSeniorStatus(AuthDetails authDetails, Long mentoringId, Status status) { + Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(authDetails, mentoringId); + mentoringUpdateService.updateStatus(mentoring, status); + } + + public void updateRefuse(AuthDetails authDetails, Long mentoringId, MentoringRefuseRequest request, Status status) { + Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(authDetails, mentoringId); + mentoringUpdateService.updateRefuse(mentoring, request.getRefuse()); + mentoringUpdateService.updateStatus(mentoring, status); + } - public void updateStatus(AuthDetails authDetails, Long mentoringId, MentoringStatusRequest request) { - User user = securityUtils.getLoggedInUser(authDetails); - Mentoring mentoring = checkIsMyMentoringUseCase.checkByRole(user, mentoringId); - mentoringUpdateService.updateStatus(mentoring, request.getStatus()); + public void updateDate(AuthDetails authDetails, Long mentoringId, MentoringDateRequest request) { + Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(authDetails, mentoringId); + if (mentoring.getStatus() != WAITING) { + throw new MentoringNotWaitingException(); + } + mentoringUpdateService.updateDate(mentoring, request.getDate()); } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java b/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java index 28a795f6..4409fc08 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java @@ -8,7 +8,6 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.CreationTimestamp; import java.time.LocalDate; @@ -42,6 +41,8 @@ public class Mentoring { @Builder.Default private int pay = 20000; + private String refuse; + @Enumerated(EnumType.STRING) @Builder.Default private Status status = Status.WAITING; @@ -55,7 +56,15 @@ public void updateStatus(Status status) { this.status = status; } + public void updateRefuse(String refuse) { + this.refuse = refuse; + } + public void updateDeletedAt() { this.deletedAt = LocalDate.now(); } + + public void updateDate(String date) { + this.date = date; + } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java b/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java index dc839f7a..7b86983c 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java @@ -2,6 +2,7 @@ import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; +import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; import org.springframework.data.jpa.repository.JpaRepository; @@ -11,4 +12,5 @@ public interface MentoringRepository extends JpaRepository { Optional findByMentoringIdAndDeletedAtIsNull(Long mentoringId); Optional> findAllByUserAndStatusAndDeletedAtIsNull(User user, Status status); + Optional> findAllBySeniorAndStatusAndDeletedAtIsNull(Senior senior, Status status); } diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java index efabf8c0..7c144be0 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java @@ -4,6 +4,7 @@ import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; import com.postgraduate.domain.mentoring.exception.MentoringNotFoundException; +import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -20,6 +21,10 @@ public List mentoringByUser(User user, Status status) { return mentoringRepository.findAllByUserAndStatusAndDeletedAtIsNull(user, status).orElse(new ArrayList<>()); } + public List mentoringBySenior(Senior senior, Status status) { + return mentoringRepository.findAllBySeniorAndStatusAndDeletedAtIsNull(senior, status).orElse(new ArrayList<>()); + } + public Mentoring byMentoringId(Long mentoringId) { return mentoringRepository.findByMentoringIdAndDeletedAtIsNull(mentoringId).orElseThrow(MentoringNotFoundException::new); } diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringUpdateService.java b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringUpdateService.java index 2574b069..ba0e6db6 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringUpdateService.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringUpdateService.java @@ -15,4 +15,12 @@ public void updateStatus(Mentoring mentoring, Status status) { } mentoring.updateStatus(status); } + + public void updateRefuse(Mentoring mentoring, String refuse) { + mentoring.updateRefuse(refuse); + } + + public void updateDate(Mentoring mentoring, String date) { + mentoring.updateDate(date); + } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringDoneException.java b/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringDoneException.java new file mode 100644 index 00000000..6da8c5c6 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringDoneException.java @@ -0,0 +1,12 @@ +package com.postgraduate.domain.mentoring.exception; + +import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.MENTORING_DONE; +import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.DONE_MENTORING; + + +public class MentoringDoneException extends MentoringException { + + public MentoringDoneException() { + super(DONE_MENTORING.getMessage(), MENTORING_DONE.getCode()); + } +} diff --git a/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringNotWaitingException.java b/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringNotWaitingException.java new file mode 100644 index 00000000..b7626f58 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringNotWaitingException.java @@ -0,0 +1,12 @@ +package com.postgraduate.domain.mentoring.exception; + +import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.MENTORING_NOT_WAITING; +import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.NOT_WAITING_MENTORING; + + +public class MentoringNotWaitingException extends MentoringException { + + public MentoringNotWaitingException() { + super(NOT_WAITING_MENTORING.getMessage(), MENTORING_NOT_WAITING.getCode()); + } +} 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 8587b4c7..cc4dff86 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java @@ -1,9 +1,12 @@ package com.postgraduate.domain.mentoring.presentation; import com.postgraduate.domain.mentoring.application.dto.req.MentoringApplyRequest; -import com.postgraduate.domain.mentoring.application.dto.req.MentoringStatusRequest; +import com.postgraduate.domain.mentoring.application.dto.req.MentoringDateRequest; +import com.postgraduate.domain.mentoring.application.dto.req.MentoringRefuseRequest; import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse; import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringResponse; +import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringDetailResponse; +import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringResponse; import com.postgraduate.domain.mentoring.application.usecase.MentoringApplyUseCase; import com.postgraduate.domain.mentoring.application.usecase.MentoringInfoUseCase; import com.postgraduate.domain.mentoring.application.usecase.MentoringManageUseCase; @@ -16,6 +19,8 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import java.util.List; + import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.*; import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.*; @@ -26,7 +31,7 @@ public class MentoringController { private final MentoringInfoUseCase infoUsecase; private final MentoringApplyUseCase applyUseCase; - private final MentoringManageUseCase updateUseCase; + private final MentoringManageUseCase manageUseCase; @GetMapping("/me") @Operation(summary = "[대학생] 신청한 멘토링 목록 조회", description = "대학생이 신청한 멘토링 목록을 조회합니다.") @@ -36,7 +41,7 @@ public ResponseDto getMentoringInfos(@RequestParam Sta } @GetMapping("/me/{mentoringId}") - @Operation(summary = "[대학생] 신청한 멘토링 상세조회", description = "대학생이 신청한 멘토링을 상세조회합니다.") + @Operation(summary = "[대학생] 신청한 멘토링 상세조회", description = "대학생이 신청한 멘토링을 상세조회합니다. <확정대기> 상태의 멘토링만 조회 가능합니다.") public ResponseDto getMentoringDetail(@AuthenticationPrincipal AuthDetails authDetails, @PathVariable Long mentoringId) { AppliedMentoringDetailResponse mentoringDetail = infoUsecase.getMentoringDetail(authDetails, mentoringId); return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_DETAIL_INFO.getMessage(), mentoringDetail); @@ -49,12 +54,58 @@ public ResponseDto applyMentoring(@AuthenticationPrincipal AuthDetails authDetai return ResponseDto.create(MENTORING_CREATE.getCode(), CREATE_MENTORING.getMessage()); } - @PatchMapping("/me/{mentoringId}") - @Operation(summary = "[대학생] 멘토링 상태 업데이트", description = "대학생이 멘토링 상태를 변경합니다.") - public ResponseDto updateMentoringStatus(@AuthenticationPrincipal AuthDetails authDetails, + @PatchMapping("/me/{mentoringId}/done") + @Operation(summary = "[대학생] 멘토링 상태 업데이트(완료)", description = "대학생이 멘토링을 완료합니다.") + public ResponseDto updateMentoringDone(@AuthenticationPrincipal AuthDetails authDetails, + @PathVariable Long mentoringId) { + manageUseCase.updateStatus(authDetails, mentoringId, Status.DONE); + return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage()); + } + + @PatchMapping("/me/{mentoringId}/cancel") + @Operation(summary = "[대학생] 멘토링 상태 업데이트(취소)", description = "대학생이 신청한 멘토링을 취소합니다.") + public ResponseDto updateMentoringCancel(@AuthenticationPrincipal AuthDetails authDetails, + @PathVariable Long mentoringId) { + manageUseCase.updateStatus(authDetails, mentoringId, Status.CANCEL); + return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage()); + } + + @GetMapping("/senior/me") + @Operation(summary = "[대학원생] 신청받은 멘토링 목록 조회", description = "대학원생이 신청받은 멘토링 목록을 조회합니다.") + public ResponseDto> getSeniorMentorings(@RequestParam Status status, @AuthenticationPrincipal AuthDetails authDetails) { + List seniorMentorings = infoUsecase.getSeniorMentorings(status, authDetails); + return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), seniorMentorings); + } + + @GetMapping("/senior/me/{mentoringId}") + @Operation(summary = "[대학원생] 신청받은 멘토링 상세조회", description = "대학원생이 신청받은 멘토링을 상세조회합니다. <완료> 상태의 멘토링은 상세조회되지 않습니다.") + public ResponseDto getSeniorMentoringDetail(@AuthenticationPrincipal AuthDetails authDetails, @PathVariable Long mentoringId) { + SeniorMentoringDetailResponse seniorMentoringDetail = infoUsecase.getSeniorMentoringDetail(authDetails, mentoringId); + return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_DETAIL_INFO.getMessage(), seniorMentoringDetail); + } + + @PatchMapping("/senior/me/{mentoringId}/time") + @Operation(summary = "[대학원생] 멘토링 시간 선택", description = "대학생이 신청한 시간 옵션 3개 중 하나를 선택합니다. 확정 대기 상태의 멘토링만 가능합니다.") + public ResponseDto updateMentoringDate(@AuthenticationPrincipal AuthDetails authDetails, + @PathVariable Long mentoringId, + @RequestBody MentoringDateRequest request) { + manageUseCase.updateDate(authDetails, mentoringId, request); + return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage()); + } + + @PatchMapping("/senior/me/{mentoringId}/expected") + @Operation(summary = "[대학원생] 멘토링 상태 업데이트(예정된 멘토링)", description = "대학원생이 멘토링을 수락합니다.") + public ResponseDto updateMentoringExpected(@AuthenticationPrincipal AuthDetails authDetails, @PathVariable Long mentoringId) { + manageUseCase.updateSeniorStatus(authDetails, mentoringId, Status.EXPECTED); + return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage()); + } + + @PatchMapping("/senior/me/{mentoringId}/cancel") + @Operation(summary = "[대학원생] 멘토링 상태 업데이트(거절)", description = "대학원생이 멘토링을 거절하고 거절사유를 변경합니다.") + public ResponseDto updateMentoringCancel(@AuthenticationPrincipal AuthDetails authDetails, @PathVariable Long mentoringId, - @RequestBody MentoringStatusRequest request) { - updateUseCase.updateStatus(authDetails, mentoringId, request); + @RequestBody MentoringRefuseRequest request) { + manageUseCase.updateRefuse(authDetails, mentoringId, request, Status.CANCEL); return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage()); } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseCode.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseCode.java index 87f176d7..cec8ef39 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseCode.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseCode.java @@ -11,7 +11,9 @@ public enum MentoringResponseCode { MENTORING_CREATE("MT202"), MENTORING_DELETE("MT203"), - MENTORING_NOT_FOUND("MT400") + MENTORING_NOT_FOUND("EX700"), + MENTORING_DONE("EX701"), + MENTORING_NOT_WAITING("EX702"), ; private final String code; } \ No newline at end of file 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 034b83ff..e53bcbbc 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 @@ -11,7 +11,10 @@ public enum MentoringResponseMessage { CREATE_MENTORING("멘토링 신청에 성공하였습니다."), UPDATE_MENTORING("멘토링 상태 갱신에 성공하였습니다."), - NOT_FOUND_MENTORING("멘토링이 존재하지 않습니다."); + NOT_FOUND_MENTORING("멘토링이 존재하지 않습니다."), + DONE_MENTORING("완료된 멘토링입니다."), + NOT_WAITING_MENTORING("확정 대기 상태의 멘토링이 아닙니다."), + ; private final String message; } diff --git a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCaseTest.java b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCaseTest.java index 717cca05..ae46d86f 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCaseTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCaseTest.java @@ -3,6 +3,8 @@ import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.service.MentoringGetService; import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.global.auth.AuthDetails; +import com.postgraduate.global.config.security.util.SecurityUtils; import com.postgraduate.global.exception.ApplicationException; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -19,12 +21,16 @@ class CheckIsMyMentoringUseCaseTest { @Mock private MentoringGetService mentoringGetService; + @Mock + private SecurityUtils securityUtils; + @InjectMocks private CheckIsMyMentoringUseCase checkIsMyMentoringUseCase; @Test public void testCheckByRoleInvalid() { - User user = new User(); + AuthDetails authDetails = mock(AuthDetails.class); + when(securityUtils.getLoggedInUser(authDetails)).thenReturn(new User()); Long mentoringId = 1L; Mentoring mentoring = mock(); @@ -32,7 +38,7 @@ public void testCheckByRoleInvalid() { when(mentoringGetService.byMentoringId(mentoringId)).thenReturn(mentoring); assertThrows(ApplicationException.class, () -> { - checkIsMyMentoringUseCase.checkByRole(user, mentoringId); + checkIsMyMentoringUseCase.byUser(authDetails, mentoringId); }); } } \ No newline at end of file