diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/api/StudentStudyHistoryController.java b/src/main/java/com/gdschongik/gdsc/domain/study/api/StudentStudyHistoryController.java index 8764e5a95..1cf0bbb7a 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/api/StudentStudyHistoryController.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/api/StudentStudyHistoryController.java @@ -3,6 +3,7 @@ import com.gdschongik.gdsc.domain.study.application.StudentStudyHistoryService; import com.gdschongik.gdsc.domain.study.dto.request.RepositoryUpdateRequest; import com.gdschongik.gdsc.domain.study.dto.response.AssignmentHistoryResponse; +import com.gdschongik.gdsc.domain.study.dto.response.StudentMyCompleteStudyResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -42,4 +43,11 @@ public ResponseEntity submitAssignment(@RequestParam(name = "studyDetailId studentStudyHistoryService.submitAssignment(studyDetailId); return ResponseEntity.ok().build(); } + + @Operation(summary = "내 스터디 수료 내역 조회", description = "내가 수료한 스터디를 조회합니다.") + @GetMapping("/me/complete") + public ResponseEntity> getMyCompletedStudy() { + List response = studentStudyHistoryService.getMyCompletedStudies(); + return ResponseEntity.ok(response); + } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/StudentStudyHistoryService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/StudentStudyHistoryService.java index d631f3779..db39a9ac5 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/StudentStudyHistoryService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/StudentStudyHistoryService.java @@ -1,28 +1,35 @@ package com.gdschongik.gdsc.domain.study.application; import static com.gdschongik.gdsc.global.exception.ErrorCode.*; +import static java.util.stream.Collectors.*; import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.domain.study.dao.AssignmentHistoryRepository; +import com.gdschongik.gdsc.domain.study.dao.StudyAchievementRepository; import com.gdschongik.gdsc.domain.study.dao.StudyDetailRepository; import com.gdschongik.gdsc.domain.study.dao.StudyHistoryRepository; import com.gdschongik.gdsc.domain.study.dao.StudyRepository; +import com.gdschongik.gdsc.domain.study.domain.AchievementType; import com.gdschongik.gdsc.domain.study.domain.AssignmentHistory; import com.gdschongik.gdsc.domain.study.domain.AssignmentHistoryGrader; import com.gdschongik.gdsc.domain.study.domain.AssignmentSubmissionFetcher; import com.gdschongik.gdsc.domain.study.domain.Study; +import com.gdschongik.gdsc.domain.study.domain.StudyAchievement; import com.gdschongik.gdsc.domain.study.domain.StudyAssignmentHistoryValidator; import com.gdschongik.gdsc.domain.study.domain.StudyDetail; import com.gdschongik.gdsc.domain.study.domain.StudyHistory; import com.gdschongik.gdsc.domain.study.domain.StudyHistoryValidator; import com.gdschongik.gdsc.domain.study.dto.request.RepositoryUpdateRequest; import com.gdschongik.gdsc.domain.study.dto.response.AssignmentHistoryResponse; +import com.gdschongik.gdsc.domain.study.dto.response.StudentMyCompleteStudyResponse; import com.gdschongik.gdsc.global.exception.CustomException; import com.gdschongik.gdsc.global.util.MemberUtil; import com.gdschongik.gdsc.infra.github.client.GithubClient; import java.io.IOException; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -44,6 +51,7 @@ public class StudentStudyHistoryService { private final StudyAssignmentHistoryValidator studyAssignmentHistoryValidator; private final AssignmentHistoryGrader assignmentHistoryGrader; private final StudyRepository studyRepository; + private final StudyAchievementRepository studyAchievementRepository; @Transactional public void updateRepository(Long studyId, RepositoryUpdateRequest request) throws IOException { @@ -107,6 +115,25 @@ public void submitAssignment(Long studyDetailId) { assignmentHistory.getSubmissionFailureType()); } + @Transactional(readOnly = true) + public List getMyCompletedStudies() { + Member currentMember = memberUtil.getCurrentMember(); + List studyHistories = studyHistoryRepository.findAllByStudent(currentMember); + List studyAchievements = studyAchievementRepository.findAllByStudent(currentMember); + + Map> achievementsByStudy = studyAchievements.stream() + .collect(groupingBy( + StudyAchievement::getStudy, mapping(StudyAchievement::getAchievementType, toList()))); + + return studyHistories.stream() + .map(history -> { + List achievementTypes = + achievementsByStudy.getOrDefault(history.getStudy(), new ArrayList<>()); + return StudentMyCompleteStudyResponse.of(history, achievementTypes); + }) + .toList(); + } + private AssignmentHistory findOrCreate(Member currentMember, StudyDetail studyDetail) { return assignmentHistoryRepository .findByMemberAndStudyDetail(currentMember, studyDetail) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyAchievementRepository.java b/src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyAchievementRepository.java index 361e1a35d..9951c1ecf 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyAchievementRepository.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyAchievementRepository.java @@ -1,7 +1,12 @@ package com.gdschongik.gdsc.domain.study.dao; +import com.gdschongik.gdsc.domain.member.domain.Member; import com.gdschongik.gdsc.domain.study.domain.StudyAchievement; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; public interface StudyAchievementRepository - extends JpaRepository, StudyAchievementCustomRepository {} + extends JpaRepository, StudyAchievementCustomRepository { + + List findAllByStudent(Member student); +} diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudentMyCompleteStudyResponse.java b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudentMyCompleteStudyResponse.java new file mode 100644 index 000000000..a7fa46d9a --- /dev/null +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudentMyCompleteStudyResponse.java @@ -0,0 +1,37 @@ +package com.gdschongik.gdsc.domain.study.dto.response; + +import com.gdschongik.gdsc.domain.common.model.SemesterType; +import com.gdschongik.gdsc.domain.study.domain.AchievementType; +import com.gdschongik.gdsc.domain.study.domain.StudyHistory; +import com.gdschongik.gdsc.domain.study.domain.StudyHistoryStatus; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; + +public record StudentMyCompleteStudyResponse( + Long studyId, + @Schema(description = "학년도") Integer academicYear, + @Schema(description = "학기") SemesterType semesterType, + @Schema(description = "이름") String title, + @Schema(description = "종류") String studyType, + @Schema(description = "상세설명 노션 링크") String notionLink, + @Schema(description = "한 줄 소개") String introduction, + @Schema(description = "멘토 이름") String mentorName, + @Schema(description = "총 주차수") Long totalWeek, + @Schema(description = "수료 여부") StudyHistoryStatus studyHistoryStatus, + @Schema(description = "우수 스터디원 선정 내역") List achievements) { + + public static StudentMyCompleteStudyResponse of(StudyHistory studyHistory, List achievements) { + return new StudentMyCompleteStudyResponse( + studyHistory.getStudy().getId(), + studyHistory.getStudy().getAcademicYear(), + studyHistory.getStudy().getSemesterType(), + studyHistory.getStudy().getTitle(), + studyHistory.getStudy().getStudyType().getValue(), + studyHistory.getStudy().getNotionLink(), + studyHistory.getStudy().getIntroduction(), + studyHistory.getStudy().getMentor().getName(), + studyHistory.getStudy().getTotalWeek(), + studyHistory.getStudyHistoryStatus(), + achievements); + } +}