diff --git a/src/main/java/igoMoney/BE/controller/ChallengeController.java b/src/main/java/igoMoney/BE/controller/ChallengeController.java index 0bfd78c..cf28075 100644 --- a/src/main/java/igoMoney/BE/controller/ChallengeController.java +++ b/src/main/java/igoMoney/BE/controller/ChallengeController.java @@ -27,9 +27,10 @@ public class ChallengeController { public ResponseEntity> getNotStartedChallengeList( @RequestParam(value="lastId", required=false, defaultValue="10") Long lastId, @RequestParam(value="pageSize", required=false, defaultValue="10") int pageSize, - @RequestParam(value="categoryId", required=false, defaultValue="-1") Integer categoryId) { + @RequestParam(value="categoryId", required=false, defaultValue="-1") Integer categoryId, + @RequestParam(value="targetAmount", required=false, defaultValue="-1") Integer targetAmount) { - List response = challengeService.getNotStartedChallengeList(lastId, pageSize, categoryId); + List response = challengeService.getNotStartedChallengeList(lastId, pageSize, categoryId, targetAmount); return ResponseEntity.status(HttpStatus.OK).body(response); } diff --git a/src/main/java/igoMoney/BE/repository/ChallengeCustomRepository.java b/src/main/java/igoMoney/BE/repository/ChallengeCustomRepository.java index 43546f3..fba379e 100644 --- a/src/main/java/igoMoney/BE/repository/ChallengeCustomRepository.java +++ b/src/main/java/igoMoney/BE/repository/ChallengeCustomRepository.java @@ -8,4 +8,6 @@ public interface ChallengeCustomRepository { List findAllNotStarted(int pageSize, Long lastId, LocalDate date); List findAllNotStartedByCategory(int pageSize, Long lastId, LocalDate date, Integer categoryId); + List findAllNotStartedByTargetAmount(int pageSize, Long lastId, LocalDate date, Integer targetAmount); + List findAllNotStartedByCategoryAndTargetAmount(int pageSize, Long lastId, LocalDate date, Integer categoryId, Integer targetAmount); } diff --git a/src/main/java/igoMoney/BE/repository/ChallengeCustomRepositoryImpl.java b/src/main/java/igoMoney/BE/repository/ChallengeCustomRepositoryImpl.java index 936e034..fada49a 100644 --- a/src/main/java/igoMoney/BE/repository/ChallengeCustomRepositoryImpl.java +++ b/src/main/java/igoMoney/BE/repository/ChallengeCustomRepositoryImpl.java @@ -38,6 +38,29 @@ public List findAllNotStartedByCategory(int pageSize, Long lastId, Lo .fetch(); } + @Override + public List findAllNotStartedByTargetAmount(int pageSize, Long lastId, LocalDate date, Integer targetAmount){ + return jpaQueryFactory.selectFrom(challenge) + .where( challenge.targetAmount.eq(targetAmount), + challenge.startDate.gt(date), + ltChallengeId(lastId)) + .orderBy(challenge.id.desc()) + .limit(pageSize) + .fetch(); + } + + @Override + public List findAllNotStartedByCategoryAndTargetAmount(int pageSize, Long lastId, LocalDate date, Integer categoryId, Integer targetAmount){ + return jpaQueryFactory.selectFrom(challenge) + .where( challenge.categoryId.eq(categoryId), + challenge.targetAmount.eq(targetAmount), + challenge.startDate.gt(date), + ltChallengeId(lastId)) + .orderBy(challenge.id.desc()) + .limit(pageSize) + .fetch(); + } + private BooleanExpression ltChallengeId(Long lastId) { if (lastId == null) { diff --git a/src/main/java/igoMoney/BE/service/ChallengeService.java b/src/main/java/igoMoney/BE/service/ChallengeService.java index 6b7737b..f3b5416 100644 --- a/src/main/java/igoMoney/BE/service/ChallengeService.java +++ b/src/main/java/igoMoney/BE/service/ChallengeService.java @@ -36,14 +36,23 @@ public class ChallengeService { DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("MM월 dd일"); // 시작 안 한 챌린지 목록 조회 - public List getNotStartedChallengeList(Long lastId, int pageSize, Integer categoryId) { + public List getNotStartedChallengeList(Long lastId, int pageSize, Integer categoryId, Integer targetAmount) { List responseList = new ArrayList<>(); List challengeList; if (categoryId == -1){ - challengeList = challengeRepository.findAllNotStarted(pageSize, lastId, LocalDate.now()); + if (targetAmount == -1){ + challengeList = challengeRepository.findAllNotStarted(pageSize, lastId, LocalDate.now()); + } else { + challengeList = challengeRepository.findAllNotStartedByTargetAmount(pageSize, lastId, LocalDate.now(), targetAmount); + } + } else{ - challengeList = challengeRepository.findAllNotStartedByCategory(pageSize, lastId, LocalDate.now(), categoryId); + if (targetAmount == -1) { + challengeList = challengeRepository.findAllNotStartedByCategory(pageSize, lastId, LocalDate.now(), categoryId); + } else { + challengeList = challengeRepository.findAllNotStartedByCategoryAndTargetAmount(pageSize, lastId, LocalDate.now(), categoryId, targetAmount); + } } for (Challenge challenge: challengeList){ ChallengeResponse challengeResponse = ChallengeResponse.builder() diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a438bec..8209800 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -16,7 +16,7 @@ spring: show-sql: false generate-ddl: true hibernate: - ddl-auto: create-drop + ddl-auto: update properties: hibernate: format_sql: true