From aefa4ad54735b947708f3ab695cca78f8c9c5f51 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 01:51:33 +0900 Subject: [PATCH 01/36] =?UTF-8?q?RAC-102=20feat:=20MentoringApplyRequest?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/req/MentoringApplyRequest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringApplyRequest.java diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringApplyRequest.java b/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringApplyRequest.java new file mode 100644 index 00000000..686c3ec2 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringApplyRequest.java @@ -0,0 +1,20 @@ +package com.postgraduate.domain.mentoring.application.dto.req; + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class MentoringApplyRequest { + @NotNull + private Long seniorId; + @NotNull + private String topic; + @NotNull + private String question; + @NotNull + private String date; +} From eda03a73a337b9cd92486988b27249f30ff57731 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 01:53:40 +0900 Subject: [PATCH 02/36] =?UTF-8?q?RAC-102=20refactor:=20res=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/{ => res}/AppliedMentoringDetailResponse.java | 2 +- .../application/dto/{ => res}/AppliedMentoringResponse.java | 3 ++- .../domain/mentoring/application/mapper/MentoringMapper.java | 1 + .../mentoring/application/usecase/MentoringInfoUseCase.java | 4 ++-- .../domain/mentoring/presentation/MentoringController.java | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) rename src/main/java/com/postgraduate/domain/mentoring/application/dto/{ => res}/AppliedMentoringDetailResponse.java (85%) rename src/main/java/com/postgraduate/domain/mentoring/application/dto/{ => res}/AppliedMentoringResponse.java (62%) diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/dto/AppliedMentoringDetailResponse.java b/src/main/java/com/postgraduate/domain/mentoring/application/dto/res/AppliedMentoringDetailResponse.java similarity index 85% rename from src/main/java/com/postgraduate/domain/mentoring/application/dto/AppliedMentoringDetailResponse.java rename to src/main/java/com/postgraduate/domain/mentoring/application/dto/res/AppliedMentoringDetailResponse.java index 9c09ff81..8c4c712a 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/dto/AppliedMentoringDetailResponse.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/dto/res/AppliedMentoringDetailResponse.java @@ -1,4 +1,4 @@ -package com.postgraduate.domain.mentoring.application.dto; +package com.postgraduate.domain.mentoring.application.dto.res; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/dto/AppliedMentoringResponse.java b/src/main/java/com/postgraduate/domain/mentoring/application/dto/res/AppliedMentoringResponse.java similarity index 62% rename from src/main/java/com/postgraduate/domain/mentoring/application/dto/AppliedMentoringResponse.java rename to src/main/java/com/postgraduate/domain/mentoring/application/dto/res/AppliedMentoringResponse.java index 7d1982cf..fed717fd 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/dto/AppliedMentoringResponse.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/dto/res/AppliedMentoringResponse.java @@ -1,5 +1,6 @@ -package com.postgraduate.domain.mentoring.application.dto; +package com.postgraduate.domain.mentoring.application.dto.res; +import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java b/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java index 08f2029e..d2ccee54 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java @@ -2,6 +2,7 @@ import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringDetailResponse; import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo; +import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.senior.domain.entity.Senior; diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java index fa59aa12..55cf975d 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java @@ -1,7 +1,7 @@ package com.postgraduate.domain.mentoring.application.usecase; -import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringDetailResponse; -import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringResponse; +import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse; +import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringResponse; import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo; import com.postgraduate.domain.mentoring.application.mapper.MentoringMapper; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java index 6a814102..a59d8ccf 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java @@ -1,7 +1,7 @@ package com.postgraduate.domain.mentoring.presentation; -import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringDetailResponse; -import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringResponse; +import com.postgraduate.domain.mentoring.application.dto.req.MentoringApplyRequest; +import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse; import com.postgraduate.domain.mentoring.application.usecase.MentoringInfoUseCase; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode; From b9d2673107a997a6befc64ba0f37b7bc9e29e923 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 01:54:08 +0900 Subject: [PATCH 03/36] =?UTF-8?q?RAC-102=20feat:=20Mentoring=20`pay`,=20`s?= =?UTF-8?q?tatus`=20=ED=95=84=EB=93=9C=20=EC=B4=88=EA=B8=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/mentoring/domain/entity/Mentoring.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java b/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java index da6c978c..396a4741 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java @@ -8,6 +8,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.CreationTimestamp; import java.time.LocalDate; @@ -38,10 +39,12 @@ public class Mentoring { private String date; @Column(nullable = false) + @ColumnDefault("40000") private int pay; @Enumerated(EnumType.STRING) - private Status status; + @Builder.Default + private Status status = Status.WAITING; @CreationTimestamp private LocalDate createdAt; From 712f8a1012e8f2919bf44aa525b560bf1d21d5e8 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 01:56:15 +0900 Subject: [PATCH 04/36] =?UTF-8?q?RAC-102=20feat:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=8B=A0=EC=B2=AD=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/mapper/MentoringMapper.java | 13 +++++++- .../usecase/MentoringApplyUseCase.java | 30 +++++++++++++++++++ .../domain/service/MentoringSaveService.java | 16 ++++++++++ .../domain/service/SeniorGetService.java | 4 +++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyUseCase.java create mode 100644 src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringSaveService.java diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java b/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java index d2ccee54..dc0bafdf 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/mapper/MentoringMapper.java @@ -1,10 +1,11 @@ package com.postgraduate.domain.mentoring.application.mapper; -import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringDetailResponse; import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo; +import com.postgraduate.domain.mentoring.application.dto.req.MentoringApplyRequest; import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.user.domain.entity.User; import java.util.List; import java.util.stream.Stream; @@ -52,4 +53,14 @@ public static AppliedMentoringDetailResponse mapToAppliedDetailInfo(Mentoring me .dates(dates) .build(); } + + public static Mentoring mapToMentoring(User user, Senior senior, MentoringApplyRequest request) { + return Mentoring.builder() + .user(user) + .senior(senior) + .topic(request.getTopic()) + .question(request.getQuestion()) + .date(request.getDate()) + .build(); + } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyUseCase.java new file mode 100644 index 00000000..cb6bb8e9 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyUseCase.java @@ -0,0 +1,30 @@ +package com.postgraduate.domain.mentoring.application.usecase; + +import com.postgraduate.domain.mentoring.application.dto.req.MentoringApplyRequest; +import com.postgraduate.domain.mentoring.application.mapper.MentoringMapper; +import com.postgraduate.domain.mentoring.domain.entity.Mentoring; +import com.postgraduate.domain.mentoring.domain.service.MentoringSaveService; +import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.senior.domain.service.SeniorGetService; +import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.global.auth.AuthDetails; +import com.postgraduate.global.config.security.util.SecurityUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class MentoringApplyUseCase { + private final SecurityUtils securityUtils; + private final MentoringSaveService mentoringSaveService; + private final SeniorGetService seniorGetService; + + public void applyMentoring(AuthDetails authDetails, MentoringApplyRequest request) { + User user = securityUtils.getLoggedInUser(authDetails); + Senior senior = seniorGetService.bySeniorId(request.getSeniorId()); + Mentoring mentoring = MentoringMapper.mapToMentoring(user, senior, request); + mentoringSaveService.save(mentoring); + } +} diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringSaveService.java b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringSaveService.java new file mode 100644 index 00000000..b8ac6ad0 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringSaveService.java @@ -0,0 +1,16 @@ +package com.postgraduate.domain.mentoring.domain.service; + +import com.postgraduate.domain.mentoring.domain.entity.Mentoring; +import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class MentoringSaveService { + private final MentoringRepository mentoringRepository; + + public Mentoring save(Mentoring mentoring) { + return mentoringRepository.save(mentoring); + } +} diff --git a/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorGetService.java b/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorGetService.java index efd0a796..fe5b8171 100644 --- a/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorGetService.java +++ b/src/main/java/com/postgraduate/domain/senior/domain/service/SeniorGetService.java @@ -14,4 +14,8 @@ public class SeniorGetService { public Senior byUser(User user) { return seniorRepository.findByUser(user).orElseThrow(/**예외 처리**/); } + + public Senior bySeniorId(Long seniorId) { + return seniorRepository.findById(seniorId).orElseThrow(/**예외 처리**/); + } } From 9f828436988110d63e649a0e121ef5afc234b66a Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 01:56:27 +0900 Subject: [PATCH 05/36] =?UTF-8?q?RAC-102=20feat:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=8B=A0=EC=B2=AD=20=EC=84=B1=EA=B3=B5=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/constant/MentoringResponseMessage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java index de7cbf73..0a4127ae 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java @@ -7,7 +7,8 @@ @RequiredArgsConstructor public enum MentoringResponseMessage { GET_MENTORING_LIST_INFO("멘토링 리스트 조회에 성공하였습니다."), - GET_MENTORING_DETAIL_INFO("멘토링 상세 조회에 성공하였습니다."); + GET_MENTORING_DETAIL_INFO("멘토링 상세 조회에 성공하였습니다."), + CREATE_MENTORING("멘토링 신청에 성공하였습니다."); private final String message; } From 1413dd296162732d94c26fcd8486b762e4a37e68 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 01:56:37 +0900 Subject: [PATCH 06/36] =?UTF-8?q?RAC-102=20feat:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=8B=A0=EC=B2=AD=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/MentoringController.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java index a59d8ccf..b4176eb8 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java @@ -2,9 +2,10 @@ import com.postgraduate.domain.mentoring.application.dto.req.MentoringApplyRequest; import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse; +import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringResponse; +import com.postgraduate.domain.mentoring.application.usecase.MentoringApplyUseCase; import com.postgraduate.domain.mentoring.application.usecase.MentoringInfoUseCase; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; -import com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode; import com.postgraduate.global.auth.AuthDetails; import com.postgraduate.global.dto.ResponseDto; import io.swagger.v3.oas.annotations.Operation; @@ -13,10 +14,9 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.MENTORING_CREATE; import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.MENTORING_FIND; -import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.GET_MENTORING_DETAIL_INFO; -import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.GET_MENTORING_LIST_INFO; -import static org.springframework.http.HttpStatus.OK; +import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.*; @RestController @RequiredArgsConstructor @@ -24,6 +24,7 @@ @Tag(name = "MENTORING Controller") public class MentoringController { private final MentoringInfoUseCase infoUsecase; + private final MentoringApplyUseCase applyUseCase; @GetMapping("/me") @Operation(description = "대학생 신청 멘토링 조회") @@ -38,4 +39,11 @@ public ResponseDto getMentoringDetail(@PathVaria AppliedMentoringDetailResponse mentoringDetail = infoUsecase.getMentoringDetail(mentoringId); return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_DETAIL_INFO.getMessage(), mentoringDetail); } + + @PostMapping() + @Operation(summary = "멘토링 신청", description = "대학생이 멘토링을 신청합니다.") + public ResponseDto applyMentoring(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody MentoringApplyRequest request) { + applyUseCase.applyMentoring(authDetails, request); + return ResponseDto.create(MENTORING_CREATE.getCode(), CREATE_MENTORING.getMessage()); + } } From b4f6c865f10230fd0ad03625ecc99634b18f8890 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 13:39:59 +0900 Subject: [PATCH 07/36] =?UTF-8?q?RAC-102=20feat:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=83=81=ED=83=9C=20=EB=B3=80=EA=B2=BD=20request?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/req/MentoringStatusRequest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringStatusRequest.java diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringStatusRequest.java b/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringStatusRequest.java new file mode 100644 index 00000000..dfe3961e --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringStatusRequest.java @@ -0,0 +1,14 @@ +package com.postgraduate.domain.mentoring.application.dto.req; + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class MentoringStatusRequest { + @NotNull + private String status; +} From d78df42d0e8b147ee36b8e2e6743021bd81855ab Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 13:41:17 +0900 Subject: [PATCH 08/36] =?UTF-8?q?RAC-102=20feat:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=83=81=ED=83=9C=20=EB=B3=80=EA=B2=BD=20service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/mentoring/domain/entity/Mentoring.java | 4 ++++ .../domain/service/MentoringUpdateService.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringUpdateService.java diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java b/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java index 396a4741..a51b6746 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java @@ -50,4 +50,8 @@ public class Mentoring { private LocalDate createdAt; private LocalDate deletedAt; + + public void updateStatus(Status status) { + this.status = status; + } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringUpdateService.java b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringUpdateService.java new file mode 100644 index 00000000..e17da63e --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringUpdateService.java @@ -0,0 +1,15 @@ +package com.postgraduate.domain.mentoring.domain.service; + +import com.postgraduate.domain.mentoring.domain.entity.Mentoring; +import com.postgraduate.domain.mentoring.domain.entity.constant.Status; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class MentoringUpdateService { + + public void updateStatus(Mentoring mentoring, Status status) { + mentoring.updateStatus(status); + } +} From 7855cc7af9894705a1b97d101ba44e8bf1a85b30 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 13:44:31 +0900 Subject: [PATCH 09/36] =?UTF-8?q?RAC-102=20refactor:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=EB=B2=88=ED=98=B8=EB=A1=9C=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=B0=BE=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentoring/application/usecase/MentoringInfoUseCase.java | 2 +- .../domain/mentoring/domain/service/MentoringGetService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java index 55cf975d..9ef165be 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java @@ -56,7 +56,7 @@ private AppliedMentoringResponse getCategories(Status status, List me } public AppliedMentoringDetailResponse getMentoringDetail(Long mentoringId) { - Mentoring mentoring = mentoringGetService.mentoringDetail(mentoringId); + Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId); AppliedMentoringDetailResponse appliedMentoringDetailResponse = MentoringMapper.mapToAppliedDetailInfo(mentoring); return appliedMentoringDetailResponse; } diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java index ff96c290..46fbc4d2 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java @@ -21,7 +21,7 @@ public List mentoringByUser(User user, Status status) { return mentorings; } - public Mentoring mentoringDetail(Long mentoringId) { + public Mentoring byMentoringId(Long mentoringId) { return mentoringRepository.findById(mentoringId).orElseThrow(); } } From aa884daba7f64d1a04ee7c8dea13a27a22cb83b2 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 13:45:38 +0900 Subject: [PATCH 10/36] =?UTF-8?q?RAC-102=20feat:=20=EB=B3=B8=EC=9D=B8=20?= =?UTF-8?q?=EB=A9=98=ED=86=A0=EB=A7=81=EC=9D=B8=EC=A7=80=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=ED=95=98=EB=8A=94=20=EC=9C=A0=EC=8A=A4=EC=BC=80?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/CheckIsMyMentoringUseCase.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java new file mode 100644 index 00000000..6a4329f5 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java @@ -0,0 +1,45 @@ +package com.postgraduate.domain.mentoring.application.usecase; + +import com.postgraduate.domain.mentoring.domain.entity.Mentoring; +import com.postgraduate.domain.mentoring.domain.service.MentoringGetService; +import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.senior.domain.service.SeniorGetService; +import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.domain.user.domain.entity.constant.Role; +import com.postgraduate.global.auth.AuthDetails; +import com.postgraduate.global.config.security.util.SecurityUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class CheckIsMyMentoringUseCase { + private final MentoringGetService mentoringGetService; + private final SecurityUtils securityUtils; + private final SeniorGetService seniorGetService; + public Mentoring checkByRole(AuthDetails authDetails, Long mentoringId) { + Role role = authDetails.getRole(); + User user = securityUtils.getLoggedInUser(authDetails); + Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId); + + switch (role) { + case ADMIN -> {} + case USER -> { + if (mentoring.getUser() != user) { + throw new IllegalArgumentException("대학생으로서 권한없음"); + } + } + case SENIOR -> { + Senior senior = seniorGetService.byUser(user); + if (mentoring.getSenior() != senior) { + throw new IllegalArgumentException("대학원생으로서 권한없음"); + } + } + default -> throw new IllegalArgumentException("권한없음"); + } + return mentoring; + } +} + From 7c33119809a7502f5ba9b7fe8aad8e753a430db8 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 13:45:51 +0900 Subject: [PATCH 11/36] =?UTF-8?q?RAC-102=20feat:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=83=81=ED=83=9C=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EC=9C=A0=EC=8A=A4=EC=BC=80=EC=9D=B4=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/MentoringUpdateUseCase.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringUpdateUseCase.java diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringUpdateUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringUpdateUseCase.java new file mode 100644 index 00000000..f25c0075 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringUpdateUseCase.java @@ -0,0 +1,23 @@ +package com.postgraduate.domain.mentoring.application.usecase; + +import com.postgraduate.domain.mentoring.application.dto.req.MentoringStatusRequest; +import com.postgraduate.domain.mentoring.domain.entity.Mentoring; +import com.postgraduate.domain.mentoring.domain.entity.constant.Status; +import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService; +import com.postgraduate.global.auth.AuthDetails; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class MentoringUpdateUseCase { + private final MentoringUpdateService mentoringUpdateService; + private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase; + + public void updateStatus(AuthDetails authDetails, Long mentoringId, MentoringStatusRequest request) { + Mentoring mentoring = checkIsMyMentoringUseCase.checkByRole(authDetails, mentoringId); + mentoringUpdateService.updateStatus(mentoring, Status.valueOf(request.getStatus())); + } +} From e8ee60c47ca0789c31ac36c543c7042cb533b6f2 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 13:46:02 +0900 Subject: [PATCH 12/36] =?UTF-8?q?RAC-102=20feat:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=83=81=ED=83=9C=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EB=A9=94=EC=8B=9C=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/constant/MentoringResponseMessage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java index 0a4127ae..ec1b0429 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java @@ -8,7 +8,8 @@ public enum MentoringResponseMessage { GET_MENTORING_LIST_INFO("멘토링 리스트 조회에 성공하였습니다."), GET_MENTORING_DETAIL_INFO("멘토링 상세 조회에 성공하였습니다."), - CREATE_MENTORING("멘토링 신청에 성공하였습니다."); + CREATE_MENTORING("멘토링 신청에 성공하였습니다."), + UPDATE_MENTORING("멘토링 상태 갱신에 성공하였습니다."); private final String message; } From cbae7149d288d2ea90490b43baeb89b717bb2d56 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 14:20:18 +0900 Subject: [PATCH 13/36] =?UTF-8?q?RAC-102=20fix:=20=EB=B3=B8=EC=9D=B8=20?= =?UTF-8?q?=EB=A9=98=ED=86=A0=EB=A7=81=20=ED=99=95=EC=9D=B8=20=EB=A1=9C?= =?UTF-8?q?=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 --- .../usecase/CheckIsMyMentoringUseCase.java | 25 +++---------------- .../usecase/MentoringUpdateUseCase.java | 6 ++++- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java index 6a4329f5..ba8ab5e9 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java @@ -5,9 +5,6 @@ import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.domain.user.domain.entity.constant.Role; -import com.postgraduate.global.auth.AuthDetails; -import com.postgraduate.global.config.security.util.SecurityUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,27 +14,13 @@ @RequiredArgsConstructor public class CheckIsMyMentoringUseCase { private final MentoringGetService mentoringGetService; - private final SecurityUtils securityUtils; private final SeniorGetService seniorGetService; - public Mentoring checkByRole(AuthDetails authDetails, Long mentoringId) { - Role role = authDetails.getRole(); - User user = securityUtils.getLoggedInUser(authDetails); + public Mentoring checkByRole(User user, Long mentoringId) { Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId); - switch (role) { - case ADMIN -> {} - case USER -> { - if (mentoring.getUser() != user) { - throw new IllegalArgumentException("대학생으로서 권한없음"); - } - } - case SENIOR -> { - Senior senior = seniorGetService.byUser(user); - if (mentoring.getSenior() != senior) { - throw new IllegalArgumentException("대학원생으로서 권한없음"); - } - } - default -> throw new IllegalArgumentException("권한없음"); + Senior senior = seniorGetService.byUser(user); + if (mentoring.getUser() != user && mentoring.getSenior() != senior) { + throw new IllegalArgumentException("권한없음"); } return mentoring; } diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringUpdateUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringUpdateUseCase.java index f25c0075..a7a31865 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringUpdateUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringUpdateUseCase.java @@ -4,7 +4,9 @@ import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService; +import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.global.auth.AuthDetails; +import com.postgraduate.global.config.security.util.SecurityUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -13,11 +15,13 @@ @Transactional @RequiredArgsConstructor public class MentoringUpdateUseCase { + private final SecurityUtils securityUtils; private final MentoringUpdateService mentoringUpdateService; private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase; public void updateStatus(AuthDetails authDetails, Long mentoringId, MentoringStatusRequest request) { - Mentoring mentoring = checkIsMyMentoringUseCase.checkByRole(authDetails, mentoringId); + User user = securityUtils.getLoggedInUser(authDetails); + Mentoring mentoring = checkIsMyMentoringUseCase.checkByRole(user, mentoringId); mentoringUpdateService.updateStatus(mentoring, Status.valueOf(request.getStatus())); } } From 259048f176c21dbe823320c8dc3f502c2f6bae32 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 14:27:57 +0900 Subject: [PATCH 14/36] =?UTF-8?q?RAC-102=20feat:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=83=81=ED=83=9C=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/MentoringController.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java index b4176eb8..5ae8cd13 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java @@ -1,10 +1,12 @@ package com.postgraduate.domain.mentoring.presentation; import com.postgraduate.domain.mentoring.application.dto.req.MentoringApplyRequest; +import com.postgraduate.domain.mentoring.application.dto.req.MentoringStatusRequest; import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse; import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringResponse; import com.postgraduate.domain.mentoring.application.usecase.MentoringApplyUseCase; import com.postgraduate.domain.mentoring.application.usecase.MentoringInfoUseCase; +import com.postgraduate.domain.mentoring.application.usecase.MentoringUpdateUseCase; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.global.auth.AuthDetails; import com.postgraduate.global.dto.ResponseDto; @@ -14,8 +16,7 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.MENTORING_CREATE; -import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.MENTORING_FIND; +import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.*; import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.*; @RestController @@ -25,6 +26,7 @@ public class MentoringController { private final MentoringInfoUseCase infoUsecase; private final MentoringApplyUseCase applyUseCase; + private final MentoringUpdateUseCase updateUseCase; @GetMapping("/me") @Operation(description = "대학생 신청 멘토링 조회") @@ -46,4 +48,13 @@ public ResponseDto applyMentoring(@AuthenticationPrincipal AuthDetails authDetai applyUseCase.applyMentoring(authDetails, request); return ResponseDto.create(MENTORING_CREATE.getCode(), CREATE_MENTORING.getMessage()); } + + @PatchMapping("/me/{mentoringId}") + @Operation(summary = "멘토링 상태 업데이트", description = "대학생, 대학원생이 멘토링 상태를 변경합니다.") + public ResponseDto applyMentoring(@AuthenticationPrincipal AuthDetails authDetails, + @PathVariable Long mentoringId, + @RequestBody MentoringStatusRequest request) { + updateUseCase.updateStatus(authDetails, mentoringId, request); + return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage()); + } } From 5951aecb055d5b9398efedbe75f3703371f0b2ed Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 14:28:15 +0900 Subject: [PATCH 15/36] =?UTF-8?q?RAC-102=20test:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=83=81=ED=83=9C=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheckIsMyMentoringUseCaseTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCaseTest.java diff --git a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCaseTest.java b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCaseTest.java new file mode 100644 index 00000000..fec9a82b --- /dev/null +++ b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCaseTest.java @@ -0,0 +1,49 @@ +package com.postgraduate.domain.mentoring.application.usecase; + +import com.postgraduate.domain.mentoring.domain.entity.Mentoring; +import com.postgraduate.domain.mentoring.domain.service.MentoringGetService; +import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.senior.domain.service.SeniorGetService; +import com.postgraduate.domain.user.domain.entity.User; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class CheckIsMyMentoringUseCaseTest { + @Mock + private MentoringGetService mentoringGetService; + @Mock + private SeniorGetService seniorGetService; + + private CheckIsMyMentoringUseCase checkIsMyMentoringUseCase; + + @BeforeEach + public void setup() { + MockitoAnnotations.openMocks(this); + checkIsMyMentoringUseCase = new CheckIsMyMentoringUseCase( + mentoringGetService, + seniorGetService + ); + } + + @Test + public void testCheckByRoleInvalid() { + User user = new User(); + Long mentoringId = 1L; + Mentoring mentoring = mock(); + Senior senior = mock(); + + when(seniorGetService.byUser(user)).thenReturn(senior); + when(mentoring.getUser()).thenReturn(new User()); + when(mentoringGetService.byMentoringId(mentoringId)).thenReturn(mentoring); + + assertThrows(IllegalArgumentException.class, () -> { + checkIsMyMentoringUseCase.checkByRole(user, mentoringId); + }); + } +} \ No newline at end of file From 42abcb3bb34a797633d97b5e817112bb839f061a Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 14:59:53 +0900 Subject: [PATCH 16/36] =?UTF-8?q?RAC-102=20fix:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=83=81=ED=83=9C=20=EB=B3=80=EA=B2=BD=20request?= =?UTF-8?q?=EC=9D=98Status=20=ED=83=80=EC=9E=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentoring/application/dto/req/MentoringStatusRequest.java | 3 ++- .../mentoring/application/usecase/MentoringUpdateUseCase.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringStatusRequest.java b/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringStatusRequest.java index dfe3961e..a2c6e5d3 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringStatusRequest.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/dto/req/MentoringStatusRequest.java @@ -1,5 +1,6 @@ package com.postgraduate.domain.mentoring.application.dto.req; +import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Getter; @@ -10,5 +11,5 @@ @NoArgsConstructor public class MentoringStatusRequest { @NotNull - private String status; + private Status status; } diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringUpdateUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringUpdateUseCase.java index a7a31865..8e5f659c 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringUpdateUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringUpdateUseCase.java @@ -22,6 +22,6 @@ public class MentoringUpdateUseCase { public void updateStatus(AuthDetails authDetails, Long mentoringId, MentoringStatusRequest request) { User user = securityUtils.getLoggedInUser(authDetails); Mentoring mentoring = checkIsMyMentoringUseCase.checkByRole(user, mentoringId); - mentoringUpdateService.updateStatus(mentoring, Status.valueOf(request.getStatus())); + mentoringUpdateService.updateStatus(mentoring, request.getStatus()); } } From 2d3d383f214f88552d3141ccedb8351086500e17 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 15:44:32 +0900 Subject: [PATCH 17/36] =?UTF-8?q?RAC-102=20feat:=20ApplicationException=20?= =?UTF-8?q?=ED=95=B8=EB=93=A4=EB=9F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/GlobalExceptionHandler.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java b/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java index caa92edf..257c646f 100644 --- a/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java @@ -1,11 +1,20 @@ package com.postgraduate.global.exception; +import com.postgraduate.global.dto.ErrorResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @Slf4j @RestControllerAdvice @RequiredArgsConstructor public class GlobalExceptionHandler { + private static final String LOG_FORMAT = "Class : {}, Code : {}, Message : {}"; + @ExceptionHandler(ApplicationException.class) + public ResponseEntity handleApplicationException(ApplicationException ex) { + log.error(LOG_FORMAT, ex.getClass().getSimpleName(), ex.getErrorCode(), ex.getMessage()); + return ResponseEntity.status(ex.getHttpStatus()).body(new ErrorResponse(ex.getErrorCode(), ex.getMessage())); + } } From cf1d301915e69a1e757f305799a61f9b9d37b934 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 15:45:28 +0900 Subject: [PATCH 18/36] =?UTF-8?q?RAC-102=20feat:=20Mentoring=20Not=20Found?= =?UTF-8?q?=20=EC=98=88=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/service/MentoringGetService.java | 3 ++- .../mentoring/exception/MentoringException.java | 10 ++++++++++ .../exception/MentoringNotFoundException.java | 13 +++++++++++++ .../constant/MentoringResponseCode.java | 5 ++++- .../constant/MentoringResponseMessage.java | 4 +++- 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/postgraduate/domain/mentoring/exception/MentoringException.java create mode 100644 src/main/java/com/postgraduate/domain/mentoring/exception/MentoringNotFoundException.java diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java index 46fbc4d2..eee2b406 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java @@ -3,6 +3,7 @@ import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; +import com.postgraduate.domain.mentoring.exception.MentoringNotFoundException; import com.postgraduate.domain.user.domain.entity.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -22,6 +23,6 @@ public List mentoringByUser(User user, Status status) { } public Mentoring byMentoringId(Long mentoringId) { - return mentoringRepository.findById(mentoringId).orElseThrow(); + return mentoringRepository.findById(mentoringId).orElseThrow(MentoringNotFoundException::new); } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringException.java b/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringException.java new file mode 100644 index 00000000..f9037c20 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringException.java @@ -0,0 +1,10 @@ +package com.postgraduate.domain.mentoring.exception; + +import com.postgraduate.global.exception.ApplicationException; +import org.springframework.http.HttpStatus; + +public class MentoringException extends ApplicationException { + protected MentoringException(String message, String errorCode, HttpStatus httpStatus) { + super(message, errorCode, httpStatus); + } +} diff --git a/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringNotFoundException.java b/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringNotFoundException.java new file mode 100644 index 00000000..2051a04d --- /dev/null +++ b/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringNotFoundException.java @@ -0,0 +1,13 @@ +package com.postgraduate.domain.mentoring.exception; + +import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.MENTORING_NOT_FOUND; +import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.NOT_FOUND_MENTORING; +import static org.springframework.http.HttpStatus.NOT_FOUND; + + +public class MentoringNotFoundException extends MentoringException { + + public MentoringNotFoundException() { + super(NOT_FOUND_MENTORING.getMessage(), MENTORING_NOT_FOUND.getCode(), NOT_FOUND); + } +} diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseCode.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseCode.java index d845fabf..e5f16082 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseCode.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseCode.java @@ -9,6 +9,9 @@ public enum MentoringResponseCode { MENTORING_FIND("MT200"), MENTORING_UPDATE("MT201"), MENTORING_CREATE("MT202"), - MENTORING_DELETE("MT203"); + MENTORING_DELETE("MT203"), + + MENTORING_NOT_FOUND("NT400") + ; private final String code; } \ No newline at end of file diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java index ec1b0429..034b83ff 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseMessage.java @@ -9,7 +9,9 @@ public enum MentoringResponseMessage { GET_MENTORING_LIST_INFO("멘토링 리스트 조회에 성공하였습니다."), GET_MENTORING_DETAIL_INFO("멘토링 상세 조회에 성공하였습니다."), CREATE_MENTORING("멘토링 신청에 성공하였습니다."), - UPDATE_MENTORING("멘토링 상태 갱신에 성공하였습니다."); + UPDATE_MENTORING("멘토링 상태 갱신에 성공하였습니다."), + + NOT_FOUND_MENTORING("멘토링이 존재하지 않습니다."); private final String message; } From f213bdf67762e50ae00a7fa0b7ba86e997c0cfe2 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 16:07:23 +0900 Subject: [PATCH 19/36] =?UTF-8?q?RAC-102=20refactor:=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/mentoring/presentation/MentoringController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java index 5ae8cd13..0480c775 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java @@ -51,9 +51,9 @@ public ResponseDto applyMentoring(@AuthenticationPrincipal AuthDetails authDetai @PatchMapping("/me/{mentoringId}") @Operation(summary = "멘토링 상태 업데이트", description = "대학생, 대학원생이 멘토링 상태를 변경합니다.") - public ResponseDto applyMentoring(@AuthenticationPrincipal AuthDetails authDetails, - @PathVariable Long mentoringId, - @RequestBody MentoringStatusRequest request) { + public ResponseDto updateMentoringStatus(@AuthenticationPrincipal AuthDetails authDetails, + @PathVariable Long mentoringId, + @RequestBody MentoringStatusRequest request) { updateUseCase.updateStatus(authDetails, mentoringId, request); return ResponseDto.create(MENTORING_UPDATE.getCode(), UPDATE_MENTORING.getMessage()); } From f0468000037eb18da4f6186acfcdcf9747a3fcae Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 16:34:02 +0900 Subject: [PATCH 20/36] =?UTF-8?q?RAC-102=20feat:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=B7=A8=EC=86=8C/=EA=B1=B0=EC=A0=88=EC=9D=98=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20`deletedAt`=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/mentoring/domain/entity/Mentoring.java | 4 ++++ .../mentoring/domain/service/MentoringUpdateService.java | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java b/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java index a51b6746..32eab1bb 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java @@ -54,4 +54,8 @@ public class Mentoring { public void updateStatus(Status status) { this.status = status; } + + public void updateDeletedAt() { + this.deletedAt = LocalDate.now(); + } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringUpdateService.java b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringUpdateService.java index e17da63e..2574b069 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringUpdateService.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringUpdateService.java @@ -10,6 +10,9 @@ public class MentoringUpdateService { public void updateStatus(Mentoring mentoring, Status status) { + if (status.equals(Status.CANCEL)) { + mentoring.updateDeletedAt(); + } mentoring.updateStatus(status); } } From a56101d1ce637c019052fd50b891308f7082f82c Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 16:39:03 +0900 Subject: [PATCH 21/36] =?UTF-8?q?RAC-102=20fix:=20=EC=B7=A8=EC=86=8C/?= =?UTF-8?q?=EA=B1=B0=EC=A0=88=EB=90=9C=20=EB=A9=98=ED=86=A0=EB=A7=81=20?= =?UTF-8?q?=EB=85=B8=EC=B6=9C=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentoring/domain/repository/MentoringRepository.java | 3 ++- .../mentoring/domain/service/MentoringGetService.java | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java b/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java index b5f2bfb8..dc839f7a 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java @@ -9,5 +9,6 @@ import java.util.Optional; public interface MentoringRepository extends JpaRepository { - Optional> findAllByUserAndStatus(User user, Status status); + Optional findByMentoringIdAndDeletedAtIsNull(Long mentoringId); + Optional> findAllByUserAndStatusAndDeletedAtIsNull(User user, Status status); } diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java index eee2b406..efabf8c0 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/service/MentoringGetService.java @@ -17,12 +17,10 @@ public class MentoringGetService { private final MentoringRepository mentoringRepository; public List mentoringByUser(User user, Status status) { - List mentorings = - mentoringRepository.findAllByUserAndStatus(user, status).orElse(new ArrayList<>()); - return mentorings; + return mentoringRepository.findAllByUserAndStatusAndDeletedAtIsNull(user, status).orElse(new ArrayList<>()); } public Mentoring byMentoringId(Long mentoringId) { - return mentoringRepository.findById(mentoringId).orElseThrow(MentoringNotFoundException::new); + return mentoringRepository.findByMentoringIdAndDeletedAtIsNull(mentoringId).orElseThrow(MentoringNotFoundException::new); } } From 546e1d80c66f2e837b961bcd4d0c3391e97c0123 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 17:28:27 +0900 Subject: [PATCH 22/36] =?UTF-8?q?RAC-102=20feat:=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EC=97=86=EC=9D=8C=20=EC=98=88=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/exception/AuthException.java | 10 ++++++++++ .../auth/exception/PermissionDeniedException.java | 14 ++++++++++++++ .../presentation/contant/AuthResponseMessage.java | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/postgraduate/domain/auth/exception/AuthException.java create mode 100644 src/main/java/com/postgraduate/domain/auth/exception/PermissionDeniedException.java diff --git a/src/main/java/com/postgraduate/domain/auth/exception/AuthException.java b/src/main/java/com/postgraduate/domain/auth/exception/AuthException.java new file mode 100644 index 00000000..f60646d7 --- /dev/null +++ b/src/main/java/com/postgraduate/domain/auth/exception/AuthException.java @@ -0,0 +1,10 @@ +package com.postgraduate.domain.auth.exception; + +import com.postgraduate.global.exception.ApplicationException; +import org.springframework.http.HttpStatus; + +public class AuthException extends ApplicationException { + protected AuthException(String message, String errorCode, HttpStatus httpStatus) { + super(message, errorCode, httpStatus); + } +} diff --git a/src/main/java/com/postgraduate/domain/auth/exception/PermissionDeniedException.java b/src/main/java/com/postgraduate/domain/auth/exception/PermissionDeniedException.java new file mode 100644 index 00000000..47839f3a --- /dev/null +++ b/src/main/java/com/postgraduate/domain/auth/exception/PermissionDeniedException.java @@ -0,0 +1,14 @@ +package com.postgraduate.domain.auth.exception; + +import org.springframework.http.HttpStatus; + +import static com.postgraduate.domain.auth.presentation.contant.AuthResponseCode.AUTH_NONE; +import static com.postgraduate.domain.auth.presentation.contant.AuthResponseMessage.PERMISSION_DENIED_MESSAGE; + + +public class PermissionDeniedException extends AuthException { + + public PermissionDeniedException() { + super(PERMISSION_DENIED_MESSAGE.getMessage(), AUTH_NONE.getCode(), HttpStatus.FORBIDDEN); + } +} diff --git a/src/main/java/com/postgraduate/domain/auth/presentation/contant/AuthResponseMessage.java b/src/main/java/com/postgraduate/domain/auth/presentation/contant/AuthResponseMessage.java index b73f7894..bb6f8186 100644 --- a/src/main/java/com/postgraduate/domain/auth/presentation/contant/AuthResponseMessage.java +++ b/src/main/java/com/postgraduate/domain/auth/presentation/contant/AuthResponseMessage.java @@ -8,6 +8,8 @@ public enum AuthResponseMessage { SUCCESS_AUTH_MESSAGE("사용자 인증에 성공하였습니다."), NOT_REGISTERED_USER_MESSAGE("가입하지 않은 유저입니다."), - SUCCESS_REGENERATE_TOKEN_MESSAGE("토큰 재발급에 성공하였습니다."); + SUCCESS_REGENERATE_TOKEN_MESSAGE("토큰 재발급에 성공하였습니다."), + + PERMISSION_DENIED_MESSAGE("권한이 없습니다."); private final String message; } From 3378a4d165bbc7a7f70fc983963ba28b433b6825 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 17:29:53 +0900 Subject: [PATCH 23/36] =?UTF-8?q?RAC-102=20feat:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=A1=B0=ED=9A=8C=20=EA=B6=8C=ED=95=9C=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20=EB=8C=80=ED=95=99=EC=83=9D=EC=9D=BC=EB=95=8C?= =?UTF-8?q?=EB=8A=94=20=EC=8B=A0=EC=B2=AD=ED=95=9C=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=EB=A7=8C=20=EB=B3=B4=EC=9D=B4=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/usecase/MentoringInfoUseCase.java | 12 ++++++------ .../mentoring/presentation/MentoringController.java | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java index 9ef165be..9d0e457d 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringInfoUseCase.java @@ -22,11 +22,11 @@ @RequiredArgsConstructor public class MentoringInfoUseCase { private final MentoringGetService mentoringGetService; - + private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase; + private final SecurityUtils securityUtils; /** * securityUtils 이후 수정 */ - private final SecurityUtils securityUtils; public AppliedMentoringResponse getMentorings(Status status, AuthDetails authDetails) { User user = securityUtils.getLoggedInUser(authDetails); @@ -55,9 +55,9 @@ private AppliedMentoringResponse getCategories(Status status, List me } } - public AppliedMentoringDetailResponse getMentoringDetail(Long mentoringId) { - Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId); - AppliedMentoringDetailResponse appliedMentoringDetailResponse = MentoringMapper.mapToAppliedDetailInfo(mentoring); - return appliedMentoringDetailResponse; + public AppliedMentoringDetailResponse getMentoringDetail(AuthDetails authDetails, Long mentoringId) { + User user = securityUtils.getLoggedInUser(authDetails); + Mentoring mentoring = checkIsMyMentoringUseCase.checkByRole(user, mentoringId); + return MentoringMapper.mapToAppliedDetailInfo(mentoring); } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java index 0480c775..1410d4be 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java @@ -29,28 +29,28 @@ public class MentoringController { private final MentoringUpdateUseCase updateUseCase; @GetMapping("/me") - @Operation(description = "대학생 신청 멘토링 조회") + @Operation(summary = "[대학생] 신청한 멘토링 목록 조회", description = "대학생이 신청한 멘토링 목록을 조회합니다.") public ResponseDto getMentoringInfos(@RequestParam Status status, @AuthenticationPrincipal AuthDetails authDetails) { AppliedMentoringResponse mentoringResponse = infoUsecase.getMentorings(status, authDetails); return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_LIST_INFO.getMessage(), mentoringResponse); } @GetMapping("/me/{mentoringId}") - @Operation(description = "대학생 신청 멘토링 상세조회") - public ResponseDto getMentoringDetail(@PathVariable Long mentoringId) { - AppliedMentoringDetailResponse mentoringDetail = infoUsecase.getMentoringDetail(mentoringId); + @Operation(summary = "[대학생] 신청한 멘토링 상세조회", description = "대학생이 신청한 멘토링을 상세조회합니다.") + public ResponseDto getMentoringDetail(@AuthenticationPrincipal AuthDetails authDetails, @PathVariable Long mentoringId) { + AppliedMentoringDetailResponse mentoringDetail = infoUsecase.getMentoringDetail(authDetails, mentoringId); return ResponseDto.create(MENTORING_FIND.getCode(), GET_MENTORING_DETAIL_INFO.getMessage(), mentoringDetail); } @PostMapping() - @Operation(summary = "멘토링 신청", description = "대학생이 멘토링을 신청합니다.") + @Operation(summary = "[대학생] 멘토링 신청", description = "대학생이 멘토링을 신청합니다.") public ResponseDto applyMentoring(@AuthenticationPrincipal AuthDetails authDetails, @RequestBody MentoringApplyRequest request) { applyUseCase.applyMentoring(authDetails, request); return ResponseDto.create(MENTORING_CREATE.getCode(), CREATE_MENTORING.getMessage()); } @PatchMapping("/me/{mentoringId}") - @Operation(summary = "멘토링 상태 업데이트", description = "대학생, 대학원생이 멘토링 상태를 변경합니다.") + @Operation(summary = "[대학생, 대학원생] 멘토링 상태 업데이트", description = "대학생, 대학원생이 멘토링 상태를 변경합니다.") public ResponseDto updateMentoringStatus(@AuthenticationPrincipal AuthDetails authDetails, @PathVariable Long mentoringId, @RequestBody MentoringStatusRequest request) { From 3a13227756f46c1192de8e226fdf86edf6253bcd Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 17:30:11 +0900 Subject: [PATCH 24/36] =?UTF-8?q?RAC-102=20fix:=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=8C=80?= =?UTF-8?q?=ED=95=99=EC=83=9D,=20=EB=8C=80=ED=95=99=EC=9B=90=EC=83=9D=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/CheckIsMyMentoringUseCase.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java index ba8ab5e9..3bbbbd5a 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java @@ -1,5 +1,6 @@ package com.postgraduate.domain.mentoring.application.usecase; +import com.postgraduate.domain.auth.exception.PermissionDeniedException; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.service.MentoringGetService; import com.postgraduate.domain.senior.domain.entity.Senior; @@ -17,10 +18,16 @@ public class CheckIsMyMentoringUseCase { private final SeniorGetService seniorGetService; public Mentoring checkByRole(User user, Long mentoringId) { Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId); + if (mentoring.getUser() != user) { + throw new PermissionDeniedException(); + } + return mentoring; + } - Senior senior = seniorGetService.byUser(user); - if (mentoring.getUser() != user && mentoring.getSenior() != senior) { - throw new IllegalArgumentException("권한없음"); + public Mentoring checkByRole(Senior senior, Long mentoringId) { + Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId); + if (mentoring.getSenior() != senior) { + throw new PermissionDeniedException(); } return mentoring; } From bce258bc06242c2004b228240cbfc55454425919 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 17:36:15 +0900 Subject: [PATCH 25/36] =?UTF-8?q?RAC-102=20fix:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=BD=94=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 --- .../application/usecase/CheckIsMyMentoringUseCase.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java index 3bbbbd5a..671c8729 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCase.java @@ -4,7 +4,6 @@ import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.service.MentoringGetService; import com.postgraduate.domain.senior.domain.entity.Senior; -import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.user.domain.entity.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -15,7 +14,6 @@ @RequiredArgsConstructor public class CheckIsMyMentoringUseCase { private final MentoringGetService mentoringGetService; - private final SeniorGetService seniorGetService; public Mentoring checkByRole(User user, Long mentoringId) { Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId); if (mentoring.getUser() != user) { From 1ad65231ccdb1b5f7bd9579cbbc8020cfd02a162 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 17:40:10 +0900 Subject: [PATCH 26/36] =?UTF-8?q?RAC-102=20fix:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EA=B0=80=EA=B2=A9=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/mentoring/domain/entity/Mentoring.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java b/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java index 32eab1bb..28a795f6 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/entity/Mentoring.java @@ -39,8 +39,8 @@ public class Mentoring { private String date; @Column(nullable = false) - @ColumnDefault("40000") - private int pay; + @Builder.Default + private int pay = 20000; @Enumerated(EnumType.STRING) @Builder.Default From dd4caf7c64fc9075395959faf6ef196f33f31359 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 19:29:39 +0900 Subject: [PATCH 27/36] =?UTF-8?q?RAC-102=20fix:=20=EC=98=A4=ED=83=80=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 --- .../mentoring/presentation/constant/MentoringResponseCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseCode.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseCode.java index e5f16082..87f176d7 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseCode.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/constant/MentoringResponseCode.java @@ -11,7 +11,7 @@ public enum MentoringResponseCode { MENTORING_CREATE("MT202"), MENTORING_DELETE("MT203"), - MENTORING_NOT_FOUND("NT400") + MENTORING_NOT_FOUND("MT400") ; private final String code; } \ No newline at end of file From e094ad5daa6fa34eb355963b85cb3045eee5a764 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 20:29:45 +0900 Subject: [PATCH 28/36] =?UTF-8?q?RAC-102=20fix:=20`ApplicationException`?= =?UTF-8?q?=EC=97=90=EC=84=9C=20HttpStatus=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../postgraduate/domain/auth/exception/AuthException.java | 5 ++--- .../domain/auth/exception/PermissionDeniedException.java | 4 +--- .../domain/mentoring/exception/MentoringException.java | 5 ++--- .../mentoring/exception/MentoringNotFoundException.java | 3 +-- .../postgraduate/global/exception/ApplicationException.java | 5 +---- 5 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/auth/exception/AuthException.java b/src/main/java/com/postgraduate/domain/auth/exception/AuthException.java index f60646d7..4cea29c2 100644 --- a/src/main/java/com/postgraduate/domain/auth/exception/AuthException.java +++ b/src/main/java/com/postgraduate/domain/auth/exception/AuthException.java @@ -1,10 +1,9 @@ package com.postgraduate.domain.auth.exception; import com.postgraduate.global.exception.ApplicationException; -import org.springframework.http.HttpStatus; public class AuthException extends ApplicationException { - protected AuthException(String message, String errorCode, HttpStatus httpStatus) { - super(message, errorCode, httpStatus); + protected AuthException(String message, String errorCode) { + super(message, errorCode); } } diff --git a/src/main/java/com/postgraduate/domain/auth/exception/PermissionDeniedException.java b/src/main/java/com/postgraduate/domain/auth/exception/PermissionDeniedException.java index 47839f3a..330088f3 100644 --- a/src/main/java/com/postgraduate/domain/auth/exception/PermissionDeniedException.java +++ b/src/main/java/com/postgraduate/domain/auth/exception/PermissionDeniedException.java @@ -1,7 +1,5 @@ package com.postgraduate.domain.auth.exception; -import org.springframework.http.HttpStatus; - import static com.postgraduate.domain.auth.presentation.contant.AuthResponseCode.AUTH_NONE; import static com.postgraduate.domain.auth.presentation.contant.AuthResponseMessage.PERMISSION_DENIED_MESSAGE; @@ -9,6 +7,6 @@ public class PermissionDeniedException extends AuthException { public PermissionDeniedException() { - super(PERMISSION_DENIED_MESSAGE.getMessage(), AUTH_NONE.getCode(), HttpStatus.FORBIDDEN); + super(PERMISSION_DENIED_MESSAGE.getMessage(), AUTH_NONE.getCode()); } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringException.java b/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringException.java index f9037c20..416e89e3 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringException.java +++ b/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringException.java @@ -1,10 +1,9 @@ package com.postgraduate.domain.mentoring.exception; import com.postgraduate.global.exception.ApplicationException; -import org.springframework.http.HttpStatus; public class MentoringException extends ApplicationException { - protected MentoringException(String message, String errorCode, HttpStatus httpStatus) { - super(message, errorCode, httpStatus); + protected MentoringException(String message, String errorCode) { + super(message, errorCode); } } diff --git a/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringNotFoundException.java b/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringNotFoundException.java index 2051a04d..d5e08bf7 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringNotFoundException.java +++ b/src/main/java/com/postgraduate/domain/mentoring/exception/MentoringNotFoundException.java @@ -2,12 +2,11 @@ import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.MENTORING_NOT_FOUND; import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.NOT_FOUND_MENTORING; -import static org.springframework.http.HttpStatus.NOT_FOUND; public class MentoringNotFoundException extends MentoringException { public MentoringNotFoundException() { - super(NOT_FOUND_MENTORING.getMessage(), MENTORING_NOT_FOUND.getCode(), NOT_FOUND); + super(NOT_FOUND_MENTORING.getMessage(), MENTORING_NOT_FOUND.getCode()); } } diff --git a/src/main/java/com/postgraduate/global/exception/ApplicationException.java b/src/main/java/com/postgraduate/global/exception/ApplicationException.java index 3c7f34ba..d61895ac 100644 --- a/src/main/java/com/postgraduate/global/exception/ApplicationException.java +++ b/src/main/java/com/postgraduate/global/exception/ApplicationException.java @@ -1,16 +1,13 @@ package com.postgraduate.global.exception; import lombok.Getter; -import org.springframework.http.HttpStatus; @Getter public abstract class ApplicationException extends RuntimeException{ private final String errorCode; - private final HttpStatus httpStatus; - protected ApplicationException(String message, String errorCode, HttpStatus httpStatus) { + protected ApplicationException(String message, String errorCode) { super(message); this.errorCode = errorCode; - this.httpStatus = httpStatus; } } \ No newline at end of file From 21391d95d4025a080c1c34f322e4adafcac8b5ef Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 20:31:59 +0900 Subject: [PATCH 29/36] =?UTF-8?q?RAC-102=20refactor:=20`MentoringUpdateUse?= =?UTF-8?q?Case`=EC=9D=84=20`MentoringManageUseCase`=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentoring/application/usecase/MentoringManageUseCase.java | 3 +-- .../domain/mentoring/presentation/MentoringController.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java index 8e5f659c..ac2383ec 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java @@ -2,7 +2,6 @@ import com.postgraduate.domain.mentoring.application.dto.req.MentoringStatusRequest; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; -import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.global.auth.AuthDetails; @@ -14,7 +13,7 @@ @Service @Transactional @RequiredArgsConstructor -public class MentoringUpdateUseCase { +public class MentoringManageUseCase { private final SecurityUtils securityUtils; private final MentoringUpdateService mentoringUpdateService; private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase; diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java index 1410d4be..ab01aa37 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java @@ -6,7 +6,7 @@ import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringResponse; import com.postgraduate.domain.mentoring.application.usecase.MentoringApplyUseCase; import com.postgraduate.domain.mentoring.application.usecase.MentoringInfoUseCase; -import com.postgraduate.domain.mentoring.application.usecase.MentoringUpdateUseCase; +import com.postgraduate.domain.mentoring.application.usecase.MentoringManageUseCase; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.global.auth.AuthDetails; import com.postgraduate.global.dto.ResponseDto; @@ -26,7 +26,7 @@ public class MentoringController { private final MentoringInfoUseCase infoUsecase; private final MentoringApplyUseCase applyUseCase; - private final MentoringUpdateUseCase updateUseCase; + private final MentoringManageUseCase updateUseCase; @GetMapping("/me") @Operation(summary = "[대학생] 신청한 멘토링 목록 조회", description = "대학생이 신청한 멘토링 목록을 조회합니다.") From 5d9a9682cefc19242ae04101a3b709524e8db731 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 20:32:33 +0900 Subject: [PATCH 30/36] =?UTF-8?q?RAC-102=20fix:=20swagger=20=EC=84=A4?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/mentoring/presentation/MentoringController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java index ab01aa37..8587b4c7 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java +++ b/src/main/java/com/postgraduate/domain/mentoring/presentation/MentoringController.java @@ -50,7 +50,7 @@ public ResponseDto applyMentoring(@AuthenticationPrincipal AuthDetails authDetai } @PatchMapping("/me/{mentoringId}") - @Operation(summary = "[대학생, 대학원생] 멘토링 상태 업데이트", description = "대학생, 대학원생이 멘토링 상태를 변경합니다.") + @Operation(summary = "[대학생] 멘토링 상태 업데이트", description = "대학생이 멘토링 상태를 변경합니다.") public ResponseDto updateMentoringStatus(@AuthenticationPrincipal AuthDetails authDetails, @PathVariable Long mentoringId, @RequestBody MentoringStatusRequest request) { From 89cab11acb4e0b2f9635d81ecbc2ad8ccbc00f1d Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 20:32:59 +0900 Subject: [PATCH 31/36] =?UTF-8?q?RAC-102=20test:=20`@InjectMocks`=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheckIsMyMentoringUseCaseTest.java | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCaseTest.java b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCaseTest.java index fec9a82b..717cca05 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCaseTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/CheckIsMyMentoringUseCaseTest.java @@ -2,47 +2,36 @@ import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.service.MentoringGetService; -import com.postgraduate.domain.senior.domain.entity.Senior; -import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.user.domain.entity.User; -import org.junit.jupiter.api.BeforeEach; +import com.postgraduate.global.exception.ApplicationException; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +@ExtendWith(MockitoExtension.class) class CheckIsMyMentoringUseCaseTest { @Mock private MentoringGetService mentoringGetService; - @Mock - private SeniorGetService seniorGetService; + @InjectMocks private CheckIsMyMentoringUseCase checkIsMyMentoringUseCase; - @BeforeEach - public void setup() { - MockitoAnnotations.openMocks(this); - checkIsMyMentoringUseCase = new CheckIsMyMentoringUseCase( - mentoringGetService, - seniorGetService - ); - } - @Test public void testCheckByRoleInvalid() { User user = new User(); Long mentoringId = 1L; Mentoring mentoring = mock(); - Senior senior = mock(); - when(seniorGetService.byUser(user)).thenReturn(senior); when(mentoring.getUser()).thenReturn(new User()); when(mentoringGetService.byMentoringId(mentoringId)).thenReturn(mentoring); - assertThrows(IllegalArgumentException.class, () -> { + assertThrows(ApplicationException.class, () -> { checkIsMyMentoringUseCase.checkByRole(user, mentoringId); }); } From c1c3c82c636c65ee8bf52103a4e22598e25e9eb4 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 3 Nov 2023 20:40:58 +0900 Subject: [PATCH 32/36] =?UTF-8?q?RAC-102=20fix:=20`GlobalExceptionHandler`?= =?UTF-8?q?=EC=97=90=EC=84=9C=20HttpStatus=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../postgraduate/global/exception/GlobalExceptionHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java b/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java index 257c646f..5d7a8ba5 100644 --- a/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/postgraduate/global/exception/GlobalExceptionHandler.java @@ -15,6 +15,6 @@ public class GlobalExceptionHandler { @ExceptionHandler(ApplicationException.class) public ResponseEntity handleApplicationException(ApplicationException ex) { log.error(LOG_FORMAT, ex.getClass().getSimpleName(), ex.getErrorCode(), ex.getMessage()); - return ResponseEntity.status(ex.getHttpStatus()).body(new ErrorResponse(ex.getErrorCode(), ex.getMessage())); + return ResponseEntity.ok(new ErrorResponse(ex.getErrorCode(), ex.getMessage())); } } From 789a29aaa1a5bff60768c8d4c7913d6723e955b8 Mon Sep 17 00:00:00 2001 From: yang Date: Sun, 5 Nov 2023 04:30:34 +0900 Subject: [PATCH 33/36] =?UTF-8?q?RAC-107=20feat=20:=20=EC=9D=B8=EA=B0=80?= =?UTF-8?q?=20code=20=EC=9D=B4=ED=9B=84=20=EC=B2=98=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dto/req/KakaoCodeRequest.java | 12 ++++++++ .../dto/res/KakaoTokenInfoResponse.java | 20 +++++++++++++ .../kakao/KakaoAccessTokenUseCase.java | 30 ++++++++++++++++++- .../usecase/kakao/KakaoSignInUseCase.java | 5 ++-- .../auth/presentation/AuthController.java | 7 ++--- 5 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoCodeRequest.java create mode 100644 src/main/java/com/postgraduate/domain/auth/application/dto/res/KakaoTokenInfoResponse.java diff --git a/src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoCodeRequest.java b/src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoCodeRequest.java new file mode 100644 index 00000000..c14ffcfb --- /dev/null +++ b/src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoCodeRequest.java @@ -0,0 +1,12 @@ +package com.postgraduate.domain.auth.application.dto.req; + +import jakarta.validation.constraints.NotNull; +import lombok.*; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class KakaoCodeRequest { + @NotNull + private String code; +} diff --git a/src/main/java/com/postgraduate/domain/auth/application/dto/res/KakaoTokenInfoResponse.java b/src/main/java/com/postgraduate/domain/auth/application/dto/res/KakaoTokenInfoResponse.java new file mode 100644 index 00000000..8636b00e --- /dev/null +++ b/src/main/java/com/postgraduate/domain/auth/application/dto/res/KakaoTokenInfoResponse.java @@ -0,0 +1,20 @@ +package com.postgraduate.domain.auth.application.dto.res; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class KakaoTokenInfoResponse { + private String access_token; + private String token_type; + private String refresh_token; + private String id_token; + private int expires_in; + private String cope; + private int refresh_token_expires_in; +} diff --git a/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java b/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java index 05ac257a..fa961917 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java +++ b/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java @@ -1,10 +1,14 @@ package com.postgraduate.domain.auth.application.usecase.kakao; import com.postgraduate.domain.auth.application.dto.res.KakaoAccessTokenResponse; +import com.postgraduate.domain.auth.application.dto.res.KakaoTokenInfoResponse; import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.MediaType; import org.springframework.stereotype.Service; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.client.WebClient; @RequiredArgsConstructor @@ -13,13 +17,37 @@ public class KakaoAccessTokenUseCase { @Value("${app-id.kakao}") private String APP_ID; + @Value("${kakao.redirect-uri}") + private String REDRECT_URI; + @Value("${kakao.authorization-grant-type}") + private String AUTHORIZATION_GRANT_TYPE; private final WebClient webClient; private static final String USER_INFO_URI = "https://kapi.kakao.com/v2/user/me"; private static final String VALIDATE_TOKEN_URI = "https://kapi.kakao.com/v1/user/access_token_info"; + public KakaoUserInfoResponse getKakaoToken(String code) { + MultiValueMap requestBody = getRequestBody(code); + KakaoTokenInfoResponse tokenInfoResponse = webClient.post() + .uri("https://kauth.kakao.com/oauth/token") + .headers(h -> h.setContentType(MediaType.APPLICATION_FORM_URLENCODED)) + .bodyValue(requestBody) + .retrieve() + .bodyToMono(KakaoTokenInfoResponse.class) + .block(); + return getUserInfo(tokenInfoResponse.getAccess_token()); + } - public KakaoUserInfoResponse getUserInfo(String accessToken) { + private MultiValueMap getRequestBody(String code) { + System.out.println(code); + MultiValueMap requestBody = new LinkedMultiValueMap<>(); + requestBody.add("grant_type", AUTHORIZATION_GRANT_TYPE); + requestBody.add("client_id", APP_ID); + requestBody.add("redirect_uri", REDRECT_URI); + requestBody.add("code", code); + return requestBody; + } + private KakaoUserInfoResponse getUserInfo(String accessToken) { verifyAccessToken(accessToken); return webClient.get() diff --git a/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCase.java b/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCase.java index e8e4f548..f70772d5 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCase.java +++ b/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCase.java @@ -1,5 +1,6 @@ package com.postgraduate.domain.auth.application.usecase.kakao; +import com.postgraduate.domain.auth.application.dto.req.KakaoCodeRequest; import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse; import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse; import com.postgraduate.domain.auth.application.dto.req.SignUpRequest; @@ -22,8 +23,8 @@ public class KakaoSignInUseCase { private final UserGetService userGetService; @Transactional - public AuthUserResponse getUser(String token) { - KakaoUserInfoResponse userInfo = kakaoTokenUseCase.getUserInfo(token); + public AuthUserResponse getUser(KakaoCodeRequest codeRequest) { + KakaoUserInfoResponse userInfo = kakaoTokenUseCase.getKakaoToken(codeRequest.getCode()); Long socialId = userInfo.getId(); Optional user = userGetService.bySocialId(socialId); return AuthMapper.mapToAuthUser(user, socialId); diff --git a/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java b/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java index ed62a293..74eb0a7a 100644 --- a/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java +++ b/src/main/java/com/postgraduate/domain/auth/presentation/AuthController.java @@ -1,6 +1,6 @@ package com.postgraduate.domain.auth.presentation; -import com.postgraduate.domain.auth.application.dto.req.KakaoLoginRequest; +import com.postgraduate.domain.auth.application.dto.req.KakaoCodeRequest; import com.postgraduate.domain.auth.application.dto.req.SignUpRequest; import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse; import com.postgraduate.domain.auth.application.dto.res.JwtTokenResponse; @@ -32,11 +32,10 @@ public class AuthController { @PostMapping("/login") @Operation(summary = "카카오 로그인", description = "회원인 경우 JWT를, 회원이 아닌 경우 socialId를 반환합니다(회원가입은 진행하지 않습니다).") - public ResponseDto authLogin(@RequestBody KakaoLoginRequest request) { - AuthUserResponse authUser = kakaoSignInUseCase.getUser(request.getAccessToken()); + public ResponseDto authLogin(@RequestBody KakaoCodeRequest tokenRequest) { + AuthUserResponse authUser = kakaoSignInUseCase.getUser(tokenRequest); if (authUser.getUser().isEmpty()) return ResponseDto.create(AUTH_NONE.getCode(), NOT_REGISTERED_USER_MESSAGE.getMessage(), authUser); - JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.getUser().get()); return ResponseDto.create(AUTH_ALREADY.getCode(), SUCCESS_AUTH_MESSAGE.getMessage(), jwtToken); } From 4c6d1d1bfb85e824557a5f06f75471fbbd7d1990 Mon Sep 17 00:00:00 2001 From: yang Date: Sun, 5 Nov 2023 04:30:43 +0900 Subject: [PATCH 34/36] =?UTF-8?q?RAC-107=20test=20:=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EC=9D=98=ED=95=9C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/kakao/KakaoSignInUseCaseTest.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCaseTest.java b/src/test/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCaseTest.java index 720a77c1..cdce4070 100644 --- a/src/test/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCaseTest.java +++ b/src/test/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoSignInUseCaseTest.java @@ -1,5 +1,6 @@ package com.postgraduate.domain.auth.application.usecase.kakao; +import com.postgraduate.domain.auth.application.dto.req.KakaoCodeRequest; import com.postgraduate.domain.auth.application.dto.res.AuthUserResponse; import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse; import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse.KakaoAccount; @@ -26,20 +27,22 @@ class KakaoSignInUseCaseTest { KakaoSignInUseCase kakaoSignInUseCase; @Test void 첫_로그인_socialId_반환() { - String token = "abcd"; - given(kakaoAccessTokenUseCase.getUserInfo(token)).willReturn(new KakaoUserInfoResponse(10000L, new KakaoAccount())); + String code = "abcdefg"; + KakaoCodeRequest kakaoCodeRequest = new KakaoCodeRequest(code); + given(kakaoAccessTokenUseCase.getKakaoToken(code)).willReturn(new KakaoUserInfoResponse(10000L, new KakaoAccount())); given(userGetService.bySocialId(10000L)).willReturn(Optional.ofNullable(null)); - AuthUserResponse authUserResponse = kakaoSignInUseCase.getUser(token); + AuthUserResponse authUserResponse = kakaoSignInUseCase.getUser(kakaoCodeRequest); Assertions.assertThat(authUserResponse.getSocialId()).isEqualTo(10000L); Assertions.assertThat(authUserResponse.getUser().isEmpty()).isTrue(); } @Test void 기존_유저_로그인_user반환() { - String token = "abcd"; - given(kakaoAccessTokenUseCase.getUserInfo(token)).willReturn(new KakaoUserInfoResponse(10000L, new KakaoAccount())); + String code = "abcdefg"; + KakaoCodeRequest kakaoCodeRequest = new KakaoCodeRequest(code); + given(kakaoAccessTokenUseCase.getKakaoToken(code)).willReturn(new KakaoUserInfoResponse(10000L, new KakaoAccount())); given(userGetService.bySocialId(10000L)).willReturn(Optional.ofNullable(new User())); - AuthUserResponse authUserResponse = kakaoSignInUseCase.getUser(token); + AuthUserResponse authUserResponse = kakaoSignInUseCase.getUser(kakaoCodeRequest); Assertions.assertThat(authUserResponse.getSocialId()).isEqualTo(10000L); Assertions.assertThat(authUserResponse.getUser().isEmpty()).isFalse(); } From d54e70abba51a41c01976859bc9210b00bcc6df9 Mon Sep 17 00:00:00 2001 From: yang Date: Sun, 5 Nov 2023 04:35:58 +0900 Subject: [PATCH 35/36] =?UTF-8?q?RAC-107=20refactor=20:=20=EC=83=81?= =?UTF-8?q?=EC=88=98=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/usecase/kakao/KakaoAccessTokenUseCase.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java b/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java index fa961917..d2b2167a 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java +++ b/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java @@ -22,13 +22,15 @@ public class KakaoAccessTokenUseCase { @Value("${kakao.authorization-grant-type}") private String AUTHORIZATION_GRANT_TYPE; private final WebClient webClient; + + private static final String KAKAO_TOKEN_URI = "https://kauth.kakao.com/oauth/token"; private static final String USER_INFO_URI = "https://kapi.kakao.com/v2/user/me"; private static final String VALIDATE_TOKEN_URI = "https://kapi.kakao.com/v1/user/access_token_info"; public KakaoUserInfoResponse getKakaoToken(String code) { MultiValueMap requestBody = getRequestBody(code); KakaoTokenInfoResponse tokenInfoResponse = webClient.post() - .uri("https://kauth.kakao.com/oauth/token") + .uri(KAKAO_TOKEN_URI) .headers(h -> h.setContentType(MediaType.APPLICATION_FORM_URLENCODED)) .bodyValue(requestBody) .retrieve() From 5f70d9f8326ecc3179f737cadae9f8d642e39e04 Mon Sep 17 00:00:00 2001 From: yang Date: Tue, 7 Nov 2023 16:22:01 +0900 Subject: [PATCH 36/36] =?UTF-8?q?RAC-107=20refactor=20:=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dto/req/KakaoLoginRequest.java | 14 -------------- .../usecase/kakao/KakaoAccessTokenUseCase.java | 1 - 2 files changed, 15 deletions(-) delete mode 100644 src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoLoginRequest.java diff --git a/src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoLoginRequest.java b/src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoLoginRequest.java deleted file mode 100644 index 4378ccc5..00000000 --- a/src/main/java/com/postgraduate/domain/auth/application/dto/req/KakaoLoginRequest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.postgraduate.domain.auth.application.dto.req; - -import jakarta.validation.constraints.NotNull; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@AllArgsConstructor -@NoArgsConstructor -public class KakaoLoginRequest { - @NotNull - private String accessToken; -} diff --git a/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java b/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java index d2b2167a..aa826d8b 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java +++ b/src/main/java/com/postgraduate/domain/auth/application/usecase/kakao/KakaoAccessTokenUseCase.java @@ -40,7 +40,6 @@ public KakaoUserInfoResponse getKakaoToken(String code) { } private MultiValueMap getRequestBody(String code) { - System.out.println(code); MultiValueMap requestBody = new LinkedMultiValueMap<>(); requestBody.add("grant_type", AUTHORIZATION_GRANT_TYPE); requestBody.add("client_id", APP_ID);