Skip to content

Commit

Permalink
feat: 나의 수강중인 스터디 조회 API 추가 (#656)
Browse files Browse the repository at this point in the history
* feat: 나의 수강중인 스터디 조회 api 추가

* fix: 진행중인 스터디만 취급하도록 수정

* rename: 메서드 및 dto 이름 변경
  • Loading branch information
Sangwook02 authored Aug 21, 2024
1 parent ae66f5e commit 554d567
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
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());
}
}

0 comments on commit 554d567

Please sign in to comment.