diff --git a/src/main/java/com/moabam/api/application/bug/BugMapper.java b/src/main/java/com/moabam/api/application/bug/BugMapper.java index 89a4fe83..0095b05a 100644 --- a/src/main/java/com/moabam/api/application/bug/BugMapper.java +++ b/src/main/java/com/moabam/api/application/bug/BugMapper.java @@ -4,8 +4,8 @@ import com.moabam.api.domain.bug.BugActionType; import com.moabam.api.domain.bug.BugHistory; import com.moabam.api.domain.bug.BugType; -import com.moabam.api.dto.TodayBugResponse; import com.moabam.api.dto.bug.BugResponse; +import com.moabam.api.dto.bug.TodayBugResponse; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/moabam/api/application/bug/BugService.java b/src/main/java/com/moabam/api/application/bug/BugService.java index 60222eb5..6093f51d 100644 --- a/src/main/java/com/moabam/api/application/bug/BugService.java +++ b/src/main/java/com/moabam/api/application/bug/BugService.java @@ -17,8 +17,8 @@ import com.moabam.api.domain.member.Member; import com.moabam.api.domain.product.Product; import com.moabam.api.domain.product.repository.ProductRepository; -import com.moabam.api.dto.TodayBugResponse; import com.moabam.api.dto.bug.BugResponse; +import com.moabam.api.dto.bug.TodayBugResponse; import com.moabam.api.dto.product.ProductsResponse; import com.moabam.global.common.util.ClockHolder; diff --git a/src/main/java/com/moabam/api/application/item/ItemMapper.java b/src/main/java/com/moabam/api/application/item/ItemMapper.java index 7499d561..f91591df 100644 --- a/src/main/java/com/moabam/api/application/item/ItemMapper.java +++ b/src/main/java/com/moabam/api/application/item/ItemMapper.java @@ -27,8 +27,9 @@ public static ItemResponse toItemResponse(Item item) { .build(); } - public static ItemsResponse toItemsResponse(List purchasedItems, List notPurchasedItems) { + public static ItemsResponse toItemsResponse(Long itemId, List purchasedItems, List notPurchasedItems) { return ItemsResponse.builder() + .defaultItemId(itemId) .purchasedItems(StreamUtils.map(purchasedItems, ItemMapper::toItemResponse)) .notPurchasedItems(StreamUtils.map(notPurchasedItems, ItemMapper::toItemResponse)) .build(); diff --git a/src/main/java/com/moabam/api/application/item/ItemService.java b/src/main/java/com/moabam/api/application/item/ItemService.java index d1d278aa..3a024c2e 100644 --- a/src/main/java/com/moabam/api/application/item/ItemService.java +++ b/src/main/java/com/moabam/api/application/item/ItemService.java @@ -39,10 +39,11 @@ public class ItemService { private final BugHistoryRepository bugHistoryRepository; public ItemsResponse getItems(Long memberId, ItemType type) { + Item defaultItem = getDefaultInventory(memberId, type).getItem(); List purchasedItems = inventorySearchRepository.findItems(memberId, type); List notPurchasedItems = itemSearchRepository.findNotPurchasedItems(memberId, type); - return ItemMapper.toItemsResponse(purchasedItems, notPurchasedItems); + return ItemMapper.toItemsResponse(defaultItem.getId(), purchasedItems, notPurchasedItems); } @Transactional @@ -80,6 +81,11 @@ private Inventory getInventory(Long memberId, Long itemId) { .orElseThrow(() -> new NotFoundException(INVENTORY_NOT_FOUND)); } + private Inventory getDefaultInventory(Long memberId, ItemType type) { + return inventorySearchRepository.findDefault(memberId, type) + .orElseThrow(() -> new NotFoundException(DEFAULT_INVENTORY_NOT_FOUND)); + } + private void validateAlreadyPurchased(Long memberId, Long itemId) { inventorySearchRepository.findOne(memberId, itemId) .ifPresent(inventory -> { diff --git a/src/main/java/com/moabam/api/dto/TodayBugResponse.java b/src/main/java/com/moabam/api/dto/bug/TodayBugResponse.java similarity index 76% rename from src/main/java/com/moabam/api/dto/TodayBugResponse.java rename to src/main/java/com/moabam/api/dto/bug/TodayBugResponse.java index fb5282d5..11ee0dcc 100644 --- a/src/main/java/com/moabam/api/dto/TodayBugResponse.java +++ b/src/main/java/com/moabam/api/dto/bug/TodayBugResponse.java @@ -1,4 +1,4 @@ -package com.moabam.api.dto; +package com.moabam.api.dto.bug; import lombok.Builder; diff --git a/src/main/java/com/moabam/api/dto/item/ItemsResponse.java b/src/main/java/com/moabam/api/dto/item/ItemsResponse.java index 085d339d..70de47ec 100644 --- a/src/main/java/com/moabam/api/dto/item/ItemsResponse.java +++ b/src/main/java/com/moabam/api/dto/item/ItemsResponse.java @@ -6,6 +6,7 @@ @Builder public record ItemsResponse( + Long defaultItemId, List purchasedItems, List notPurchasedItems ) { diff --git a/src/main/java/com/moabam/api/presentation/BugController.java b/src/main/java/com/moabam/api/presentation/BugController.java index 41dfa8d1..95de7f5b 100644 --- a/src/main/java/com/moabam/api/presentation/BugController.java +++ b/src/main/java/com/moabam/api/presentation/BugController.java @@ -7,8 +7,8 @@ import org.springframework.web.bind.annotation.RestController; import com.moabam.api.application.bug.BugService; -import com.moabam.api.dto.TodayBugResponse; import com.moabam.api.dto.bug.BugResponse; +import com.moabam.api.dto.bug.TodayBugResponse; import com.moabam.api.dto.product.ProductsResponse; import com.moabam.global.auth.annotation.CurrentMember; import com.moabam.global.auth.model.AuthorizationMember; diff --git a/src/main/java/com/moabam/global/error/model/ErrorMessage.java b/src/main/java/com/moabam/global/error/model/ErrorMessage.java index a1bc6d53..90c493c0 100644 --- a/src/main/java/com/moabam/global/error/model/ErrorMessage.java +++ b/src/main/java/com/moabam/global/error/model/ErrorMessage.java @@ -40,6 +40,7 @@ public enum ErrorMessage { ITEM_UNLOCK_LEVEL_HIGH("아이템 해금 레벨이 높습니다."), ITEM_NOT_PURCHASABLE_BY_BUG_TYPE("해당 벌레 타입으로는 구매할 수 없는 아이템입니다."), INVENTORY_NOT_FOUND("구매하지 않은 아이템은 적용할 수 없습니다."), + DEFAULT_INVENTORY_NOT_FOUND("현재 적용된 아이템이 없습니다."), INVENTORY_CONFLICT("이미 구매한 아이템입니다."), INVALID_BUG_COUNT("벌레 개수는 0 이상이어야 합니다."), diff --git a/src/test/java/com/moabam/api/application/item/ItemServiceTest.java b/src/test/java/com/moabam/api/application/item/ItemServiceTest.java index c48fcb12..c0f06cab 100644 --- a/src/test/java/com/moabam/api/application/item/ItemServiceTest.java +++ b/src/test/java/com/moabam/api/application/item/ItemServiceTest.java @@ -70,6 +70,8 @@ void get_products_success() { ItemType type = ItemType.MORNING; Item item1 = morningSantaSkin().build(); Item item2 = morningKillerSkin().build(); + Inventory inventory = inventory(memberId, item1); + given(inventorySearchRepository.findDefault(memberId, type)).willReturn(Optional.of(inventory)); given(inventorySearchRepository.findItems(memberId, type)).willReturn(List.of(item1, item2)); given(itemSearchRepository.findNotPurchasedItems(memberId, type)).willReturn(emptyList()); diff --git a/src/test/java/com/moabam/api/presentation/BugControllerTest.java b/src/test/java/com/moabam/api/presentation/BugControllerTest.java index c0bf7dbd..a2c66b1e 100644 --- a/src/test/java/com/moabam/api/presentation/BugControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/BugControllerTest.java @@ -32,8 +32,8 @@ import com.moabam.api.domain.bug.repository.BugHistorySearchRepository; import com.moabam.api.domain.product.Product; import com.moabam.api.domain.product.repository.ProductRepository; -import com.moabam.api.dto.TodayBugResponse; import com.moabam.api.dto.bug.BugResponse; +import com.moabam.api.dto.bug.TodayBugResponse; import com.moabam.api.dto.product.ProductsResponse; import com.moabam.support.annotation.WithMember; import com.moabam.support.common.WithoutFilterSupporter; diff --git a/src/test/java/com/moabam/api/presentation/ItemControllerTest.java b/src/test/java/com/moabam/api/presentation/ItemControllerTest.java index 78e367c4..120f210a 100644 --- a/src/test/java/com/moabam/api/presentation/ItemControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/ItemControllerTest.java @@ -30,6 +30,7 @@ import com.moabam.api.application.item.ItemMapper; import com.moabam.api.application.member.MemberService; import com.moabam.api.domain.bug.BugType; +import com.moabam.api.domain.item.Inventory; import com.moabam.api.domain.item.Item; import com.moabam.api.domain.item.ItemType; import com.moabam.api.domain.item.repository.InventoryRepository; @@ -70,9 +71,10 @@ void success() throws Exception { // given Long memberId = getAuthorizationMember().id(); Item item1 = itemRepository.save(morningSantaSkin().build()); - inventoryRepository.save(inventory(memberId, item1)); + Inventory inventory = inventoryRepository.save(inventory(memberId, item1)); + inventory.select(); Item item2 = itemRepository.save(morningKillerSkin().build()); - ItemsResponse expected = ItemMapper.toItemsResponse(List.of(item1), List.of(item2)); + ItemsResponse expected = ItemMapper.toItemsResponse(item1.getId(), List.of(item1), List.of(item2)); // expected String content = mockMvc.perform(get("/items")