From 17408023f5b415854c378eba40ae585ff60ff695 Mon Sep 17 00:00:00 2001 From: pkl0912 Date: Mon, 2 Sep 2024 00:20:33 +0900 Subject: [PATCH 1/3] =?UTF-8?q?#32=20[fix]=20=EB=B9=A0=EB=A5=B8=20?= =?UTF-8?q?=ED=9A=8C=EA=B3=A0=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/IntReviewRepository.java | 10 +--- .../controller/MidReviewController.java | 2 - .../letscareer/mid_review/dto/FastDTO.java | 11 ----- .../dto/response/FastReviewsResponse.java | 13 ----- .../repository/MidReviewRepository.java | 10 +--- .../mid_review/service/MidReviewService.java | 10 ---- .../controller/ScheduleController.java | 14 ++++++ .../letscareer/schedule/dto/FastDTO.java | 9 ++++ .../dto/response/FastReviewListResponse.java | 13 +++++ .../repository/ScheduleRepository.java | 1 + .../schedule/service/ScheduleService.java | 47 +++++++++++++++++++ .../stage/repository/StageRepository.java | 1 + 12 files changed, 89 insertions(+), 52 deletions(-) delete mode 100644 src/main/java/com/example/letscareer/mid_review/dto/FastDTO.java delete mode 100644 src/main/java/com/example/letscareer/mid_review/dto/response/FastReviewsResponse.java create mode 100644 src/main/java/com/example/letscareer/schedule/dto/FastDTO.java create mode 100644 src/main/java/com/example/letscareer/schedule/dto/response/FastReviewListResponse.java diff --git a/src/main/java/com/example/letscareer/int_review/repository/IntReviewRepository.java b/src/main/java/com/example/letscareer/int_review/repository/IntReviewRepository.java index 7982626..1b0a336 100644 --- a/src/main/java/com/example/letscareer/int_review/repository/IntReviewRepository.java +++ b/src/main/java/com/example/letscareer/int_review/repository/IntReviewRepository.java @@ -1,17 +1,11 @@ package com.example.letscareer.int_review.repository; import com.example.letscareer.int_review.domain.IntReview; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; +import com.example.letscareer.stage.domain.Stage; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; -import java.time.LocalDate; -import java.util.Date; - @Repository public interface IntReviewRepository extends JpaRepository { - @Query("SELECT ir FROM IntReview ir JOIN ir.stage s WHERE ir.user.userId = :userId AND s.date BETWEEN :startDate AND :endDate") - Page findAllByUserIdAndStageDeadlineWithin3Days(Long userId, LocalDate startDate, LocalDate endDate, Pageable pageable); + Boolean existsByStage(Stage stage); } diff --git a/src/main/java/com/example/letscareer/mid_review/controller/MidReviewController.java b/src/main/java/com/example/letscareer/mid_review/controller/MidReviewController.java index f28fa4f..4efef9a 100644 --- a/src/main/java/com/example/letscareer/mid_review/controller/MidReviewController.java +++ b/src/main/java/com/example/letscareer/mid_review/controller/MidReviewController.java @@ -3,12 +3,10 @@ import com.example.letscareer.common.dto.ApiResponse; import com.example.letscareer.common.dto.ErrorResponse; import com.example.letscareer.common.dto.SuccessNonDataResponse; -import com.example.letscareer.common.dto.SuccessResponse; import com.example.letscareer.common.exception.enums.SuccessCode; import com.example.letscareer.common.exception.model.BadRequestException; import com.example.letscareer.common.exception.model.NotFoundException; import com.example.letscareer.mid_review.dto.request.PostMidReviewRequest; -import com.example.letscareer.mid_review.dto.response.FastReviewsResponse; import com.example.letscareer.mid_review.service.MidReviewService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/com/example/letscareer/mid_review/dto/FastDTO.java b/src/main/java/com/example/letscareer/mid_review/dto/FastDTO.java deleted file mode 100644 index caf57a6..0000000 --- a/src/main/java/com/example/letscareer/mid_review/dto/FastDTO.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.example.letscareer.mid_review.dto; - -public record FastDTO( - Long stageId, - Long reviewId, - String company, - String department, - String type, - Integer plusDay -) { -} diff --git a/src/main/java/com/example/letscareer/mid_review/dto/response/FastReviewsResponse.java b/src/main/java/com/example/letscareer/mid_review/dto/response/FastReviewsResponse.java deleted file mode 100644 index 076a969..0000000 --- a/src/main/java/com/example/letscareer/mid_review/dto/response/FastReviewsResponse.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.example.letscareer.mid_review.dto.response; - -import com.example.letscareer.mid_review.dto.FastDTO; - -import java.util.List; - -public record FastReviewsResponse( - Integer page, - Integer size, - Integer cnt, - List fastReviews -) { -} diff --git a/src/main/java/com/example/letscareer/mid_review/repository/MidReviewRepository.java b/src/main/java/com/example/letscareer/mid_review/repository/MidReviewRepository.java index 9771ffd..9b868b2 100644 --- a/src/main/java/com/example/letscareer/mid_review/repository/MidReviewRepository.java +++ b/src/main/java/com/example/letscareer/mid_review/repository/MidReviewRepository.java @@ -1,17 +1,11 @@ package com.example.letscareer.mid_review.repository; import com.example.letscareer.mid_review.domain.MidReview; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; +import com.example.letscareer.stage.domain.Stage; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; -import java.time.LocalDate; -import java.util.Date; - @Repository public interface MidReviewRepository extends JpaRepository { - @Query("SELECT mr FROM MidReview mr JOIN mr.stage s WHERE mr.user.userId = :userId AND s.date BETWEEN :startDate AND :endDate") - Page findAllByUserIdAndStageDeadlineWithin3Days(Long userId, LocalDate startDate, LocalDate endDate, Pageable pageable); + Boolean existsByStage(Stage stage); } diff --git a/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java b/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java index 7725ff5..67cad7c 100644 --- a/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java +++ b/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java @@ -1,10 +1,8 @@ package com.example.letscareer.mid_review.service; import com.example.letscareer.common.exception.model.NotFoundException; -import com.example.letscareer.int_review.domain.IntReview; import com.example.letscareer.int_review.repository.IntReviewRepository; import com.example.letscareer.mid_review.domain.MidReview; -import com.example.letscareer.mid_review.dto.FastDTO; import com.example.letscareer.mid_review.dto.request.PostMidReviewRequest; import com.example.letscareer.mid_review.dto.response.FastReviewsResponse; import com.example.letscareer.mid_review.repository.MidReviewRepository; @@ -17,18 +15,10 @@ import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.time.LocalDate; -import java.time.ZoneId; import java.time.temporal.ChronoUnit; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Date; -import java.util.List; import static com.example.letscareer.common.exception.enums.ErrorCode.*; diff --git a/src/main/java/com/example/letscareer/schedule/controller/ScheduleController.java b/src/main/java/com/example/letscareer/schedule/controller/ScheduleController.java index c7883b7..2063c2f 100644 --- a/src/main/java/com/example/letscareer/schedule/controller/ScheduleController.java +++ b/src/main/java/com/example/letscareer/schedule/controller/ScheduleController.java @@ -10,6 +10,7 @@ import com.example.letscareer.schedule.dto.request.SchedulePostRequest; import com.example.letscareer.schedule.dto.response.AlwaysResponse; import com.example.letscareer.schedule.dto.response.DateClickScheduleResponse; +import com.example.letscareer.schedule.dto.response.FastReviewListResponse; import com.example.letscareer.schedule.dto.response.ScheduleResponse; import com.example.letscareer.schedule.service.ScheduleService; import lombok.RequiredArgsConstructor; @@ -63,6 +64,19 @@ public ApiResponse getSchedules( return ErrorResponse.error(e.getErrorCode()); } } + @GetMapping("/reviews/fast") + public ApiResponse getFastReviews( + @RequestHeader("userId") Long userId, + @RequestParam("page") int page, + @RequestParam("size") int size) { + + try { + FastReviewListResponse fastReviewListResponse = scheduleService.getFastReviews(userId, page, size); + return SuccessResponse.success(SuccessCode.SCHEDULE_SUCCESS, fastReviewListResponse); + }catch (NotFoundException | BadRequestException e) { + return ErrorResponse.error(e.getErrorCode()); + } + } @PostMapping public ApiResponse postNewSchedule( diff --git a/src/main/java/com/example/letscareer/schedule/dto/FastDTO.java b/src/main/java/com/example/letscareer/schedule/dto/FastDTO.java new file mode 100644 index 0000000..da5b632 --- /dev/null +++ b/src/main/java/com/example/letscareer/schedule/dto/FastDTO.java @@ -0,0 +1,9 @@ +package com.example.letscareer.schedule.dto; + +public record FastDTO( + Long stageId, + Long reviewId, + String company, + String department +) { +} diff --git a/src/main/java/com/example/letscareer/schedule/dto/response/FastReviewListResponse.java b/src/main/java/com/example/letscareer/schedule/dto/response/FastReviewListResponse.java new file mode 100644 index 0000000..441cc75 --- /dev/null +++ b/src/main/java/com/example/letscareer/schedule/dto/response/FastReviewListResponse.java @@ -0,0 +1,13 @@ +package com.example.letscareer.schedule.dto.response; + +import com.example.letscareer.schedule.dto.FastDTO; + +import java.util.List; + +public record FastReviewListResponse( + Integer page, + Integer size, + Integer cnt, + List fastReviews +) { +} diff --git a/src/main/java/com/example/letscareer/schedule/repository/ScheduleRepository.java b/src/main/java/com/example/letscareer/schedule/repository/ScheduleRepository.java index 529cd5b..2821864 100644 --- a/src/main/java/com/example/letscareer/schedule/repository/ScheduleRepository.java +++ b/src/main/java/com/example/letscareer/schedule/repository/ScheduleRepository.java @@ -11,4 +11,5 @@ @Repository public interface ScheduleRepository extends JpaRepository { Page findAllByUserUserIdAndAlwaysTrue(Long userId, Pageable pageable); + Page findAllByUserUserId(Long userId, Pageable pageable); } diff --git a/src/main/java/com/example/letscareer/schedule/service/ScheduleService.java b/src/main/java/com/example/letscareer/schedule/service/ScheduleService.java index 0a4d742..d369319 100644 --- a/src/main/java/com/example/letscareer/schedule/service/ScheduleService.java +++ b/src/main/java/com/example/letscareer/schedule/service/ScheduleService.java @@ -1,14 +1,18 @@ package com.example.letscareer.schedule.service; import com.example.letscareer.common.exception.model.NotFoundException; +import com.example.letscareer.int_review.repository.IntReviewRepository; +import com.example.letscareer.mid_review.repository.MidReviewRepository; import com.example.letscareer.schedule.domain.Progress; import com.example.letscareer.schedule.domain.Schedule; import com.example.letscareer.schedule.dto.AlwaysDTO; import com.example.letscareer.schedule.dto.DateScheduleDTO; +import com.example.letscareer.schedule.dto.FastDTO; import com.example.letscareer.schedule.dto.StageDTO; import com.example.letscareer.schedule.dto.request.SchedulePostRequest; import com.example.letscareer.schedule.dto.response.AlwaysResponse; import com.example.letscareer.schedule.dto.response.DateClickScheduleResponse; +import com.example.letscareer.schedule.dto.response.FastReviewListResponse; import com.example.letscareer.schedule.dto.response.ScheduleResponse; import com.example.letscareer.schedule.repository.ScheduleRepository; import com.example.letscareer.stage.domain.Stage; @@ -38,6 +42,8 @@ public class ScheduleService { private final UserRepository userRepository; private final StageRepository stageRepository; private final ScheduleRepository scheduleRepository; + private final IntReviewRepository intReviewRepository; + private final MidReviewRepository midReviewRepository; public ScheduleResponse getSchedules(final Long userId, final int month, final int page, final int size) { @@ -187,6 +193,47 @@ public AlwaysResponse getAlwaysList(final Long userId, final int page, final int return new AlwaysResponse(page, size, alwaysList); } + public FastReviewListResponse getFastReviews(final Long userId, final int page, final int size){ + LocalDate today = LocalDate.now(); + LocalDate threeDaysLater = today.plusDays(4); // D+3까지 포함 + + Pageable pageable = PageRequest.of(page - 1, size); // JPA는 페이지 인덱스가 0부터 시작 + + // 사용자 ID로 모든 Schedule 조회 + Page schedulePage = scheduleRepository.findAllByUserUserId(userId, pageable); + + List fastReviews = new ArrayList<>(); + + int cnt = 0; // D+3까지 회고 없는 stage 개수 + + for (Schedule schedule : schedulePage) { + // 오늘부터 D+3 사이의 Stage를 조회 + List stages = stageRepository.findAllByScheduleAndDateBetween(schedule, today, threeDaysLater); + + for (Stage stage : stages) { + boolean hasIntReview = intReviewRepository.existsByStage(stage); + boolean hasMidReview = midReviewRepository.existsByStage(stage); + + if (!hasIntReview && !hasMidReview) { + // 회고가 없는 Stage만 리스트에 추가 + cnt++; // 회고 없는 stage 개수 증가 + fastReviews.add(new FastDTO( + stage.getStageId(), + schedule.getScheduleId(), + schedule.getCompany(), + schedule.getDepartment() + )); + } + } + } + + return new FastReviewListResponse( + page, + size, + cnt, + fastReviews + ); + } @Transactional public void postSchedule(Long userId,SchedulePostRequest request){ Optional userOptional = userRepository.findByUserId(userId); diff --git a/src/main/java/com/example/letscareer/stage/repository/StageRepository.java b/src/main/java/com/example/letscareer/stage/repository/StageRepository.java index baee37a..e471f01 100644 --- a/src/main/java/com/example/letscareer/stage/repository/StageRepository.java +++ b/src/main/java/com/example/letscareer/stage/repository/StageRepository.java @@ -23,4 +23,5 @@ public interface StageRepository extends JpaRepository { @Query("SELECT st FROM Stage st WHERE st.schedule.user.userId = :userId AND st.date = :date") ListfindAllByUserIdAndDate(@Param("userId") Long userId, @Param("date") LocalDate date); Optional findTopByScheduleScheduleIdOrderByOrderDesc(Long scheudleId); + List findAllByScheduleAndDateBetween(Schedule schedule, LocalDate today, LocalDate threeDaysLater); } From 50cf66bc2a7672f154d66c54252ce3a7e5b8be8a Mon Sep 17 00:00:00 2001 From: pkl0912 Date: Mon, 2 Sep 2024 00:29:43 +0900 Subject: [PATCH 2/3] =?UTF-8?q?#32=20[fix]=20=EB=B9=A0=EB=A5=B8=20?= =?UTF-8?q?=ED=9A=8C=EA=B3=A0=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mid_review/service/MidReviewService.java | 13 ------------- .../example/letscareer/schedule/dto/FastDTO.java | 2 +- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java b/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java index 91af543..327b4dc 100644 --- a/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java +++ b/src/main/java/com/example/letscareer/mid_review/service/MidReviewService.java @@ -4,7 +4,6 @@ import com.example.letscareer.int_review.repository.IntReviewRepository; import com.example.letscareer.mid_review.domain.MidReview; import com.example.letscareer.mid_review.dto.request.PostMidReviewRequest; -import com.example.letscareer.mid_review.dto.response.FastReviewsResponse; import com.example.letscareer.mid_review.repository.MidReviewRepository; import com.example.letscareer.schedule.domain.Schedule; import com.example.letscareer.schedule.repository.ScheduleRepository; @@ -17,9 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.time.LocalDate; -import java.time.temporal.ChronoUnit; - import static com.example.letscareer.common.exception.enums.ErrorCode.*; @Service @@ -28,7 +24,6 @@ public class MidReviewService { @Autowired private final MidReviewRepository midReviewRepository; - private final IntReviewRepository intReviewRepository; private final ScheduleRepository scheduleRepository; private final StageRepository stageRepository; private final UserRepository userRepository; @@ -51,12 +46,4 @@ public void postMidReview(Long userId, Long scheduleId, Long stageId, PostMidRev midReviewRepository.save(midReview); } - public static int calculatePlusDays(LocalDate date) { - LocalDate now = LocalDate.now(); - - // 현재 날짜와 대상 날짜 간의 차이를 일 단위로 계산 - long daysBetween = ChronoUnit.DAYS.between(now, date); - - return (int)daysBetween; - } } diff --git a/src/main/java/com/example/letscareer/schedule/dto/FastDTO.java b/src/main/java/com/example/letscareer/schedule/dto/FastDTO.java index da5b632..e18a08b 100644 --- a/src/main/java/com/example/letscareer/schedule/dto/FastDTO.java +++ b/src/main/java/com/example/letscareer/schedule/dto/FastDTO.java @@ -2,7 +2,7 @@ public record FastDTO( Long stageId, - Long reviewId, + Long scheduleId, String company, String department ) { From 083c963ba52008f32b93c98d60b9e40ea7c1565e Mon Sep 17 00:00:00 2001 From: pkl0912 Date: Mon, 2 Sep 2024 00:32:11 +0900 Subject: [PATCH 3/3] =?UTF-8?q?#32=20[fix]=20=EB=B9=A0=EB=A5=B8=20?= =?UTF-8?q?=ED=9A=8C=EA=B3=A0=20successcode=20=EC=88=98=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/letscareer/common/exception/enums/SuccessCode.java | 1 + .../letscareer/schedule/controller/ScheduleController.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/letscareer/common/exception/enums/SuccessCode.java b/src/main/java/com/example/letscareer/common/exception/enums/SuccessCode.java index 3d93ccc..3fab3a5 100644 --- a/src/main/java/com/example/letscareer/common/exception/enums/SuccessCode.java +++ b/src/main/java/com/example/letscareer/common/exception/enums/SuccessCode.java @@ -11,6 +11,7 @@ public enum SuccessCode { SCHEDULE_SUCCESS(HttpStatus.OK, "일정 찾기 성공입니다."), POST_SCHEDULE_SUCCESS(HttpStatus.OK, "새 일정 추가 성공입니다."), + FAST_REVIEW_LIST_SUCEESS(HttpStatus.OK, "빠른 회고 리스트 찾기 성공입니다"), TODO_SUCCESS(HttpStatus.OK, "투두 찾기 성공입니다."), TODO_SAVE_SUCCESS(HttpStatus.OK, "투두 저장 성공입니다"), TODO_DELETE_SUCCESS(HttpStatus.OK, "투두 삭제 성공입니다"), diff --git a/src/main/java/com/example/letscareer/schedule/controller/ScheduleController.java b/src/main/java/com/example/letscareer/schedule/controller/ScheduleController.java index 2063c2f..b25b30b 100644 --- a/src/main/java/com/example/letscareer/schedule/controller/ScheduleController.java +++ b/src/main/java/com/example/letscareer/schedule/controller/ScheduleController.java @@ -72,7 +72,7 @@ public ApiResponse getFastReviews( try { FastReviewListResponse fastReviewListResponse = scheduleService.getFastReviews(userId, page, size); - return SuccessResponse.success(SuccessCode.SCHEDULE_SUCCESS, fastReviewListResponse); + return SuccessResponse.success(SuccessCode.FAST_REVIEW_LIST_SUCEESS, fastReviewListResponse); }catch (NotFoundException | BadRequestException e) { return ErrorResponse.error(e.getErrorCode()); }