Skip to content

Commit

Permalink
feat: 스터디 수료 내역 조회 API (#798)
Browse files Browse the repository at this point in the history
* feat: StudyAchievementRepository 생성

* feat: 스터디 수료 내역 조회 로직 작성

* feat: 스터디 수료내역 조회 컨트롤러 추가

* refactor: 우수 스터디원 조회 로직 개선

* chore: import 코드 기존 방식으로 변경

* chore: 메서드 이름 개선

* refactor: DTO에서 achievement null 처리

* chore: import Collector

* refactor: 우수 스터디원이 없으면 null 반환

* refactor: 우수 스터디원 선정 내역 기본값을 리스트로 설정

* chore: 우수 스터디원 필드 스웨거 설명 수정
  • Loading branch information
kckc0608 authored Oct 10, 2024
1 parent b707e4c commit a2e3a40
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
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>> getMyCompletedStudy() {
List<StudentMyCompleteStudyResponse> response = studentStudyHistoryService.getMyCompletedStudies();
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -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;
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,25 @@ public void submitAssignment(Long studyDetailId) {
assignmentHistory.getSubmissionFailureType());
}

@Transactional(readOnly = true)
public List<StudentMyCompleteStudyResponse> getMyCompletedStudies() {
Member currentMember = memberUtil.getCurrentMember();
List<StudyHistory> studyHistories = studyHistoryRepository.findAllByStudent(currentMember);
List<StudyAchievement> studyAchievements = studyAchievementRepository.findAllByStudent(currentMember);

Map<Study, List<AchievementType>> achievementsByStudy = studyAchievements.stream()
.collect(groupingBy(
StudyAchievement::getStudy, mapping(StudyAchievement::getAchievementType, toList())));

return studyHistories.stream()
.map(history -> {
List<AchievementType> 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<StudyAchievement, Long>, StudyAchievementCustomRepository {}
extends JpaRepository<StudyAchievement, Long>, StudyAchievementCustomRepository {

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) {

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

0 comments on commit a2e3a40

Please sign in to comment.