From 5cca03dc77ea7095183f51f7811b2dafcdea485a Mon Sep 17 00:00:00 2001 From: "chosw1002@naver.com" Date: Tue, 29 Oct 2024 16:21:14 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20StudyTodoResponse=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/StudentStudyDetailController.java | 6 ++--- .../study/application/MentorStudyService.java | 18 ++++++------- .../StudentStudyDetailService.java | 8 +++--- .../dto/response/StudyStudentResponse.java | 24 ++++++++--------- ...doResponse.java => StudyTaskResponse.java} | 27 +++++++++---------- .../gdsc/global/util/ExcelUtil.java | 18 ++++++------- 6 files changed, 50 insertions(+), 51 deletions(-) rename src/main/java/com/gdschongik/gdsc/domain/study/dto/response/{StudyTodoResponse.java => StudyTaskResponse.java} (80%) diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/api/StudentStudyDetailController.java b/src/main/java/com/gdschongik/gdsc/domain/study/api/StudentStudyDetailController.java index 68cba2679..e6cd52abc 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/api/StudentStudyDetailController.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/api/StudentStudyDetailController.java @@ -4,7 +4,7 @@ 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.StudyStudentCurriculumResponse; -import com.gdschongik.gdsc.domain.study.dto.response.StudyTodoResponse; +import com.gdschongik.gdsc.domain.study.dto.response.StudyTaskResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import java.util.List; @@ -33,8 +33,8 @@ public ResponseEntity getSubmittableAssignments( @Operation(summary = "내 할일 리스트 조회", description = "해당 스터디의 내 할일 리스트를 조회합니다") @GetMapping("/todo") - public ResponseEntity> getStudyTodoList(@RequestParam(name = "studyId") Long studyId) { - List response = studentStudyDetailService.getStudyTodoList(studyId); + public ResponseEntity> getStudyTodoList(@RequestParam(name = "studyId") Long studyId) { + List response = studentStudyDetailService.getStudyTodoList(studyId); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java index 5a590107b..299721032 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyService.java @@ -21,7 +21,7 @@ import com.gdschongik.gdsc.domain.study.dto.request.StudyUpdateRequest; import com.gdschongik.gdsc.domain.study.dto.response.StudyResponse; import com.gdschongik.gdsc.domain.study.dto.response.StudyStudentResponse; -import com.gdschongik.gdsc.domain.study.dto.response.StudyTodoResponse; +import com.gdschongik.gdsc.domain.study.dto.response.StudyTaskResponse; import com.gdschongik.gdsc.global.exception.CustomException; import com.gdschongik.gdsc.global.util.ExcelUtil; import com.gdschongik.gdsc.global.util.MemberUtil; @@ -87,15 +87,15 @@ public Page getStudyStudents(Long studyId, Pageable pageab List currentAssignmentHistories = assignmentHistoryMap.getOrDefault(studyHistory.getStudent().getId(), new ArrayList<>()); - List studyTodos = new ArrayList<>(); + List studyTasks = new ArrayList<>(); studyDetails.forEach(studyDetail -> { - studyTodos.add(StudyTodoResponse.createAttendanceType( + studyTasks.add(StudyTaskResponse.createAttendanceType( studyDetail, LocalDate.now(), isAttended(currentAttendances, studyDetail))); - studyTodos.add(StudyTodoResponse.createAssignmentType( + studyTasks.add(StudyTaskResponse.createAssignmentType( studyDetail, getSubmittedAssignment(currentAssignmentHistories, studyDetail))); }); - response.add(StudyStudentResponse.of(studyHistory, currentStudyAchievements, studyTodos)); + response.add(StudyStudentResponse.of(studyHistory, currentStudyAchievements, studyTasks)); }); return new PageImpl<>(response, pageable, studyHistories.getTotalElements()); @@ -224,15 +224,15 @@ public byte[] createStudyExcel(Long studyId) { List currentAssignmentHistories = assignmentHistoryMap.getOrDefault(studyHistory.getStudent().getId(), new ArrayList<>()); - List studyTodos = new ArrayList<>(); + List studyTasks = new ArrayList<>(); studyDetails.forEach(studyDetail -> { - studyTodos.add(StudyTodoResponse.createAttendanceType( + studyTasks.add(StudyTaskResponse.createAttendanceType( studyDetail, LocalDate.now(), isAttended(currentAttendances, studyDetail))); - studyTodos.add(StudyTodoResponse.createAssignmentType( + studyTasks.add(StudyTaskResponse.createAssignmentType( studyDetail, getSubmittedAssignment(currentAssignmentHistories, studyDetail))); }); - content.add(StudyStudentResponse.of(studyHistory, currentStudyAchievements, studyTodos)); + content.add(StudyStudentResponse.of(studyHistory, currentStudyAchievements, studyTasks)); }); return excelUtil.createStudyExcel(study, content); diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/application/StudentStudyDetailService.java b/src/main/java/com/gdschongik/gdsc/domain/study/application/StudentStudyDetailService.java index 65050b595..4a4412313 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/application/StudentStudyDetailService.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/application/StudentStudyDetailService.java @@ -54,7 +54,7 @@ studyDetail, getSubmittedAssignment(assignmentHistories, studyDetail))) } @Transactional(readOnly = true) - public List getStudyTodoList(Long studyId) { + public List getStudyTodoList(Long studyId) { Member member = memberUtil.getCurrentMember(); final List studyDetails = studyDetailRepository.findAllByStudyIdOrderByWeekAsc(studyId); final List assignmentHistories = @@ -62,19 +62,19 @@ public List getStudyTodoList(Long studyId) { final List attendances = attendanceRepository.findByMemberAndStudyId(member, studyId); LocalDate now = LocalDate.now(); - List response = new ArrayList<>(); + List response = new ArrayList<>(); // 출석체크 정보 (개설 상태이고, 오늘이 출석체크날짜인 것) studyDetails.stream() .filter(studyDetail -> studyDetail.getCurriculum().isOpen() && studyDetail.getAttendanceDay().equals(now)) - .forEach(studyDetail -> response.add(StudyTodoResponse.createAttendanceType( + .forEach(studyDetail -> response.add(StudyTaskResponse.createAttendanceType( studyDetail, now, isAttended(attendances, studyDetail)))); // 과제 정보 (오늘이 과제 제출 기간에 포함된 과제 정보) studyDetails.stream() .filter(studyDetail -> studyDetail.getAssignment().isOpen() && studyDetail.getAssignment().isDeadlineRemaining()) - .forEach(studyDetail -> response.add(StudyTodoResponse.createAssignmentType( + .forEach(studyDetail -> response.add(StudyTaskResponse.createAssignmentType( studyDetail, getSubmittedAssignment(assignmentHistories, studyDetail)))); return response; } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java index 35ed19f34..be2877331 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java @@ -2,7 +2,7 @@ import static com.gdschongik.gdsc.domain.study.domain.AchievementType.*; import static com.gdschongik.gdsc.domain.study.dto.response.AssignmentSubmissionStatusResponse.*; -import static com.gdschongik.gdsc.domain.study.dto.response.StudyTodoResponse.StudyTodoType.*; +import static com.gdschongik.gdsc.domain.study.dto.response.StudyTaskResponse.StudyTaskType.*; import com.gdschongik.gdsc.domain.study.domain.AchievementType; import com.gdschongik.gdsc.domain.study.domain.StudyAchievement; @@ -21,17 +21,17 @@ public record StudyStudentResponse( @Schema(description = "수료 상태") StudyHistoryStatus studyHistoryStatus, @Schema(description = "1차 우수 스터디원") boolean isFirstRoundOutstandingStudent, @Schema(description = "2차 우수 스터디원") boolean isSecondRoundOutstandingStudent, - @Schema(description = "과제 및 출석 이력") List studyTodos, + @Schema(description = "과제 및 출석 이력") List studyTasks, @Schema(description = "과제 수행률") double assignmentRate, @Schema(description = "출석률") double attendanceRate) { public static StudyStudentResponse of( - StudyHistory studyHistory, List studyAchievements, List studyTodos) { - List assignments = studyTodos.stream() - .filter(studyTodoResponse -> studyTodoResponse.todoType() == ASSIGNMENT) + StudyHistory studyHistory, List studyAchievements, List studyTasks) { + List assignments = studyTasks.stream() + .filter(studyTaskResponse -> studyTaskResponse.taskType() == ASSIGNMENT) .toList(); - List attendances = studyTodos.stream() - .filter(studyTodoResponse -> studyTodoResponse.todoType() == ATTENDANCE) + List attendances = studyTasks.stream() + .filter(studyTaskResponse -> studyTaskResponse.taskType() == ATTENDANCE) .toList(); long successAssignmentsCount = countAssignmentByStatus(assignments, SUCCESS); @@ -50,7 +50,7 @@ public static StudyStudentResponse of( studyHistory.getStudyHistoryStatus(), isOutstandingStudent(FIRST_ROUND_OUTSTANDING_STUDENT, studyAchievements), isOutstandingStudent(SECOND_ROUND_OUTSTANDING_STUDENT, studyAchievements), - studyTodos, + studyTasks, calculateRateOrZero(successAssignmentsCount, assignments.size() - cancelledAssignmentsCount), calculateRateOrZero(attendedCount, attendances.size() - cancelledAttendanceCount)); } @@ -62,15 +62,15 @@ private static boolean isOutstandingStudent( } private static long countAssignmentByStatus( - List assignments, AssignmentSubmissionStatusResponse status) { + List assignments, AssignmentSubmissionStatusResponse status) { return assignments.stream() - .filter(studyTodoResponse -> studyTodoResponse.assignmentSubmissionStatus() == status) + .filter(studyTaskResponse -> studyTaskResponse.assignmentSubmissionStatus() == status) .count(); } - private static long countAttendanceByStatus(List attendances, AttendanceStatusResponse status) { + private static long countAttendanceByStatus(List attendances, AttendanceStatusResponse status) { return attendances.stream() - .filter(studyTodoResponse -> studyTodoResponse.attendanceStatus() == status) + .filter(studyTaskResponse -> studyTaskResponse.attendanceStatus() == status) .count(); } diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyTodoResponse.java b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyTaskResponse.java similarity index 80% rename from src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyTodoResponse.java rename to src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyTaskResponse.java index 518fd512b..5ec00b72e 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyTodoResponse.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyTaskResponse.java @@ -1,7 +1,7 @@ package com.gdschongik.gdsc.domain.study.dto.response; -import static com.gdschongik.gdsc.domain.study.dto.response.StudyTodoResponse.StudyTodoType.ASSIGNMENT; -import static com.gdschongik.gdsc.domain.study.dto.response.StudyTodoResponse.StudyTodoType.ATTENDANCE; +import static com.gdschongik.gdsc.domain.study.dto.response.StudyTaskResponse.StudyTaskType.ASSIGNMENT; +import static com.gdschongik.gdsc.domain.study.dto.response.StudyTaskResponse.StudyTaskType.ATTENDANCE; import com.gdschongik.gdsc.domain.study.domain.AssignmentHistory; import com.gdschongik.gdsc.domain.study.domain.StudyDetail; @@ -11,19 +11,18 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -// todo: 활용이 다양해졌으므로 rename 필요 -public record StudyTodoResponse( +public record StudyTaskResponse( Long studyDetailId, @Schema(description = "현 주차수") Long week, - @Schema(description = "할일 타입") StudyTodoType todoType, + @Schema(description = "할일 타입") StudyTaskType taskType, @Schema(description = "마감 시각") LocalDateTime deadLine, @Schema(description = "출석 상태 (출석타입일 때만 사용)") AttendanceStatusResponse attendanceStatus, @Schema(description = "과제 제목 (과제타입일 때만 사용)") String assignmentTitle, @Schema(description = "과제 제출 상태 (과제타입일 때만 사용)") AssignmentSubmissionStatusResponse assignmentSubmissionStatus) { - public static StudyTodoResponse createAttendanceType(StudyDetail studyDetail, LocalDate now, boolean isAttended) { + public static StudyTaskResponse createAttendanceType(StudyDetail studyDetail, LocalDate now, boolean isAttended) { if (studyDetail.getCurriculum().isCancelled()) { - return new StudyTodoResponse( + return new StudyTaskResponse( studyDetail.getId(), studyDetail.getWeek(), ATTENDANCE, @@ -32,7 +31,7 @@ public static StudyTodoResponse createAttendanceType(StudyDetail studyDetail, Lo null, null); } - return new StudyTodoResponse( + return new StudyTaskResponse( studyDetail.getId(), studyDetail.getWeek(), ATTENDANCE, @@ -42,9 +41,9 @@ public static StudyTodoResponse createAttendanceType(StudyDetail studyDetail, Lo null); } - public static StudyTodoResponse createAssignmentType(StudyDetail studyDetail, AssignmentHistory assignmentHistory) { + public static StudyTaskResponse createAssignmentType(StudyDetail studyDetail, AssignmentHistory assignmentHistory) { if (studyDetail.getAssignment().isCancelled()) { - return new StudyTodoResponse( + return new StudyTaskResponse( studyDetail.getId(), studyDetail.getWeek(), ASSIGNMENT, @@ -54,7 +53,7 @@ public static StudyTodoResponse createAssignmentType(StudyDetail studyDetail, As AssignmentSubmissionStatusResponse.of(null, studyDetail)); } - return new StudyTodoResponse( + return new StudyTaskResponse( studyDetail.getId(), studyDetail.getWeek(), ASSIGNMENT, @@ -65,16 +64,16 @@ public static StudyTodoResponse createAssignmentType(StudyDetail studyDetail, As } public boolean isAttendance() { - return todoType == ATTENDANCE; + return taskType == ATTENDANCE; } public boolean isAssignment() { - return todoType == ASSIGNMENT; + return taskType == ASSIGNMENT; } @Getter @RequiredArgsConstructor - public enum StudyTodoType { + public enum StudyTaskType { ATTENDANCE("출석"), ASSIGNMENT("과제"); diff --git a/src/main/java/com/gdschongik/gdsc/global/util/ExcelUtil.java b/src/main/java/com/gdschongik/gdsc/global/util/ExcelUtil.java index a7037d37a..f4d1cfe00 100644 --- a/src/main/java/com/gdschongik/gdsc/global/util/ExcelUtil.java +++ b/src/main/java/com/gdschongik/gdsc/global/util/ExcelUtil.java @@ -8,7 +8,7 @@ import com.gdschongik.gdsc.domain.member.domain.MemberRole; import com.gdschongik.gdsc.domain.study.domain.Study; import com.gdschongik.gdsc.domain.study.dto.response.StudyStudentResponse; -import com.gdschongik.gdsc.domain.study.dto.response.StudyTodoResponse; +import com.gdschongik.gdsc.domain.study.dto.response.StudyTaskResponse; import com.gdschongik.gdsc.global.exception.CustomException; import com.gdschongik.gdsc.global.exception.ErrorCode; import jakarta.annotation.Nullable; @@ -90,16 +90,16 @@ private void createStudySheet(Workbook workbook, Study study, List studentRow + student.studyTasks().stream() + .filter(StudyTaskResponse::isAssignment) + .forEach(task -> studentRow .createCell(cellIndex.getAndIncrement()) - .setCellValue(todo.assignmentSubmissionStatus().getValue())); - student.studyTodos().stream() - .filter(StudyTodoResponse::isAttendance) - .forEach(todo -> studentRow + .setCellValue(task.assignmentSubmissionStatus().getValue())); + student.studyTasks().stream() + .filter(StudyTaskResponse::isAttendance) + .forEach(task -> studentRow .createCell(cellIndex.getAndIncrement()) - .setCellValue(todo.attendanceStatus().getValue())); + .setCellValue(task.attendanceStatus().getValue())); }); }