-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 오늘 얻은 벌레 조회 API 구현 * refactor: 쿼리 1번으로 수정 * feat: @CurrentMember 적용 * test: 벌레 조회 Controller 통합 테스트 * chore: 주석 제거 * test: 오늘 보상 벌레 조회 Controller 테스트 * test: memberService mock 처리 * chore: enum 비교 equals로 변경
- Loading branch information
Showing
10 changed files
with
178 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/moabam/api/domain/repository/BugHistorySearchRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.moabam.api.domain.repository; | ||
|
||
import static com.moabam.api.domain.bug.QBugHistory.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import com.moabam.api.domain.bug.BugActionType; | ||
import com.moabam.api.domain.bug.BugHistory; | ||
import com.moabam.global.common.util.DynamicQuery; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class BugHistorySearchRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
public List<BugHistory> find(Long memberId, BugActionType actionType, LocalDateTime dateTime) { | ||
return jpaQueryFactory | ||
.selectFrom(bugHistory) | ||
.where( | ||
DynamicQuery.generateEq(memberId, bugHistory.memberId::eq), | ||
DynamicQuery.generateEq(actionType, bugHistory.actionType::eq), | ||
DynamicQuery.generateEq(dateTime, this::equalDate) | ||
) | ||
.fetch(); | ||
} | ||
|
||
private BooleanExpression equalDate(LocalDateTime dateTime) { | ||
return bugHistory.createdAt.year().eq(dateTime.getYear()) | ||
.and(bugHistory.createdAt.month().eq(dateTime.getMonthValue())) | ||
.and(bugHistory.createdAt.dayOfMonth().eq(dateTime.getDayOfMonth())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.moabam.api.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record TodayBugResponse( | ||
int morningBug, | ||
int nightBug | ||
) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/java/com/moabam/support/fixture/BugHistoryFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.moabam.support.fixture; | ||
|
||
import com.moabam.api.domain.bug.BugActionType; | ||
import com.moabam.api.domain.bug.BugHistory; | ||
import com.moabam.api.domain.bug.BugType; | ||
|
||
public final class BugHistoryFixture { | ||
|
||
public static BugHistory rewardMorningBug(Long memberId, int quantity) { | ||
return BugHistory.builder() | ||
.memberId(memberId) | ||
.bugType(BugType.MORNING) | ||
.actionType(BugActionType.REWARD) | ||
.quantity(quantity) | ||
.build(); | ||
} | ||
|
||
public static BugHistory rewardNightBug(Long memberId, int quantity) { | ||
return BugHistory.builder() | ||
.memberId(memberId) | ||
.bugType(BugType.NIGHT) | ||
.actionType(BugActionType.REWARD) | ||
.quantity(quantity) | ||
.build(); | ||
} | ||
} |