Skip to content

Commit

Permalink
fix: 아이템 선택 시 멤버 기본 스킨 이미지 업데이트 (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmebin authored Nov 29, 2023
1 parent 6a6ced1 commit 458e67b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/moabam/api/domain/item/Inventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Inventory> actual = inventorySearchRepository.findDefault(member.getId(), inventory.getItemType());
Expand All @@ -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<Inventory> actual = inventorySearchRepository.findDefaultInventories(List.of(member1.getId(),
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 458e67b

Please sign in to comment.