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 구현 #647

Merged
merged 19 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
21dcdd7
feat: 이번주 과제 조회 API 구현
AlmondBreez3 Aug 18, 2024
dc17536
feat: 불필요한 코드 제거 및 엔드포인트 수정
AlmondBreez3 Aug 20, 2024
f1d9c91
feat: 코드 오타 수정
AlmondBreez3 Aug 20, 2024
0fe4c06
fix: 레포지토리 메소드 위치 수정
AlmondBreez3 Aug 20, 2024
ed8f8d1
feat: 이번주까지 마감인 과제들 반환 로직 추가
AlmondBreez3 Aug 21, 2024
6513447
Merge branch 'develop' of https://github.com/GDSC-Hongik/gdsc-server …
AlmondBreez3 Aug 21, 2024
15c5bb7
feat: 도메인 메소드에 추가
AlmondBreez3 Aug 21, 2024
1b29a9a
feat: 도메인 메소드 주석 가독성 향상
AlmondBreez3 Aug 21, 2024
1c614a8
fix: 머지 컨플릭트 수정
AlmondBreez3 Aug 21, 2024
c71c2ff
fix: 머지 컨플릭트 해결
AlmondBreez3 Aug 22, 2024
7197c4a
feat: 과제 제출 내역이 null일때 고려해서 response반환
AlmondBreez3 Aug 22, 2024
36692d4
feat: 과제 제출 이력이 없을 때 StudyDetail에서 가져와서 반환
AlmondBreez3 Aug 23, 2024
f86e788
feat: 과제 응답 클래스명 변경
AlmondBreez3 Aug 23, 2024
d9fccc6
feat: 과제 응답 로직 개선
AlmondBreez3 Aug 23, 2024
497038a
feat: 과제 응답 Response 개선
AlmondBreez3 Aug 23, 2024
8b09f4f
feat: npe 예방 코드
AlmondBreez3 Aug 23, 2024
0ca5d97
fix: 머지 컨플릭트 해결
AlmondBreez3 Aug 24, 2024
1a50295
Merge branch 'develop' of https://github.com/GDSC-Hongik/gdsc-server …
AlmondBreez3 Aug 24, 2024
dc9d745
feat: merge develop
AlmondBreez3 Aug 24, 2024
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,8 +2,10 @@

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.AssignmentStatusResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -26,4 +28,12 @@ public ResponseEntity<AssignmentDashboardResponse> getSubmittableAssignments(
AssignmentDashboardResponse response = studentStudyDetailService.getSubmittableAssignments(studyId);
return ResponseEntity.ok(response);
}

@Operation(summary = "이번주 제출해야 할 과제 조회", description = "마감 기한이 이번주까지인 과제를 조회합니다.")
@GetMapping("/assignments/upcoming")
public ResponseEntity<List<AssignmentStatusResponse>> getUpcomingAssignments(
@RequestParam(name = "studyId") Long studyId) {
List<AssignmentStatusResponse> response = studentStudyDetailService.getUpcomingAssignments(studyId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.gdschongik.gdsc.domain.study.domain.AssignmentHistory;
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.AssignmentStatusResponse;
import com.gdschongik.gdsc.domain.study.dto.response.AssignmentSubmittableDto;
import com.gdschongik.gdsc.global.exception.CustomException;
import com.gdschongik.gdsc.global.exception.ErrorCode;
Expand All @@ -31,7 +32,7 @@ public AssignmentDashboardResponse getSubmittableAssignments(Long studyId) {
.orElseThrow(() -> new CustomException(ErrorCode.STUDY_HISTORY_NOT_FOUND));

List<AssignmentHistory> assignmentHistories =
assignmentHistoryRepository.findAssignmentHistoriesByMenteeAndStudy(currentMember, studyId);
assignmentHistoryRepository.findAssignmentHistoriesByMenteeAndStudyId(currentMember, studyId);
boolean isAnySubmitted = assignmentHistories.stream().anyMatch(AssignmentHistory::isSubmitted);
List<AssignmentSubmittableDto> submittableAssignments = assignmentHistories.stream()
.filter(assignmentHistory -> assignmentHistory.getStudyDetail().isAssignmentDeadlineRemaining())
Expand All @@ -40,4 +41,16 @@ public AssignmentDashboardResponse getSubmittableAssignments(Long studyId) {

return AssignmentDashboardResponse.of(studyHistory.getRepositoryLink(), isAnySubmitted, submittableAssignments);
}

@Transactional(readOnly = true)
public List<AssignmentStatusResponse> getUpcomingAssignments(Long studyId) {
Member currentMember = memberUtil.getCurrentMember();
List<AssignmentHistory> assignmentHistories =
assignmentHistoryRepository.findAssignmentHistoriesByMenteeAndStudyId(currentMember, studyId).stream()
.filter(assignmentHistory ->
assignmentHistory.getStudyDetail().isAssignmentDeadlineThisWeek())
.toList();
Copy link
Member

Choose a reason for hiding this comment

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

이렇게 하면 아직 제출 시도를 하지 않은 Assignment는 AssignmentHistory가 없으므로 누락될 수 있을 것 같습니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

슬기님꺼 피알 머지 되면 처리할게영 그럼!


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

return assignmentHistoryRepository.findAssignmentHistoriesByMenteeAndStudy(currentMember, studyId).stream()
return assignmentHistoryRepository.findAssignmentHistoriesByMenteeAndStudyId(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> findAssignmentHistoriesByMenteeAndStudy(Member member, Long studyId);
List<AssignmentHistory> findAssignmentHistoriesByMenteeAndStudyId(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> findAssignmentHistoriesByMenteeAndStudy(Member currentMember, Long studyId) {
public List<AssignmentHistory> findAssignmentHistoriesByMenteeAndStudyId(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 @@ -94,6 +94,10 @@ public boolean isAssignmentDeadlineRemaining() {
return assignment.isDeadlineRemaining();
}

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

// 스터디 시작일자 + 현재 주차 * 7 + (스터디 요일 - 스터디 기간 시작 요일)
public LocalDate getAttendanceDay() {
return study.getStartDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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 @@ -91,4 +93,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,36 @@
package com.gdschongik.gdsc.domain.study.dto.response;

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 AssignmentStatusResponse(
Long studyDetailId,
@Schema(description = "과제 상태") StudyStatus assignmentStatus,
@Schema(description = "주차") Long week,
@Nullable @Schema(description = "과제 제목") String title,
// TODO 추후 처리 예정
@Nullable @Schema(description = "과제 제출 상태") AssignmentSubmissionStatus assignmentSubmissionStatus,
Copy link
Member

Choose a reason for hiding this comment

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

이 부분은 #638 에서 처리할거라 todo만 달아주세요

@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) {
public static AssignmentStatusResponse from(AssignmentHistory assignmentHistory) {
StudyDetail studyDetail = assignmentHistory.getStudyDetail();
Assignment assignment = studyDetail.getAssignment();
return new AssignmentStatusResponse(
studyDetail.getId(),
assignment.getStatus(),
studyDetail.getWeek(),
assignment.getTitle(),
assignmentHistory.getSubmissionStatus(),
assignment.getDescriptionLink(),
assignment.getDeadline(),
assignmentHistory.getSubmissionLink(),
assignmentHistory.getSubmissionFailureType(),
assignmentHistory.getCommittedAt());
}
}