Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 스터디 수강생 명단 조회 #623

Merged
merged 24 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9de4594
feat: 스터디원 조회 api 스펙
AlmondBreez3 Aug 14, 2024
46bce0c
Merge branch 'develop' of https://github.com/GDSC-Hongik/gdsc-server …
AlmondBreez3 Aug 14, 2024
59eeb9a
feat: 멘토 특정 스터디 수강생 명단 조회 구현
AlmondBreez3 Aug 14, 2024
456ee61
feat: 해당 스터디의 멘토인지 검증하는 로직 추가
AlmondBreez3 Aug 14, 2024
a9465b6
feat: 자잘한 컨벤션 지키기
AlmondBreez3 Aug 14, 2024
73c601d
feat: endpoint수정하기
AlmondBreez3 Aug 14, 2024
019ca34
feat: 외부 도메인 서비스에 의해 참조 엔티티에 대한 검증 책임 구현
AlmondBreez3 Aug 14, 2024
90846e6
feat: 디스코드 관련 명칭 수정
AlmondBreez3 Aug 14, 2024
55f4ce6
feat: 어드민, 멘토, 즉 게스트인 회원에 대한 접근을 검증하는 로직 추가
AlmondBreez3 Aug 14, 2024
90f22ff
feat: 어드민도 스터디의 수강생 명단 볼 수 있게 구성
AlmondBreez3 Aug 16, 2024
a5c3d2e
feat: 오타 수정
AlmondBreez3 Aug 16, 2024
05f9f6e
feat: 테스트 추가
AlmondBreez3 Aug 16, 2024
dc87777
feat: 테스트 추가 및 로직 수정
AlmondBreez3 Aug 16, 2024
2f28e48
feat: 스터디 validator확장성 고려해서 수정
AlmondBreez3 Aug 16, 2024
3a3bc02
feat: 변경된 validator 매개변수 테스트코드에 반영
AlmondBreez3 Aug 16, 2024
6aeede4
feat: 변경된 매개변수 코드에 적용하기
AlmondBreez3 Aug 16, 2024
ee35677
feat: 복잡한 예외 케이스 분리하기
AlmondBreez3 Aug 16, 2024
9790339
feat: 스터디 validator 테스트 오류 수정
AlmondBreez3 Aug 16, 2024
7fc485d
feat: description 수정, 불필요한 로직 수정
AlmondBreez3 Aug 16, 2024
aa9a407
feat: 코드 컨벤션 지키기
AlmondBreez3 Aug 17, 2024
203449b
feat: 오타 수정
AlmondBreez3 Aug 17, 2024
7e5c230
fix: 머지 컨플릭트 수정하기
AlmondBreez3 Aug 17, 2024
758a038
Merge branch 'develop' of https://github.com/GDSC-Hongik/gdsc-server …
AlmondBreez3 Aug 17, 2024
b870af0
feat: develop과 merge
AlmondBreez3 Aug 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,4 +27,11 @@ public ResponseEntity<List<MentorStudyResponse>> getStudiesInCharge() {
List<MentorStudyResponse> response = mentorStudyService.getStudiesInCharge();
return ResponseEntity.ok(response);
}

@Operation(summary = "내 스터디 수강생 명단 조회", description = "내가 멘토로 있는 스터디 수강생 명단을 조회합니다")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Operation(summary = "스터디 수강생 명단 조회", description = "내가 멘토로 있는 스터디 수강생 명단을 조회합니다")
@Operation(summary = "스터디 수강생 명단 조회", description = "해당 스터디의 수강생 명단을 조회합니다")

@GetMapping("/me/{studyId}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/me/{studyId}는 스터디의 정보를 조회하는 엔드포인트 아닌가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 다른 controller랑 겹치지 않아서 단순히 이렇게 해놨는데
/me/students/{studyId}
로 바꾸겠습니다

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그럼 내 학생들의 스터디를 조회한다는 의미가 되는데, 더 적절해지지 않아질 것 같습니다

public ResponseEntity<List<StudyStudentResponse>> getStudyStudents(@PathVariable Long studyId) {
List<StudyStudentResponse> response = mentorStudyService.getStudyStudents(studyId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.gdschongik.gdsc.domain.study.application;

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;
Expand All @@ -16,11 +21,26 @@ public class MentorStudyService {

private final MemberUtil memberUtil;
private final StudyRepository studyRepository;
private final StudyHistoryRepository studyHistoryRepository;

@Transactional(readOnly = true)
public List<MentorStudyResponse> getStudiesInCharge() {
Member currentMember = memberUtil.getCurrentMember();
List<Study> myStudies = studyRepository.findAllByMentor(currentMember);
return myStudies.stream().map(MentorStudyResponse::from).toList();
}

@Transactional(readOnly = true)
public List<StudyStudentResponse> getStudyStudents(Long studyId) {
Member currentMember = memberUtil.getCurrentMember();

Study study =
studyRepository.findById(studyId).orElseThrow(() -> new CustomException(ErrorCode.STUDY_NOT_FOUND));

study.validateMentor(currentMember);

List<StudyHistory> studyHistories = studyHistoryRepository.findByStudyId(studyId);

return studyHistories.stream().map(StudyStudentResponse::from).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface StudyHistoryRepository extends JpaRepository<StudyHistory, Long
List<StudyHistory> findAllByMentee(Member member);

Optional<StudyHistory> findByMenteeAndStudy(Member member, Study study);

List<StudyHistory> findByStudyId(Long studyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public static Study createStudy(
.build();
}

// 검증 로직

private static void validateApplicationStartDateBeforeSessionStartDate(
LocalDateTime applicationStartDate, LocalDateTime startDate) {
if (!applicationStartDate.isBefore(startDate)) {
Expand Down Expand Up @@ -163,6 +165,12 @@ private static void validateAssignmentLineStudyTime(LocalTime studyStartTime, Lo
}
}

public void validateMentor(Member currentMember) {
if (currentMember != mentor) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엔티티는 id로 동등 여부를 확인합니다.
그리고 스터디는 자신의 내부 값에 대해서만 검증 책임을 가지지, 참조 엔티티인 멤버에 대한 검증 책임을 가지지 않습니다.
만약 스터디의 멘토가 특정 멤버와 일치하는지 확인하고 싶다면 그건 외부 도메인 서비스에 의해서 수행되어야 합니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 넵 studyValidator만들어서 따로 구현하겠습니다

throw new CustomException(STUDY_MENTOR_INVALID);
}
}

// 데이터 전달 로직
public boolean isApplicable() {
return applicationPeriod.isOpen();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.gdschongik.gdsc.domain.study.dto.response;

import com.gdschongik.gdsc.domain.study.domain.StudyHistory;
import io.swagger.v3.oas.annotations.media.Schema;

public record StudyStudentResponse(
@Schema(description = "멤버 아이디") Long memberId,
@Schema(description = "학생 이름") String name,
@Schema(description = "학번") String studentId,
@Schema(description = "디스코드 사용자명") String discordName,
@Schema(description = "디스코드 닉네임") String discordUsername,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
studyHistory.getMentee().getDiscordId(),
studyHistory.getMentee().getDiscordUsername(),
studyHistory.getMentee().getDiscordUsername(),
studyHistory.getMentee().getNickname(),

studyHistory.getRepositoryLink());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, "과제 스터디는 스터디 시간을 입력할 수 없습니다."),
Expand Down