From 9de459411d9856d02d355a1cd9a35bdce94abde7 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Wed, 14 Aug 2024 19:22:38 +0900 Subject: [PATCH 01/22] =?UTF-8?q?feat:=20=EC=8A=A4=ED=84=B0=EB=94=94?= =?UTF-8?q?=EC=9B=90=20=EC=A1=B0=ED=9A=8C=20api=20=EC=8A=A4=ED=8E=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../study/api/MentorStudyController.java | 9 +++++++++ .../study/application/MentorStudyService.java | 14 ++++++++++++++ .../study/dao/StudyHistoryRepository.java | 2 ++ .../dto/response/StudyStudentResponse.java | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java b/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java index 8ce49f9bc..9112421a3 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java @@ -2,12 +2,14 @@ import com.gdschongik.gdsc.domain.study.application.MentorStudyService; import com.gdschongik.gdsc.domain.study.dto.response.MentorStudyResponse; +import com.gdschongik.gdsc.domain.study.dto.response.StudyStudentResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -25,4 +27,11 @@ public ResponseEntity> getStudiesInCharge() { List response = mentorStudyService.getStudiesInCharge(); return ResponseEntity.ok(response); } + + @Operation(summary = "내 스터디 수강생 명단 조회", description = "내가 멘토로 있는 스터디 수강생 명단을 조회합니다") + @GetMapping("/me/{studyId}") + public ResponseEntity> getStudyStudents(@PathVariable Long studyId) { + List response = mentorStudyService.getStudyStudents(studyId); + return ResponseEntity.ok(response); + } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java index 061338e1b..2d5bbeb0f 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java @@ -1,9 +1,15 @@ package com.gdschongik.gdsc.domain.study.application; +import com.gdschongik.gdsc.domain.member.dao.MemberRepository; import com.gdschongik.gdsc.domain.member.domain.Member; +import com.gdschongik.gdsc.domain.study.dao.StudyHistoryRepository; import com.gdschongik.gdsc.domain.study.dao.StudyRepository; import com.gdschongik.gdsc.domain.study.domain.Study; +import com.gdschongik.gdsc.domain.study.domain.StudyHistory; import com.gdschongik.gdsc.domain.study.dto.response.MentorStudyResponse; +import com.gdschongik.gdsc.domain.study.dto.response.StudyStudentResponse; +import com.gdschongik.gdsc.global.exception.CustomException; +import com.gdschongik.gdsc.global.exception.ErrorCode; import com.gdschongik.gdsc.global.util.MemberUtil; import java.util.List; import lombok.RequiredArgsConstructor; @@ -16,6 +22,7 @@ public class MentorStudyService { private final MemberUtil memberUtil; private final StudyRepository studyRepository; + private final StudyHistoryRepository studyHistoryRepository; @Transactional(readOnly = true) public List getStudiesInCharge() { @@ -23,4 +30,11 @@ public List getStudiesInCharge() { List myStudies = studyRepository.findAllByMentor(currentMember); return myStudies.stream().map(MentorStudyResponse::from).toList(); } + + @Transactional(readOnly = true) + public List getStudyStudents(Long studyId) { + List studyHistories = studyHistoryRepository.findByStudyId(studyId); + + return studyHistories.stream().map(StudyStudentResponse::from).toList(); + } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyHistoryRepository.java b/src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyHistoryRepository.java index f706aea27..b3db9eba3 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyHistoryRepository.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyHistoryRepository.java @@ -12,4 +12,6 @@ public interface StudyHistoryRepository extends JpaRepository findAllByMentee(Member member); Optional findByMenteeAndStudy(Member member, Study study); + + List findByStudyId(Long studyId); } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java new file mode 100644 index 000000000..03029948d --- /dev/null +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java @@ -0,0 +1,18 @@ +package com.gdschongik.gdsc.domain.study.dto.response; + +import com.gdschongik.gdsc.domain.member.domain.Member; +import com.gdschongik.gdsc.domain.study.domain.StudyHistory; +import io.swagger.v3.oas.annotations.media.Schema; + +public record StudyStudentResponse( + Long memberId, + String name, + String studentId, + String githubLink, + String discordName, + String discordUsername +) { + public static StudyStudentResponse from(StudyHistory studyHistory) { + return null; + } +} From 59eeb9abfeb6b7a9d761fa21d9ed44e37581a2a2 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Wed, 14 Aug 2024 22:47:35 +0900 Subject: [PATCH 02/22] =?UTF-8?q?feat:=20=EB=A9=98=ED=86=A0=20=ED=8A=B9?= =?UTF-8?q?=EC=A0=95=20=EC=8A=A4=ED=84=B0=EB=94=94=20=EC=88=98=EA=B0=95?= =?UTF-8?q?=EC=83=9D=20=EB=AA=85=EB=8B=A8=20=EC=A1=B0=ED=9A=8C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../study/application/MentorStudyService.java | 3 --- .../dto/response/StudyStudentResponse.java | 22 +++++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java index 2d5bbeb0f..5b0d0293a 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java @@ -1,6 +1,5 @@ package com.gdschongik.gdsc.domain.study.application; -import com.gdschongik.gdsc.domain.member.dao.MemberRepository; import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.domain.study.dao.StudyHistoryRepository; import com.gdschongik.gdsc.domain.study.dao.StudyRepository; @@ -8,8 +7,6 @@ import com.gdschongik.gdsc.domain.study.domain.StudyHistory; import com.gdschongik.gdsc.domain.study.dto.response.MentorStudyResponse; import com.gdschongik.gdsc.domain.study.dto.response.StudyStudentResponse; -import com.gdschongik.gdsc.global.exception.CustomException; -import com.gdschongik.gdsc.global.exception.ErrorCode; import com.gdschongik.gdsc.global.util.MemberUtil; import java.util.List; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java index 03029948d..d1e602a01 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java @@ -1,18 +1,22 @@ package com.gdschongik.gdsc.domain.study.dto.response; -import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.domain.study.domain.StudyHistory; import io.swagger.v3.oas.annotations.media.Schema; public record StudyStudentResponse( - Long memberId, - String name, - String studentId, - String githubLink, - String discordName, - String discordUsername -) { + @Schema(description = "멤버 아이디") Long memberId, + @Schema(description = "학생 이름") String name, + @Schema(description = "학번") String studentId, + @Schema(description = "디스코드 사용자명") String discordName, + @Schema(description = "디스코드 닉네임") String discordUsername, + @Schema(description = "깃허브 링크") String githubLink) { public static StudyStudentResponse from(StudyHistory studyHistory) { - return null; + return new StudyStudentResponse( + studyHistory.getMentee().getId(), + studyHistory.getMentee().getName(), + studyHistory.getMentee().getStudentId(), + studyHistory.getMentee().getDiscordId(), + studyHistory.getMentee().getDiscordUsername(), + studyHistory.getRepositoryLink()); } } From 456ee611ce3a92c9a07742c4e5c274ada1db44f3 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Wed, 14 Aug 2024 23:08:33 +0900 Subject: [PATCH 03/22] =?UTF-8?q?feat:=20=ED=95=B4=EB=8B=B9=20=EC=8A=A4?= =?UTF-8?q?=ED=84=B0=EB=94=94=EC=9D=98=20=EB=A9=98=ED=86=A0=EC=9D=B8?= =?UTF-8?q?=EC=A7=80=20=EA=B2=80=EC=A6=9D=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/study/application/MentorStudyService.java | 9 +++++++++ .../com/gdschongik/gdsc/domain/study/domain/Study.java | 8 ++++++++ .../com/gdschongik/gdsc/global/exception/ErrorCode.java | 1 + 3 files changed, 18 insertions(+) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java index 5b0d0293a..5bd806b7f 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java @@ -7,6 +7,8 @@ import com.gdschongik.gdsc.domain.study.domain.StudyHistory; import com.gdschongik.gdsc.domain.study.dto.response.MentorStudyResponse; import com.gdschongik.gdsc.domain.study.dto.response.StudyStudentResponse; +import com.gdschongik.gdsc.global.exception.CustomException; +import com.gdschongik.gdsc.global.exception.ErrorCode; import com.gdschongik.gdsc.global.util.MemberUtil; import java.util.List; import lombok.RequiredArgsConstructor; @@ -30,6 +32,13 @@ public List getStudiesInCharge() { @Transactional(readOnly = true) public List getStudyStudents(Long studyId) { + Member currentMember = memberUtil.getCurrentMember(); + + Study study = + studyRepository.findById(studyId).orElseThrow(() -> new CustomException(ErrorCode.STUDY_NOT_FOUND)); + + study.validateMentor(currentMember); + List studyHistories = studyHistoryRepository.findByStudyId(studyId); return studyHistories.stream().map(StudyStudentResponse::from).toList(); diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/Study.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/Study.java index 0d6639b31..cb7fd134c 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/Study.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/Study.java @@ -127,6 +127,8 @@ public static Study createStudy( .build(); } + // 검증 로직 + private static void validateApplicationStartDateBeforeSessionStartDate( LocalDateTime applicationStartDate, LocalDateTime startDate) { if (!applicationStartDate.isBefore(startDate)) { @@ -163,6 +165,12 @@ private static void validateAssignmentLineStudyTime(LocalTime studyStartTime, Lo } } + public void validateMentor(Member currentMember) { + if (currentMember != mentor) { + throw new CustomException(STUDY_MENTOR_INVALID); + } + } + // 데이터 전달 로직 public boolean isApplicable() { return applicationPeriod.isOpen(); diff --git a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java index b17d81072..c4b2962f4 100644 --- a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java +++ b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java @@ -100,6 +100,7 @@ public enum ErrorCode { // Study STUDY_APPLICATION_START_DATE_INVALID(HttpStatus.CONFLICT, "스터디 신청기간 시작일이 스터디 시작일보다 빠릅니다."), STUDY_MENTOR_IS_UNAUTHORIZED(HttpStatus.CONFLICT, "게스트인 회원은 멘토로 지정할 수 없습니다."), + STUDY_MENTOR_INVALID(HttpStatus.CONFLICT, "사용자가 해당 스터디의 멘토가 아닙니다"), ON_OFF_LINE_STUDY_TIME_IS_ESSENTIAL(HttpStatus.CONFLICT, "온오프라인 스터디는 스터디 시간이 필요합니다."), STUDY_TIME_INVALID(HttpStatus.CONFLICT, "스터디종료 시각이 스터디시작 시각보다 빠릅니다."), ASSIGNMENT_STUDY_CAN_NOT_INPUT_STUDY_TIME(HttpStatus.CONFLICT, "과제 스터디는 스터디 시간을 입력할 수 없습니다."), From a9465b6e9378132cca4f2584640a7468585dc34c Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Wed, 14 Aug 2024 23:11:14 +0900 Subject: [PATCH 04/22] =?UTF-8?q?feat:=20=EC=9E=90=EC=9E=98=ED=95=9C=20?= =?UTF-8?q?=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=A7=80=ED=82=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/application/MentorStudyService.java | 2 -- .../java/com/gdschongik/gdsc/global/exception/ErrorCode.java | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java index 5bd806b7f..28eee9784 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java @@ -33,10 +33,8 @@ public List getStudiesInCharge() { @Transactional(readOnly = true) public List getStudyStudents(Long studyId) { Member currentMember = memberUtil.getCurrentMember(); - Study study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(ErrorCode.STUDY_NOT_FOUND)); - study.validateMentor(currentMember); List studyHistories = studyHistoryRepository.findByStudyId(studyId); diff --git a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java index c4b2962f4..f6828ca91 100644 --- a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java +++ b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java @@ -100,7 +100,7 @@ public enum ErrorCode { // Study STUDY_APPLICATION_START_DATE_INVALID(HttpStatus.CONFLICT, "스터디 신청기간 시작일이 스터디 시작일보다 빠릅니다."), STUDY_MENTOR_IS_UNAUTHORIZED(HttpStatus.CONFLICT, "게스트인 회원은 멘토로 지정할 수 없습니다."), - STUDY_MENTOR_INVALID(HttpStatus.CONFLICT, "사용자가 해당 스터디의 멘토가 아닙니다"), + STUDY_MENTOR_INVALID(HttpStatus.CONFLICT, "사용자가 해당 스터디의 멘토가 아닙니다."), ON_OFF_LINE_STUDY_TIME_IS_ESSENTIAL(HttpStatus.CONFLICT, "온오프라인 스터디는 스터디 시간이 필요합니다."), STUDY_TIME_INVALID(HttpStatus.CONFLICT, "스터디종료 시각이 스터디시작 시각보다 빠릅니다."), ASSIGNMENT_STUDY_CAN_NOT_INPUT_STUDY_TIME(HttpStatus.CONFLICT, "과제 스터디는 스터디 시간을 입력할 수 없습니다."), From 73c601d2f3201b3c6b6982b8a128c599510795f2 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Wed, 14 Aug 2024 23:22:40 +0900 Subject: [PATCH 05/22] =?UTF-8?q?feat:=20endpoint=EC=88=98=EC=A0=95?= =?UTF-8?q?=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdschongik/gdsc/domain/study/api/MentorStudyController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java b/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java index 9112421a3..fda3709d9 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java @@ -29,7 +29,7 @@ public ResponseEntity> getStudiesInCharge() { } @Operation(summary = "내 스터디 수강생 명단 조회", description = "내가 멘토로 있는 스터디 수강생 명단을 조회합니다") - @GetMapping("/me/{studyId}") + @GetMapping("/me/students/{studyId}") public ResponseEntity> getStudyStudents(@PathVariable Long studyId) { List response = mentorStudyService.getStudyStudents(studyId); return ResponseEntity.ok(response); From 019ca34c4bb772d6cee6e0b3539b486f314c1926 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Wed, 14 Aug 2024 23:27:50 +0900 Subject: [PATCH 06/22] =?UTF-8?q?feat:=20=EC=99=B8=EB=B6=80=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EC=84=9C=EB=B9=84=EC=8A=A4=EC=97=90=20?= =?UTF-8?q?=EC=9D=98=ED=95=B4=20=EC=B0=B8=EC=A1=B0=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=EC=97=90=20=EB=8C=80=ED=95=9C=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EC=B1=85=EC=9E=84=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../study/application/MentorStudyService.java | 5 ++++- .../gdsc/domain/study/domain/Study.java | 6 ------ .../gdsc/domain/study/domain/StudyValidator.java | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java index 28eee9784..3edd8d63b 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java @@ -5,6 +5,7 @@ import com.gdschongik.gdsc.domain.study.dao.StudyRepository; import com.gdschongik.gdsc.domain.study.domain.Study; import com.gdschongik.gdsc.domain.study.domain.StudyHistory; +import com.gdschongik.gdsc.domain.study.domain.StudyValidator; import com.gdschongik.gdsc.domain.study.dto.response.MentorStudyResponse; import com.gdschongik.gdsc.domain.study.dto.response.StudyStudentResponse; import com.gdschongik.gdsc.global.exception.CustomException; @@ -22,6 +23,7 @@ public class MentorStudyService { private final MemberUtil memberUtil; private final StudyRepository studyRepository; private final StudyHistoryRepository studyHistoryRepository; + private final StudyValidator studyValidator; @Transactional(readOnly = true) public List getStudiesInCharge() { @@ -35,8 +37,9 @@ public List getStudyStudents(Long studyId) { Member currentMember = memberUtil.getCurrentMember(); Study study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(ErrorCode.STUDY_NOT_FOUND)); - study.validateMentor(currentMember); + studyValidator.validateStudyMentor( + currentMember.getId(), study.getMentor().getId()); List studyHistories = studyHistoryRepository.findByStudyId(studyId); return studyHistories.stream().map(StudyStudentResponse::from).toList(); diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/Study.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/Study.java index cb7fd134c..1eb1e3e31 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/Study.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/Study.java @@ -165,12 +165,6 @@ private static void validateAssignmentLineStudyTime(LocalTime studyStartTime, Lo } } - public void validateMentor(Member currentMember) { - if (currentMember != mentor) { - throw new CustomException(STUDY_MENTOR_INVALID); - } - } - // 데이터 전달 로직 public boolean isApplicable() { return applicationPeriod.isOpen(); diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java new file mode 100644 index 000000000..5351ebda3 --- /dev/null +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java @@ -0,0 +1,15 @@ +package com.gdschongik.gdsc.domain.study.domain; + +import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_INVALID; + +import com.gdschongik.gdsc.global.annotation.DomainService; +import com.gdschongik.gdsc.global.exception.CustomException; + +@DomainService +public class StudyValidator { + public void validateStudyMentor(Long currentMemberId, Long mentorId) { + if (!currentMemberId.equals(mentorId)) { + throw new CustomException(STUDY_MENTOR_INVALID); + } + } +} From 90846e650bddb6950660f76d9eb2eb4f4846f747 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Thu, 15 Aug 2024 02:13:01 +0900 Subject: [PATCH 07/22] =?UTF-8?q?feat:=20=EB=94=94=EC=8A=A4=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EA=B4=80=EB=A0=A8=20=EB=AA=85=EC=B9=AD=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/study/dto/response/StudyStudentResponse.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java index d1e602a01..894fd8b40 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java @@ -7,16 +7,16 @@ public record StudyStudentResponse( @Schema(description = "멤버 아이디") Long memberId, @Schema(description = "학생 이름") String name, @Schema(description = "학번") String studentId, - @Schema(description = "디스코드 사용자명") String discordName, - @Schema(description = "디스코드 닉네임") String discordUsername, + @Schema(description = "디스코드 사용자명") String discordUserName, + @Schema(description = "디스코드 닉네임") String nickname, @Schema(description = "깃허브 링크") String githubLink) { public static StudyStudentResponse from(StudyHistory studyHistory) { return new StudyStudentResponse( studyHistory.getMentee().getId(), studyHistory.getMentee().getName(), studyHistory.getMentee().getStudentId(), - studyHistory.getMentee().getDiscordId(), studyHistory.getMentee().getDiscordUsername(), + studyHistory.getMentee().getNickname(), studyHistory.getRepositoryLink()); } } From 55f4ce6edad0ecf3b52309c8868af58eef984099 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Thu, 15 Aug 2024 02:17:24 +0900 Subject: [PATCH 08/22] =?UTF-8?q?feat:=20=EC=96=B4=EB=93=9C=EB=AF=BC,=20?= =?UTF-8?q?=EB=A9=98=ED=86=A0,=20=EC=A6=89=20=EA=B2=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=9D=B8=20=ED=9A=8C=EC=9B=90=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC=EC=9D=84=20=EA=B2=80=EC=A6=9D=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/study/application/MentorStudyService.java | 3 +-- .../gdsc/domain/study/domain/StudyValidator.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java index 3edd8d63b..cdc673c4e 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java @@ -38,8 +38,7 @@ public List getStudyStudents(Long studyId) { Study study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(ErrorCode.STUDY_NOT_FOUND)); - studyValidator.validateStudyMentor( - currentMember.getId(), study.getMentor().getId()); + studyValidator.validateStudyMentor(currentMember, study.getMentor().getId()); List studyHistories = studyHistoryRepository.findByStudyId(studyId); return studyHistories.stream().map(StudyStudentResponse::from).toList(); diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java index 5351ebda3..dea0f3911 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java @@ -1,14 +1,20 @@ package com.gdschongik.gdsc.domain.study.domain; import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_INVALID; +import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_IS_UNAUTHORIZED; +import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.global.annotation.DomainService; import com.gdschongik.gdsc.global.exception.CustomException; @DomainService public class StudyValidator { - public void validateStudyMentor(Long currentMemberId, Long mentorId) { - if (!currentMemberId.equals(mentorId)) { + public void validateStudyMentor(Member currentMember, Long mentorId) { + if (currentMember.isGuest()) { + throw new CustomException(STUDY_MENTOR_IS_UNAUTHORIZED); + } + + if (!currentMember.getId().equals(mentorId)) { throw new CustomException(STUDY_MENTOR_INVALID); } } From 90f22ffd7f4bbc0896ba158b8c7b297d68bf89ee Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Fri, 16 Aug 2024 14:56:54 +0900 Subject: [PATCH 09/22] =?UTF-8?q?feat:=20=EC=96=B4=EB=93=9C=EB=AF=BC?= =?UTF-8?q?=EB=8F=84=20=EC=8A=A4=ED=84=B0=EB=94=94=EC=9D=98=20=EC=88=98?= =?UTF-8?q?=EA=B0=95=EC=83=9D=20=EB=AA=85=EB=8B=A8=20=EB=B3=BC=20=EC=88=98?= =?UTF-8?q?=20=EC=9E=88=EA=B2=8C=20=EA=B5=AC=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gdschongik/gdsc/domain/member/domain/Member.java | 4 ++++ .../gdsc/domain/study/application/MentorStudyService.java | 5 ++++- .../gdschongik/gdsc/domain/study/domain/StudyValidator.java | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java b/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java index 2270544d3..bedb886f2 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java +++ b/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java @@ -345,4 +345,8 @@ public boolean isAssociate() { public boolean isRegular() { return role.equals(REGULAR); } + + public boolean isAdmin() { + return role.equals(ADMIN); + } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java index cdc673c4e..0301cf59e 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java @@ -38,9 +38,12 @@ public List getStudyStudents(Long studyId) { Study study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(ErrorCode.STUDY_NOT_FOUND)); - studyValidator.validateStudyMentor(currentMember, study.getMentor().getId()); List studyHistories = studyHistoryRepository.findByStudyId(studyId); + if (!currentMember.isAdmin()) { + studyValidator.validateStudyMentor(currentMember, study.getMentor().getId()); + } + return studyHistories.stream().map(StudyStudentResponse::from).toList(); } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java index dea0f3911..eea51127a 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java @@ -10,7 +10,7 @@ @DomainService public class StudyValidator { public void validateStudyMentor(Member currentMember, Long mentorId) { - if (currentMember.isGuest()) { + if (currentMember.isGuest() || currentMember.isAssociate() || currentMember.isRegular()) { throw new CustomException(STUDY_MENTOR_IS_UNAUTHORIZED); } From a5c3d2e5b701d8066036bdbced5b408d88b10d82 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Fri, 16 Aug 2024 15:12:27 +0900 Subject: [PATCH 10/22] =?UTF-8?q?feat:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gdschongik/gdsc/domain/member/domain/Member.java | 2 +- .../gdsc/domain/study/dto/response/StudyStudentResponse.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java b/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java index bedb886f2..e7afe0dae 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java +++ b/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java @@ -347,6 +347,6 @@ public boolean isRegular() { } public boolean isAdmin() { - return role.equals(ADMIN); + return manageRole.equals(ADMIN); } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java index 894fd8b40..8f35cc2c7 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java @@ -7,7 +7,7 @@ public record StudyStudentResponse( @Schema(description = "멤버 아이디") Long memberId, @Schema(description = "학생 이름") String name, @Schema(description = "학번") String studentId, - @Schema(description = "디스코드 사용자명") String discordUserName, + @Schema(description = "디스코드 사용자명") String discordUsername, @Schema(description = "디스코드 닉네임") String nickname, @Schema(description = "깃허브 링크") String githubLink) { public static StudyStudentResponse from(StudyHistory studyHistory) { From 05f9f6e175acddb3d9c59c11d3e3b50996a7b849 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Fri, 16 Aug 2024 15:32:18 +0900 Subject: [PATCH 11/22] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/study/domain/StudyValidator.java | 5 --- .../study/domain/StudyValidatorTest.java | 41 +++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java index eea51127a..bdfcaea69 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java @@ -1,7 +1,6 @@ package com.gdschongik.gdsc.domain.study.domain; import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_INVALID; -import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_IS_UNAUTHORIZED; import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.global.annotation.DomainService; @@ -10,10 +9,6 @@ @DomainService public class StudyValidator { public void validateStudyMentor(Member currentMember, Long mentorId) { - if (currentMember.isGuest() || currentMember.isAssociate() || currentMember.isRegular()) { - throw new CustomException(STUDY_MENTOR_IS_UNAUTHORIZED); - } - if (!currentMember.getId().equals(mentorId)) { throw new CustomException(STUDY_MENTOR_INVALID); } diff --git a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java new file mode 100644 index 000000000..f406e4a72 --- /dev/null +++ b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java @@ -0,0 +1,41 @@ +package com.gdschongik.gdsc.domain.study.domain; + +import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_INVALID; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import com.gdschongik.gdsc.domain.member.domain.Member; +import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period; +import com.gdschongik.gdsc.global.exception.CustomException; +import com.gdschongik.gdsc.helper.FixtureHelper; +import java.time.LocalDateTime; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +public class StudyValidatorTest { + + FixtureHelper fixtureHelper = new FixtureHelper(); + + StudyValidator studyValidator = new StudyValidator(); + + @Nested + class 스터디_수강원_명단_조회시 { + + @Test + public void 멘토가_아니라면_실패한다() { + // given + Member currentMember = fixtureHelper.createAssociateMember(1L); + Member mentor = fixtureHelper.createAssociateMember(2L); + LocalDateTime assignmentCreatedDate = LocalDateTime.now().minusDays(1); + Study study = fixtureHelper.createStudy( + mentor, + Period.createPeriod(assignmentCreatedDate.plusDays(5), assignmentCreatedDate.plusDays(10)), + Period.createPeriod(assignmentCreatedDate.minusDays(5), assignmentCreatedDate)); + + // when & then + assertThatThrownBy(() -> studyValidator.validateStudyMentor( + currentMember, study.getMentor().getId())) + .isInstanceOf(CustomException.class) + .hasMessage(STUDY_MENTOR_INVALID.getMessage()); + } + } +} From dc87777bd47fead2da15d68d4f83455bc5c1bec8 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Fri, 16 Aug 2024 19:54:48 +0900 Subject: [PATCH 12/22] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../study/application/MentorStudyService.java | 5 +-- .../domain/study/domain/StudyValidator.java | 2 +- .../study/domain/StudyValidatorTest.java | 44 ++++++++++++++++++- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java index 0301cf59e..cdc673c4e 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java @@ -38,12 +38,9 @@ public List getStudyStudents(Long studyId) { Study study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(ErrorCode.STUDY_NOT_FOUND)); + studyValidator.validateStudyMentor(currentMember, study.getMentor().getId()); List studyHistories = studyHistoryRepository.findByStudyId(studyId); - if (!currentMember.isAdmin()) { - studyValidator.validateStudyMentor(currentMember, study.getMentor().getId()); - } - return studyHistories.stream().map(StudyStudentResponse::from).toList(); } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java index bdfcaea69..2d78dcd83 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java @@ -9,7 +9,7 @@ @DomainService public class StudyValidator { public void validateStudyMentor(Member currentMember, Long mentorId) { - if (!currentMember.getId().equals(mentorId)) { + if (!currentMember.isAdmin() && !currentMember.getId().equals(mentorId)) { throw new CustomException(STUDY_MENTOR_INVALID); } } diff --git a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java index f406e4a72..67b5b937d 100644 --- a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java +++ b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java @@ -1,7 +1,7 @@ package com.gdschongik.gdsc.domain.study.domain; import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_INVALID; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.*; import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period; @@ -37,5 +37,47 @@ class 스터디_수강원_명단_조회시 { .isInstanceOf(CustomException.class) .hasMessage(STUDY_MENTOR_INVALID.getMessage()); } + + @Test + public void 멘토이지만_자신이_맡은_스터디가_아니라면_실패한다() { + // given + Member currentMember = fixtureHelper.createAssociateMember(1L); + Member mentor = fixtureHelper.createAssociateMember(2L); + LocalDateTime assignmentCreatedDate = LocalDateTime.now().minusDays(1); + Study study = fixtureHelper.createStudy( + mentor, + Period.createPeriod(assignmentCreatedDate.plusDays(5), assignmentCreatedDate.plusDays(10)), + Period.createPeriod(assignmentCreatedDate.minusDays(5), assignmentCreatedDate)); + + Study currentMentorStudy = fixtureHelper.createStudy( + currentMember, + Period.createPeriod(assignmentCreatedDate.plusDays(5), assignmentCreatedDate.plusDays(10)), + Period.createPeriod(assignmentCreatedDate.minusDays(5), assignmentCreatedDate)); + + // when & then + assertThat(currentMentorStudy.getMentor().getId()).isEqualTo(currentMember.getId()); + assertThatThrownBy(() -> studyValidator.validateStudyMentor( + currentMember, study.getMentor().getId())) + .isInstanceOf(CustomException.class) + .hasMessage(STUDY_MENTOR_INVALID.getMessage()); + } + + @Test + public void 어드민이라면_성공한다() { + // given + Member admin = fixtureHelper.createAssociateMember(1L); + Member mentor = fixtureHelper.createAssociateMember(2L); + LocalDateTime assignmentCreatedDate = LocalDateTime.now().minusDays(1); + Study study = fixtureHelper.createStudy( + mentor, + Period.createPeriod(assignmentCreatedDate.plusDays(5), assignmentCreatedDate.plusDays(10)), + Period.createPeriod(assignmentCreatedDate.minusDays(5), assignmentCreatedDate)); + + // when & then + assertThatThrownBy(() -> studyValidator.validateStudyMentor( + admin, study.getMentor().getId())) + .isInstanceOf(CustomException.class) + .hasMessage(STUDY_MENTOR_INVALID.getMessage()); + } } } From 2f28e48a9771e4ad400da241ca01103d4c599764 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Fri, 16 Aug 2024 20:08:09 +0900 Subject: [PATCH 13/22] =?UTF-8?q?feat:=20=EC=8A=A4=ED=84=B0=EB=94=94=20val?= =?UTF-8?q?idator=ED=99=95=EC=9E=A5=EC=84=B1=20=EA=B3=A0=EB=A0=A4=ED=95=B4?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdschongik/gdsc/domain/study/domain/StudyValidator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java index 2d78dcd83..04b161dc7 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java @@ -8,8 +8,9 @@ @DomainService public class StudyValidator { - public void validateStudyMentor(Member currentMember, Long mentorId) { - if (!currentMember.isAdmin() && !currentMember.getId().equals(mentorId)) { + public void validateStudyMentor(Member currentMember, Study study) { + if (!currentMember.isAdmin() + && !currentMember.getId().equals(study.getMentor().getId())) { throw new CustomException(STUDY_MENTOR_INVALID); } } From 3a3bc021641837f555faa9510d18dbd49cd67323 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Fri, 16 Aug 2024 20:12:47 +0900 Subject: [PATCH 14/22] =?UTF-8?q?feat:=20=EB=B3=80=EA=B2=BD=EB=90=9C=20val?= =?UTF-8?q?idator=20=EB=A7=A4=EA=B0=9C=EB=B3=80=EC=88=98=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=EC=97=90=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/domain/StudyValidatorTest.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java index 67b5b937d..c38ccbaa0 100644 --- a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java +++ b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java @@ -32,8 +32,7 @@ class 스터디_수강원_명단_조회시 { Period.createPeriod(assignmentCreatedDate.minusDays(5), assignmentCreatedDate)); // when & then - assertThatThrownBy(() -> studyValidator.validateStudyMentor( - currentMember, study.getMentor().getId())) + assertThatThrownBy(() -> studyValidator.validateStudyMentor(currentMember, study)) .isInstanceOf(CustomException.class) .hasMessage(STUDY_MENTOR_INVALID.getMessage()); } @@ -56,8 +55,7 @@ class 스터디_수강원_명단_조회시 { // when & then assertThat(currentMentorStudy.getMentor().getId()).isEqualTo(currentMember.getId()); - assertThatThrownBy(() -> studyValidator.validateStudyMentor( - currentMember, study.getMentor().getId())) + assertThatThrownBy(() -> studyValidator.validateStudyMentor(currentMember, study)) .isInstanceOf(CustomException.class) .hasMessage(STUDY_MENTOR_INVALID.getMessage()); } @@ -74,8 +72,7 @@ class 스터디_수강원_명단_조회시 { Period.createPeriod(assignmentCreatedDate.minusDays(5), assignmentCreatedDate)); // when & then - assertThatThrownBy(() -> studyValidator.validateStudyMentor( - admin, study.getMentor().getId())) + assertThatThrownBy(() -> studyValidator.validateStudyMentor(admin, study)) .isInstanceOf(CustomException.class) .hasMessage(STUDY_MENTOR_INVALID.getMessage()); } From 6aeede4a32c2b4634af44df13297f97c216d8983 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Fri, 16 Aug 2024 20:18:01 +0900 Subject: [PATCH 15/22] =?UTF-8?q?feat:=20=EB=B3=80=EA=B2=BD=EB=90=9C=20?= =?UTF-8?q?=EB=A7=A4=EA=B0=9C=EB=B3=80=EC=88=98=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EC=97=90=20=EC=A0=81=EC=9A=A9=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/application/MentorStudyService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java index cdc673c4e..c2227117b 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java @@ -38,7 +38,7 @@ public List getStudyStudents(Long studyId) { Study study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(ErrorCode.STUDY_NOT_FOUND)); - studyValidator.validateStudyMentor(currentMember, study.getMentor().getId()); + studyValidator.validateStudyMentor(currentMember, study); List studyHistories = studyHistoryRepository.findByStudyId(studyId); return studyHistories.stream().map(StudyStudentResponse::from).toList(); From ee35677120782876ca1195ffeaa60cc87acaf1fe Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Fri, 16 Aug 2024 20:53:02 +0900 Subject: [PATCH 16/22] =?UTF-8?q?feat:=20=EB=B3=B5=EC=9E=A1=ED=95=9C=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/member/domain/Member.java | 4 ++++ .../domain/study/api/MentorStudyController.java | 2 +- .../gdsc/domain/study/domain/StudyValidator.java | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java b/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java index e7afe0dae..7878ec3e1 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java +++ b/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java @@ -349,4 +349,8 @@ public boolean isRegular() { public boolean isAdmin() { return manageRole.equals(ADMIN); } + + public boolean isMentor() { + return manageRole.equals(MENTOR); + } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java b/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java index fda3709d9..4aec648be 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java @@ -29,7 +29,7 @@ public ResponseEntity> getStudiesInCharge() { } @Operation(summary = "내 스터디 수강생 명단 조회", description = "내가 멘토로 있는 스터디 수강생 명단을 조회합니다") - @GetMapping("/me/students/{studyId}") + @GetMapping("/{studyId}/students") public ResponseEntity> getStudyStudents(@PathVariable Long studyId) { List response = mentorStudyService.getStudyStudents(studyId); return ResponseEntity.ok(response); diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java index 04b161dc7..d6aa5c10a 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java @@ -1,6 +1,7 @@ package com.gdschongik.gdsc.domain.study.domain; import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_INVALID; +import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_IS_UNAUTHORIZED; import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.global.annotation.DomainService; @@ -9,8 +10,18 @@ @DomainService public class StudyValidator { public void validateStudyMentor(Member currentMember, Study study) { - if (!currentMember.isAdmin() - && !currentMember.getId().equals(study.getMentor().getId())) { + // 어드민인 경우 검증 통과 + if (currentMember.isAdmin()) { + return; + } + + // 어드민이 아니고 멘토 역할도 아니면 경우에 예외가 밸생합니다. + if (!currentMember.isAdmin() || !currentMember.isMentor()) { + throw new CustomException(STUDY_MENTOR_IS_UNAUTHORIZED); + } + + // 해당 스터디의 담당 멘토인지 검증 + if (!currentMember.getId().equals(study.getMentor().getId())) { throw new CustomException(STUDY_MENTOR_INVALID); } } From 9790339d4fa1ece15a76473b3566cbc5bad27a87 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Fri, 16 Aug 2024 22:03:25 +0900 Subject: [PATCH 17/22] =?UTF-8?q?feat:=20=EC=8A=A4=ED=84=B0=EB=94=94=20val?= =?UTF-8?q?idator=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=98=A4=EB=A5=98=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 --- .../gdsc/domain/member/domain/Member.java | 2 +- .../domain/study/domain/StudyValidator.java | 2 +- .../study/domain/StudyValidatorTest.java | 35 +++++++++++++------ .../gdschongik/gdsc/helper/FixtureHelper.java | 16 ++++++++- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java b/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java index 7878ec3e1..da0a9124f 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java +++ b/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java @@ -351,6 +351,6 @@ public boolean isAdmin() { } public boolean isMentor() { - return manageRole.equals(MENTOR); + return studyRole.equals(MENTOR); } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java index d6aa5c10a..ddbdfa242 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java @@ -16,7 +16,7 @@ public void validateStudyMentor(Member currentMember, Study study) { } // 어드민이 아니고 멘토 역할도 아니면 경우에 예외가 밸생합니다. - if (!currentMember.isAdmin() || !currentMember.isMentor()) { + if (!currentMember.isAdmin() && !currentMember.isMentor()) { throw new CustomException(STUDY_MENTOR_IS_UNAUTHORIZED); } diff --git a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java index c38ccbaa0..a8fd2e08d 100644 --- a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java +++ b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java @@ -1,6 +1,7 @@ package com.gdschongik.gdsc.domain.study.domain; import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_INVALID; +import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_IS_UNAUTHORIZED; import static org.assertj.core.api.Assertions.*; import com.gdschongik.gdsc.domain.member.domain.Member; @@ -17,14 +18,27 @@ public class StudyValidatorTest { StudyValidator studyValidator = new StudyValidator(); + // FixtureHelper 래핑 메서드 + private Member createMentor(Long id) { + return fixtureHelper.createMentor(id); + } + + private Member createMember(Long id) { + return fixtureHelper.createAssociateMember(id); + } + + private Member createAdmin(Long id) { + return fixtureHelper.createAdmin(id); + } + @Nested class 스터디_수강원_명단_조회시 { @Test - public void 멘토가_아니라면_실패한다() { + public void 멘토역할이_아니라면_실패한다() { // given - Member currentMember = fixtureHelper.createAssociateMember(1L); - Member mentor = fixtureHelper.createAssociateMember(2L); + Member currentMember = createMember(1L); + Member mentor = createMentor(2L); LocalDateTime assignmentCreatedDate = LocalDateTime.now().minusDays(1); Study study = fixtureHelper.createStudy( mentor, @@ -34,14 +48,14 @@ class 스터디_수강원_명단_조회시 { // when & then assertThatThrownBy(() -> studyValidator.validateStudyMentor(currentMember, study)) .isInstanceOf(CustomException.class) - .hasMessage(STUDY_MENTOR_INVALID.getMessage()); + .hasMessage(STUDY_MENTOR_IS_UNAUTHORIZED.getMessage()); } @Test public void 멘토이지만_자신이_맡은_스터디가_아니라면_실패한다() { // given - Member currentMember = fixtureHelper.createAssociateMember(1L); - Member mentor = fixtureHelper.createAssociateMember(2L); + Member currentMember = createMentor(1L); + Member mentor = createMentor(2L); LocalDateTime assignmentCreatedDate = LocalDateTime.now().minusDays(1); Study study = fixtureHelper.createStudy( mentor, @@ -63,8 +77,8 @@ class 스터디_수강원_명단_조회시 { @Test public void 어드민이라면_성공한다() { // given - Member admin = fixtureHelper.createAssociateMember(1L); - Member mentor = fixtureHelper.createAssociateMember(2L); + Member admin = createAdmin(1L); + Member mentor = createMentor(2L); LocalDateTime assignmentCreatedDate = LocalDateTime.now().minusDays(1); Study study = fixtureHelper.createStudy( mentor, @@ -72,9 +86,8 @@ class 스터디_수강원_명단_조회시 { Period.createPeriod(assignmentCreatedDate.minusDays(5), assignmentCreatedDate)); // when & then - assertThatThrownBy(() -> studyValidator.validateStudyMentor(admin, study)) - .isInstanceOf(CustomException.class) - .hasMessage(STUDY_MENTOR_INVALID.getMessage()); + assertThatCode(() -> studyValidator.validateStudyMentor(admin, study)) + .doesNotThrowAnyException(); } } } diff --git a/src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java b/src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java index f6a4c1cdf..a108ca013 100644 --- a/src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java +++ b/src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java @@ -1,7 +1,8 @@ package com.gdschongik.gdsc.helper; import static com.gdschongik.gdsc.domain.member.domain.Department.*; -import static com.gdschongik.gdsc.domain.member.domain.Member.*; +import static com.gdschongik.gdsc.domain.member.domain.MemberManageRole.ADMIN; +import static com.gdschongik.gdsc.domain.member.domain.MemberStudyRole.MENTOR; import static com.gdschongik.gdsc.global.common.constant.MemberConstant.*; import static com.gdschongik.gdsc.global.common.constant.RecruitmentConstant.*; import static com.gdschongik.gdsc.global.common.constant.SemesterConstant.*; @@ -46,6 +47,19 @@ public Member createRegularMember(Long id) { return member; } + public Member createAdmin(Long id) { + Member member = createRegularMember(id); + ReflectionTestUtils.setField(member, "manageRole", ADMIN); + return member; + } + + public Member createMentor(Long id) { + Member member = createRegularMember(id); + member.assignToMentor(); + ReflectionTestUtils.setField(member, "studyRole", MENTOR); + return member; + } + public RecruitmentRound createRecruitmentRound( LocalDateTime startDate, LocalDateTime endDate, From 7fc485d9122e5764a4883f1882deafa686358c4b Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Fri, 16 Aug 2024 23:29:54 +0900 Subject: [PATCH 18/22] =?UTF-8?q?feat:=20description=20=EC=88=98=EC=A0=95,?= =?UTF-8?q?=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20=EB=A1=9C=EC=A7=81=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 --- .../gdschongik/gdsc/domain/study/api/MentorStudyController.java | 2 +- .../com/gdschongik/gdsc/domain/study/domain/StudyValidator.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java b/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java index 4aec648be..0ff6c784f 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyController.java @@ -28,7 +28,7 @@ public ResponseEntity> getStudiesInCharge() { return ResponseEntity.ok(response); } - @Operation(summary = "내 스터디 수강생 명단 조회", description = "내가 멘토로 있는 스터디 수강생 명단을 조회합니다") + @Operation(summary = "스터디 수강생 명단 조회", description = "해당 스터디의 수강생 명단을 조회합니다") @GetMapping("/{studyId}/students") public ResponseEntity> getStudyStudents(@PathVariable Long studyId) { List response = mentorStudyService.getStudyStudents(studyId); diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java index ddbdfa242..e5ba0427f 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java @@ -16,7 +16,7 @@ public void validateStudyMentor(Member currentMember, Study study) { } // 어드민이 아니고 멘토 역할도 아니면 경우에 예외가 밸생합니다. - if (!currentMember.isAdmin() && !currentMember.isMentor()) { + if (!currentMember.isMentor()) { throw new CustomException(STUDY_MENTOR_IS_UNAUTHORIZED); } From aa9a4073e22cb714ccab530bef1ad0885b6a6a2d Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Sat, 17 Aug 2024 12:48:02 +0900 Subject: [PATCH 19/22] =?UTF-8?q?feat:=20=EC=BD=94=EB=93=9C=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=20=EC=A7=80=ED=82=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/domain/StudyValidatorTest.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java index a8fd2e08d..f87386fe0 100644 --- a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java +++ b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java @@ -15,7 +15,6 @@ public class StudyValidatorTest { FixtureHelper fixtureHelper = new FixtureHelper(); - StudyValidator studyValidator = new StudyValidator(); // FixtureHelper 래핑 메서드 @@ -32,10 +31,10 @@ private Member createAdmin(Long id) { } @Nested - class 스터디_수강원_명단_조회시 { + class 스터디_수강자_명단_조회시 { @Test - public void 멘토역할이_아니라면_실패한다() { + void 멘토역할이_아니라면_실패한다() { // given Member currentMember = createMember(1L); Member mentor = createMentor(2L); @@ -52,7 +51,7 @@ class 스터디_수강원_명단_조회시 { } @Test - public void 멘토이지만_자신이_맡은_스터디가_아니라면_실패한다() { + void 멘토이지만_자신이_맡은_스터디가_아니라면_실패한다() { // given Member currentMember = createMentor(1L); Member mentor = createMentor(2L); @@ -75,7 +74,7 @@ class 스터디_수강원_명단_조회시 { } @Test - public void 어드민이라면_성공한다() { + void 어드민이라면_성공한다() { // given Member admin = createAdmin(1L); Member mentor = createMentor(2L); From 203449b1b53af326784e369358e600a7977649ae Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Sat, 17 Aug 2024 22:46:34 +0900 Subject: [PATCH 20/22] =?UTF-8?q?feat:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/domain/StudyValidator.java | 9 ++++----- .../com/gdschongik/gdsc/global/exception/ErrorCode.java | 1 + .../gdsc/domain/study/domain/StudyValidatorTest.java | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java index e5ba0427f..eadb76831 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java @@ -1,12 +1,11 @@ package com.gdschongik.gdsc.domain.study.domain; -import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_INVALID; -import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_IS_UNAUTHORIZED; - import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.global.annotation.DomainService; import com.gdschongik.gdsc.global.exception.CustomException; +import static com.gdschongik.gdsc.global.exception.ErrorCode.*; + @DomainService public class StudyValidator { public void validateStudyMentor(Member currentMember, Study study) { @@ -15,9 +14,9 @@ public void validateStudyMentor(Member currentMember, Study study) { return; } - // 어드민이 아니고 멘토 역할도 아니면 경우에 예외가 밸생합니다. + // 어드민이 아니고 멘토 역할도 아니면 예외가 밸생합니다. if (!currentMember.isMentor()) { - throw new CustomException(STUDY_MENTOR_IS_UNAUTHORIZED); + throw new CustomException(STUDY_ACCESS_NOT_ALLOWED); } // 해당 스터디의 담당 멘토인지 검증 diff --git a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java index f6828ca91..be3f0045d 100644 --- a/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java +++ b/src/main/java/com/gdschongik/gdsc/global/exception/ErrorCode.java @@ -100,6 +100,7 @@ public enum ErrorCode { // Study STUDY_APPLICATION_START_DATE_INVALID(HttpStatus.CONFLICT, "스터디 신청기간 시작일이 스터디 시작일보다 빠릅니다."), STUDY_MENTOR_IS_UNAUTHORIZED(HttpStatus.CONFLICT, "게스트인 회원은 멘토로 지정할 수 없습니다."), + STUDY_ACCESS_NOT_ALLOWED(HttpStatus.FORBIDDEN, "관리자 또는 멘토 역할이 아닌 회원은 이 작업을 수행할 수 없습니다."), STUDY_MENTOR_INVALID(HttpStatus.CONFLICT, "사용자가 해당 스터디의 멘토가 아닙니다."), ON_OFF_LINE_STUDY_TIME_IS_ESSENTIAL(HttpStatus.CONFLICT, "온오프라인 스터디는 스터디 시간이 필요합니다."), STUDY_TIME_INVALID(HttpStatus.CONFLICT, "스터디종료 시각이 스터디시작 시각보다 빠릅니다."), diff --git a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java index f87386fe0..71155a7be 100644 --- a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java +++ b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java @@ -1,7 +1,6 @@ package com.gdschongik.gdsc.domain.study.domain; -import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_INVALID; -import static com.gdschongik.gdsc.global.exception.ErrorCode.STUDY_MENTOR_IS_UNAUTHORIZED; +import static com.gdschongik.gdsc.global.exception.ErrorCode.*; import static org.assertj.core.api.Assertions.*; import com.gdschongik.gdsc.domain.member.domain.Member; @@ -31,7 +30,7 @@ private Member createAdmin(Long id) { } @Nested - class 스터디_수강자_명단_조회시 { + class 스터디_검증시{ @Test void 멘토역할이_아니라면_실패한다() { @@ -47,7 +46,7 @@ class 스터디_수강자_명단_조회시 { // when & then assertThatThrownBy(() -> studyValidator.validateStudyMentor(currentMember, study)) .isInstanceOf(CustomException.class) - .hasMessage(STUDY_MENTOR_IS_UNAUTHORIZED.getMessage()); + .hasMessage(STUDY_ACCESS_NOT_ALLOWED.getMessage()); } @Test From 7e5c23025a0e3bf045a31196498733c2f38481dc Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Sat, 17 Aug 2024 22:49:20 +0900 Subject: [PATCH 21/22] =?UTF-8?q?fix:=20=EB=A8=B8=EC=A7=80=20=EC=BB=A8?= =?UTF-8?q?=ED=94=8C=EB=A6=AD=ED=8A=B8=20=EC=88=98=EC=A0=95=ED=95=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdsc/domain/study/dao/StudyHistoryRepository.java | 4 ++-- src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyHistoryRepository.java b/src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyHistoryRepository.java index eedfe1e6b..126c24145 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyHistoryRepository.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyHistoryRepository.java @@ -9,10 +9,10 @@ public interface StudyHistoryRepository extends JpaRepository { + List findByStudyId(Long studyId); + // TODO mentee -> student로 변경 List findAllByMentee(Member member); Optional findByMenteeAndStudy(Member member, Study study); - - List findByStudyId(Long studyId); } diff --git a/src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java b/src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java index a108ca013..b2ad75dcb 100644 --- a/src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java +++ b/src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java @@ -1,12 +1,12 @@ package com.gdschongik.gdsc.helper; import static com.gdschongik.gdsc.domain.member.domain.Department.*; -import static com.gdschongik.gdsc.domain.member.domain.MemberManageRole.ADMIN; -import static com.gdschongik.gdsc.domain.member.domain.MemberStudyRole.MENTOR; import static com.gdschongik.gdsc.global.common.constant.MemberConstant.*; import static com.gdschongik.gdsc.global.common.constant.RecruitmentConstant.*; import static com.gdschongik.gdsc.global.common.constant.SemesterConstant.*; import static com.gdschongik.gdsc.global.common.constant.StudyConstant.*; +import static com.gdschongik.gdsc.domain.member.domain.MemberManageRole.ADMIN; +import static com.gdschongik.gdsc.domain.member.domain.MemberStudyRole.MENTOR; import com.gdschongik.gdsc.domain.common.model.SemesterType; import com.gdschongik.gdsc.domain.common.vo.Money; From b870af08427d4bc69f95689818531d0096fc1d07 Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Sat, 17 Aug 2024 22:50:26 +0900 Subject: [PATCH 22/22] =?UTF-8?q?feat:=20develop=EA=B3=BC=20merge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gdschongik/gdsc/domain/study/domain/StudyValidator.java | 4 ++-- .../gdsc/domain/study/domain/StudyValidatorTest.java | 2 +- src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java index eadb76831..ce22c17e5 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyValidator.java @@ -1,11 +1,11 @@ package com.gdschongik.gdsc.domain.study.domain; +import static com.gdschongik.gdsc.global.exception.ErrorCode.*; + import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.global.annotation.DomainService; import com.gdschongik.gdsc.global.exception.CustomException; -import static com.gdschongik.gdsc.global.exception.ErrorCode.*; - @DomainService public class StudyValidator { public void validateStudyMentor(Member currentMember, Study study) { diff --git a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java index 71155a7be..6507a1fef 100644 --- a/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java +++ b/src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyValidatorTest.java @@ -30,7 +30,7 @@ private Member createAdmin(Long id) { } @Nested - class 스터디_검증시{ + class 스터디_검증시 { @Test void 멘토역할이_아니라면_실패한다() { diff --git a/src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java b/src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java index f0284adac..5874f7e71 100644 --- a/src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java +++ b/src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java @@ -1,12 +1,12 @@ package com.gdschongik.gdsc.helper; import static com.gdschongik.gdsc.domain.member.domain.Department.*; +import static com.gdschongik.gdsc.domain.member.domain.MemberManageRole.ADMIN; +import static com.gdschongik.gdsc.domain.member.domain.MemberStudyRole.MENTOR; import static com.gdschongik.gdsc.global.common.constant.MemberConstant.*; import static com.gdschongik.gdsc.global.common.constant.RecruitmentConstant.*; import static com.gdschongik.gdsc.global.common.constant.SemesterConstant.*; import static com.gdschongik.gdsc.global.common.constant.StudyConstant.*; -import static com.gdschongik.gdsc.domain.member.domain.MemberManageRole.ADMIN; -import static com.gdschongik.gdsc.domain.member.domain.MemberStudyRole.MENTOR; import com.gdschongik.gdsc.domain.common.model.SemesterType; import com.gdschongik.gdsc.domain.common.vo.Money;