Skip to content

Commit

Permalink
[BE] FIX : Item 관련 일부 메서드 이름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Z1Park committed Jun 4, 2024
1 parent d37f1db commit ed0261b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public CoinCollectionRewardResponseDto collectCoinAndIssueReward(Long userId) {
// DB에 코인 저장
Item coinCollect = itemQueryService.getBySku(Sku.COIN_COLLECT);
int reward = (int) (coinCollect.getPrice().longValue());
itemHistoryCommandService.purchaseItem(userId, coinCollect.getId());
itemHistoryCommandService.createItemHistory(userId, coinCollect.getId());

// 출석 일자에 따른 랜덤 리워드 지급
Long coinCollectionCountInMonth =
Expand All @@ -201,7 +201,7 @@ public CoinCollectionRewardResponseDto collectCoinAndIssueReward(Long userId) {
Sku coinSku = itemPolicyService.getRewardSku(randomPercentage);
Item coinReward = itemQueryService.getBySku(coinSku);

itemHistoryCommandService.purchaseItem(userId, coinReward.getId());
itemHistoryCommandService.createItemHistory(userId, coinReward.getId());
reward += coinReward.getPrice();
}

Expand Down Expand Up @@ -241,11 +241,12 @@ public void useItem(Long userId, Sku sku, ItemUseRequestDto data) {
Item item = itemQueryService.getBySku(sku);
List<ItemHistory> itemInInventory =
itemHistoryQueryService.findUnusedItemsInUserInventory(user.getId(), item.getId());
ItemHistory firstItem = itemPolicyService.verifyEmptyItems(itemInInventory);
ItemHistory oldestItemHistory =
itemPolicyService.verifyNotEmptyAndFindOldest(itemInInventory);
ItemUsage itemUsage = getItemUsage(userId, item, data);

eventPublisher.publishEvent(itemUsage);
firstItem.updateUsedAt();
oldestItemHistory.updateUsedAt();
}

/**
Expand Down Expand Up @@ -298,7 +299,7 @@ public void purchaseItem(Long userId, Sku sku) {
itemPolicyService.verifyIsAffordable(userCoin, price);

// 아이템 구매 처리
itemHistoryCommandService.purchaseItem(user.getId(), item.getId());
itemHistoryCommandService.createItemHistory(user.getId(), item.getId());

LockUtil.lockRedisCoin(userId, () -> {
// 코인 차감
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ItemHistoryCommandService {

private final ItemHistoryRepository itemHistoryRepository;

public void purchaseItem(Long userId, Long itemId) {
public void createItemHistory(Long userId, Long itemId) {
ItemHistory itemHistory = ItemHistory.of(userId, itemId, null);
itemHistoryRepository.save(itemHistory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void verifyIsAlreadyCollectedCoin(boolean isChecked) {
}
}

public ItemHistory verifyEmptyItems(List<ItemHistory> itemInInventory) {
public ItemHistory verifyNotEmptyAndFindOldest(List<ItemHistory> itemInInventory) {
return itemInInventory.stream()
.min(Comparator.comparing(ItemHistory::getPurchaseAt))
.orElseThrow(ExceptionStatus.ITEM_NOT_OWNED::asServiceException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void issueLentExtension() {
Item coinRewardItem = itemQueryService.getBySku(Sku.COIN_FULL_TIME);
users.forEach(user -> {
Long userId = user.getId();
itemHistoryCommandService.purchaseItem(userId, coinRewardItem.getId());
itemHistoryCommandService.createItemHistory(userId, coinRewardItem.getId());
LockUtil.lockRedisCoin(userId, () ->
saveCoinChangeOnRedis(userId, coinRewardItem.getPrice()));
});
Expand Down

0 comments on commit ed0261b

Please sign in to comment.