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>> getMyCompletedStudy() {
List<StudentMyCompleteStudyResponse> response = studentStudyHistoryService.getMyCompletedStudies();
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
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.List;
import java.util.Map;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -44,6 +50,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 +114,24 @@ 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.get(history.getStudy());
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,38 @@
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 jakarta.annotation.Nullable;
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,
@Nullable @Schema(description = "우수 스터디원 여부") List<AchievementType> achievements) {
kckc0608 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

'우수 스터디원 여부' 보다 더 적절한 네이밍이 있을 것 같습니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

'우수 스터디원 선정 내역' 정도로 고쳐봤는데, 다른 아이디어가 잘 안떠오르네요. 혹시 좋은 아이디어 있을까요?

Copy link
Member

Choose a reason for hiding this comment

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

넹 그정도면 될 것 같아요
'여부'는 뭔가 boolean과 어울리는 느낌이어서...


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