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: 스터디 수료 내역 조회 API #798

Merged
merged 12 commits into from
Oct 10, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,4 +43,11 @@ public ResponseEntity<Void> submitAssignment(@RequestParam(name = "studyDetailId
studentStudyHistoryService.submitAssignment(studyDetailId);
return ResponseEntity.ok().build();
}

@Operation(summary = "내 스터디 수료 내역 조회", description = "내가 수료한 스터디를 조회합니다.")
@GetMapping("/me/complete")
public ResponseEntity<List<StudentMyCompleteStudyResponse>> getMyCompleteStudy() {
kckc0608 marked this conversation as resolved.
Show resolved Hide resolved
List<StudentMyCompleteStudyResponse> response = studentStudyHistoryService.getMyCompleteStudies();
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@

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 java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.kohsuke.github.GHRepository;
Expand All @@ -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 {
Expand Down Expand Up @@ -107,6 +115,28 @@ public void submitAssignment(Long studyDetailId) {
assignmentHistory.getSubmissionFailureType());
}

@Transactional(readOnly = true)
public List<StudentMyCompleteStudyResponse> getMyCompleteStudies() {
kckc0608 marked this conversation as resolved.
Show resolved Hide resolved
Member currentMember = memberUtil.getCurrentMember();
List<StudyHistory> studyHistories = studyHistoryRepository.findAllByStudent(currentMember);
List<StudyAchievement> studyAchievements = studyAchievementRepository.findAllByStudent(currentMember);

Map<Study, List<AchievementType>> achievementsByStudy = studyAchievements.stream()
.collect(Collectors.groupingBy(
kckc0608 marked this conversation as resolved.
Show resolved Hide resolved
StudyAchievement::getStudy,
Collectors.mapping(StudyAchievement::getAchievementType, Collectors.toList())));

return studyHistories.stream()
.map(history -> {
List<AchievementType> achievementTypes = achievementsByStudy.get(history.getStudy());
if (achievementTypes == null) {
achievementTypes = new ArrayList<>();
}
kckc0608 marked this conversation as resolved.
Show resolved Hide resolved
return StudentMyCompleteStudyResponse.of(history, achievementTypes);
})
.toList();
}

private AssignmentHistory findOrCreate(Member currentMember, StudyDetail studyDetail) {
return assignmentHistoryRepository
.findByMemberAndStudyDetail(currentMember, studyDetail)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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<StudyAchievement, Long> {

List<StudyAchievement> findAllByStudent(Member student);
}
Original file line number Diff line number Diff line change
@@ -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<AchievementType> achievements) {
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 = "우수 스터디원 여부") List<AchievementType> achievements) {
@Nullable @Schema(description = "우수 스터디원 여부") List<AchievementType> achievements) {


public static StudentMyCompleteStudyResponse of(StudyHistory studyHistory, List<AchievementType> 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);
}
}