From 8e1431c26dda9b1861157798d798f492b32f9a47 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Tue, 1 Jul 2025 08:19:33 +0900 Subject: [PATCH 01/33] =?UTF-8?q?feat:=20=EB=A9=98=ED=86=A0=EB=A7=81=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 4 ++ .../controller/MentoringController.java | 34 +++++++++++++ .../mentor/dto/MentoringApplyRequest.java | 11 ++++ .../mentor/dto/MentoringApplyResponse.java | 12 +++++ .../repository/MentoringRepository.java | 7 +++ .../service/MentoringCommandService.java | 51 +++++++++++++++++++ 6 files changed, 119 insertions(+) create mode 100644 src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java create mode 100644 src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyRequest.java create mode 100644 src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyResponse.java create mode 100644 src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java create mode 100644 src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java diff --git a/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java b/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java index 90a53dad3..ec16165d6 100644 --- a/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java +++ b/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java @@ -104,6 +104,10 @@ public enum ErrorCode { // database DATA_INTEGRITY_VIOLATION(HttpStatus.CONFLICT.value(), "데이터베이스 무결성 제약조건 위반이 발생했습니다."), + // mentor + SELF_MENTORING_NOT_ALLOWED(HttpStatus.BAD_REQUEST.value(), "자기 자신을 멘토로 설정할 수 없습니다."), + ALREADY_MENTOR(HttpStatus.BAD_REQUEST.value(), "이미 멘토로 등록된 사용자입니다."), + // general JSON_PARSING_FAILED(HttpStatus.BAD_REQUEST.value(), "JSON 파싱을 할 수 없습니다."), JWT_EXCEPTION(HttpStatus.BAD_REQUEST.value(), "JWT 토큰을 처리할 수 없습니다."), diff --git a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java new file mode 100644 index 000000000..339722091 --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java @@ -0,0 +1,34 @@ +package com.example.solidconnection.mentor.controller; + +import com.example.solidconnection.common.resolver.AuthorizedUser; +import com.example.solidconnection.mentor.dto.MentoringApplyRequest; +import com.example.solidconnection.mentor.dto.MentoringApplyResponse; +import com.example.solidconnection.mentor.service.MentoringCommandService; +import com.example.solidconnection.siteuser.domain.SiteUser; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/mentorings") +public class MentoringController { + + private final MentoringCommandService mentoringCommandService; + + @PostMapping("/apply") + public ResponseEntity applyMentoring( + @AuthorizedUser SiteUser siteUser, + @Valid @RequestBody MentoringApplyRequest mentoringApplyRequest + ) { + MentoringApplyResponse response = mentoringCommandService.applyMentoring(siteUser.getId(), mentoringApplyRequest); + return ResponseEntity + .status(HttpStatus.OK) + .body(response); + } +} diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyRequest.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyRequest.java new file mode 100644 index 000000000..be72c412b --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyRequest.java @@ -0,0 +1,11 @@ +package com.example.solidconnection.mentor.dto; + +import jakarta.validation.constraints.NotNull; + +public record MentoringApplyRequest( + + @NotNull(message = "멘토 id를 입력해주세요.") + + Long mentorId +) { +} diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyResponse.java new file mode 100644 index 000000000..eb4b21ac1 --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyResponse.java @@ -0,0 +1,12 @@ +package com.example.solidconnection.mentor.dto; + +import com.example.solidconnection.mentor.domain.Mentoring; + +public record MentoringApplyResponse( + Long mentoringId +) { + + public static MentoringApplyResponse from(Mentoring mentoring) { + return new MentoringApplyResponse(mentoring.getId()); + } +} diff --git a/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java b/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java new file mode 100644 index 000000000..c524bda9a --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java @@ -0,0 +1,7 @@ +package com.example.solidconnection.mentor.repository; + +import com.example.solidconnection.mentor.domain.Mentoring; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MentoringRepository extends JpaRepository { +} diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java new file mode 100644 index 000000000..17d94c5e5 --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -0,0 +1,51 @@ +package com.example.solidconnection.mentor.service; + +import com.example.solidconnection.application.domain.VerifyStatus; +import com.example.solidconnection.common.exception.CustomException; +import com.example.solidconnection.mentor.domain.Mentoring; +import com.example.solidconnection.mentor.dto.MentoringApplyRequest; +import com.example.solidconnection.mentor.dto.MentoringApplyResponse; +import com.example.solidconnection.mentor.repository.MentorRepository; +import com.example.solidconnection.mentor.repository.MentoringRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import static com.example.solidconnection.common.exception.ErrorCode.ALREADY_MENTOR; +import static com.example.solidconnection.common.exception.ErrorCode.SELF_MENTORING_NOT_ALLOWED; + +@Service +@RequiredArgsConstructor +public class MentoringCommandService { + + private final MentoringRepository mentoringRepository; + private final MentorRepository mentorRepository; + + @Transactional + public MentoringApplyResponse applyMentoring(Long siteUserId, MentoringApplyRequest mentoringApplyRequest) { + validateSelfMentoring(siteUserId, mentoringApplyRequest); + validateAlreadyMentor(siteUserId); + + Mentoring mentoring = Mentoring.builder() + .mentorId(mentoringApplyRequest.mentorId()) + .menteeId(siteUserId) + .verifyStatus(VerifyStatus.PENDING) + .build(); + + return MentoringApplyResponse.from( + mentoringRepository.save(mentoring) + ); + } + + private void validateSelfMentoring(Long siteUserId, MentoringApplyRequest request) { + if (siteUserId.equals(request.mentorId())) { + throw new CustomException(SELF_MENTORING_NOT_ALLOWED); + } + } + + private void validateAlreadyMentor(Long siteUserId) { + if (mentorRepository.existsById(siteUserId)) { + throw new CustomException(ALREADY_MENTOR); + } + } +} From 8877521aca62d04573e53571a6d92a5726660454 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Tue, 1 Jul 2025 11:05:53 +0900 Subject: [PATCH 02/33] =?UTF-8?q?feat:=20=EB=A9=98=ED=86=A0=EB=A7=81=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C,?= =?UTF-8?q?=20=EB=A9=98=ED=86=A0=EB=A7=81=20=EC=88=98=EB=9D=BD/=EA=B1=B0?= =?UTF-8?q?=EC=A0=88=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 4 ++ .../controller/MentoringController.java | 29 ++++++++++++ .../mentor/dto/MentoringConfirmRequest.java | 12 +++++ .../mentor/dto/MentoringConfirmResponse.java | 11 +++++ .../mentor/dto/MentoringResponse.java | 28 +++++++++++ .../repository/MentoringRepository.java | 4 ++ .../service/MentoringCommandService.java | 46 +++++++++++++++++++ .../mentor/service/MentoringQueryService.java | 36 +++++++++++++++ 8 files changed, 170 insertions(+) create mode 100644 src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java create mode 100644 src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmResponse.java create mode 100644 src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java create mode 100644 src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java diff --git a/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java b/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java index ec16165d6..e6a0a3ed1 100644 --- a/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java +++ b/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java @@ -107,6 +107,10 @@ public enum ErrorCode { // mentor SELF_MENTORING_NOT_ALLOWED(HttpStatus.BAD_REQUEST.value(), "자기 자신을 멘토로 설정할 수 없습니다."), ALREADY_MENTOR(HttpStatus.BAD_REQUEST.value(), "이미 멘토로 등록된 사용자입니다."), + MENTOR_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 사용자는 멘토로 등록되어 있지 않습니다."), + MENTORING_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 멘토링 신청을 찾을 수 없습니다."), + UNAUTHORIZED_MENTORING_CONFIRM(HttpStatus.FORBIDDEN.value(), "멘토링 승인 권한이 없습니다."), + MENTORING_ALREADY_CONFIRMED(HttpStatus.BAD_REQUEST.value(), "이미 승인 또는 거절된 멘토링입니다."), // general JSON_PARSING_FAILED(HttpStatus.BAD_REQUEST.value(), "JSON 파싱을 할 수 없습니다."), diff --git a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java index 339722091..2432cda75 100644 --- a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java +++ b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java @@ -3,23 +3,33 @@ import com.example.solidconnection.common.resolver.AuthorizedUser; import com.example.solidconnection.mentor.dto.MentoringApplyRequest; import com.example.solidconnection.mentor.dto.MentoringApplyResponse; +import com.example.solidconnection.mentor.dto.MentoringConfirmRequest; +import com.example.solidconnection.mentor.dto.MentoringConfirmResponse; +import com.example.solidconnection.mentor.dto.MentoringResponse; import com.example.solidconnection.mentor.service.MentoringCommandService; +import com.example.solidconnection.mentor.service.MentoringQueryService; import com.example.solidconnection.siteuser.domain.SiteUser; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @RestController @RequiredArgsConstructor @RequestMapping("/mentorings") public class MentoringController { private final MentoringCommandService mentoringCommandService; + private final MentoringQueryService mentoringQueryService; @PostMapping("/apply") public ResponseEntity applyMentoring( @@ -31,4 +41,23 @@ public ResponseEntity applyMentoring( .status(HttpStatus.OK) .body(response); } + + // TODO: RequireRoleAccess 어노테이션 추가 필요 + @GetMapping("/apply") + public ResponseEntity> getMentorings( + @AuthorizedUser SiteUser siteUser + ) { + List responses = mentoringQueryService.getMentorings(siteUser.getId()); + return ResponseEntity.ok(responses); + } + + @PatchMapping("/{mentoring-id}/apply") + public ResponseEntity confirmMentoring( + @AuthorizedUser SiteUser siteUser, + @PathVariable("mentoring-id") Long mentoringId, + @Valid @RequestBody MentoringConfirmRequest mentoringConfirmRequest + ) { + MentoringConfirmResponse response = mentoringCommandService.confirmMentoring(siteUser.getId(), mentoringId, mentoringConfirmRequest); + return ResponseEntity.ok(response); + } } diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java new file mode 100644 index 000000000..cbd08b375 --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java @@ -0,0 +1,12 @@ +package com.example.solidconnection.mentor.dto; + +import com.example.solidconnection.application.domain.VerifyStatus; +import jakarta.validation.constraints.NotNull; + +public record MentoringConfirmRequest( + + @NotNull(message = "승인 상태를 설정해주세요.") + VerifyStatus status, + String rejectedReason +) { +} diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmResponse.java new file mode 100644 index 000000000..a45c0aa44 --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmResponse.java @@ -0,0 +1,11 @@ +package com.example.solidconnection.mentor.dto; + +import com.example.solidconnection.mentor.domain.Mentoring; + +public record MentoringConfirmResponse( + Long mentoringId +) { + public static MentoringConfirmResponse from(Mentoring mentoring) { + return new MentoringConfirmResponse(mentoring.getId()); + } +} diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java new file mode 100644 index 000000000..1db31a4b9 --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java @@ -0,0 +1,28 @@ +package com.example.solidconnection.mentor.dto; + +import com.example.solidconnection.application.domain.VerifyStatus; +import com.example.solidconnection.mentor.domain.Mentoring; + +import java.time.ZonedDateTime; + +public record MentoringResponse( + Long id, + Long mentorId, + Long menteeId, + ZonedDateTime createdAt, + ZonedDateTime confirmedAt, + VerifyStatus verifyStatus, + String rejectedReason +) { + public static MentoringResponse from(Mentoring mentoring) { + return new MentoringResponse( + mentoring.getId(), + mentoring.getMentorId(), + mentoring.getMenteeId(), + mentoring.getCreatedAt(), + mentoring.getConfirmedAt(), + mentoring.getVerifyStatus(), + mentoring.getRejectedReason() + ); + } +} diff --git a/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java b/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java index c524bda9a..fa20702d1 100644 --- a/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java +++ b/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java @@ -3,5 +3,9 @@ import com.example.solidconnection.mentor.domain.Mentoring; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface MentoringRepository extends JpaRepository { + + List findAllByMentorId(Long mentorId); } diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index 17d94c5e5..49b9e682a 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -2,9 +2,12 @@ import com.example.solidconnection.application.domain.VerifyStatus; import com.example.solidconnection.common.exception.CustomException; +import com.example.solidconnection.mentor.domain.Mentor; import com.example.solidconnection.mentor.domain.Mentoring; import com.example.solidconnection.mentor.dto.MentoringApplyRequest; import com.example.solidconnection.mentor.dto.MentoringApplyResponse; +import com.example.solidconnection.mentor.dto.MentoringConfirmRequest; +import com.example.solidconnection.mentor.dto.MentoringConfirmResponse; import com.example.solidconnection.mentor.repository.MentorRepository; import com.example.solidconnection.mentor.repository.MentoringRepository; import lombok.RequiredArgsConstructor; @@ -12,7 +15,12 @@ import org.springframework.transaction.annotation.Transactional; import static com.example.solidconnection.common.exception.ErrorCode.ALREADY_MENTOR; +import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_ALREADY_CONFIRMED; +import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_NOT_FOUND; +import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND; +import static com.example.solidconnection.common.exception.ErrorCode.REJECTED_REASON_REQUIRED; import static com.example.solidconnection.common.exception.ErrorCode.SELF_MENTORING_NOT_ALLOWED; +import static com.example.solidconnection.common.exception.ErrorCode.UNAUTHORIZED_MENTORING_CONFIRM; @Service @RequiredArgsConstructor @@ -37,6 +45,31 @@ public MentoringApplyResponse applyMentoring(Long siteUserId, MentoringApplyRequ ); } + @Transactional + public MentoringConfirmResponse confirmMentoring(Long siteUserId, Long mentoringId, MentoringConfirmRequest mentoringConfirmRequest) { + Mentoring mentoring = mentoringRepository.findById(mentoringId) + .orElseThrow(() -> new CustomException(MENTORING_NOT_FOUND)); + + Mentor mentor = mentorRepository.findById(mentoring.getMentorId()) + .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); + + validateUnauthorizedMentoring(siteUserId, mentor); + validateAlreadyConfirmed(mentoring); + + if (mentoringConfirmRequest.status() == VerifyStatus.APPROVED) { + mentor.increaseMenteeCount(); + } + else if (mentoringConfirmRequest.status() == VerifyStatus.REJECTED) { + if (mentoringConfirmRequest.rejectedReason() == null || mentoringConfirmRequest.rejectedReason().isBlank()) { + throw new CustomException(REJECTED_REASON_REQUIRED); + } + } + + mentoring.confirm(mentoringConfirmRequest.status(), mentoringConfirmRequest.rejectedReason()); + + return MentoringConfirmResponse.from(mentoring); + } + private void validateSelfMentoring(Long siteUserId, MentoringApplyRequest request) { if (siteUserId.equals(request.mentorId())) { throw new CustomException(SELF_MENTORING_NOT_ALLOWED); @@ -48,4 +81,17 @@ private void validateAlreadyMentor(Long siteUserId) { throw new CustomException(ALREADY_MENTOR); } } + + // 멘토는 본인의 멘토링에 대해 confirm해야 한다. + private void validateUnauthorizedMentoring(Long siteUserId, Mentor mentor) { + if (!siteUserId.equals(mentor.getSiteUserId())) { + throw new CustomException(UNAUTHORIZED_MENTORING_CONFIRM); + } + } + + private void validateAlreadyConfirmed(Mentoring mentoring) { + if (mentoring.getVerifyStatus() != VerifyStatus.PENDING) { + throw new CustomException(MENTORING_ALREADY_CONFIRMED); + } + } } diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java new file mode 100644 index 000000000..4f325b9a2 --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java @@ -0,0 +1,36 @@ +package com.example.solidconnection.mentor.service; + +import com.example.solidconnection.common.exception.CustomException; +import com.example.solidconnection.mentor.domain.Mentor; +import com.example.solidconnection.mentor.domain.Mentoring; +import com.example.solidconnection.mentor.dto.MentoringResponse; +import com.example.solidconnection.mentor.repository.MentorRepository; +import com.example.solidconnection.mentor.repository.MentoringRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND; + +@Service +@RequiredArgsConstructor +public class MentoringQueryService { + + private final MentoringRepository mentoringRepository; + private final MentorRepository mentorRepository; + + @Transactional(readOnly = true) + public List getMentorings(Long siteUserId) { + Mentor mentor = mentorRepository.findBySiteUserId(siteUserId) + .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); + + List mentorings = mentoringRepository.findAllByMentorId(mentor.getId()); + + return mentorings.stream() + .map(MentoringResponse::from) + .collect(Collectors.toList()); + } +} From 6e299a393324603fdd4dcbe9856e24c03435b3a1 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Tue, 1 Jul 2025 11:21:20 +0900 Subject: [PATCH 03/33] =?UTF-8?q?feat:=20=EB=A9=98=ED=86=A0=EB=A7=81=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ErrorCode.java | 2 +- .../controller/MentoringController.java | 10 +++++++++ .../mentor/dto/MentoringCheckResponse.java | 10 +++++++++ .../service/MentoringCommandService.java | 22 ++++++++++++++++--- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/example/solidconnection/mentor/dto/MentoringCheckResponse.java diff --git a/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java b/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java index e6a0a3ed1..a7d989c84 100644 --- a/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java +++ b/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java @@ -109,7 +109,7 @@ public enum ErrorCode { ALREADY_MENTOR(HttpStatus.BAD_REQUEST.value(), "이미 멘토로 등록된 사용자입니다."), MENTOR_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 사용자는 멘토로 등록되어 있지 않습니다."), MENTORING_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 멘토링 신청을 찾을 수 없습니다."), - UNAUTHORIZED_MENTORING_CONFIRM(HttpStatus.FORBIDDEN.value(), "멘토링 승인 권한이 없습니다."), + UNAUTHORIZED_MENTORING(HttpStatus.FORBIDDEN.value(), "멘토링 권한이 없습니다."), MENTORING_ALREADY_CONFIRMED(HttpStatus.BAD_REQUEST.value(), "이미 승인 또는 거절된 멘토링입니다."), // general diff --git a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java index 2432cda75..9705c73ad 100644 --- a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java +++ b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java @@ -3,6 +3,7 @@ import com.example.solidconnection.common.resolver.AuthorizedUser; import com.example.solidconnection.mentor.dto.MentoringApplyRequest; import com.example.solidconnection.mentor.dto.MentoringApplyResponse; +import com.example.solidconnection.mentor.dto.MentoringCheckResponse; import com.example.solidconnection.mentor.dto.MentoringConfirmRequest; import com.example.solidconnection.mentor.dto.MentoringConfirmResponse; import com.example.solidconnection.mentor.dto.MentoringResponse; @@ -60,4 +61,13 @@ public ResponseEntity confirmMentoring( MentoringConfirmResponse response = mentoringCommandService.confirmMentoring(siteUser.getId(), mentoringId, mentoringConfirmRequest); return ResponseEntity.ok(response); } + + @PatchMapping("/{mentoring-id}/check") + public ResponseEntity checkMentoring( + @AuthorizedUser SiteUser siteUser, + @PathVariable("mentoring-id") Long mentoringId + ) { + MentoringCheckResponse response = mentoringCommandService.checkMentoring(siteUser.getId(), mentoringId); + return ResponseEntity.ok(response); + } } diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringCheckResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringCheckResponse.java new file mode 100644 index 000000000..2dbd8d53a --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringCheckResponse.java @@ -0,0 +1,10 @@ +package com.example.solidconnection.mentor.dto; + +public record MentoringCheckResponse( + Long mentoringId +) { + + public static MentoringCheckResponse from(Long mentoringId) { + return new MentoringCheckResponse(mentoringId); + } +} diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index 49b9e682a..8b836f467 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -6,6 +6,7 @@ import com.example.solidconnection.mentor.domain.Mentoring; import com.example.solidconnection.mentor.dto.MentoringApplyRequest; import com.example.solidconnection.mentor.dto.MentoringApplyResponse; +import com.example.solidconnection.mentor.dto.MentoringCheckResponse; import com.example.solidconnection.mentor.dto.MentoringConfirmRequest; import com.example.solidconnection.mentor.dto.MentoringConfirmResponse; import com.example.solidconnection.mentor.repository.MentorRepository; @@ -20,7 +21,7 @@ import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND; import static com.example.solidconnection.common.exception.ErrorCode.REJECTED_REASON_REQUIRED; import static com.example.solidconnection.common.exception.ErrorCode.SELF_MENTORING_NOT_ALLOWED; -import static com.example.solidconnection.common.exception.ErrorCode.UNAUTHORIZED_MENTORING_CONFIRM; +import static com.example.solidconnection.common.exception.ErrorCode.UNAUTHORIZED_MENTORING; @Service @RequiredArgsConstructor @@ -70,6 +71,21 @@ else if (mentoringConfirmRequest.status() == VerifyStatus.REJECTED) { return MentoringConfirmResponse.from(mentoring); } + @Transactional + public MentoringCheckResponse checkMentoring(Long siteUserId, Long mentoringId) { + Mentoring mentoring = mentoringRepository.findById(mentoringId) + .orElseThrow(() -> new CustomException(MENTORING_NOT_FOUND)); + + Mentor mentor = mentorRepository.findById(mentoring.getMentorId()) + .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); + + validateUnauthorizedMentoring(siteUserId, mentor); + + mentoring.check(); + + return MentoringCheckResponse.from(mentoring.getId()); + } + private void validateSelfMentoring(Long siteUserId, MentoringApplyRequest request) { if (siteUserId.equals(request.mentorId())) { throw new CustomException(SELF_MENTORING_NOT_ALLOWED); @@ -82,10 +98,10 @@ private void validateAlreadyMentor(Long siteUserId) { } } - // 멘토는 본인의 멘토링에 대해 confirm해야 한다. + // 멘토는 본인의 멘토링에 대해 confirm 및 check해야 한다. private void validateUnauthorizedMentoring(Long siteUserId, Mentor mentor) { if (!siteUserId.equals(mentor.getSiteUserId())) { - throw new CustomException(UNAUTHORIZED_MENTORING_CONFIRM); + throw new CustomException(UNAUTHORIZED_MENTORING); } } From 03c79e33ccb38b037cd05fbeca69b12321733a0e Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Tue, 1 Jul 2025 11:54:15 +0900 Subject: [PATCH 04/33] =?UTF-8?q?feat:=20=EB=A9=98=ED=86=A0=EB=A7=81=20?= =?UTF-8?q?=EC=8B=A0=EA=B7=9C=20=EC=8B=A0=EC=B2=AD=20=EA=B1=B4=EC=88=98=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentor/controller/MentoringController.java | 9 +++++++++ .../mentor/dto/MentoringCountResponse.java | 10 ++++++++++ .../mentor/repository/MentoringRepository.java | 1 + .../mentor/service/MentoringQueryService.java | 11 +++++++++++ 4 files changed, 31 insertions(+) create mode 100644 src/main/java/com/example/solidconnection/mentor/dto/MentoringCountResponse.java diff --git a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java index 9705c73ad..0b6af78e0 100644 --- a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java +++ b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java @@ -6,6 +6,7 @@ import com.example.solidconnection.mentor.dto.MentoringCheckResponse; import com.example.solidconnection.mentor.dto.MentoringConfirmRequest; import com.example.solidconnection.mentor.dto.MentoringConfirmResponse; +import com.example.solidconnection.mentor.dto.MentoringCountResponse; import com.example.solidconnection.mentor.dto.MentoringResponse; import com.example.solidconnection.mentor.service.MentoringCommandService; import com.example.solidconnection.mentor.service.MentoringQueryService; @@ -70,4 +71,12 @@ public ResponseEntity checkMentoring( MentoringCheckResponse response = mentoringCommandService.checkMentoring(siteUser.getId(), mentoringId); return ResponseEntity.ok(response); } + + @GetMapping("/check") + public ResponseEntity getNewMentoringsCount( + @AuthorizedUser SiteUser siteUser + ) { + MentoringCountResponse responses = mentoringQueryService.getNewMentoringsCount(siteUser.getId()); + return ResponseEntity.ok(responses); + } } diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringCountResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringCountResponse.java new file mode 100644 index 000000000..8ee02ac07 --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringCountResponse.java @@ -0,0 +1,10 @@ +package com.example.solidconnection.mentor.dto; + +public record MentoringCountResponse( + int mentoringCount +) { + + public static MentoringCountResponse from(int mentoringCount) { + return new MentoringCountResponse(mentoringCount); + } +} diff --git a/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java b/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java index fa20702d1..c3de98350 100644 --- a/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java +++ b/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java @@ -8,4 +8,5 @@ public interface MentoringRepository extends JpaRepository { List findAllByMentorId(Long mentorId); + int countByMentorIdAndCheckedAtIsNull(Long mentorId); } diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java index 4f325b9a2..f9ebebdb8 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java @@ -3,6 +3,7 @@ import com.example.solidconnection.common.exception.CustomException; import com.example.solidconnection.mentor.domain.Mentor; import com.example.solidconnection.mentor.domain.Mentoring; +import com.example.solidconnection.mentor.dto.MentoringCountResponse; import com.example.solidconnection.mentor.dto.MentoringResponse; import com.example.solidconnection.mentor.repository.MentorRepository; import com.example.solidconnection.mentor.repository.MentoringRepository; @@ -33,4 +34,14 @@ public List getMentorings(Long siteUserId) { .map(MentoringResponse::from) .collect(Collectors.toList()); } + + @Transactional(readOnly = true) + public MentoringCountResponse getNewMentoringsCount(Long siteUserId) { + Mentor mentor = mentorRepository.findBySiteUserId(siteUserId) + .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); + + int count = mentoringRepository.countByMentorIdAndCheckedAtIsNull(mentor.getId()); + + return MentoringCountResponse.from(count); + } } From e30dd3b0d7847c83aae3379935ae76a89fa01eaa Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Tue, 1 Jul 2025 12:50:54 +0900 Subject: [PATCH 05/33] =?UTF-8?q?chore:=20=EC=A0=84=EB=B0=98=EC=A0=81?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 통일성 있게 .ok(response) 사용 - 단일 객체는 단수형(response) 사용 --- .../mentor/controller/MentoringController.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java index 0b6af78e0..15d12a25c 100644 --- a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java +++ b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java @@ -13,7 +13,6 @@ import com.example.solidconnection.siteuser.domain.SiteUser; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; @@ -39,9 +38,7 @@ public ResponseEntity applyMentoring( @Valid @RequestBody MentoringApplyRequest mentoringApplyRequest ) { MentoringApplyResponse response = mentoringCommandService.applyMentoring(siteUser.getId(), mentoringApplyRequest); - return ResponseEntity - .status(HttpStatus.OK) - .body(response); + return ResponseEntity.ok(response); } // TODO: RequireRoleAccess 어노테이션 추가 필요 @@ -76,7 +73,7 @@ public ResponseEntity checkMentoring( public ResponseEntity getNewMentoringsCount( @AuthorizedUser SiteUser siteUser ) { - MentoringCountResponse responses = mentoringQueryService.getNewMentoringsCount(siteUser.getId()); - return ResponseEntity.ok(responses); + MentoringCountResponse response = mentoringQueryService.getNewMentoringsCount(siteUser.getId()); + return ResponseEntity.ok(response); } } From 37c7bf6aeecfcb4dae4dd868ad3482064bfd78d4 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Tue, 1 Jul 2025 14:03:36 +0900 Subject: [PATCH 06/33] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EA=B0=9C=ED=96=89=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solidconnection/mentor/dto/MentoringApplyRequest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyRequest.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyRequest.java index be72c412b..73c18e250 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyRequest.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyRequest.java @@ -5,7 +5,6 @@ public record MentoringApplyRequest( @NotNull(message = "멘토 id를 입력해주세요.") - Long mentorId ) { } From 95df8a34ac7a6257a1502892d9a5c70957e2cb49 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 11:32:54 +0900 Subject: [PATCH 07/33] =?UTF-8?q?chore:=20rebase=20=EC=8B=9C=20=EB=B0=98?= =?UTF-8?q?=EC=98=81=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solidconnection/mentor/domain/Mentor.java | 4 ++++ .../solidconnection/mentor/domain/Mentoring.java | 16 ++++++++++++++++ .../mentor/dto/MentoringConfirmRequest.java | 2 +- .../mentor/dto/MentoringResponse.java | 2 +- .../mentor/repository/MentorRepository.java | 10 ++++++++++ .../mentor/service/MentoringCommandService.java | 9 ++++----- 6 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java diff --git a/src/main/java/com/example/solidconnection/mentor/domain/Mentor.java b/src/main/java/com/example/solidconnection/mentor/domain/Mentor.java index 81f9d6177..87fe963a1 100644 --- a/src/main/java/com/example/solidconnection/mentor/domain/Mentor.java +++ b/src/main/java/com/example/solidconnection/mentor/domain/Mentor.java @@ -45,4 +45,8 @@ public class Mentor { @OneToMany(mappedBy = "mentor", cascade = CascadeType.ALL, orphanRemoval = true) private List channels = new ArrayList<>(); + + public void increaseMenteeCount() { + this.menteeCount++; + } } diff --git a/src/main/java/com/example/solidconnection/mentor/domain/Mentoring.java b/src/main/java/com/example/solidconnection/mentor/domain/Mentoring.java index 38811a014..55c3d06be 100644 --- a/src/main/java/com/example/solidconnection/mentor/domain/Mentoring.java +++ b/src/main/java/com/example/solidconnection/mentor/domain/Mentoring.java @@ -12,6 +12,7 @@ import jakarta.persistence.PrePersist; import lombok.AccessLevel; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; @@ -24,6 +25,7 @@ @Entity @Getter +@Builder @EntityListeners(AuditingEntityListener.class) @DynamicInsert @AllArgsConstructor @@ -60,4 +62,18 @@ public class Mentoring { public void onPrePersist() { this.createdAt = ZonedDateTime.now(UTC).truncatedTo(MICROS); // 나노초 6자리 까지만 저장 } + + public void confirm(VerifyStatus status, String rejectedReason) { + this.verifyStatus = status; + this.rejectedReason = rejectedReason; + this.confirmedAt = ZonedDateTime.now(UTC).truncatedTo(MICROS); + + if (this.checkedAt == null) { + this.checkedAt = this.confirmedAt; + } + } + + public void check() { + this.checkedAt = ZonedDateTime.now(UTC).truncatedTo(MICROS); + } } diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java index cbd08b375..2995b9f8d 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java @@ -1,6 +1,6 @@ package com.example.solidconnection.mentor.dto; -import com.example.solidconnection.application.domain.VerifyStatus; +import com.example.solidconnection.common.VerifyStatus; import jakarta.validation.constraints.NotNull; public record MentoringConfirmRequest( diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java index 1db31a4b9..d6ed86840 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java @@ -1,6 +1,6 @@ package com.example.solidconnection.mentor.dto; -import com.example.solidconnection.application.domain.VerifyStatus; +import com.example.solidconnection.common.VerifyStatus; import com.example.solidconnection.mentor.domain.Mentoring; import java.time.ZonedDateTime; diff --git a/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java b/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java new file mode 100644 index 000000000..5270f1559 --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java @@ -0,0 +1,10 @@ +package com.example.solidconnection.mentor.repository; + +import com.example.solidconnection.mentor.domain.Mentor; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface MentorRepository extends JpaRepository { + Optional findBySiteUserId(Long siteUserId); +} diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index 8b836f467..e22b9931e 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -1,6 +1,6 @@ package com.example.solidconnection.mentor.service; -import com.example.solidconnection.application.domain.VerifyStatus; +import com.example.solidconnection.common.VerifyStatus; import com.example.solidconnection.common.exception.CustomException; import com.example.solidconnection.mentor.domain.Mentor; import com.example.solidconnection.mentor.domain.Mentoring; @@ -60,10 +60,9 @@ public MentoringConfirmResponse confirmMentoring(Long siteUserId, Long mentoring if (mentoringConfirmRequest.status() == VerifyStatus.APPROVED) { mentor.increaseMenteeCount(); } - else if (mentoringConfirmRequest.status() == VerifyStatus.REJECTED) { - if (mentoringConfirmRequest.rejectedReason() == null || mentoringConfirmRequest.rejectedReason().isBlank()) { - throw new CustomException(REJECTED_REASON_REQUIRED); - } + else if (mentoringConfirmRequest.status() == VerifyStatus.REJECTED + && (mentoringConfirmRequest.rejectedReason() == null || mentoringConfirmRequest.rejectedReason().isBlank())) { + throw new CustomException(REJECTED_REASON_REQUIRED); } mentoring.confirm(mentoringConfirmRequest.status(), mentoringConfirmRequest.rejectedReason()); From 11d1b32f1ee1d6cb0a4de527d9f4907e6ccf8871 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 12:10:11 +0900 Subject: [PATCH 08/33] =?UTF-8?q?chore:=20=EB=A9=98=ED=86=A0=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=A1=9C=EC=A7=81=EC=97=90=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EB=B6=80=EC=97=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentor/controller/MentoringController.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java index 15d12a25c..856ae794f 100644 --- a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java +++ b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java @@ -10,6 +10,8 @@ import com.example.solidconnection.mentor.dto.MentoringResponse; import com.example.solidconnection.mentor.service.MentoringCommandService; import com.example.solidconnection.mentor.service.MentoringQueryService; +import com.example.solidconnection.security.annotation.RequireRoleAccess; +import com.example.solidconnection.siteuser.domain.Role; import com.example.solidconnection.siteuser.domain.SiteUser; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -41,7 +43,7 @@ public ResponseEntity applyMentoring( return ResponseEntity.ok(response); } - // TODO: RequireRoleAccess 어노테이션 추가 필요 + @RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR}) @GetMapping("/apply") public ResponseEntity> getMentorings( @AuthorizedUser SiteUser siteUser @@ -50,6 +52,7 @@ public ResponseEntity> getMentorings( return ResponseEntity.ok(responses); } + @RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR}) @PatchMapping("/{mentoring-id}/apply") public ResponseEntity confirmMentoring( @AuthorizedUser SiteUser siteUser, @@ -60,6 +63,7 @@ public ResponseEntity confirmMentoring( return ResponseEntity.ok(response); } + @RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR}) @PatchMapping("/{mentoring-id}/check") public ResponseEntity checkMentoring( @AuthorizedUser SiteUser siteUser, @@ -69,6 +73,7 @@ public ResponseEntity checkMentoring( return ResponseEntity.ok(response); } + @RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR}) @GetMapping("/check") public ResponseEntity getNewMentoringsCount( @AuthorizedUser SiteUser siteUser From 77896f175da2099730a795dc0fe0f36988453a81 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 13:19:22 +0900 Subject: [PATCH 09/33] =?UTF-8?q?test:=20=EB=A9=98=ED=86=A0=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=ED=94=BD=EC=8A=A4=EC=B2=98=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentor/fixture/MentorFixture.java | 21 +++++ .../mentor/fixture/MentorFixtureBuilder.java | 68 ++++++++++++++++ .../mentor/fixture/MentoringFixture.java | 78 +++++++++++++++++++ .../fixture/MentoringFixtureBuilder.java | 77 ++++++++++++++++++ 4 files changed, 244 insertions(+) create mode 100644 src/test/java/com/example/solidconnection/mentor/fixture/MentorFixture.java create mode 100644 src/test/java/com/example/solidconnection/mentor/fixture/MentorFixtureBuilder.java create mode 100644 src/test/java/com/example/solidconnection/mentor/fixture/MentoringFixture.java create mode 100644 src/test/java/com/example/solidconnection/mentor/fixture/MentoringFixtureBuilder.java diff --git a/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixture.java b/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixture.java new file mode 100644 index 000000000..2422c2e91 --- /dev/null +++ b/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixture.java @@ -0,0 +1,21 @@ +package com.example.solidconnection.mentor.fixture; + +import com.example.solidconnection.mentor.domain.Mentor; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.test.context.TestComponent; + +@TestComponent +@RequiredArgsConstructor +public class MentorFixture { + + private final MentorFixtureBuilder mentorFixtureBuilder; + + public Mentor 멘토(Long siteUserId, Long universityId) { + return mentorFixtureBuilder.mentor() + .siteUserId(siteUserId) + .universityId(universityId) + .introduction("멘토 소개") + .passTip("멘토 팁") + .create(); + } +} diff --git a/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixtureBuilder.java b/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixtureBuilder.java new file mode 100644 index 000000000..2d7a32f78 --- /dev/null +++ b/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixtureBuilder.java @@ -0,0 +1,68 @@ +package com.example.solidconnection.mentor.fixture; + +import com.example.solidconnection.mentor.domain.Mentor; +import com.example.solidconnection.mentor.repository.MentorRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.test.context.TestComponent; + +@TestComponent +@RequiredArgsConstructor +public class MentorFixtureBuilder { + + private final MentorRepository mentorRepository; + + private int menteeCount = 0; + private boolean hasBadge = false; + private String introduction; + private String passTip; + private Long siteUserId; + private Long universityId; + + public MentorFixtureBuilder mentor() { + return new MentorFixtureBuilder(mentorRepository); + } + + public MentorFixtureBuilder menteeCount(int menteeCount) { + this.menteeCount = menteeCount; + return this; + } + + public MentorFixtureBuilder hasBadge(boolean hasBadge) { + this.hasBadge = hasBadge; + return this; + } + + public MentorFixtureBuilder introduction(String introduction) { + this.introduction = introduction; + return this; + } + + public MentorFixtureBuilder passTip(String passTip) { + this.passTip = passTip; + return this; + } + + public MentorFixtureBuilder siteUserId(Long siteUserId) { + this.siteUserId = siteUserId; + return this; + } + + public MentorFixtureBuilder universityId(Long universityId) { + this.universityId = universityId; + return this; + } + + public Mentor create() { + Mentor mentor = new Mentor( + null, + menteeCount, + hasBadge, + introduction, + passTip, + siteUserId, + universityId, + null + ); + return mentorRepository.save(mentor); + } +} diff --git a/src/test/java/com/example/solidconnection/mentor/fixture/MentoringFixture.java b/src/test/java/com/example/solidconnection/mentor/fixture/MentoringFixture.java new file mode 100644 index 000000000..8b1dc5ec6 --- /dev/null +++ b/src/test/java/com/example/solidconnection/mentor/fixture/MentoringFixture.java @@ -0,0 +1,78 @@ +package com.example.solidconnection.mentor.fixture; + +import com.example.solidconnection.common.VerifyStatus; +import com.example.solidconnection.mentor.domain.Mentoring; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.test.context.TestComponent; + +import java.time.ZonedDateTime; + +import static java.time.ZoneOffset.UTC; +import static java.time.temporal.ChronoUnit.MICROS; + +@TestComponent +@RequiredArgsConstructor +public class MentoringFixture { + + private final MentoringFixtureBuilder mentoringFixtureBuilder; + + public Mentoring 대기중_멘토링(long mentorId, long menteeId) { + return mentoringFixtureBuilder.mentoring() + .mentorId(mentorId) + .menteeId(menteeId) + .create(); + } + + public Mentoring 승인된_멘토링(long mentorId, long menteeId) { + ZonedDateTime now = getCurrentTime(); + return mentoringFixtureBuilder.mentoring() + .mentorId(mentorId) + .menteeId(menteeId) + .verifyStatus(VerifyStatus.APPROVED) + .confirmedAt(now) + .checkedAt(now) + .create(); + } + + public Mentoring 거절된_멘토링(long mentorId, long menteeId, String rejectedReason) { + ZonedDateTime now = getCurrentTime(); + return mentoringFixtureBuilder.mentoring() + .mentorId(mentorId) + .menteeId(menteeId) + .verifyStatus(VerifyStatus.REJECTED) + .rejectedReason(rejectedReason) + .confirmedAt(now) + .checkedAt(now) + .create(); + } + + public Mentoring 확인되지_않은_멘토링(long mentorId, long menteeId) { + return mentoringFixtureBuilder.mentoring() + .mentorId(mentorId) + .menteeId(menteeId) + .checkedAt(null) + .create(); + } + + public Mentoring 멘토링( + long mentorId, + long menteeId, + VerifyStatus status, + String rejectedReason, + ZonedDateTime confirmedAt, + ZonedDateTime checkedAt) { + + return mentoringFixtureBuilder.mentoring() + .mentorId(mentorId) + .menteeId(menteeId) + .verifyStatus(status) + .rejectedReason(rejectedReason) + .confirmedAt(confirmedAt) + .checkedAt(checkedAt) + .create(); + } + + private ZonedDateTime getCurrentTime() { + return ZonedDateTime.now(UTC).truncatedTo(MICROS); + } +} diff --git a/src/test/java/com/example/solidconnection/mentor/fixture/MentoringFixtureBuilder.java b/src/test/java/com/example/solidconnection/mentor/fixture/MentoringFixtureBuilder.java new file mode 100644 index 000000000..0c579de5b --- /dev/null +++ b/src/test/java/com/example/solidconnection/mentor/fixture/MentoringFixtureBuilder.java @@ -0,0 +1,77 @@ +package com.example.solidconnection.mentor.fixture; + +import com.example.solidconnection.common.VerifyStatus; +import com.example.solidconnection.mentor.domain.Mentoring; +import com.example.solidconnection.mentor.repository.MentoringRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.test.context.TestComponent; + +import java.time.ZonedDateTime; + +@TestComponent +@RequiredArgsConstructor +public class MentoringFixtureBuilder { + + private final MentoringRepository mentoringRepository; + + private ZonedDateTime createdAt; + private ZonedDateTime confirmedAt; + private ZonedDateTime checkedAt; + private VerifyStatus verifyStatus = VerifyStatus.PENDING; + private String rejectedReason; + private long mentorId; + private long menteeId; + + public MentoringFixtureBuilder mentoring() { + return new MentoringFixtureBuilder(mentoringRepository); + } + + public MentoringFixtureBuilder createdAt(ZonedDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + public MentoringFixtureBuilder confirmedAt(ZonedDateTime confirmedAt) { + this.confirmedAt = confirmedAt; + return this; + } + + public MentoringFixtureBuilder checkedAt(ZonedDateTime checkedAt) { + this.checkedAt = checkedAt; + return this; + } + + public MentoringFixtureBuilder verifyStatus(VerifyStatus verifyStatus) { + this.verifyStatus = verifyStatus; + return this; + } + + public MentoringFixtureBuilder rejectedReason(String rejectedReason) { + this.rejectedReason = rejectedReason; + return this; + } + + public MentoringFixtureBuilder mentorId(long mentorId) { + this.mentorId = mentorId; + return this; + } + + public MentoringFixtureBuilder menteeId(long menteeId) { + this.menteeId = menteeId; + return this; + } + + public Mentoring create() { + Mentoring mentoring = new Mentoring( + null, + createdAt, + confirmedAt, + checkedAt, + verifyStatus, + rejectedReason, + mentorId, + menteeId + ); + return mentoringRepository.save(mentoring); + } +} From e049bbb50e19c86fde44098517e19a54f59d9ef5 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 13:43:19 +0900 Subject: [PATCH 10/33] =?UTF-8?q?test:=20=EB=A9=98=ED=86=A0=EB=A7=81=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MentoringQueryServiceTest.java | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java diff --git a/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java b/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java new file mode 100644 index 000000000..2e988e535 --- /dev/null +++ b/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java @@ -0,0 +1,134 @@ +package com.example.solidconnection.mentor.service; + +import com.example.solidconnection.common.exception.CustomException; +import com.example.solidconnection.mentor.domain.Mentor; +import com.example.solidconnection.mentor.domain.Mentoring; +import com.example.solidconnection.mentor.dto.MentoringCountResponse; +import com.example.solidconnection.mentor.dto.MentoringResponse; +import com.example.solidconnection.mentor.fixture.MentorFixture; +import com.example.solidconnection.mentor.fixture.MentoringFixture; +import com.example.solidconnection.siteuser.domain.SiteUser; +import com.example.solidconnection.siteuser.fixture.SiteUserFixture; +import com.example.solidconnection.support.TestContainerSpringBootTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; + +@TestContainerSpringBootTest +@DisplayName("멘토링 조회 서비스 테스트") +class MentoringQueryServiceTest { + + @Autowired + private MentoringQueryService mentoringQueryService; + + @Autowired + private SiteUserFixture siteUserFixture; + + @Autowired + private MentorFixture mentorFixture; + + @Autowired + private MentoringFixture mentoringFixture; + + private SiteUser mentorUser; + private SiteUser menteeUser; + private Mentor mentor; + + @BeforeEach + void setUp() { + mentorUser = siteUserFixture.멘토(1, "mentor1"); + menteeUser = siteUserFixture.사용자(2, "mentee1"); + mentor = mentorFixture.멘토(mentorUser.getId(), 1L); + } + + @Nested + class 멘토링_목록_조회_테스트 { + + @Test + void 멘토의_모든_멘토링을_조회한다() { + // given + Mentoring mentoring1 = mentoringFixture.대기중_멘토링(mentor.getId(), menteeUser.getId()); + Mentoring mentoring2 = mentoringFixture.승인된_멘토링(mentor.getId(), menteeUser.getId()); + Mentoring mentoring3 = mentoringFixture.거절된_멘토링(mentor.getId(), menteeUser.getId(), "거절 사유"); + + // when + List responses = mentoringQueryService.getMentorings(mentorUser.getId()); + + // then + assertAll( + () -> assertThat(responses).hasSize(3), + () -> assertThat(responses).extracting(MentoringResponse::id) + .containsExactlyInAnyOrder( + mentoring1.getId(), + mentoring2.getId(), + mentoring3.getId() + ) + ); + } + + @Test + void 멘티가_멘토링을_조회하면_예외를_반환한다() { + // when & then + assertThatThrownBy(() -> mentoringQueryService.getMentorings(menteeUser.getId())) + .isInstanceOf(CustomException.class) + .hasMessage(MENTOR_NOT_FOUND.getMessage()); + } + + @Test + void 멘토링이_없는_경우_빈_리스트를_반환한다() { + // when + List responses = mentoringQueryService.getMentorings(mentorUser.getId()); + + // then + assertThat(responses).isEmpty(); + } + } + + @Nested + class 새_멘토링_개수_조회_테스트 { + + @Test + void 확인되지_않은_멘토링_개수를_반환한다() { + // given + mentoringFixture.확인되지_않은_멘토링(mentor.getId(), menteeUser.getId()); + mentoringFixture.확인되지_않은_멘토링(mentor.getId(), menteeUser.getId()); + mentoringFixture.승인된_멘토링(mentor.getId(), menteeUser.getId()); + + // when + MentoringCountResponse response = mentoringQueryService.getNewMentoringsCount(mentorUser.getId()); + + // then + assertThat(response.mentoringCount()).isEqualTo(2); + } + + @Test + void 확인되지_않은_멘토링이_없으면_0을_반환한다() { + // given + mentoringFixture.승인된_멘토링(mentor.getId(), menteeUser.getId()); + + // when + MentoringCountResponse response = mentoringQueryService.getNewMentoringsCount(mentorUser.getId()); + + // then + assertThat(response.mentoringCount()).isZero(); + } + + @Test + void 멘티가_멘토링_개수를_조회하면_예외를_반환한다() { + // when & then + assertThatThrownBy(() -> + mentoringQueryService.getNewMentoringsCount(menteeUser.getId())) + .isInstanceOf(CustomException.class) + .hasMessage(MENTOR_NOT_FOUND.getMessage()); + } + } +} From 564135a7cd047c437a517487b7ccca5bae763eb7 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 14:29:38 +0900 Subject: [PATCH 11/33] =?UTF-8?q?fix:=20=EC=9D=B4=EB=AF=B8=20=EB=A9=98?= =?UTF-8?q?=ED=86=A0=EC=9D=B8=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 파라미터는 siteUserId이므로 이를 통해 멘토 존재 여부를 구해야 함. --- .../solidconnection/mentor/service/MentoringCommandService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index e22b9931e..90d4a247b 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -92,7 +92,7 @@ private void validateSelfMentoring(Long siteUserId, MentoringApplyRequest reques } private void validateAlreadyMentor(Long siteUserId) { - if (mentorRepository.existsById(siteUserId)) { + if (mentorRepository.existsBySiteUserId(siteUserId)) { throw new CustomException(ALREADY_MENTOR); } } From c0c96b22a3c47ffcf486283ca63475614f37d961 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 14:37:05 +0900 Subject: [PATCH 12/33] =?UTF-8?q?chore:=20=EB=A9=98=ED=86=A0=EA=B0=80=20?= =?UTF-8?q?=EC=9E=90=EA=B8=B0=20=EC=9E=90=EC=8B=A0=EC=97=90=20=EB=8C=80?= =?UTF-8?q?=ED=95=B4=20=EB=A9=98=ED=86=A0=EB=A7=81=EC=9D=84=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=ED=95=98=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 멘토링을 신청하는 사용자가 멘토인지 여부로 검증 가능 --- .../solidconnection/common/exception/ErrorCode.java | 1 - .../mentor/repository/MentorRepository.java | 1 + .../mentor/service/MentoringCommandService.java | 8 -------- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java b/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java index a7d989c84..ee3f8e112 100644 --- a/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java +++ b/src/main/java/com/example/solidconnection/common/exception/ErrorCode.java @@ -105,7 +105,6 @@ public enum ErrorCode { DATA_INTEGRITY_VIOLATION(HttpStatus.CONFLICT.value(), "데이터베이스 무결성 제약조건 위반이 발생했습니다."), // mentor - SELF_MENTORING_NOT_ALLOWED(HttpStatus.BAD_REQUEST.value(), "자기 자신을 멘토로 설정할 수 없습니다."), ALREADY_MENTOR(HttpStatus.BAD_REQUEST.value(), "이미 멘토로 등록된 사용자입니다."), MENTOR_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 사용자는 멘토로 등록되어 있지 않습니다."), MENTORING_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 멘토링 신청을 찾을 수 없습니다."), diff --git a/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java b/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java index 5270f1559..7f84e3b8e 100644 --- a/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java +++ b/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java @@ -7,4 +7,5 @@ public interface MentorRepository extends JpaRepository { Optional findBySiteUserId(Long siteUserId); + boolean existsBySiteUserId(Long siteUserId); } diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index 90d4a247b..ad8029561 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -20,7 +20,6 @@ import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_NOT_FOUND; import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND; import static com.example.solidconnection.common.exception.ErrorCode.REJECTED_REASON_REQUIRED; -import static com.example.solidconnection.common.exception.ErrorCode.SELF_MENTORING_NOT_ALLOWED; import static com.example.solidconnection.common.exception.ErrorCode.UNAUTHORIZED_MENTORING; @Service @@ -32,7 +31,6 @@ public class MentoringCommandService { @Transactional public MentoringApplyResponse applyMentoring(Long siteUserId, MentoringApplyRequest mentoringApplyRequest) { - validateSelfMentoring(siteUserId, mentoringApplyRequest); validateAlreadyMentor(siteUserId); Mentoring mentoring = Mentoring.builder() @@ -85,12 +83,6 @@ public MentoringCheckResponse checkMentoring(Long siteUserId, Long mentoringId) return MentoringCheckResponse.from(mentoring.getId()); } - private void validateSelfMentoring(Long siteUserId, MentoringApplyRequest request) { - if (siteUserId.equals(request.mentorId())) { - throw new CustomException(SELF_MENTORING_NOT_ALLOWED); - } - } - private void validateAlreadyMentor(Long siteUserId) { if (mentorRepository.existsBySiteUserId(siteUserId)) { throw new CustomException(ALREADY_MENTOR); From c4de14013a492a9c48e747ea54b4b6e95a9f6708 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 14:46:33 +0900 Subject: [PATCH 13/33] =?UTF-8?q?chore:=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentor/fixture/MentoringFixture.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/test/java/com/example/solidconnection/mentor/fixture/MentoringFixture.java b/src/test/java/com/example/solidconnection/mentor/fixture/MentoringFixture.java index 8b1dc5ec6..3d5896662 100644 --- a/src/test/java/com/example/solidconnection/mentor/fixture/MentoringFixture.java +++ b/src/test/java/com/example/solidconnection/mentor/fixture/MentoringFixture.java @@ -54,24 +54,6 @@ public class MentoringFixture { .create(); } - public Mentoring 멘토링( - long mentorId, - long menteeId, - VerifyStatus status, - String rejectedReason, - ZonedDateTime confirmedAt, - ZonedDateTime checkedAt) { - - return mentoringFixtureBuilder.mentoring() - .mentorId(mentorId) - .menteeId(menteeId) - .verifyStatus(status) - .rejectedReason(rejectedReason) - .confirmedAt(confirmedAt) - .checkedAt(checkedAt) - .create(); - } - private ZonedDateTime getCurrentTime() { return ZonedDateTime.now(UTC).truncatedTo(MICROS); } From 21198fd8fe50ea3056e2fb8b8312be9e128d20d2 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 14:47:07 +0900 Subject: [PATCH 14/33] =?UTF-8?q?test:=20=EB=A9=98=ED=86=A0=EB=A7=81=20CUD?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MentoringCommandServiceTest.java | 246 ++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java diff --git a/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java b/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java new file mode 100644 index 000000000..4f30882e4 --- /dev/null +++ b/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java @@ -0,0 +1,246 @@ +package com.example.solidconnection.mentor.service; + +import com.example.solidconnection.common.VerifyStatus; +import com.example.solidconnection.common.exception.CustomException; +import com.example.solidconnection.mentor.domain.Mentor; +import com.example.solidconnection.mentor.domain.Mentoring; +import com.example.solidconnection.mentor.dto.MentoringApplyRequest; +import com.example.solidconnection.mentor.dto.MentoringApplyResponse; +import com.example.solidconnection.mentor.dto.MentoringCheckResponse; +import com.example.solidconnection.mentor.dto.MentoringConfirmRequest; +import com.example.solidconnection.mentor.dto.MentoringConfirmResponse; +import com.example.solidconnection.mentor.fixture.MentorFixture; +import com.example.solidconnection.mentor.fixture.MentoringFixture; +import com.example.solidconnection.mentor.repository.MentorRepository; +import com.example.solidconnection.mentor.repository.MentoringRepository; +import com.example.solidconnection.siteuser.domain.SiteUser; +import com.example.solidconnection.siteuser.fixture.SiteUserFixture; +import com.example.solidconnection.support.TestContainerSpringBootTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import static com.example.solidconnection.common.exception.ErrorCode.ALREADY_MENTOR; +import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_ALREADY_CONFIRMED; +import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_NOT_FOUND; +import static com.example.solidconnection.common.exception.ErrorCode.REJECTED_REASON_REQUIRED; +import static com.example.solidconnection.common.exception.ErrorCode.UNAUTHORIZED_MENTORING; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; +@TestContainerSpringBootTest +@DisplayName("멘토링 CUD 서비스 테스트") +class MentoringCommandServiceTest { + + @Autowired + private MentoringCommandService mentoringCommandService; + + @Autowired + private MentorRepository mentorRepository; + + @Autowired + private MentoringRepository mentoringRepository; + + @Autowired + private SiteUserFixture siteUserFixture; + + @Autowired + private MentorFixture mentorFixture; + + @Autowired + private MentoringFixture mentoringFixture; + + private SiteUser mentorUser1; + private SiteUser mentorUser2; + + private SiteUser menteeUser; + private Mentor mentor1; + private Mentor mentor2; + + @BeforeEach + void setUp() { + mentorUser1 = siteUserFixture.멘토(1, "mentor1"); + menteeUser = siteUserFixture.사용자(2, "mentee1"); + mentorUser2 = siteUserFixture.멘토(3, "mentor2"); + + mentor1 = mentorFixture.멘토(mentorUser1.getId(), 1L); + mentor2 = mentorFixture.멘토(mentorUser2.getId(), 2L); + } + + @Nested + class 멘토링_신청_테스트 { + + @Test + void 멘토링을_성공적으로_신청한다() { + // given + MentoringApplyRequest request = new MentoringApplyRequest(mentor1.getId()); + + // when + MentoringApplyResponse response = mentoringCommandService.applyMentoring(menteeUser.getId(), request); + + // then + Mentoring mentoring = mentoringRepository.findById(response.mentoringId()).orElseThrow(); + + assertAll( + () -> assertThat(mentoring.getMentorId()).isEqualTo(mentor1.getId()), + () -> assertThat(mentoring.getMenteeId()).isEqualTo(menteeUser.getId()), + () -> assertThat(mentoring.getVerifyStatus()).isEqualTo(VerifyStatus.PENDING) + ); + } + + @Test + void 이미_멘토인_사용자가_신청시_예외를_반환한다() { + // given + MentoringApplyRequest request = new MentoringApplyRequest(mentor2.getId()); + + // when & then + assertThatThrownBy(() -> + mentoringCommandService.applyMentoring(mentorUser1.getId(), request)) + .isInstanceOf(CustomException.class) + .hasMessage(ALREADY_MENTOR.getMessage()); + } + } + + @Nested + class 멘토링_승인_거절_테스트 { + + @Test + void 멘토링을_성공적으로_승인한다() { + // given + Mentoring mentoring = mentoringFixture.대기중_멘토링(mentor1.getId(), menteeUser.getId()); + MentoringConfirmRequest request = new MentoringConfirmRequest(VerifyStatus.APPROVED, null); + int beforeMenteeCount = mentor1.getMenteeCount(); + + // when + MentoringConfirmResponse response = mentoringCommandService.confirmMentoring(mentorUser1.getId(), mentoring.getId(), request); + + // then + Mentoring confirmedMentoring = mentoringRepository.findById(response.mentoringId()).orElseThrow(); + Mentor mentor = mentorRepository.findById(mentor1.getId()).orElseThrow(); + + assertAll( + () -> assertThat(confirmedMentoring.getVerifyStatus()).isEqualTo(VerifyStatus.APPROVED), + () -> assertThat(confirmedMentoring.getConfirmedAt()).isNotNull(), + () -> assertThat(confirmedMentoring.getCheckedAt()).isNotNull(), + () -> assertThat(mentor.getMenteeCount()).isEqualTo(beforeMenteeCount + 1) + ); + } + + @Test + void 멘토링을_성공적으로_거절한다() { + // given + Mentoring mentoring = mentoringFixture.대기중_멘토링(mentor1.getId(), menteeUser.getId()); + String rejectedReason = "멘토링 거절 사유"; + MentoringConfirmRequest request = new MentoringConfirmRequest(VerifyStatus.REJECTED, rejectedReason); + int beforeMenteeCount = mentor1.getMenteeCount(); + + // when + MentoringConfirmResponse response = mentoringCommandService.confirmMentoring(mentorUser1.getId(), mentoring.getId(), request); + + // then + Mentoring confirmedMentoring = mentoringRepository.findById(response.mentoringId()).orElseThrow(); + Mentor mentor = mentorRepository.findById(mentor1.getId()).orElseThrow(); + + assertAll( + () -> assertThat(confirmedMentoring.getVerifyStatus()).isEqualTo(VerifyStatus.REJECTED), + () -> assertThat(confirmedMentoring.getRejectedReason()).isEqualTo(rejectedReason), + () -> assertThat(confirmedMentoring.getConfirmedAt()).isNotNull(), + () -> assertThat(confirmedMentoring.getCheckedAt()).isNotNull(), + () -> assertThat(mentor.getMenteeCount()).isEqualTo(beforeMenteeCount) + ); + } + + @Test + void 거절_시_사유가_없으면_예외를_반환한다() { + // given + Mentoring mentoring = mentoringFixture.대기중_멘토링(mentor1.getId(), menteeUser.getId()); + MentoringConfirmRequest request = new MentoringConfirmRequest(VerifyStatus.REJECTED, null); + + // when & then + assertThatThrownBy(() -> + mentoringCommandService.confirmMentoring(mentorUser1.getId(), mentoring.getId(), request)) + .isInstanceOf(CustomException.class) + .hasMessage(REJECTED_REASON_REQUIRED.getMessage()); + } + + @Test + void 다른_멘토의_멘토링을_승인할_수_없다() { + // given + Mentoring mentoring = mentoringFixture.대기중_멘토링(mentor1.getId(), menteeUser.getId()); + MentoringConfirmRequest request = new MentoringConfirmRequest(VerifyStatus.APPROVED, null); + + // when & then + assertThatThrownBy(() -> + mentoringCommandService.confirmMentoring(mentorUser2.getId(), mentoring.getId(), request)) + .isInstanceOf(CustomException.class) + .hasMessage(UNAUTHORIZED_MENTORING.getMessage()); + } + + @Test + void 이미_처리된_멘토링은_다시_승인할_수_없다() { + // given + Mentoring mentoring = mentoringFixture.승인된_멘토링(mentor1.getId(), menteeUser.getId()); + MentoringConfirmRequest request = new MentoringConfirmRequest(VerifyStatus.APPROVED, null); + + // when & then + assertThatThrownBy(() -> + mentoringCommandService.confirmMentoring(mentorUser1.getId(), mentoring.getId(), request)) + .isInstanceOf(CustomException.class) + .hasMessage(MENTORING_ALREADY_CONFIRMED.getMessage()); + } + + @Test + void 존재하지_않는_멘토링_아이디로_요청시_예외를_반환한다() { + // given + MentoringConfirmRequest request = new MentoringConfirmRequest(VerifyStatus.APPROVED, null); + Long invalidMentoringId = 9999L; + + // when & then + assertThatThrownBy(() -> mentoringCommandService.confirmMentoring(mentorUser1.getId(), invalidMentoringId, request)) + .isInstanceOf(CustomException.class) + .hasMessage(MENTORING_NOT_FOUND.getMessage()); + } + } + + @Nested + class 멘토링_확인_테스트 { + + @Test + void 멘토링을_성공적으로_확인_처리한다() { + // given + Mentoring mentoring = mentoringFixture.확인되지_않은_멘토링(mentor1.getId(), menteeUser.getId()); + + // when + MentoringCheckResponse response = mentoringCommandService.checkMentoring(mentorUser1.getId(), mentoring.getId()); + + // then + Mentoring checked = mentoringRepository.findById(response.mentoringId()).orElseThrow(); + + assertThat(checked.getCheckedAt()).isNotNull(); + } + + @Test + void 다른_멘토의_멘토링은_확인할_수_없다() { + // given + Mentoring mentoring = mentoringFixture.확인되지_않은_멘토링(mentor1.getId(), menteeUser.getId()); + + // when & then + assertThatThrownBy(() -> mentoringCommandService.checkMentoring(mentorUser2.getId(), mentoring.getId())) + .isInstanceOf(CustomException.class) + .hasMessage(UNAUTHORIZED_MENTORING.getMessage()); + } + + @Test + void 존재하지_않는_멘토링_아이디로_요청시_예외를_반환한다() { + // given + Long invalidMentoringId = 9999L; + + // when & then + assertThatThrownBy(() -> mentoringCommandService.checkMentoring(mentorUser1.getId(), invalidMentoringId)) + .isInstanceOf(CustomException.class) + .hasMessage(MENTORING_NOT_FOUND.getMessage()); + } + } +} From b8c9e9ccce164deaed57cac522ba8b33849632e6 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 19:08:50 +0900 Subject: [PATCH 15/33] =?UTF-8?q?refactor:=20List=20=EC=9E=90=EC=B2=B4?= =?UTF-8?q?=EB=A5=BC=20Response=EB=A1=9C=20=EB=A6=AC=ED=84=B4=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentor/controller/MentoringController.java | 5 +++-- .../mentor/dto/MentoringListResponse.java | 11 +++++++++++ .../mentor/service/MentoringQueryService.java | 11 ++++++----- .../mentor/service/MentoringQueryServiceTest.java | 13 ++++++------- 4 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/example/solidconnection/mentor/dto/MentoringListResponse.java diff --git a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java index 856ae794f..150067c90 100644 --- a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java +++ b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java @@ -7,6 +7,7 @@ import com.example.solidconnection.mentor.dto.MentoringConfirmRequest; import com.example.solidconnection.mentor.dto.MentoringConfirmResponse; import com.example.solidconnection.mentor.dto.MentoringCountResponse; +import com.example.solidconnection.mentor.dto.MentoringListResponse; import com.example.solidconnection.mentor.dto.MentoringResponse; import com.example.solidconnection.mentor.service.MentoringCommandService; import com.example.solidconnection.mentor.service.MentoringQueryService; @@ -45,10 +46,10 @@ public ResponseEntity applyMentoring( @RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR}) @GetMapping("/apply") - public ResponseEntity> getMentorings( + public ResponseEntity getMentorings( @AuthorizedUser SiteUser siteUser ) { - List responses = mentoringQueryService.getMentorings(siteUser.getId()); + MentoringListResponse responses = mentoringQueryService.getMentorings(siteUser.getId()); return ResponseEntity.ok(responses); } diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringListResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringListResponse.java new file mode 100644 index 000000000..cdd8ad26e --- /dev/null +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringListResponse.java @@ -0,0 +1,11 @@ +package com.example.solidconnection.mentor.dto; + +import java.util.List; + +public record MentoringListResponse( + List mentoringResponseList +) { + public static MentoringListResponse from(List mentoringResponseList) { + return new MentoringListResponse(mentoringResponseList); + } +} diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java index f9ebebdb8..58ce33de3 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java @@ -4,6 +4,7 @@ import com.example.solidconnection.mentor.domain.Mentor; import com.example.solidconnection.mentor.domain.Mentoring; import com.example.solidconnection.mentor.dto.MentoringCountResponse; +import com.example.solidconnection.mentor.dto.MentoringListResponse; import com.example.solidconnection.mentor.dto.MentoringResponse; import com.example.solidconnection.mentor.repository.MentorRepository; import com.example.solidconnection.mentor.repository.MentoringRepository; @@ -12,7 +13,6 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; -import java.util.stream.Collectors; import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND; @@ -24,15 +24,16 @@ public class MentoringQueryService { private final MentorRepository mentorRepository; @Transactional(readOnly = true) - public List getMentorings(Long siteUserId) { + public MentoringListResponse getMentorings(Long siteUserId) { Mentor mentor = mentorRepository.findBySiteUserId(siteUserId) .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); List mentorings = mentoringRepository.findAllByMentorId(mentor.getId()); - - return mentorings.stream() + List mentoringResponses = mentorings.stream() .map(MentoringResponse::from) - .collect(Collectors.toList()); + .toList(); + + return MentoringListResponse.from(mentoringResponses); } @Transactional(readOnly = true) diff --git a/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java b/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java index 2e988e535..1abd986ba 100644 --- a/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java +++ b/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java @@ -4,6 +4,7 @@ import com.example.solidconnection.mentor.domain.Mentor; import com.example.solidconnection.mentor.domain.Mentoring; import com.example.solidconnection.mentor.dto.MentoringCountResponse; +import com.example.solidconnection.mentor.dto.MentoringListResponse; import com.example.solidconnection.mentor.dto.MentoringResponse; import com.example.solidconnection.mentor.fixture.MentorFixture; import com.example.solidconnection.mentor.fixture.MentoringFixture; @@ -16,8 +17,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import java.util.List; - import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -61,12 +60,12 @@ class 멘토링_목록_조회_테스트 { Mentoring mentoring3 = mentoringFixture.거절된_멘토링(mentor.getId(), menteeUser.getId(), "거절 사유"); // when - List responses = mentoringQueryService.getMentorings(mentorUser.getId()); + MentoringListResponse responses = mentoringQueryService.getMentorings(mentorUser.getId()); // then assertAll( - () -> assertThat(responses).hasSize(3), - () -> assertThat(responses).extracting(MentoringResponse::id) + () -> assertThat(responses.mentoringResponseList()).hasSize(3), + () -> assertThat(responses.mentoringResponseList()).extracting(MentoringResponse::id) .containsExactlyInAnyOrder( mentoring1.getId(), mentoring2.getId(), @@ -86,10 +85,10 @@ class 멘토링_목록_조회_테스트 { @Test void 멘토링이_없는_경우_빈_리스트를_반환한다() { // when - List responses = mentoringQueryService.getMentorings(mentorUser.getId()); + MentoringListResponse responses = mentoringQueryService.getMentorings(mentorUser.getId()); // then - assertThat(responses).isEmpty(); + assertThat(responses.mentoringResponseList()).isEmpty(); } } From 52f21d0b034b7ad4d760cea34579b6fe79250c97 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 19:40:31 +0900 Subject: [PATCH 16/33] =?UTF-8?q?refactor:=20Long=20->=20long=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentor/dto/MentoringApplyResponse.java | 2 +- .../mentor/dto/MentoringCheckResponse.java | 4 ++-- .../mentor/dto/MentoringConfirmResponse.java | 2 +- .../mentor/dto/MentoringResponse.java | 6 +++--- .../mentor/service/MentoringCommandService.java | 12 ++++++------ .../mentor/service/MentoringQueryService.java | 4 ++-- .../mentor/fixture/MentorFixtureBuilder.java | 4 ++-- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyResponse.java index eb4b21ac1..d77523aa7 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyResponse.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyResponse.java @@ -3,7 +3,7 @@ import com.example.solidconnection.mentor.domain.Mentoring; public record MentoringApplyResponse( - Long mentoringId + long mentoringId ) { public static MentoringApplyResponse from(Mentoring mentoring) { diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringCheckResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringCheckResponse.java index 2dbd8d53a..581ddd141 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringCheckResponse.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringCheckResponse.java @@ -1,10 +1,10 @@ package com.example.solidconnection.mentor.dto; public record MentoringCheckResponse( - Long mentoringId + long mentoringId ) { - public static MentoringCheckResponse from(Long mentoringId) { + public static MentoringCheckResponse from(long mentoringId) { return new MentoringCheckResponse(mentoringId); } } diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmResponse.java index a45c0aa44..79ad48bf4 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmResponse.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmResponse.java @@ -3,7 +3,7 @@ import com.example.solidconnection.mentor.domain.Mentoring; public record MentoringConfirmResponse( - Long mentoringId + long mentoringId ) { public static MentoringConfirmResponse from(Mentoring mentoring) { return new MentoringConfirmResponse(mentoring.getId()); diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java index d6ed86840..82124e6fa 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java @@ -6,9 +6,9 @@ import java.time.ZonedDateTime; public record MentoringResponse( - Long id, - Long mentorId, - Long menteeId, + long id, + long mentorId, + long menteeId, ZonedDateTime createdAt, ZonedDateTime confirmedAt, VerifyStatus verifyStatus, diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index ad8029561..e072e8f0a 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -30,7 +30,7 @@ public class MentoringCommandService { private final MentorRepository mentorRepository; @Transactional - public MentoringApplyResponse applyMentoring(Long siteUserId, MentoringApplyRequest mentoringApplyRequest) { + public MentoringApplyResponse applyMentoring(long siteUserId, MentoringApplyRequest mentoringApplyRequest) { validateAlreadyMentor(siteUserId); Mentoring mentoring = Mentoring.builder() @@ -45,7 +45,7 @@ public MentoringApplyResponse applyMentoring(Long siteUserId, MentoringApplyRequ } @Transactional - public MentoringConfirmResponse confirmMentoring(Long siteUserId, Long mentoringId, MentoringConfirmRequest mentoringConfirmRequest) { + public MentoringConfirmResponse confirmMentoring(long siteUserId, long mentoringId, MentoringConfirmRequest mentoringConfirmRequest) { Mentoring mentoring = mentoringRepository.findById(mentoringId) .orElseThrow(() -> new CustomException(MENTORING_NOT_FOUND)); @@ -69,7 +69,7 @@ else if (mentoringConfirmRequest.status() == VerifyStatus.REJECTED } @Transactional - public MentoringCheckResponse checkMentoring(Long siteUserId, Long mentoringId) { + public MentoringCheckResponse checkMentoring(long siteUserId, long mentoringId) { Mentoring mentoring = mentoringRepository.findById(mentoringId) .orElseThrow(() -> new CustomException(MENTORING_NOT_FOUND)); @@ -83,15 +83,15 @@ public MentoringCheckResponse checkMentoring(Long siteUserId, Long mentoringId) return MentoringCheckResponse.from(mentoring.getId()); } - private void validateAlreadyMentor(Long siteUserId) { + private void validateAlreadyMentor(long siteUserId) { if (mentorRepository.existsBySiteUserId(siteUserId)) { throw new CustomException(ALREADY_MENTOR); } } // 멘토는 본인의 멘토링에 대해 confirm 및 check해야 한다. - private void validateUnauthorizedMentoring(Long siteUserId, Mentor mentor) { - if (!siteUserId.equals(mentor.getSiteUserId())) { + private void validateUnauthorizedMentoring(long siteUserId, Mentor mentor) { + if (siteUserId != mentor.getSiteUserId()) { throw new CustomException(UNAUTHORIZED_MENTORING); } } diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java index 58ce33de3..25376adf0 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java @@ -24,7 +24,7 @@ public class MentoringQueryService { private final MentorRepository mentorRepository; @Transactional(readOnly = true) - public MentoringListResponse getMentorings(Long siteUserId) { + public MentoringListResponse getMentorings(long siteUserId) { Mentor mentor = mentorRepository.findBySiteUserId(siteUserId) .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); @@ -37,7 +37,7 @@ public MentoringListResponse getMentorings(Long siteUserId) { } @Transactional(readOnly = true) - public MentoringCountResponse getNewMentoringsCount(Long siteUserId) { + public MentoringCountResponse getNewMentoringsCount(long siteUserId) { Mentor mentor = mentorRepository.findBySiteUserId(siteUserId) .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); diff --git a/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixtureBuilder.java b/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixtureBuilder.java index 2d7a32f78..d499ecc2a 100644 --- a/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixtureBuilder.java +++ b/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixtureBuilder.java @@ -15,8 +15,8 @@ public class MentorFixtureBuilder { private boolean hasBadge = false; private String introduction; private String passTip; - private Long siteUserId; - private Long universityId; + private long siteUserId; + private long universityId; public MentorFixtureBuilder mentor() { return new MentorFixtureBuilder(mentorRepository); From a897b0e18174f168d09eb8f336505954909e1862 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 19:44:44 +0900 Subject: [PATCH 17/33] =?UTF-8?q?refactor:=20=EA=B0=9C=ED=96=89=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solidconnection/mentor/dto/MentoringConfirmRequest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java index 2995b9f8d..88a493f3d 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java @@ -7,6 +7,7 @@ public record MentoringConfirmRequest( @NotNull(message = "승인 상태를 설정해주세요.") VerifyStatus status, + String rejectedReason ) { } From b4a2cc5cf229f5989e6281f3583b1c32888cdeda Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 19:54:47 +0900 Subject: [PATCH 18/33] =?UTF-8?q?refactor:=20=EC=B2=98=EC=9D=8C=20?= =?UTF-8?q?=EA=B0=9C=ED=96=89=20=EC=B6=94=EA=B0=80,=20Long=20->=20long?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solidconnection/mentor/repository/MentorRepository.java | 5 +++-- .../mentor/repository/MentoringRepository.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java b/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java index 7f84e3b8e..bd15cc4ab 100644 --- a/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java +++ b/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java @@ -6,6 +6,7 @@ import java.util.Optional; public interface MentorRepository extends JpaRepository { - Optional findBySiteUserId(Long siteUserId); - boolean existsBySiteUserId(Long siteUserId); + + Optional findBySiteUserId(long siteUserId); + boolean existsBySiteUserId(long siteUserId); } diff --git a/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java b/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java index c3de98350..96aa40c3c 100644 --- a/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java +++ b/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java @@ -7,6 +7,6 @@ public interface MentoringRepository extends JpaRepository { - List findAllByMentorId(Long mentorId); - int countByMentorIdAndCheckedAtIsNull(Long mentorId); + List findAllByMentorId(long mentorId); + int countByMentorIdAndCheckedAtIsNull(long mentorId); } From 36723f7d094636b4d9f51338748e566ac6a35d11 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 22:26:28 +0900 Subject: [PATCH 19/33] =?UTF-8?q?refactor:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EA=B0=84=20=EA=B0=9C=ED=96=89=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solidconnection/mentor/repository/MentorRepository.java | 1 + .../solidconnection/mentor/repository/MentoringRepository.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java b/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java index bd15cc4ab..a8d6c91c3 100644 --- a/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java +++ b/src/main/java/com/example/solidconnection/mentor/repository/MentorRepository.java @@ -8,5 +8,6 @@ public interface MentorRepository extends JpaRepository { Optional findBySiteUserId(long siteUserId); + boolean existsBySiteUserId(long siteUserId); } diff --git a/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java b/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java index 96aa40c3c..d0bb648eb 100644 --- a/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java +++ b/src/main/java/com/example/solidconnection/mentor/repository/MentoringRepository.java @@ -8,5 +8,6 @@ public interface MentoringRepository extends JpaRepository { List findAllByMentorId(long mentorId); + int countByMentorIdAndCheckedAtIsNull(long mentorId); } From 91a1784e7b1b85dd8d2fe12113b864bd2b51c19b Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 22:31:53 +0900 Subject: [PATCH 20/33] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MentoringCommandService.java | 4 +--- .../service/MentoringQueryServiceTest.java | 20 ------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index e072e8f0a..ff5a71a8a 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -39,9 +39,7 @@ public MentoringApplyResponse applyMentoring(long siteUserId, MentoringApplyRequ .verifyStatus(VerifyStatus.PENDING) .build(); - return MentoringApplyResponse.from( - mentoringRepository.save(mentoring) - ); + return MentoringApplyResponse.from(mentoringRepository.save(mentoring)); } @Transactional diff --git a/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java b/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java index 1abd986ba..511f98d8d 100644 --- a/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java +++ b/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java @@ -1,6 +1,5 @@ package com.example.solidconnection.mentor.service; -import com.example.solidconnection.common.exception.CustomException; import com.example.solidconnection.mentor.domain.Mentor; import com.example.solidconnection.mentor.domain.Mentoring; import com.example.solidconnection.mentor.dto.MentoringCountResponse; @@ -17,9 +16,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; @TestContainerSpringBootTest @@ -74,14 +71,6 @@ class 멘토링_목록_조회_테스트 { ); } - @Test - void 멘티가_멘토링을_조회하면_예외를_반환한다() { - // when & then - assertThatThrownBy(() -> mentoringQueryService.getMentorings(menteeUser.getId())) - .isInstanceOf(CustomException.class) - .hasMessage(MENTOR_NOT_FOUND.getMessage()); - } - @Test void 멘토링이_없는_경우_빈_리스트를_반환한다() { // when @@ -120,14 +109,5 @@ class 새_멘토링_개수_조회_테스트 { // then assertThat(response.mentoringCount()).isZero(); } - - @Test - void 멘티가_멘토링_개수를_조회하면_예외를_반환한다() { - // when & then - assertThatThrownBy(() -> - mentoringQueryService.getNewMentoringsCount(menteeUser.getId())) - .isInstanceOf(CustomException.class) - .hasMessage(MENTOR_NOT_FOUND.getMessage()); - } } } From f88a75d26f5f5d7fc6918ad6809d9e95533e35f6 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 22:34:23 +0900 Subject: [PATCH 21/33] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - import 문 개행 추가 - 테스트 이름 컨벤션 준수하도록 변경 --- .../mentor/service/MentoringCommandServiceTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java b/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java index 4f30882e4..5db6da33b 100644 --- a/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java +++ b/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java @@ -27,6 +27,7 @@ import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_NOT_FOUND; import static com.example.solidconnection.common.exception.ErrorCode.REJECTED_REASON_REQUIRED; import static com.example.solidconnection.common.exception.ErrorCode.UNAUTHORIZED_MENTORING; + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; @@ -91,7 +92,7 @@ class 멘토링_신청_테스트 { } @Test - void 이미_멘토인_사용자가_신청시_예외를_반환한다() { + void 이미_멘토인_사용자가_신청시_예외_응답을_반환한다() { // given MentoringApplyRequest request = new MentoringApplyRequest(mentor2.getId()); @@ -153,7 +154,7 @@ class 멘토링_승인_거절_테스트 { } @Test - void 거절_시_사유가_없으면_예외를_반환한다() { + void 거절_시_사유가_없으면_예외_응답을_반환한다() { // given Mentoring mentoring = mentoringFixture.대기중_멘토링(mentor1.getId(), menteeUser.getId()); MentoringConfirmRequest request = new MentoringConfirmRequest(VerifyStatus.REJECTED, null); @@ -192,7 +193,7 @@ class 멘토링_승인_거절_테스트 { } @Test - void 존재하지_않는_멘토링_아이디로_요청시_예외를_반환한다() { + void 존재하지_않는_멘토링_아이디로_요청시_예외_응답을_반환한다() { // given MentoringConfirmRequest request = new MentoringConfirmRequest(VerifyStatus.APPROVED, null); Long invalidMentoringId = 9999L; @@ -233,7 +234,7 @@ class 멘토링_확인_테스트 { } @Test - void 존재하지_않는_멘토링_아이디로_요청시_예외를_반환한다() { + void 존재하지_않는_멘토링_아이디로_요청시_예외_응답을_반환한다() { // given Long invalidMentoringId = 9999L; From 045bd5030b76aedf1e3b8e96a03ca0b523268c35 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 22:59:56 +0900 Subject: [PATCH 22/33] =?UTF-8?q?refactor:=20=EC=BB=A8=EB=B2=A4=EC=85=98?= =?UTF-8?q?=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - private 함수는 마지막으로 사용되는 public 함수 아래에 작성한다. - Long -> long --- .../service/MentoringCommandService.java | 24 +++++++++---------- .../mentor/fixture/MentorFixture.java | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index ff5a71a8a..79f625b4b 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -42,6 +42,12 @@ public MentoringApplyResponse applyMentoring(long siteUserId, MentoringApplyRequ return MentoringApplyResponse.from(mentoringRepository.save(mentoring)); } + private void validateAlreadyMentor(long siteUserId) { + if (mentorRepository.existsBySiteUserId(siteUserId)) { + throw new CustomException(ALREADY_MENTOR); + } + } + @Transactional public MentoringConfirmResponse confirmMentoring(long siteUserId, long mentoringId, MentoringConfirmRequest mentoringConfirmRequest) { Mentoring mentoring = mentoringRepository.findById(mentoringId) @@ -66,6 +72,12 @@ else if (mentoringConfirmRequest.status() == VerifyStatus.REJECTED return MentoringConfirmResponse.from(mentoring); } + private void validateAlreadyConfirmed(Mentoring mentoring) { + if (mentoring.getVerifyStatus() != VerifyStatus.PENDING) { + throw new CustomException(MENTORING_ALREADY_CONFIRMED); + } + } + @Transactional public MentoringCheckResponse checkMentoring(long siteUserId, long mentoringId) { Mentoring mentoring = mentoringRepository.findById(mentoringId) @@ -81,22 +93,10 @@ public MentoringCheckResponse checkMentoring(long siteUserId, long mentoringId) return MentoringCheckResponse.from(mentoring.getId()); } - private void validateAlreadyMentor(long siteUserId) { - if (mentorRepository.existsBySiteUserId(siteUserId)) { - throw new CustomException(ALREADY_MENTOR); - } - } - // 멘토는 본인의 멘토링에 대해 confirm 및 check해야 한다. private void validateUnauthorizedMentoring(long siteUserId, Mentor mentor) { if (siteUserId != mentor.getSiteUserId()) { throw new CustomException(UNAUTHORIZED_MENTORING); } } - - private void validateAlreadyConfirmed(Mentoring mentoring) { - if (mentoring.getVerifyStatus() != VerifyStatus.PENDING) { - throw new CustomException(MENTORING_ALREADY_CONFIRMED); - } - } } diff --git a/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixture.java b/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixture.java index 2422c2e91..40718b2da 100644 --- a/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixture.java +++ b/src/test/java/com/example/solidconnection/mentor/fixture/MentorFixture.java @@ -10,7 +10,7 @@ public class MentorFixture { private final MentorFixtureBuilder mentorFixtureBuilder; - public Mentor 멘토(Long siteUserId, Long universityId) { + public Mentor 멘토(long siteUserId, long universityId) { return mentorFixtureBuilder.mentor() .siteUserId(siteUserId) .universityId(universityId) From ceac93e70da88e169cc0b35630129eabc87629ea Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Wed, 2 Jul 2025 23:15:03 +0900 Subject: [PATCH 23/33] =?UTF-8?q?refactor:=20=EB=B9=84=EC=A6=88=EB=8B=88?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=ED=9D=90=EB=A6=84=EC=97=90=20?= =?UTF-8?q?=EB=A7=9E=EA=B2=8C=20=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentor/service/MentoringCommandService.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index 79f625b4b..100b5a2da 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -59,16 +59,17 @@ public MentoringConfirmResponse confirmMentoring(long siteUserId, long mentoring validateUnauthorizedMentoring(siteUserId, mentor); validateAlreadyConfirmed(mentoring); - if (mentoringConfirmRequest.status() == VerifyStatus.APPROVED) { - mentor.increaseMenteeCount(); - } - else if (mentoringConfirmRequest.status() == VerifyStatus.REJECTED + if (mentoringConfirmRequest.status() == VerifyStatus.REJECTED && (mentoringConfirmRequest.rejectedReason() == null || mentoringConfirmRequest.rejectedReason().isBlank())) { throw new CustomException(REJECTED_REASON_REQUIRED); } mentoring.confirm(mentoringConfirmRequest.status(), mentoringConfirmRequest.rejectedReason()); + if (mentoringConfirmRequest.status() == VerifyStatus.APPROVED) { + mentor.increaseMenteeCount(); + } + return MentoringConfirmResponse.from(mentoring); } From d7e81e49fe5c9e3054644f59d1892318d91a04a8 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Fri, 4 Jul 2025 19:57:18 +0900 Subject: [PATCH 24/33] =?UTF-8?q?chore:=20=EC=BD=94=EB=93=9C=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=20=EB=94=B0=EB=A5=B4=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DTO 첫 개행 제거 - import 문 개행 수정 --- .../solidconnection/mentor/dto/MentoringApplyRequest.java | 1 - .../solidconnection/mentor/dto/MentoringConfirmRequest.java | 1 - .../mentor/service/MentoringCommandServiceTest.java | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyRequest.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyRequest.java index 73c18e250..27d03afae 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyRequest.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringApplyRequest.java @@ -3,7 +3,6 @@ import jakarta.validation.constraints.NotNull; public record MentoringApplyRequest( - @NotNull(message = "멘토 id를 입력해주세요.") Long mentorId ) { diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java index 88a493f3d..8436f263e 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringConfirmRequest.java @@ -4,7 +4,6 @@ import jakarta.validation.constraints.NotNull; public record MentoringConfirmRequest( - @NotNull(message = "승인 상태를 설정해주세요.") VerifyStatus status, diff --git a/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java b/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java index 5db6da33b..29c6a3f6f 100644 --- a/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java +++ b/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java @@ -27,10 +27,10 @@ import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_NOT_FOUND; import static com.example.solidconnection.common.exception.ErrorCode.REJECTED_REASON_REQUIRED; import static com.example.solidconnection.common.exception.ErrorCode.UNAUTHORIZED_MENTORING; - import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertAll; + @TestContainerSpringBootTest @DisplayName("멘토링 CUD 서비스 테스트") class MentoringCommandServiceTest { From 6783242d22398d4b4113d799f700339602562049 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Fri, 4 Jul 2025 20:06:23 +0900 Subject: [PATCH 25/33] =?UTF-8?q?refactor:=20=EB=A9=98=ED=86=A0=20?= =?UTF-8?q?=EC=97=AC=EB=B6=80=20=EA=B2=80=EC=A6=9D=EC=9D=84=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EB=A7=90=EA=B3=A0=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=EC=97=90=EC=84=9C=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - RequireRoleAccess 어노테이션을 사용하여 멘티 여부 검증 --- .../mentor/controller/MentoringController.java | 4 +--- .../mentor/service/MentoringCommandService.java | 9 --------- .../mentor/service/MentoringCommandServiceTest.java | 13 ------------- 3 files changed, 1 insertion(+), 25 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java index 150067c90..1d7993c98 100644 --- a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java +++ b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java @@ -8,7 +8,6 @@ import com.example.solidconnection.mentor.dto.MentoringConfirmResponse; import com.example.solidconnection.mentor.dto.MentoringCountResponse; import com.example.solidconnection.mentor.dto.MentoringListResponse; -import com.example.solidconnection.mentor.dto.MentoringResponse; import com.example.solidconnection.mentor.service.MentoringCommandService; import com.example.solidconnection.mentor.service.MentoringQueryService; import com.example.solidconnection.security.annotation.RequireRoleAccess; @@ -25,8 +24,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.List; - @RestController @RequiredArgsConstructor @RequestMapping("/mentorings") @@ -35,6 +32,7 @@ public class MentoringController { private final MentoringCommandService mentoringCommandService; private final MentoringQueryService mentoringQueryService; + @RequireRoleAccess(roles = Role.MENTEE) @PostMapping("/apply") public ResponseEntity applyMentoring( @AuthorizedUser SiteUser siteUser, diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index 100b5a2da..f0804f622 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -15,7 +15,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.example.solidconnection.common.exception.ErrorCode.ALREADY_MENTOR; import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_ALREADY_CONFIRMED; import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_NOT_FOUND; import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND; @@ -31,8 +30,6 @@ public class MentoringCommandService { @Transactional public MentoringApplyResponse applyMentoring(long siteUserId, MentoringApplyRequest mentoringApplyRequest) { - validateAlreadyMentor(siteUserId); - Mentoring mentoring = Mentoring.builder() .mentorId(mentoringApplyRequest.mentorId()) .menteeId(siteUserId) @@ -42,12 +39,6 @@ public MentoringApplyResponse applyMentoring(long siteUserId, MentoringApplyRequ return MentoringApplyResponse.from(mentoringRepository.save(mentoring)); } - private void validateAlreadyMentor(long siteUserId) { - if (mentorRepository.existsBySiteUserId(siteUserId)) { - throw new CustomException(ALREADY_MENTOR); - } - } - @Transactional public MentoringConfirmResponse confirmMentoring(long siteUserId, long mentoringId, MentoringConfirmRequest mentoringConfirmRequest) { Mentoring mentoring = mentoringRepository.findById(mentoringId) diff --git a/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java b/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java index 29c6a3f6f..f99f00375 100644 --- a/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java +++ b/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java @@ -22,7 +22,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import static com.example.solidconnection.common.exception.ErrorCode.ALREADY_MENTOR; import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_ALREADY_CONFIRMED; import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_NOT_FOUND; import static com.example.solidconnection.common.exception.ErrorCode.REJECTED_REASON_REQUIRED; @@ -90,18 +89,6 @@ class 멘토링_신청_테스트 { () -> assertThat(mentoring.getVerifyStatus()).isEqualTo(VerifyStatus.PENDING) ); } - - @Test - void 이미_멘토인_사용자가_신청시_예외_응답을_반환한다() { - // given - MentoringApplyRequest request = new MentoringApplyRequest(mentor2.getId()); - - // when & then - assertThatThrownBy(() -> - mentoringCommandService.applyMentoring(mentorUser1.getId(), request)) - .isInstanceOf(CustomException.class) - .hasMessage(ALREADY_MENTOR.getMessage()); - } } @Nested From 020f1cb3b7011b0410897101659d662e8af44d53 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Fri, 4 Jul 2025 20:35:30 +0900 Subject: [PATCH 26/33] =?UTF-8?q?chore:=20=EC=BB=A8=EB=B2=A4=EC=85=98=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Long -> long - 의미에 맞도록 서비스 계층의 validate 함수명 변경 --- .../mentor/service/MentoringCommandService.java | 10 +++++----- .../mentor/service/MentoringCommandServiceTest.java | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index f0804f622..59ae44c48 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -47,8 +47,8 @@ public MentoringConfirmResponse confirmMentoring(long siteUserId, long mentoring Mentor mentor = mentorRepository.findById(mentoring.getMentorId()) .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); - validateUnauthorizedMentoring(siteUserId, mentor); - validateAlreadyConfirmed(mentoring); + validateMentoringOwnership(siteUserId, mentor); + validateMentoringPermission(mentoring); if (mentoringConfirmRequest.status() == VerifyStatus.REJECTED && (mentoringConfirmRequest.rejectedReason() == null || mentoringConfirmRequest.rejectedReason().isBlank())) { @@ -64,7 +64,7 @@ public MentoringConfirmResponse confirmMentoring(long siteUserId, long mentoring return MentoringConfirmResponse.from(mentoring); } - private void validateAlreadyConfirmed(Mentoring mentoring) { + private void validateMentoringPermission(Mentoring mentoring) { if (mentoring.getVerifyStatus() != VerifyStatus.PENDING) { throw new CustomException(MENTORING_ALREADY_CONFIRMED); } @@ -78,7 +78,7 @@ public MentoringCheckResponse checkMentoring(long siteUserId, long mentoringId) Mentor mentor = mentorRepository.findById(mentoring.getMentorId()) .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); - validateUnauthorizedMentoring(siteUserId, mentor); + validateMentoringOwnership(siteUserId, mentor); mentoring.check(); @@ -86,7 +86,7 @@ public MentoringCheckResponse checkMentoring(long siteUserId, long mentoringId) } // 멘토는 본인의 멘토링에 대해 confirm 및 check해야 한다. - private void validateUnauthorizedMentoring(long siteUserId, Mentor mentor) { + private void validateMentoringOwnership(long siteUserId, Mentor mentor) { if (siteUserId != mentor.getSiteUserId()) { throw new CustomException(UNAUTHORIZED_MENTORING); } diff --git a/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java b/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java index f99f00375..c6953488d 100644 --- a/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java +++ b/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java @@ -183,7 +183,7 @@ class 멘토링_승인_거절_테스트 { void 존재하지_않는_멘토링_아이디로_요청시_예외_응답을_반환한다() { // given MentoringConfirmRequest request = new MentoringConfirmRequest(VerifyStatus.APPROVED, null); - Long invalidMentoringId = 9999L; + long invalidMentoringId = 9999L; // when & then assertThatThrownBy(() -> mentoringCommandService.confirmMentoring(mentorUser1.getId(), invalidMentoringId, request)) @@ -223,7 +223,7 @@ class 멘토링_확인_테스트 { @Test void 존재하지_않는_멘토링_아이디로_요청시_예외_응답을_반환한다() { // given - Long invalidMentoringId = 9999L; + long invalidMentoringId = 9999L; // when & then assertThatThrownBy(() -> mentoringCommandService.checkMentoring(mentorUser1.getId(), invalidMentoringId)) From adc7121a9b69e5aa3ad4bcbe34816a5e6a51242d Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Fri, 4 Jul 2025 20:55:19 +0900 Subject: [PATCH 27/33] =?UTF-8?q?refactor:=20API=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EC=9D=91=EB=8B=B5=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentor/dto/MentoringCountResponse.java | 6 ++--- .../mentor/dto/MentoringListResponse.java | 6 ++--- .../mentor/dto/MentoringResponse.java | 26 ++++++++----------- .../mentor/service/MentoringQueryService.java | 11 +++++++- .../service/MentoringQueryServiceTest.java | 10 +++---- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringCountResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringCountResponse.java index 8ee02ac07..428b0b7f3 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringCountResponse.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringCountResponse.java @@ -1,10 +1,10 @@ package com.example.solidconnection.mentor.dto; public record MentoringCountResponse( - int mentoringCount + int uncheckedCount ) { - public static MentoringCountResponse from(int mentoringCount) { - return new MentoringCountResponse(mentoringCount); + public static MentoringCountResponse from(int uncheckedCount) { + return new MentoringCountResponse(uncheckedCount); } } diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringListResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringListResponse.java index cdd8ad26e..d943db618 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringListResponse.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringListResponse.java @@ -3,9 +3,9 @@ import java.util.List; public record MentoringListResponse( - List mentoringResponseList + List requests ) { - public static MentoringListResponse from(List mentoringResponseList) { - return new MentoringListResponse(mentoringResponseList); + public static MentoringListResponse from(List requests) { + return new MentoringListResponse(requests); } } diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java index 82124e6fa..9230ae4d9 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java @@ -1,28 +1,24 @@ package com.example.solidconnection.mentor.dto; -import com.example.solidconnection.common.VerifyStatus; import com.example.solidconnection.mentor.domain.Mentoring; +import com.example.solidconnection.siteuser.domain.SiteUser; import java.time.ZonedDateTime; public record MentoringResponse( - long id, - long mentorId, - long menteeId, - ZonedDateTime createdAt, - ZonedDateTime confirmedAt, - VerifyStatus verifyStatus, - String rejectedReason + long mentoringId, + String profileImageUrl, + String nickname, + boolean isChecked, + ZonedDateTime createAt ) { - public static MentoringResponse from(Mentoring mentoring) { + public static MentoringResponse from(Mentoring mentoring, SiteUser mentee) { return new MentoringResponse( mentoring.getId(), - mentoring.getMentorId(), - mentoring.getMenteeId(), - mentoring.getCreatedAt(), - mentoring.getConfirmedAt(), - mentoring.getVerifyStatus(), - mentoring.getRejectedReason() + mentee.getProfileImageUrl(), + mentee.getNickname(), + mentoring.getCheckedAt() != null, + mentoring.getCreatedAt() ); } } diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java index 25376adf0..cf40b73a5 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringQueryService.java @@ -1,6 +1,7 @@ package com.example.solidconnection.mentor.service; import com.example.solidconnection.common.exception.CustomException; +import com.example.solidconnection.common.exception.ErrorCode; import com.example.solidconnection.mentor.domain.Mentor; import com.example.solidconnection.mentor.domain.Mentoring; import com.example.solidconnection.mentor.dto.MentoringCountResponse; @@ -8,6 +9,8 @@ import com.example.solidconnection.mentor.dto.MentoringResponse; import com.example.solidconnection.mentor.repository.MentorRepository; import com.example.solidconnection.mentor.repository.MentoringRepository; +import com.example.solidconnection.siteuser.domain.SiteUser; +import com.example.solidconnection.siteuser.repository.SiteUserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,6 +25,7 @@ public class MentoringQueryService { private final MentoringRepository mentoringRepository; private final MentorRepository mentorRepository; + private final SiteUserRepository siteUserRepository; @Transactional(readOnly = true) public MentoringListResponse getMentorings(long siteUserId) { @@ -30,7 +34,12 @@ public MentoringListResponse getMentorings(long siteUserId) { List mentorings = mentoringRepository.findAllByMentorId(mentor.getId()); List mentoringResponses = mentorings.stream() - .map(MentoringResponse::from) + .map(mentoring -> { + SiteUser mentee = siteUserRepository.findById(mentoring.getMenteeId()) + .orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND)); + + return MentoringResponse.from(mentoring, mentee); + }) .toList(); return MentoringListResponse.from(mentoringResponses); diff --git a/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java b/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java index 511f98d8d..869de8a3c 100644 --- a/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java +++ b/src/test/java/com/example/solidconnection/mentor/service/MentoringQueryServiceTest.java @@ -61,8 +61,8 @@ class 멘토링_목록_조회_테스트 { // then assertAll( - () -> assertThat(responses.mentoringResponseList()).hasSize(3), - () -> assertThat(responses.mentoringResponseList()).extracting(MentoringResponse::id) + () -> assertThat(responses.requests()).hasSize(3), + () -> assertThat(responses.requests()).extracting(MentoringResponse::mentoringId) .containsExactlyInAnyOrder( mentoring1.getId(), mentoring2.getId(), @@ -77,7 +77,7 @@ class 멘토링_목록_조회_테스트 { MentoringListResponse responses = mentoringQueryService.getMentorings(mentorUser.getId()); // then - assertThat(responses.mentoringResponseList()).isEmpty(); + assertThat(responses.requests()).isEmpty(); } } @@ -95,7 +95,7 @@ class 새_멘토링_개수_조회_테스트 { MentoringCountResponse response = mentoringQueryService.getNewMentoringsCount(mentorUser.getId()); // then - assertThat(response.mentoringCount()).isEqualTo(2); + assertThat(response.uncheckedCount()).isEqualTo(2); } @Test @@ -107,7 +107,7 @@ class 새_멘토링_개수_조회_테스트 { MentoringCountResponse response = mentoringQueryService.getNewMentoringsCount(mentorUser.getId()); // then - assertThat(response.mentoringCount()).isZero(); + assertThat(response.uncheckedCount()).isZero(); } } } From deb9ff2575f6742e5af604a4086ded262e1fe378 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Fri, 4 Jul 2025 21:00:57 +0900 Subject: [PATCH 28/33] =?UTF-8?q?chore:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/solidconnection/mentor/dto/MentoringResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java b/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java index 9230ae4d9..595f28b7b 100644 --- a/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java +++ b/src/main/java/com/example/solidconnection/mentor/dto/MentoringResponse.java @@ -10,7 +10,7 @@ public record MentoringResponse( String profileImageUrl, String nickname, boolean isChecked, - ZonedDateTime createAt + ZonedDateTime createdAt ) { public static MentoringResponse from(Mentoring mentoring, SiteUser mentee) { return new MentoringResponse( From 04a328844f7484e2f0718c46b206dbd51f3a4b0f Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Fri, 4 Jul 2025 21:44:57 +0900 Subject: [PATCH 29/33] =?UTF-8?q?refactor:=20=EB=B9=8C=EB=8D=94=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solidconnection/mentor/domain/Mentoring.java | 8 ++++++-- .../mentor/service/MentoringCommandService.java | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/domain/Mentoring.java b/src/main/java/com/example/solidconnection/mentor/domain/Mentoring.java index 55c3d06be..dd2353df6 100644 --- a/src/main/java/com/example/solidconnection/mentor/domain/Mentoring.java +++ b/src/main/java/com/example/solidconnection/mentor/domain/Mentoring.java @@ -12,7 +12,6 @@ import jakarta.persistence.PrePersist; import lombok.AccessLevel; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.DynamicInsert; @@ -25,7 +24,6 @@ @Entity @Getter -@Builder @EntityListeners(AuditingEntityListener.class) @DynamicInsert @AllArgsConstructor @@ -58,6 +56,12 @@ public class Mentoring { @Column private long menteeId; + public Mentoring(long mentorId, long menteeId, VerifyStatus verifyStatus) { + this.mentorId = mentorId; + this.menteeId = menteeId; + this.verifyStatus = verifyStatus; + } + @PrePersist public void onPrePersist() { this.createdAt = ZonedDateTime.now(UTC).truncatedTo(MICROS); // 나노초 6자리 까지만 저장 diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index 59ae44c48..f711859bd 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -30,11 +30,11 @@ public class MentoringCommandService { @Transactional public MentoringApplyResponse applyMentoring(long siteUserId, MentoringApplyRequest mentoringApplyRequest) { - Mentoring mentoring = Mentoring.builder() - .mentorId(mentoringApplyRequest.mentorId()) - .menteeId(siteUserId) - .verifyStatus(VerifyStatus.PENDING) - .build(); + Mentoring mentoring = new Mentoring( + mentoringApplyRequest.mentorId(), + siteUserId, + VerifyStatus.PENDING + ); return MentoringApplyResponse.from(mentoringRepository.save(mentoring)); } From a8be7a60f3dcdd93ce04e3d10ad23fa0cc46ac27 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Mon, 7 Jul 2025 08:18:02 +0900 Subject: [PATCH 30/33] =?UTF-8?q?chore:=20validateMentoringOwnership=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B0=94=EB=94=94=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 주석의 내용을 잘 대변하도록 변경 --- .../mentor/service/MentoringCommandService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index f711859bd..e70ecb099 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -44,10 +44,10 @@ public MentoringConfirmResponse confirmMentoring(long siteUserId, long mentoring Mentoring mentoring = mentoringRepository.findById(mentoringId) .orElseThrow(() -> new CustomException(MENTORING_NOT_FOUND)); - Mentor mentor = mentorRepository.findById(mentoring.getMentorId()) + Mentor mentor = mentorRepository.findBySiteUserId(siteUserId) .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); - validateMentoringOwnership(siteUserId, mentor); + validateMentoringOwnership(mentor, mentoring); validateMentoringPermission(mentoring); if (mentoringConfirmRequest.status() == VerifyStatus.REJECTED @@ -75,10 +75,10 @@ public MentoringCheckResponse checkMentoring(long siteUserId, long mentoringId) Mentoring mentoring = mentoringRepository.findById(mentoringId) .orElseThrow(() -> new CustomException(MENTORING_NOT_FOUND)); - Mentor mentor = mentorRepository.findById(mentoring.getMentorId()) + Mentor mentor = mentorRepository.findBySiteUserId(siteUserId) .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); - validateMentoringOwnership(siteUserId, mentor); + validateMentoringOwnership(mentor, mentoring); mentoring.check(); @@ -86,8 +86,8 @@ public MentoringCheckResponse checkMentoring(long siteUserId, long mentoringId) } // 멘토는 본인의 멘토링에 대해 confirm 및 check해야 한다. - private void validateMentoringOwnership(long siteUserId, Mentor mentor) { - if (siteUserId != mentor.getSiteUserId()) { + private void validateMentoringOwnership(Mentor mentor, Mentoring mentoring) { + if (mentoring.getMentorId() != mentor.getId()) { throw new CustomException(UNAUTHORIZED_MENTORING); } } From 10f44bc2d93ef652cb0302109ddb20db84c7d5a0 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Mon, 7 Jul 2025 08:19:55 +0900 Subject: [PATCH 31/33] =?UTF-8?q?chore:=20=EC=BD=94=EB=94=A9=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=EC=97=90=20=EB=A7=9E=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 파라미터 3개인 경우 개행하지 않는다 - 적절한 이름으로 컨트롤러 메서드명 수정 --- .../mentor/controller/MentoringController.java | 2 +- .../mentor/service/MentoringCommandService.java | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java index 1d7993c98..9df73e41c 100644 --- a/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java +++ b/src/main/java/com/example/solidconnection/mentor/controller/MentoringController.java @@ -74,7 +74,7 @@ public ResponseEntity checkMentoring( @RequireRoleAccess(roles = {Role.ADMIN, Role.MENTOR}) @GetMapping("/check") - public ResponseEntity getNewMentoringsCount( + public ResponseEntity getUncheckedMentoringsCount( @AuthorizedUser SiteUser siteUser ) { MentoringCountResponse response = mentoringQueryService.getNewMentoringsCount(siteUser.getId()); diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index e70ecb099..d7a9e8288 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -30,11 +30,7 @@ public class MentoringCommandService { @Transactional public MentoringApplyResponse applyMentoring(long siteUserId, MentoringApplyRequest mentoringApplyRequest) { - Mentoring mentoring = new Mentoring( - mentoringApplyRequest.mentorId(), - siteUserId, - VerifyStatus.PENDING - ); + Mentoring mentoring = new Mentoring(mentoringApplyRequest.mentorId(), siteUserId, VerifyStatus.PENDING); return MentoringApplyResponse.from(mentoringRepository.save(mentoring)); } From d059e938b8e1dffe20a5f1845ca89251ee1a1f64 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Mon, 7 Jul 2025 21:49:13 +0900 Subject: [PATCH 32/33] =?UTF-8?q?chore:=20=EC=BD=94=EB=94=A9=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=EC=97=90=20=EB=A7=9E=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 적절한 이름으로 컨트롤러 메서드명 수정 --- .../mentor/service/MentoringCommandService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java index d7a9e8288..f7a9495ad 100644 --- a/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java +++ b/src/main/java/com/example/solidconnection/mentor/service/MentoringCommandService.java @@ -44,7 +44,7 @@ public MentoringConfirmResponse confirmMentoring(long siteUserId, long mentoring .orElseThrow(() -> new CustomException(MENTOR_NOT_FOUND)); validateMentoringOwnership(mentor, mentoring); - validateMentoringPermission(mentoring); + validateMentoringNotConfirmed(mentoring); if (mentoringConfirmRequest.status() == VerifyStatus.REJECTED && (mentoringConfirmRequest.rejectedReason() == null || mentoringConfirmRequest.rejectedReason().isBlank())) { @@ -60,7 +60,7 @@ public MentoringConfirmResponse confirmMentoring(long siteUserId, long mentoring return MentoringConfirmResponse.from(mentoring); } - private void validateMentoringPermission(Mentoring mentoring) { + private void validateMentoringNotConfirmed(Mentoring mentoring) { if (mentoring.getVerifyStatus() != VerifyStatus.PENDING) { throw new CustomException(MENTORING_ALREADY_CONFIRMED); } From 0cf6c2062a2e54bbd5711ef825202dd963dffaa5 Mon Sep 17 00:00:00 2001 From: seonghyeok Date: Mon, 7 Jul 2025 21:50:10 +0900 Subject: [PATCH 33/33] =?UTF-8?q?chore:=20=EC=BD=94=EB=94=A9=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=EC=97=90=20=EB=A7=9E=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 불필요한 개행 제거 --- .../mentor/service/MentoringCommandServiceTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java b/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java index c6953488d..e9d218716 100644 --- a/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java +++ b/src/test/java/com/example/solidconnection/mentor/service/MentoringCommandServiceTest.java @@ -160,8 +160,7 @@ class 멘토링_승인_거절_테스트 { MentoringConfirmRequest request = new MentoringConfirmRequest(VerifyStatus.APPROVED, null); // when & then - assertThatThrownBy(() -> - mentoringCommandService.confirmMentoring(mentorUser2.getId(), mentoring.getId(), request)) + assertThatThrownBy(() -> mentoringCommandService.confirmMentoring(mentorUser2.getId(), mentoring.getId(), request)) .isInstanceOf(CustomException.class) .hasMessage(UNAUTHORIZED_MENTORING.getMessage()); } @@ -173,8 +172,7 @@ class 멘토링_승인_거절_테스트 { MentoringConfirmRequest request = new MentoringConfirmRequest(VerifyStatus.APPROVED, null); // when & then - assertThatThrownBy(() -> - mentoringCommandService.confirmMentoring(mentorUser1.getId(), mentoring.getId(), request)) + assertThatThrownBy(() -> mentoringCommandService.confirmMentoring(mentorUser1.getId(), mentoring.getId(), request)) .isInstanceOf(CustomException.class) .hasMessage(MENTORING_ALREADY_CONFIRMED.getMessage()); }