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

#82 [refactor] 지원 대시보드 api 수정 #83

Merged
merged 1 commit into from
Sep 8, 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
@@ -1,16 +1,16 @@
package com.example.letscareer.schedule.domain.dto;

import com.example.letscareer.schedule.domain.model.Progress;
import com.example.letscareer.stage.domain.model.Status;

import java.time.LocalDate;

public record StageDTO(
public record ScheduleDTO(
Long scheduleId,
Long stageId,
String company,
String department,
String type,
LocalDate deadline,
int dday,
Progress progress){
String status){
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.example.letscareer.schedule.domain.dto.response;

import com.example.letscareer.schedule.domain.dto.StageDTO;
import com.example.letscareer.schedule.domain.dto.ScheduleDTO;

import java.util.List;

public record CalendarResponse(
Integer docCount,
Integer midCount,
Integer interviewCount,
List<StageDTO> schedules
List<ScheduleDTO> schedules
) {
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.example.letscareer.schedule.domain.dto.response;

import com.example.letscareer.schedule.domain.dto.StageDTO;
import com.example.letscareer.schedule.domain.dto.ScheduleDTO;

import java.util.List;

public record ScheduleResponse(
Integer page,
Integer size,
Long total,
List<StageDTO> schedules
List<ScheduleDTO> schedules

) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,35 @@ public ScheduleResponse getSchedulesComing(final Long userId, final int month, f
Page<Stage> stagePage = stageRepository.findAllByUserIdAndMonth(userId, month, pageable);
long total = stagePage.getTotalElements();

List<StageDTO> schedules = new ArrayList<>();
List<ScheduleDTO> schedules = new ArrayList<>();

for (Stage stage : stagePage) {
Schedule schedule = stage.getSchedule();
if (schedule != null) {
Long scheduleId = schedule.getScheduleId();
Long stageId = stage.getStageId();
String type = stage.getType().getValue();
String status = stage.getStatus().getValue();
LocalDate deadline = stage.getDate();

Integer dday = (deadline != null) ? stage.calculateDday() : null;

schedules.add(new StageDTO(
schedules.add(new ScheduleDTO(
scheduleId,
stageId,
schedule.getCompany(),
schedule.getDepartment(),
type,
deadline,
dday,
schedule.getProgress()
status
));
}
}

//sort -1, -3, +1
schedules.sort(
Comparator.<StageDTO>comparingInt(dto -> (dto.dday() < 0 ? -1 : 1)) // 음수 dday 우선 정렬
Comparator.<ScheduleDTO>comparingInt(dto -> (dto.dday() < 0 ? -1 : 1)) // 음수 dday 우선 정렬
.thenComparingInt(dto -> Math.abs(dto.dday())) // 절대값 기준 정렬
);
return new ScheduleResponse(
Expand All @@ -102,14 +103,15 @@ public CalendarResponse getSchedulesCalendar(final Long userId, final int month)
int midCount = 0;
int interviewCount = 0;

List<StageDTO> schedules = new ArrayList<>();
List<ScheduleDTO> schedules = new ArrayList<>();

for (Stage stage : stages) {
Schedule schedule = stage.getSchedule();
if (schedule != null) {
Long scheduleId = schedule.getScheduleId();
Long stageId = stage.getStageId();
String type = stage.getType().getValue();
String status = stage.getStatus().getValue();
LocalDate deadline = stage.getDate();

switch (stage.getType()) {
Expand All @@ -125,15 +127,15 @@ public CalendarResponse getSchedulesCalendar(final Long userId, final int month)
}
Integer dday = (deadline != null) ? stage.calculateDday() : null;

schedules.add(new StageDTO(
schedules.add(new ScheduleDTO(
scheduleId,
stageId,
schedule.getCompany(),
schedule.getDepartment(),
type,
deadline,
dday,
schedule.getProgress()
status
));
}
}
Expand Down Expand Up @@ -174,7 +176,7 @@ public DateClickScheduleResponse getDateSchedules(final Long userId, final Local
Integer dday = (stage.getDate() != null) ? stage.calculateDday() : null;

// 진행 상태
String progress = schedule.getProgress().getValue();
String progress = stage.getStatus().getValue();

// DTO로 변환하여 리스트에 추가
schedules.add(new DateScheduleDTO(
Expand Down Expand Up @@ -236,10 +238,6 @@ public FastReviewListResponse getFastReviews(final Long userId, final int page,
// 먼저 userId로 Schedule 목록을 가져옴
List<Schedule> schedules = scheduleRepository.findAllByUserUserId(userId);

if (schedules.isEmpty()) {
return new FastReviewListResponse(page, size, 0, new ArrayList<>());
}

// QueryDSL로 Stage 조회
Page<Stage> stagePage = stageRepository.findAllByScheduleInAndDateBetweenAndIntReviewNotExistsAndMidReviewNotExists(
schedules, threeDaysPrevious, today, pageable);
Expand Down
Loading