From 0589c4faa0e9653bc5076e16b2591b08ee5dd24f Mon Sep 17 00:00:00 2001 From: yeji Date: Mon, 27 Nov 2023 00:02:10 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20jpa=20query=20method=EB=A1=9C=20?= =?UTF-8?q?=EB=B9=84=EC=8A=B7=ED=95=9C=20=ED=96=89=EC=82=AC=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dhs/domain/program/repository/ProgramRepository.java | 4 +++- .../efub/dhs/domain/program/service/ProgramService.java | 9 +++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/efub/dhs/domain/program/repository/ProgramRepository.java b/src/main/java/com/efub/dhs/domain/program/repository/ProgramRepository.java index 4af50de..637d236 100644 --- a/src/main/java/com/efub/dhs/domain/program/repository/ProgramRepository.java +++ b/src/main/java/com/efub/dhs/domain/program/repository/ProgramRepository.java @@ -1,5 +1,6 @@ package com.efub.dhs.domain.program.repository; +import java.time.LocalDateTime; import java.util.List; import org.springframework.data.domain.Page; @@ -13,7 +14,8 @@ public interface ProgramRepository extends JpaRepository, ProgramRepositoryCustom { - List findAllByCategoryAndIsOpenOrderByDeadlineAsc(Category category, Boolean isOpen); + List findTop3ByCategoryAndIsOpenAndDeadlineAfterAndProgramIdNotOrderByDeadlineAsc(Category category, + Boolean isOpen, LocalDateTime deadline, Long programId); Page findAllByHost(Member host, Pageable pageable); diff --git a/src/main/java/com/efub/dhs/domain/program/service/ProgramService.java b/src/main/java/com/efub/dhs/domain/program/service/ProgramService.java index fb1adbd..b71be94 100644 --- a/src/main/java/com/efub/dhs/domain/program/service/ProgramService.java +++ b/src/main/java/com/efub/dhs/domain/program/service/ProgramService.java @@ -127,12 +127,9 @@ public ProgramMemberDto findProgramMemberInfo(Program program, Member member) { public List findSimilarPrograms(Program program, Member member) { List similarProgramList = - programRepository.findAllByCategoryAndIsOpenOrderByDeadlineAsc(program.getCategory(), true); - similarProgramList.remove(program); - - List filteredSimilarProgramList = getProgramByRemainingDays(similarProgramList, 3); - - return convertToProgramOutlineResponseDtoList(filteredSimilarProgramList, member); + programRepository.findTop3ByCategoryAndIsOpenAndDeadlineAfterAndProgramIdNotOrderByDeadlineAsc( + program.getCategory(), true, LocalDateTime.now(), program.getProgramId()); + return convertToProgramOutlineResponseDtoList(similarProgramList, member); } public List convertToProgramOutlineResponseDtoList(