Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: get home/receiver #41

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface GiftboxRepository extends JpaRepository<Giftbox, Long> {
@Query("SELECT gb FROM Giftbox gb WHERE gb.receiver.id = ?1 and gb.isAvailable = true")
List<Giftbox> findAllByReceiverIdAndIsAvailable(Long receiver_id);

@Query("SELECT SUM(gb.amount) FROM Giftbox gb WHERE gb.store = ?1")
Integer getSumByStore(Store store);
@Query("SELECT SUM(gb.amount) FROM Giftbox gb " +
"WHERE gb.store = ?1 AND gb.isAvailable = true AND gb.receiver.id = ?2")
Integer getSumByStore(Store store, Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ public ApiResponse receiverHome(){
return ApiResponse.failure(Error.NOT_AUTHENTICATED_EXCEPTION);
}
Receiver receiver = authUtils.getReceiver();
Long receiver_id = receiver.getId();

//사용 가능한 꾸러미만 조회
List<Giftbox> giftboxList = Optional.ofNullable(giftboxRepository.findAllByReceiverIdAndIsAvailable(receiver.getId()))
.orElse(Collections.emptyList());

//사용처별 꾸러미 잔액
Optional<Integer> cuGiftBox = Optional.ofNullable(giftboxRepository.getSumByStore(Store.CU));
Optional<Integer> gs25GiftBox = Optional.ofNullable(giftboxRepository.getSumByStore(Store.GS25));
Optional<Integer> sevenelevenGiftBox = Optional.ofNullable(giftboxRepository.getSumByStore(Store.SEVENELEVEN));
//수혜자의 사용처별 꾸러미 잔액
Optional<Integer> cuGiftBox = Optional.ofNullable(giftboxRepository.getSumByStore(Store.CU,receiver_id));
Optional<Integer> gs25GiftBox = Optional.ofNullable(giftboxRepository.getSumByStore(Store.GS25,receiver_id));
Optional<Integer> sevenelevenGiftBox = Optional.ofNullable(giftboxRepository.getSumByStore(Store.SEVENELEVEN,receiver_id));
Integer cu = cuGiftBox.orElse(0);
Integer gs25 = gs25GiftBox.orElse(0);
Integer seveneleven = sevenelevenGiftBox.orElse(0);
Expand Down
Loading