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

#32 [fix] 빠른 회고 api 수정 #40

Merged
merged 4 commits into from
Sep 1, 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
Expand Up @@ -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, "투두 삭제 성공입니다"),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IntReview, Long> {
@Query("SELECT ir FROM IntReview ir JOIN ir.stage s WHERE ir.user.userId = :userId AND s.date BETWEEN :startDate AND :endDate")
Page<IntReview> findAllByUserIdAndStageDeadlineWithin3Days(Long userId, LocalDate startDate, LocalDate endDate, Pageable pageable);
Boolean existsByStage(Stage stage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/com/example/letscareer/mid_review/dto/FastDTO.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<MidReview, Long> {
@Query("SELECT mr FROM MidReview mr JOIN mr.stage s WHERE mr.user.userId = :userId AND s.date BETWEEN :startDate AND :endDate")
Page<MidReview> findAllByUserIdAndStageDeadlineWithin3Days(Long userId, LocalDate startDate, LocalDate endDate, Pageable pageable);
Boolean existsByStage(Stage stage);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
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;
import com.example.letscareer.schedule.domain.Schedule;
import com.example.letscareer.schedule.repository.ScheduleRepository;
Expand All @@ -17,19 +14,8 @@
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.*;

@Service
Expand All @@ -38,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;
Expand All @@ -61,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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.FAST_REVIEW_LIST_SUCEESS, fastReviewListResponse);
}catch (NotFoundException | BadRequestException e) {
return ErrorResponse.error(e.getErrorCode());
}
}

@PostMapping
public ApiResponse postNewSchedule(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.letscareer.schedule.dto;

public record FastDTO(
Long stageId,
Long scheduleId,
String company,
String department
) {
}
Original file line number Diff line number Diff line change
@@ -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<FastDTO> fastReviews
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@Repository
public interface ScheduleRepository extends JpaRepository<Schedule, Long> {
Page<Schedule> findAllByUserUserIdAndAlwaysTrue(Long userId, Pageable pageable);

Page<Schedule> findAllByUserUserId(Long userId, Pageable pageable);
Optional<Schedule> findByUserAndScheduleId(User user, Long scheduleId);

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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<Schedule> schedulePage = scheduleRepository.findAllByUserUserId(userId, pageable);

List<FastDTO> fastReviews = new ArrayList<>();

int cnt = 0; // D+3까지 회고 없는 stage 개수

for (Schedule schedule : schedulePage) {
// 오늘부터 D+3 사이의 Stage를 조회
List<Stage> 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<User> userOptional = userRepository.findByUserId(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public interface StageRepository extends JpaRepository<Stage, Long> {
@Query("SELECT st FROM Stage st WHERE st.schedule.user.userId = :userId AND st.date = :date")
List<Stage>findAllByUserIdAndDate(@Param("userId") Long userId, @Param("date") LocalDate date);
Optional<Stage> findTopByScheduleScheduleIdOrderByOrderDesc(Long scheudleId);

List<Stage> findAllByScheduleAndDateBetween(Schedule schedule, LocalDate today, LocalDate threeDaysLater);
Optional<Stage> findByStageIdAndSchedule(Long stageId, Schedule schedule);
}
Loading