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 7 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/students/{studyId}")
Copy link
Contributor

Choose a reason for hiding this comment

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

{studyId}가 맨앞에 오는게 좋을거같아요! /mentor/studies/{studyId} 이렇게요!
그리고 studyId가 들어가는데 me가 들어갈필요는 없을거같아요!

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,15 @@
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.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;
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 +22,26 @@ public class MentorStudyService {

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

@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));

studyValidator.validateStudyMentor(
currentMember.getId(), study.getMentor().getId());
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
Original file line number Diff line number Diff line change
@@ -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)) {
Copy link
Member

Choose a reason for hiding this comment

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

이러면 어드민이 접근할 수 없지 않나요?

throw new CustomException(STUDY_MENTOR_INVALID);
}
}
}
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