Skip to content

Commit

Permalink
Type: 시작안한 챌린지 조회 API - targetAmount 필터링 추가 (#96)
Browse files Browse the repository at this point in the history
[Chore] 시작안한 챌린지 조회 API - targetAmount 필터링 추가
  • Loading branch information
pingowl authored Nov 27, 2023
2 parents 921bb09 + d9ef48c commit 5fc0b56
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/main/java/igoMoney/BE/controller/ChallengeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public class ChallengeController {
public ResponseEntity<List<ChallengeResponse>> 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<ChallengeResponse> response = challengeService.getNotStartedChallengeList(lastId, pageSize, categoryId);
List<ChallengeResponse> response = challengeService.getNotStartedChallengeList(lastId, pageSize, categoryId, targetAmount);

return ResponseEntity.status(HttpStatus.OK).body(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
public interface ChallengeCustomRepository {
List<Challenge> findAllNotStarted(int pageSize, Long lastId, LocalDate date);
List<Challenge> findAllNotStartedByCategory(int pageSize, Long lastId, LocalDate date, Integer categoryId);
List<Challenge> findAllNotStartedByTargetAmount(int pageSize, Long lastId, LocalDate date, Integer targetAmount);
List<Challenge> findAllNotStartedByCategoryAndTargetAmount(int pageSize, Long lastId, LocalDate date, Integer categoryId, Integer targetAmount);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ public List<Challenge> findAllNotStartedByCategory(int pageSize, Long lastId, Lo
.fetch();
}

@Override
public List<Challenge> 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<Challenge> 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) {
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/igoMoney/BE/service/ChallengeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,23 @@ public class ChallengeService {
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("MM월 dd일");

// 시작 안 한 챌린지 목록 조회
public List<ChallengeResponse> getNotStartedChallengeList(Long lastId, int pageSize, Integer categoryId) {
public List<ChallengeResponse> getNotStartedChallengeList(Long lastId, int pageSize, Integer categoryId, Integer targetAmount) {

List<ChallengeResponse> responseList = new ArrayList<>();
List<Challenge> 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()
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spring:
show-sql: false
generate-ddl: true
hibernate:
ddl-auto: create-drop
ddl-auto: update
properties:
hibernate:
format_sql: true
Expand Down

0 comments on commit 5fc0b56

Please sign in to comment.