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 8e0f9f72..b0f7f0f9 100644 --- a/src/main/java/com/moabam/api/application/item/ItemService.java +++ b/src/main/java/com/moabam/api/application/item/ItemService.java @@ -60,11 +60,12 @@ public void purchaseItem(Long memberId, Long itemId, PurchaseItemRequest request @Transactional public void selectItem(Long memberId, Long itemId) { + Member member = memberService.findMember(memberId); Inventory inventory = getInventory(memberId, itemId); inventorySearchRepository.findDefault(memberId, inventory.getItemType()) .ifPresent(Inventory::deselect); - inventory.select(); + inventory.select(member); } private Item getItem(Long itemId) { diff --git a/src/main/java/com/moabam/api/domain/item/Inventory.java b/src/main/java/com/moabam/api/domain/item/Inventory.java index c17d507b..44c6ab26 100644 --- a/src/main/java/com/moabam/api/domain/item/Inventory.java +++ b/src/main/java/com/moabam/api/domain/item/Inventory.java @@ -4,6 +4,7 @@ import org.hibernate.annotations.ColumnDefault; +import com.moabam.api.domain.member.Member; import com.moabam.global.common.entity.BaseTimeEntity; import jakarta.persistence.Column; @@ -54,8 +55,9 @@ public ItemType getItemType() { return this.item.getType(); } - public void select() { + public void select(Member member) { this.isDefault = true; + member.changeDefaultSkintUrl(this.item); } public void deselect() { 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 dca4b164..280c70fe 100644 --- a/src/test/java/com/moabam/api/application/item/ItemServiceTest.java +++ b/src/test/java/com/moabam/api/application/item/ItemServiceTest.java @@ -160,6 +160,7 @@ void success() { Inventory inventory = inventory(memberId, nightMageSkin()); Inventory defaultInventory = inventory(memberId, nightMageSkin()); ItemType itemType = inventory.getItemType(); + given(memberService.findMember(memberId)).willReturn(member()); given(inventorySearchRepository.findOne(memberId, itemId)).willReturn(Optional.of(inventory)); given(inventorySearchRepository.findDefault(memberId, itemType)).willReturn(Optional.of(defaultInventory)); diff --git a/src/test/java/com/moabam/api/domain/item/repository/InventorySearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/item/repository/InventorySearchRepositoryTest.java index 1e6a3299..649a73e7 100644 --- a/src/test/java/com/moabam/api/domain/item/repository/InventorySearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/item/repository/InventorySearchRepositoryTest.java @@ -103,7 +103,7 @@ void find_default_success() { Member member = memberRepository.save(member("11314", "test")); Item item = itemRepository.save(nightMageSkin()); Inventory inventory = inventoryRepository.save(inventory(member.getId(), item)); - inventory.select(); + inventory.select(member); // when Optional actual = inventorySearchRepository.findDefault(member.getId(), inventory.getItemType()); @@ -121,8 +121,8 @@ void find_all_default_type_night_success() { Item item = itemRepository.save(nightMageSkin()); Inventory inventory1 = inventoryRepository.save(inventory(member1.getId(), item)); Inventory inventory2 = inventoryRepository.save(inventory(member2.getId(), item)); - inventory1.select(); - inventory2.select(); + inventory1.select(member1); + inventory2.select(member2); // when List actual = inventorySearchRepository.findDefaultInventories(List.of(member1.getId(), @@ -151,10 +151,10 @@ void bird_find_success() { itemRepository.saveAll(List.of(night, morning, killer)); Inventory nightInven = InventoryFixture.inventory(member.getId(), night); - nightInven.select(); + nightInven.select(member); Inventory morningInven = InventoryFixture.inventory(member.getId(), morning); - morningInven.select(); + morningInven.select(member); Inventory killerInven = InventoryFixture.inventory(member.getId(), killer); inventoryRepository.saveAll(List.of(nightInven, morningInven, killerInven)); diff --git a/src/test/java/com/moabam/api/presentation/ItemControllerTest.java b/src/test/java/com/moabam/api/presentation/ItemControllerTest.java index 3cdd53d7..4745e997 100644 --- a/src/test/java/com/moabam/api/presentation/ItemControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/ItemControllerTest.java @@ -76,7 +76,7 @@ void success() throws Exception { Long memberId = getAuthMember().id(); Item item1 = itemRepository.save(morningSantaSkin().build()); Inventory inventory = inventoryRepository.save(inventory(memberId, item1)); - inventory.select(); + inventory.select(member()); Item item2 = itemRepository.save(morningKillerSkin().build()); ItemsResponse expected = ItemMapper.toItemsResponse(item1.getId(), List.of(item1), List.of(item2)); @@ -153,6 +153,7 @@ void select_item_success() throws Exception { // given Long memberId = getAuthMember().id(); Item item = itemRepository.save(nightMageSkin()); + given(memberService.findMember(memberId)).willReturn(member()); inventoryRepository.save(inventory(memberId, item)); // when, then diff --git a/src/test/java/com/moabam/api/presentation/MemberControllerTest.java b/src/test/java/com/moabam/api/presentation/MemberControllerTest.java index 659bc5a8..f9ce684a 100644 --- a/src/test/java/com/moabam/api/presentation/MemberControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/MemberControllerTest.java @@ -266,10 +266,10 @@ void search_my_info_success() throws Exception { itemRepository.saveAll(List.of(night, morning, killer)); Inventory nightInven = InventoryFixture.inventory(member.getId(), night); - nightInven.select(); + nightInven.select(member); Inventory morningInven = InventoryFixture.inventory(member.getId(), morning); - morningInven.select(); + morningInven.select(member); Inventory killerInven = InventoryFixture.inventory(member.getId(), killer); inventoryRepository.saveAll(List.of(nightInven, morningInven, killerInven)); @@ -316,10 +316,10 @@ void search_my_info_with_no_badge_success() throws Exception { itemRepository.saveAll(List.of(night, morning, killer)); Inventory nightInven = InventoryFixture.inventory(member.getId(), night); - nightInven.select(); + nightInven.select(member); Inventory morningInven = InventoryFixture.inventory(member.getId(), morning); - morningInven.select(); + morningInven.select(member); Inventory killerInven = InventoryFixture.inventory(member.getId(), killer); inventoryRepository.saveAll(List.of(nightInven, morningInven, killerInven)); @@ -377,10 +377,10 @@ void search_friend_info_success() throws Exception { itemRepository.saveAll(List.of(night, morning, killer)); Inventory nightInven = InventoryFixture.inventory(friend.getId(), night); - nightInven.select(); + nightInven.select(member); Inventory morningInven = InventoryFixture.inventory(friend.getId(), morning); - morningInven.select(); + morningInven.select(member); Inventory killerInven = InventoryFixture.inventory(friend.getId(), killer); friend.changeDefaultSkintUrl(morning); @@ -435,13 +435,13 @@ void search_member_failBy_default_skin_size() throws Exception { itemRepository.saveAll(List.of(night, morning, killer)); Inventory nightInven = InventoryFixture.inventory(member.getId(), night); - nightInven.select(); + nightInven.select(member); Inventory morningInven = InventoryFixture.inventory(member.getId(), morning); - morningInven.select(); + morningInven.select(member); Inventory killerInven = InventoryFixture.inventory(member.getId(), killer); - killerInven.select(); + killerInven.select(member); inventoryRepository.saveAll(List.of(nightInven, morningInven, killerInven)); // expected diff --git a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java index 0577f001..61170e45 100644 --- a/src/test/java/com/moabam/api/presentation/RoomControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/RoomControllerTest.java @@ -807,9 +807,9 @@ void get_room_details_test() throws Exception { Inventory inventory1 = InventoryFixture.inventory(1L, item); Inventory inventory2 = InventoryFixture.inventory(member2.getId(), item); Inventory inventory3 = InventoryFixture.inventory(member3.getId(), item); - inventory1.select(); - inventory2.select(); - inventory3.select(); + inventory1.select(member); + inventory2.select(member2); + inventory3.select(member3); itemRepository.save(item); inventoryRepository.saveAll(List.of(inventory1, inventory2, inventory3)); @@ -1017,7 +1017,7 @@ void get_un_joined_room_details() throws Exception { Item item = ItemFixture.nightMageSkin(); Inventory inventory = InventoryFixture.inventory(member1.getId(), item); - inventory.select(); + inventory.select(member1); itemRepository.save(item); inventoryRepository.save(inventory);