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: 스터디 주차별 출결번호 조회 #688

Merged
merged 5 commits into from
Aug 26, 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 @@ -3,6 +3,7 @@
import com.gdschongik.gdsc.domain.study.application.MentorStudyDetailService;
import com.gdschongik.gdsc.domain.study.dto.request.AssignmentCreateUpdateRequest;
import com.gdschongik.gdsc.domain.study.dto.response.AssignmentResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudyMentorAttendanceResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudySessionResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -67,8 +68,16 @@ public ResponseEntity<Void> cancelStudyAssignment(@PathVariable Long studyDetail
// TODO 스터디 세션 워딩을 커리큘럼으로 변경해야함
@Operation(summary = "스터디 주차별 커리큘럼 목록 조회", description = "멘토가 자신의 스터디 커리큘럼 목록을 조회합니다")
@GetMapping("/sessions")
public ResponseEntity<List<StudySessionResponse>> getStudySessions(@RequestParam(name = "study") Long studyId) {
public ResponseEntity<List<StudySessionResponse>> getStudySessions(@RequestParam(name = "studyId") Long studyId) {
List<StudySessionResponse> response = mentorStudyDetailService.getSessions(studyId);
return ResponseEntity.ok(response);
}

@Operation(summary = "스터디 주차별 출결번호 조회", description = "멘토가 자신의 스터디 출결번호 목록을 조회합니다. 지난 출석은 목록에서 제외합니다.")
@GetMapping("/attendances")
public ResponseEntity<List<StudyMentorAttendanceResponse>> getAttendanceNumbers(
@RequestParam(name = "studyId") Long studyId) {
List<StudyMentorAttendanceResponse> response = mentorStudyDetailService.getAttendanceNumbers(studyId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import com.gdschongik.gdsc.domain.study.domain.StudyDetailValidator;
import com.gdschongik.gdsc.domain.study.dto.request.AssignmentCreateUpdateRequest;
import com.gdschongik.gdsc.domain.study.dto.response.AssignmentResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudyMentorAttendanceResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudySessionResponse;
import com.gdschongik.gdsc.global.exception.CustomException;
import com.gdschongik.gdsc.global.util.MemberUtil;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -90,4 +92,15 @@ public List<StudySessionResponse> getSessions(Long studyId) {
List<StudyDetail> studyDetails = studyDetailRepository.findAllByStudyIdOrderByWeekAsc(studyId);
return studyDetails.stream().map(StudySessionResponse::from).toList();
}

@Transactional(readOnly = true)
public List<StudyMentorAttendanceResponse> getAttendanceNumbers(Long studyId) {
List<StudyDetail> studyDetails = studyDetailRepository.findAllByStudyIdOrderByWeekAsc(studyId);

// 출석일이 오늘 or 오늘이후인 StudyDetail
return studyDetails.stream()
.filter(studyDetail -> studyDetail.isAttendanceDayNotPassed(LocalDate.now()))
.map(StudyMentorAttendanceResponse::from)
.toList();
}
Comment on lines +97 to +105
Copy link

Choose a reason for hiding this comment

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

예외 처리 및 엣지 케이스를 고려하세요.

현재 메서드는 예외 처리나 엣지 케이스를 고려하지 않고 있습니다. 예를 들어, studyDetailRepository.findAllByStudyIdOrderByWeekAsc(studyId)가 빈 리스트를 반환할 경우를 처리하는 로직이 필요할 수 있습니다.

다음과 같은 코드를 추가하여 예외 처리를 강화할 수 있습니다:

@Transactional(readOnly = true)
public List<StudyMentorAttendanceResponse> getAttendanceNumbers(Long studyId) {
    List<StudyDetail> studyDetails = studyDetailRepository.findAllByStudyIdOrderByWeekAsc(studyId);
    if (studyDetails.isEmpty()) {
        throw new CustomException(STUDY_DETAILS_NOT_FOUND);
    }

    return studyDetails.stream()
            .filter(studyDetail -> studyDetail.isAttendanceDayNotPassed(LocalDate.now()))
            .map(StudyMentorAttendanceResponse::from)
            .toList();
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public List<StudyMentorAttendanceResponse> getAttendanceNumbers(Long studyId) {
List<StudyDetail> studyDetails = studyDetailRepository.findAllByStudyIdOrderByWeekAsc(studyId);
// 출석일이 오늘 or 오늘이후인 StudyDetail
return studyDetails.stream()
.filter(studyDetail -> studyDetail.isAttendanceDayNotPassed(LocalDate.now()))
.map(StudyMentorAttendanceResponse::from)
.toList();
}
@Transactional(readOnly = true)
public List<StudyMentorAttendanceResponse> getAttendanceNumbers(Long studyId) {
List<StudyDetail> studyDetails = studyDetailRepository.findAllByStudyIdOrderByWeekAsc(studyId);
if (studyDetails.isEmpty()) {
throw new CustomException(STUDY_DETAILS_NOT_FOUND);
}
return studyDetails.stream()
.filter(studyDetail -> studyDetail.isAttendanceDayNotPassed(LocalDate.now()))
.map(StudyMentorAttendanceResponse::from)
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public LocalDate getAttendanceDay() {
return startDate.plusDays(daysToAdd);
}

// 출석일이 오늘 or 오늘이후인지 확인
public boolean isAttendanceDayNotPassed(LocalDate now) {
return !getAttendanceDay().isBefore(now);
}

public void updateSession(
LocalTime startAt, String title, String description, Difficulty difficulty, StudyStatus status) {
session = Session.generateSession(startAt, title, description, difficulty, status);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.gdschongik.gdsc.domain.study.dto.response;

import com.gdschongik.gdsc.domain.study.domain.StudyDetail;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;

public record StudyMentorAttendanceResponse(
Long studyDetailId,
@Schema(description = "주차수") Long week,
@Schema(description = "마감시각") LocalDateTime deadLine,
@Schema(description = "출석번호") String attendanceNumber) {
public static StudyMentorAttendanceResponse from(StudyDetail studyDetail) {
return new StudyMentorAttendanceResponse(
studyDetail.getId(),
studyDetail.getWeek(),
studyDetail.getAttendanceDay().atTime(23, 59, 59),
studyDetail.getAttendanceNumber());
}
}