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 추가 #656

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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,6 +2,7 @@

import com.gdschongik.gdsc.domain.study.application.StudentStudyService;
import com.gdschongik.gdsc.domain.study.dto.request.StudyAttendCreateRequest;
import com.gdschongik.gdsc.domain.study.dto.response.StudentMyCurrentStudyResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudyApplicableResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -52,4 +53,11 @@ public ResponseEntity<Void> attend(
studentStudyService.attend(studyDetailId, request);
return ResponseEntity.ok().build();
}

@Operation(summary = "내 수강중인 스터디 조회", description = "나의 수강 중인 스터디를 조회합니다.")
@GetMapping("/me/ongoing")
public ResponseEntity<StudentMyCurrentStudyResponse> getMyCurrentStudy() {
StudentMyCurrentStudyResponse response = studentStudyService.getMyCurrentStudy();
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.gdschongik.gdsc.domain.study.domain.Attendance;
import com.gdschongik.gdsc.domain.study.domain.AttendanceValidator;
import com.gdschongik.gdsc.domain.study.dto.request.StudyAttendCreateRequest;
import com.gdschongik.gdsc.domain.study.dto.response.StudentMyCurrentStudyResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudyApplicableResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudyResponse;
import com.gdschongik.gdsc.global.exception.CustomException;
Expand Down Expand Up @@ -100,4 +101,14 @@ public void attend(Long studyDetailId, StudyAttendCreateRequest request) {

log.info("[StudyService] 스터디 출석: attendanceId={}", attendance.getId());
}

@Transactional(readOnly = true)
public StudentMyCurrentStudyResponse getMyCurrentStudy() {
Member currentMember = memberUtil.getCurrentMember();
StudyHistory studyHistory = studyHistoryRepository.findAllByMentee(currentMember).stream()
.filter(s -> s.getStudy().isStudyOngoing())
.findFirst()
.orElse(null);
return StudentMyCurrentStudyResponse.from(studyHistory);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.gdschongik.gdsc.domain.study.dto.response;

import com.gdschongik.gdsc.domain.study.domain.StudyHistory;

public record StudentMyCurrentStudyResponse(Long studyId) {
public static StudentMyCurrentStudyResponse from(StudyHistory studyHistory) {
if (studyHistory == null) {
return new StudentMyCurrentStudyResponse(null);
}
return new StudentMyCurrentStudyResponse(studyHistory.getStudy().getId());
}
}