Skip to content

Commit

Permalink
feat: 이번주 과제 조회 API 구현 (#647)
Browse files Browse the repository at this point in the history
* feat: 이번주 과제 조회 API 구현

* feat: 불필요한 코드 제거 및 엔드포인트 수정

* feat: 코드 오타 수정

* fix: 레포지토리 메소드 위치 수정

* feat: 이번주까지 마감인 과제들 반환 로직 추가

* feat: 도메인 메소드에 추가

* feat: 도메인 메소드 주석 가독성 향상

* feat: 과제 제출 내역이 null일때 고려해서 response반환

* feat: 과제 제출 이력이 없을 때 StudyDetail에서 가져와서 반환

* feat: 과제 응답 클래스명 변경

* feat: 과제 응답 로직 개선

* feat: npe 예방 코드

* fix: 머지 컨플릭트 해결

* feat: merge develop
  • Loading branch information
AlmondBreez3 authored Aug 24, 2024
1 parent bcd0e50 commit 9baf58c
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gdschongik.gdsc.domain.study.application.StudentStudyDetailService;
import com.gdschongik.gdsc.domain.study.dto.response.AssignmentDashboardResponse;
import com.gdschongik.gdsc.domain.study.dto.response.AssignmentHistoryStatusResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudyStudentSessionResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudyTodoResponse;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -45,4 +46,12 @@ public ResponseEntity<List<StudyStudentSessionResponse>> getStudySessions(
List<StudyStudentSessionResponse> response = studentStudyDetailService.getStudySessions(studyId);
return ResponseEntity.ok(response);
}

@Operation(summary = "이번주 제출해야 할 과제 조회", description = "마감 기한이 이번주까지인 과제를 조회합니다.")
@GetMapping("/assignments/upcoming")
public ResponseEntity<List<AssignmentHistoryStatusResponse>> getUpcomingAssignments(
@RequestParam(name = "studyId") Long studyId) {
List<AssignmentHistoryStatusResponse> response = studentStudyDetailService.getUpcomingAssignments(studyId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.gdschongik.gdsc.domain.study.domain.StudyDetail;
import com.gdschongik.gdsc.domain.study.domain.StudyHistory;
import com.gdschongik.gdsc.domain.study.dto.response.AssignmentDashboardResponse;
import com.gdschongik.gdsc.domain.study.dto.response.AssignmentHistoryStatusResponse;
import com.gdschongik.gdsc.domain.study.dto.response.AssignmentSubmittableDto;
import com.gdschongik.gdsc.domain.study.dto.response.StudyStudentSessionResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudyTodoResponse;
Expand Down Expand Up @@ -41,7 +42,7 @@ public AssignmentDashboardResponse getSubmittableAssignments(Long studyId) {
.findByStudentAndStudyId(currentMember, studyId)
.orElseThrow(() -> new CustomException(ErrorCode.STUDY_HISTORY_NOT_FOUND));
List<AssignmentHistory> assignmentHistories =
assignmentHistoryRepository.findAssignmentHistoriesByStudentAndStudy(currentMember, studyId);
assignmentHistoryRepository.findAssignmentHistoriesByStudentAndStudyId(currentMember, studyId);
List<StudyDetail> studyDetails = studyDetailRepository.findAllByStudyIdOrderByWeekAsc(studyId).stream()
.filter(studyDetail ->
studyDetail.getAssignment().isOpen() && studyDetail.isAssignmentDeadlineRemaining())
Expand All @@ -61,7 +62,7 @@ public List<StudyTodoResponse> getStudyTodoList(Long studyId) {
Member member = memberUtil.getCurrentMember();
final List<StudyDetail> studyDetails = studyDetailRepository.findAllByStudyIdOrderByWeekAsc(studyId);
final List<AssignmentHistory> assignmentHistories =
assignmentHistoryRepository.findAssignmentHistoriesByStudentAndStudy(member, studyId);
assignmentHistoryRepository.findAssignmentHistoriesByStudentAndStudyId(member, studyId);
final List<Attendance> attendances = attendanceRepository.findByMemberAndStudyId(member, studyId);

LocalDate now = LocalDate.now();
Expand All @@ -86,7 +87,7 @@ public List<StudyStudentSessionResponse> getStudySessions(Long studyId) {
Member member = memberUtil.getCurrentMember();
final List<StudyDetail> studyDetails = studyDetailRepository.findAllByStudyIdOrderByWeekAsc(studyId);
final List<AssignmentHistory> assignmentHistories =
assignmentHistoryRepository.findAssignmentHistoriesByStudentAndStudy(member, studyId);
assignmentHistoryRepository.findAssignmentHistoriesByStudentAndStudyId(member, studyId);
final List<Attendance> attendances = attendanceRepository.findByMemberAndStudyId(member, studyId);

return studyDetails.stream()
Expand All @@ -111,4 +112,23 @@ private boolean isAttended(List<Attendance> attendances, StudyDetail studyDetail
return attendances.stream()
.anyMatch(attendance -> attendance.getStudyDetail().getId().equals(studyDetail.getId()));
}

@Transactional(readOnly = true)
public List<AssignmentHistoryStatusResponse> getUpcomingAssignments(Long studyId) {
Member currentMember = memberUtil.getCurrentMember();
List<StudyDetail> studyDetails = studyDetailRepository.findAllByStudyId(studyId).stream()
.filter(studyDetail ->
studyDetail.getAssignment().isOpen() && studyDetail.isAssignmentDeadlineThisWeek())
.toList();
List<AssignmentHistory> assignmentHistories =
assignmentHistoryRepository.findAssignmentHistoriesByStudentAndStudyId(currentMember, studyId).stream()
.filter(assignmentHistory ->
assignmentHistory.getStudyDetail().isAssignmentDeadlineThisWeek())
.toList();

return studyDetails.stream()
.map(studyDetail -> AssignmentHistoryStatusResponse.of(
studyDetail, getSubmittedAssignment(assignmentHistories, studyDetail)))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private String getOwnerRepo(String repositoryLink) {
public List<AssignmentHistoryResponse> getAllAssignmentHistories(Long studyId) {
Member currentMember = memberUtil.getCurrentMember();

return assignmentHistoryRepository.findAssignmentHistoriesByStudentAndStudy(currentMember, studyId).stream()
return assignmentHistoryRepository.findAssignmentHistoriesByStudentAndStudyId(currentMember, studyId).stream()
.map(AssignmentHistoryResponse::from)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public interface AssignmentHistoryCustomRepository {

boolean existsSubmittedAssignmentByMemberAndStudy(Member member, Study study);

List<AssignmentHistory> findAssignmentHistoriesByStudentAndStudy(Member member, Long studyId);
List<AssignmentHistory> findAssignmentHistoriesByStudentAndStudyId(Member member, Long studyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private BooleanExpression isSubmitted() {
}

@Override
public List<AssignmentHistory> findAssignmentHistoriesByStudentAndStudy(Member currentMember, Long studyId) {
public List<AssignmentHistory> findAssignmentHistoriesByStudentAndStudyId(Member currentMember, Long studyId) {
return queryFactory
.selectFrom(assignmentHistory)
.join(assignmentHistory.studyDetail, studyDetail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
public interface StudyDetailRepository extends JpaRepository<StudyDetail, Long> {

List<StudyDetail> findAllByStudyIdOrderByWeekAsc(Long studyId);

List<StudyDetail> findAllByStudyId(Long studyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public boolean isAssignmentDeadlineRemaining() {
return assignment.isDeadlineRemaining();
}

public boolean isAssignmentDeadlineThisWeek() {
return assignment.isDeadLineThisWeek();
}

// 스터디 시작일자 + 현재 주차 * 7 + (스터디 요일 - 스터디 기간 시작 요일)
public LocalDate getAttendanceDay() {
// 스터디 시작일자
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import jakarta.persistence.Embeddable;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Builder;
Expand Down Expand Up @@ -93,4 +95,17 @@ public boolean isDeadlineRemaining() {
LocalDateTime now = LocalDateTime.now();
return now.isBefore(deadline);
}

public boolean isDeadLineThisWeek() {
// 현재 날짜와 마감일의 날짜 부분을 비교할 것이므로 LocalDate로 변환
LocalDate now = LocalDate.now();
LocalDate startOfWeek = now.with(DayOfWeek.MONDAY); // 이번 주 월요일
LocalDate endOfWeek = now.with(DayOfWeek.SUNDAY); // 이번 주 일요일

// 마감일의 날짜 부분을 가져옴
LocalDate deadlineDate = deadline.toLocalDate();

// 마감일이 이번 주 내에 있는지 확인
return !deadlineDate.isBefore(startOfWeek) && !deadlineDate.isAfter(endOfWeek);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.gdschongik.gdsc.domain.study.dto.response;

import static com.gdschongik.gdsc.domain.study.domain.SubmissionFailureType.NOT_SUBMITTED;

import com.gdschongik.gdsc.domain.study.domain.*;
import com.gdschongik.gdsc.domain.study.domain.vo.Assignment;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import java.time.LocalDateTime;

public record AssignmentHistoryStatusResponse(
Long studyDetailId,
@Schema(description = "과제 상태") StudyStatus assignmentStatus,
@Schema(description = "주차") Long week,
@Nullable @Schema(description = "과제 제목") String title,
// TODO 추후 처리 예정
@Nullable @Schema(description = "과제 제출 상태") AssignmentSubmissionStatus assignmentSubmissionStatus,
@Nullable @Schema(description = "과제 명세 링크") String descriptionLink,
@Nullable @Schema(description = "마감 기한") LocalDateTime deadline,
@Nullable @Schema(description = "과제 제출 링크") String submissionLink,
@Nullable @Schema(description = "과제 제출 실패 사유. 제출 여부도 포함되어 있습니다. 미제출 상태라면 기본 과제 정보만 반환합니다.")
SubmissionFailureType submissionFailureType,
@Nullable @Schema(description = "최종 수정 일시") LocalDateTime committedAt) {

// 과제 제출이 없는 경우, 과제 정보만 사용하여 AssignmentHistoryStatusResponse 생성
public static AssignmentHistoryStatusResponse of(StudyDetail studyDetail, AssignmentHistory assignmentHistory) {
if (assignmentHistory == null) {
return new AssignmentHistoryStatusResponse(
studyDetail.getId(),
studyDetail.getAssignment().getStatus(),
studyDetail.getWeek(),
studyDetail.getAssignment().getTitle(),
null,
studyDetail.getAssignment().getDescriptionLink(),
studyDetail.getAssignment().getDeadline(),
null,
NOT_SUBMITTED,
null);
}

Assignment assignment = studyDetail.getAssignment();
return new AssignmentHistoryStatusResponse(
studyDetail.getId(),
assignment.getStatus(),
studyDetail.getWeek(),
assignment.getTitle(),
assignmentHistory.getSubmissionStatus(),
assignment.getDescriptionLink(),
assignment.getDeadline(),
assignmentHistory.getSubmissionLink(),
assignmentHistory.getSubmissionFailureType(),
assignmentHistory.getCommittedAt());
}
}

0 comments on commit 9baf58c

Please sign in to comment.