From d78cd55bee1241c0f94e2068000ca904445f5cfb Mon Sep 17 00:00:00 2001 From: Hanbee Lee Date: Mon, 29 Jan 2024 23:37:56 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EB=8F=85=EB=A6=BD=20=EC=98=81=ED=99=94=20a?= =?UTF-8?q?sc=EB=A1=9C=20=EB=B0=98=ED=99=98=ED=95=98=EA=B8=B0=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../screening/service/ScreeningUploadUseCase.java | 4 ++-- .../diverseMovie/adaptor/DiverseMovieAdaptor.java | 15 ++++++++++++--- .../adaptor/RecommendedPopcornAdaptor.java | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Api/src/main/java/com/example/api/screening/service/ScreeningUploadUseCase.java b/Api/src/main/java/com/example/api/screening/service/ScreeningUploadUseCase.java index aa2c6cc..2bd638e 100644 --- a/Api/src/main/java/com/example/api/screening/service/ScreeningUploadUseCase.java +++ b/Api/src/main/java/com/example/api/screening/service/ScreeningUploadUseCase.java @@ -36,7 +36,7 @@ public String uploadImage(MultipartFile file) throws IOException { public Screening execute(PostScreeningRequest request) { Long userId = SecurityUtil.getCurrentUserId(); validateExecution(userId); - System.out.println(request.getHostName()); + final HostInfo hostInfo = HostInfo.of( request.getHostName(), request.getHostPhoneNumber(), @@ -55,7 +55,7 @@ public Screening execute(PostScreeningRequest request) { request.isHasAgreed(), request.getCategory() ); - System.out.print("finished"); + Screening screen = screeningAdaptor.save(newScreening); process(screen,userId); diff --git a/Domain/src/main/java/com/example/domains/diverseMovie/adaptor/DiverseMovieAdaptor.java b/Domain/src/main/java/com/example/domains/diverseMovie/adaptor/DiverseMovieAdaptor.java index cf7e70a..51a0414 100644 --- a/Domain/src/main/java/com/example/domains/diverseMovie/adaptor/DiverseMovieAdaptor.java +++ b/Domain/src/main/java/com/example/domains/diverseMovie/adaptor/DiverseMovieAdaptor.java @@ -8,6 +8,9 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.temporal.WeekFields; import java.util.List; import java.util.stream.Collectors; @@ -24,17 +27,23 @@ public void save(DiverseMovie diverseMovie) { } public List findTop5ByOrderByCreatedAtDesc() { + LocalDateTime now = LocalDateTime.now(); + + // Get the start and end of the current week + LocalDateTime startOfWeek = LocalDate.now().with(WeekFields.ISO.dayOfWeek(), 1).atStartOfDay(); + LocalDateTime endOfWeek = now; + return jpaQueryFactory .select(new QDiverseMovieResponseDto( diverseMovie.id, diverseMovie.movieTitle, diverseMovie.movieImgUrl, diverseMovie.movieRank - )) // Change "SomeRank" to your actual rank logic + )) .from(diverseMovie) - .orderBy(diverseMovie.createdAt.desc()) + .where(diverseMovie.createdAt.between(startOfWeek, endOfWeek)) // Filter movies created within the current week + .orderBy(diverseMovie.createdAt.asc()) .limit(5) .fetch(); } - } diff --git a/Domain/src/main/java/com/example/domains/recommendedPopcorn/adaptor/RecommendedPopcornAdaptor.java b/Domain/src/main/java/com/example/domains/recommendedPopcorn/adaptor/RecommendedPopcornAdaptor.java index 31c840e..4379449 100644 --- a/Domain/src/main/java/com/example/domains/recommendedPopcorn/adaptor/RecommendedPopcornAdaptor.java +++ b/Domain/src/main/java/com/example/domains/recommendedPopcorn/adaptor/RecommendedPopcornAdaptor.java @@ -16,6 +16,7 @@ import java.time.DayOfWeek; import java.time.LocalDate; import java.util.*; +import java.util.concurrent.ThreadLocalRandom; @Adaptor @RequiredArgsConstructor @@ -83,7 +84,7 @@ public Set generate(List thisWeekList) { Set arr = new HashSet<>(); Random random = new Random(); while (arr.size()!=3) { - Long randomIndex = random.nextLong(thisWeekList.get(0).getId(),recommendedPopcornRepository.findAll().size()+1); + long randomIndex = ThreadLocalRandom.current().nextLong(thisWeekList.get(0).getId(), recommendedPopcornRepository.findAll().size() + 1); arr.add(randomIndex); } return arr;