From d03feb319ed85a66927ba0f816ebd8ea20698bfe Mon Sep 17 00:00:00 2001 From: Kim Heebin Date: Tue, 28 Nov 2023 16:27:36 +0900 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20=EB=B2=8C=EB=A0=88=20=EB=B3=B4?= =?UTF-8?q?=EC=83=81/=EC=B6=A9=EC=A0=84/=EC=82=AC=EC=9A=A9=20=EC=8B=9C=20?= =?UTF-8?q?=EB=82=B4=EC=97=AD=20=EC=A0=80=EC=9E=A5=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#165)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 벌레 사용 + 벌레 내역 저장 로직 하나의 메서드로 분리 * refactor: 벌레 보상 + 벌레 내역 저장 로직 하나의 메서드로 분리 * test: 아이템 서비스 테스트 수정 * test: BugService Mock 추가 * test: 벌레 사용/충전/보상 서비스 테스트 * refactor: 쿠폰 사용 + 벌레 내역 저장 로직 하나의 메서드로 분리 * fix: 불필요한 Mock 제거 --- .../moabam/api/application/bug/BugMapper.java | 36 +++++++++--- .../api/application/bug/BugService.java | 51 +++++++++++++--- .../api/application/coupon/CouponService.java | 9 +-- .../api/application/item/ItemService.java | 10 +--- .../room/CertificationService.java | 6 +- .../java/com/moabam/api/domain/bug/Bug.java | 31 +++++----- .../api/presentation/ItemController.java | 3 +- .../api/application/bug/BugServiceTest.java | 58 +++++++++++++++++-- .../application/coupon/CouponServiceTest.java | 9 +-- .../api/application/item/ItemServiceTest.java | 12 ++-- .../room/CertificationServiceTest.java | 12 ++-- .../api/presentation/ItemControllerTest.java | 4 ++ 12 files changed, 169 insertions(+), 72 deletions(-) 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 cf40d215..af91b206 100644 --- a/src/main/java/com/moabam/api/application/bug/BugMapper.java +++ b/src/main/java/com/moabam/api/application/bug/BugMapper.java @@ -20,15 +20,6 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class BugMapper { - public static BugHistory toUseBugHistory(Long memberId, BugType bugType, int quantity) { - return BugHistory.builder() - .memberId(memberId) - .bugType(bugType) - .actionType(BugActionType.USE) - .quantity(quantity) - .build(); - } - public static BugResponse toBugResponse(Bug bug) { return BugResponse.builder() .morningBug(bug.getMorningBug()) @@ -54,6 +45,15 @@ public static BugHistoryResponse toBugHistoryResponse(List new NotFoundException(PRODUCT_NOT_FOUND)); } + + private CouponWallet getCouponWallet(Long couponWalletId, Long memberId) { + return couponWalletSearchRepository.findByIdAndMemberId(couponWalletId, memberId) + .orElseThrow(() -> new NotFoundException(ErrorMessage.NOT_FOUND_COUPON_WALLET)); + } } diff --git a/src/main/java/com/moabam/api/application/coupon/CouponService.java b/src/main/java/com/moabam/api/application/coupon/CouponService.java index 1d36be55..3653802c 100644 --- a/src/main/java/com/moabam/api/application/coupon/CouponService.java +++ b/src/main/java/com/moabam/api/application/coupon/CouponService.java @@ -6,7 +6,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.moabam.api.application.member.MemberService; +import com.moabam.api.application.bug.BugService; import com.moabam.api.domain.bug.BugType; import com.moabam.api.domain.coupon.Coupon; import com.moabam.api.domain.coupon.CouponWallet; @@ -14,7 +14,6 @@ import com.moabam.api.domain.coupon.repository.CouponSearchRepository; import com.moabam.api.domain.coupon.repository.CouponWalletRepository; import com.moabam.api.domain.coupon.repository.CouponWalletSearchRepository; -import com.moabam.api.domain.member.Member; import com.moabam.api.domain.member.Role; import com.moabam.api.dto.coupon.CouponResponse; import com.moabam.api.dto.coupon.CouponStatusRequest; @@ -35,7 +34,7 @@ public class CouponService { private final ClockHolder clockHolder; - private final MemberService memberService; + private final BugService bugService; private final CouponManageService couponManageService; private final CouponRepository couponRepository; private final CouponSearchRepository couponSearchRepository; @@ -59,9 +58,7 @@ public void use(Long memberId, Long couponWalletId) { Coupon coupon = couponWallet.getCoupon(); BugType bugType = coupon.getType().getBugType(); - Member member = memberService.findMember(memberId); - member.getBug().increase(bugType, coupon.getPoint()); - + bugService.applyCoupon(memberId, bugType, coupon.getPoint()); couponWalletRepository.delete(couponWallet); } 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 a0d5015f..8e0f9f72 100644 --- a/src/main/java/com/moabam/api/application/item/ItemService.java +++ b/src/main/java/com/moabam/api/application/item/ItemService.java @@ -7,10 +7,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.moabam.api.application.bug.BugMapper; +import com.moabam.api.application.bug.BugService; import com.moabam.api.application.member.MemberService; -import com.moabam.api.domain.bug.Bug; -import com.moabam.api.domain.bug.repository.BugHistoryRepository; import com.moabam.api.domain.item.Inventory; import com.moabam.api.domain.item.Item; import com.moabam.api.domain.item.ItemType; @@ -32,11 +30,11 @@ public class ItemService { private final MemberService memberService; + private final BugService bugService; private final ItemRepository itemRepository; private final ItemSearchRepository itemSearchRepository; private final InventoryRepository inventoryRepository; private final InventorySearchRepository inventorySearchRepository; - private final BugHistoryRepository bugHistoryRepository; public ItemsResponse getItems(Long memberId, ItemType type) { Item defaultItem = getDefaultInventory(memberId, type).getItem(); @@ -54,12 +52,10 @@ public void purchaseItem(Long memberId, Long itemId, PurchaseItemRequest request validateAlreadyPurchased(memberId, itemId); item.validatePurchasable(request.bugType(), member.getLevel()); - Bug bug = member.getBug(); int price = item.getPrice(request.bugType()); - bug.use(request.bugType(), price); + bugService.use(member, request.bugType(), price); inventoryRepository.save(ItemMapper.toInventory(memberId, item)); - bugHistoryRepository.save(BugMapper.toUseBugHistory(memberId, request.bugType(), price)); } @Transactional diff --git a/src/main/java/com/moabam/api/application/room/CertificationService.java b/src/main/java/com/moabam/api/application/room/CertificationService.java index f8e72e9d..3a679550 100644 --- a/src/main/java/com/moabam/api/application/room/CertificationService.java +++ b/src/main/java/com/moabam/api/application/room/CertificationService.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.moabam.api.application.bug.BugService; import com.moabam.api.application.member.MemberService; import com.moabam.api.application.room.mapper.CertificationsMapper; import com.moabam.api.domain.bug.BugType; @@ -51,6 +52,7 @@ public class CertificationService { private final DailyRoomCertificationRepository dailyRoomCertificationRepository; private final DailyMemberCertificationRepository dailyMemberCertificationRepository; private final MemberService memberService; + private final BugService bugService; private final ClockHolder clockHolder; @Transactional @@ -88,7 +90,7 @@ public void certifyRoom(CertifiedMemberInfo certifyInfo) { return; } - member.getBug().increase(bugType, room.getLevel()); + bugService.reward(member, bugType, room.getLevel()); } public boolean existsMemberCertification(Long memberId, Long roomId, LocalDate date) { @@ -187,6 +189,6 @@ private void provideBugToCompletedMembers(BugType bugType, List completedMember.getBug().increase(bugType, expAppliedRoomLevel)); + .forEach(completedMember -> bugService.reward(completedMember, bugType, expAppliedRoomLevel)); } } diff --git a/src/main/java/com/moabam/api/domain/bug/Bug.java b/src/main/java/com/moabam/api/domain/bug/Bug.java index ae07f4d6..f581c870 100644 --- a/src/main/java/com/moabam/api/domain/bug/Bug.java +++ b/src/main/java/com/moabam/api/domain/bug/Bug.java @@ -45,10 +45,11 @@ private int validateBugCount(int bug) { return bug; } - public void use(BugType bugType, int price) { + public void use(BugType bugType, int count) { int currentBug = getBug(bugType); - validateEnoughBug(currentBug, price); - decrease(bugType, price); + + validateEnoughBug(currentBug, count); + decrease(bugType, count); } private int getBug(BugType bugType) { @@ -59,29 +60,29 @@ private int getBug(BugType bugType) { }; } - private void validateEnoughBug(int currentBug, int price) { - if (price > currentBug) { + private void validateEnoughBug(int currentBug, int count) { + if (currentBug < count) { throw new BadRequestException(BUG_NOT_ENOUGH); } } - private void decrease(BugType bugType, int bug) { + private void decrease(BugType bugType, int count) { switch (bugType) { - case MORNING -> this.morningBug -= bug; - case NIGHT -> this.nightBug -= bug; - case GOLDEN -> this.goldenBug -= bug; + case MORNING -> this.morningBug -= count; + case NIGHT -> this.nightBug -= count; + case GOLDEN -> this.goldenBug -= count; } } - public void increase(BugType bugType, int bug) { + public void increase(BugType bugType, int count) { switch (bugType) { - case MORNING -> this.morningBug += bug; - case NIGHT -> this.nightBug += bug; - case GOLDEN -> this.goldenBug += bug; + case MORNING -> this.morningBug += count; + case NIGHT -> this.nightBug += count; + case GOLDEN -> this.goldenBug += count; } } - public void charge(int quantity) { - this.goldenBug += quantity; + public void charge(int count) { + this.goldenBug += count; } } diff --git a/src/main/java/com/moabam/api/presentation/ItemController.java b/src/main/java/com/moabam/api/presentation/ItemController.java index fbb55663..7b55c155 100644 --- a/src/main/java/com/moabam/api/presentation/ItemController.java +++ b/src/main/java/com/moabam/api/presentation/ItemController.java @@ -35,8 +35,7 @@ public ItemsResponse getItems(@Auth AuthMember member, @RequestParam ItemType ty @PostMapping("/{itemId}/purchase") @ResponseStatus(HttpStatus.OK) - public void purchaseItem(@Auth AuthMember member, - @PathVariable Long itemId, + public void purchaseItem(@Auth AuthMember member, @PathVariable Long itemId, @Valid @RequestBody PurchaseItemRequest request) { itemService.purchaseItem(member.id(), itemId, request); } diff --git a/src/test/java/com/moabam/api/application/bug/BugServiceTest.java b/src/test/java/com/moabam/api/application/bug/BugServiceTest.java index e2bb6d8e..7c147a98 100644 --- a/src/test/java/com/moabam/api/application/bug/BugServiceTest.java +++ b/src/test/java/com/moabam/api/application/bug/BugServiceTest.java @@ -1,6 +1,7 @@ package com.moabam.api.application.bug; import static com.moabam.api.domain.product.ProductType.*; +import static com.moabam.support.fixture.BugFixture.*; import static com.moabam.support.fixture.CouponFixture.*; import static com.moabam.support.fixture.MemberFixture.*; import static com.moabam.support.fixture.ProductFixture.*; @@ -18,11 +19,13 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.moabam.api.application.coupon.CouponService; import com.moabam.api.application.member.MemberService; import com.moabam.api.application.payment.PaymentMapper; import com.moabam.api.domain.bug.Bug; +import com.moabam.api.domain.bug.BugType; +import com.moabam.api.domain.bug.repository.BugHistoryRepository; import com.moabam.api.domain.coupon.CouponWallet; +import com.moabam.api.domain.coupon.repository.CouponWalletSearchRepository; import com.moabam.api.domain.member.Member; import com.moabam.api.domain.payment.Payment; import com.moabam.api.domain.payment.repository.PaymentRepository; @@ -46,7 +49,7 @@ class BugServiceTest { MemberService memberService; @Mock - CouponService couponService; + BugHistoryRepository bugHistoryRepository; @Mock ProductRepository productRepository; @@ -54,6 +57,9 @@ class BugServiceTest { @Mock PaymentRepository paymentRepository; + @Mock + CouponWalletSearchRepository couponWalletSearchRepository; + @DisplayName("벌레를 조회한다.") @Test void get_bug_success() { @@ -100,12 +106,13 @@ void apply_coupon_success() { Long memberId = 1L; Long productId = 1L; Long couponWalletId = 1L; + CouponWallet couponWallet = CouponWallet.create(memberId, discount1000Coupon()); Payment payment = PaymentMapper.toPayment(memberId, bugProduct()); PurchaseProductRequest request = new PurchaseProductRequest(couponWalletId); given(productRepository.findById(productId)).willReturn(Optional.of(bugProduct())); given(paymentRepository.save(any(Payment.class))).willReturn(payment); - given(couponService.getWalletByIdAndMemberId(couponWalletId, memberId)).willReturn( - CouponWallet.create(memberId, discount1000Coupon())); + given(couponWalletSearchRepository.findByIdAndMemberId(couponWalletId, memberId)).willReturn( + Optional.of(couponWallet)); // when PurchaseProductResponse response = bugService.purchaseBugProduct(memberId, productId, request); @@ -130,4 +137,47 @@ void product_not_found_exception() { .hasMessage("존재하지 않는 상품입니다."); } } + + @DisplayName("벌레를 사용한다.") + @Test + void use_success() { + // given + Member member = spy(member()); + given(member.getId()).willReturn(1L); + + // when + bugService.use(member, BugType.MORNING, 5); + + // then + assertThat(member.getBug().getMorningBug()).isEqualTo(MORNING_BUG - 5); + } + + @DisplayName("벌레 보상을 준다.") + @Test + void reward_success() { + // given + Member member = spy(member()); + given(member.getId()).willReturn(1L); + + // when + bugService.reward(member, BugType.NIGHT, 5); + + // then + assertThat(member.getBug().getNightBug()).isEqualTo(NIGHT_BUG + 5); + } + + @DisplayName("벌레를 충전한다.") + @Test + void charge_success() { + // given + Long memberId = 1L; + Member member = member(); + given(memberService.findMember(memberId)).willReturn(member); + + // when + bugService.charge(memberId, bugProduct()); + + // then + assertThat(member.getBug().getGoldenBug()).isEqualTo(GOLDEN_BUG + BUG_PRODUCT_QUANTITY); + } } diff --git a/src/test/java/com/moabam/api/application/coupon/CouponServiceTest.java b/src/test/java/com/moabam/api/application/coupon/CouponServiceTest.java index de7e817e..86db23f0 100644 --- a/src/test/java/com/moabam/api/application/coupon/CouponServiceTest.java +++ b/src/test/java/com/moabam/api/application/coupon/CouponServiceTest.java @@ -17,7 +17,7 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.moabam.api.application.member.MemberService; +import com.moabam.api.application.bug.BugService; import com.moabam.api.domain.coupon.Coupon; import com.moabam.api.domain.coupon.CouponType; import com.moabam.api.domain.coupon.CouponWallet; @@ -25,7 +25,6 @@ import com.moabam.api.domain.coupon.repository.CouponSearchRepository; import com.moabam.api.domain.coupon.repository.CouponWalletRepository; import com.moabam.api.domain.coupon.repository.CouponWalletSearchRepository; -import com.moabam.api.domain.member.Member; import com.moabam.api.domain.member.Role; import com.moabam.api.dto.coupon.CouponResponse; import com.moabam.api.dto.coupon.CouponStatusRequest; @@ -40,9 +39,7 @@ import com.moabam.global.error.model.ErrorMessage; import com.moabam.support.annotation.WithMember; import com.moabam.support.common.FilterProcessExtension; -import com.moabam.support.fixture.BugFixture; import com.moabam.support.fixture.CouponFixture; -import com.moabam.support.fixture.MemberFixture; @ExtendWith({MockitoExtension.class, FilterProcessExtension.class}) class CouponServiceTest { @@ -54,7 +51,7 @@ class CouponServiceTest { CouponManageService couponManageService; @Mock - MemberService memberService; + BugService bugService; @Mock CouponRepository couponRepository; @@ -321,11 +318,9 @@ void getByWalletIdAndMemberId_success() { @Test void use_success() { // Given - Member member = MemberFixture.member(BugFixture.zeroBug()); Coupon coupon = CouponFixture.coupon(CouponType.GOLDEN, 1000); CouponWallet couponWallet = CouponWallet.create(1L, coupon); - given(memberService.findMember(any(Long.class))).willReturn(member); given(couponWalletSearchRepository.findByIdAndMemberId(any(Long.class), any(Long.class))) .willReturn(Optional.of(couponWallet)); 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 6abe441d..dca4b164 100644 --- a/src/test/java/com/moabam/api/application/item/ItemServiceTest.java +++ b/src/test/java/com/moabam/api/application/item/ItemServiceTest.java @@ -19,8 +19,8 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import com.moabam.api.application.bug.BugService; import com.moabam.api.application.member.MemberService; -import com.moabam.api.domain.bug.BugHistory; import com.moabam.api.domain.bug.BugType; import com.moabam.api.domain.bug.repository.BugHistoryRepository; import com.moabam.api.domain.item.Inventory; @@ -47,6 +47,9 @@ class ItemServiceTest { @Mock MemberService memberService; + @Mock + BugService bugService; + @Mock ItemRepository itemRepository; @@ -106,11 +109,8 @@ void success() { itemService.purchaseItem(memberId, itemId, request); // Then - verify(memberService).findMember(memberId); - verify(itemRepository).findById(itemId); - verify(inventorySearchRepository).findOne(memberId, itemId); + verify(bugService).use(any(Member.class), any(BugType.class), anyInt()); verify(inventoryRepository).save(any(Inventory.class)); - verify(bugHistoryRepository).save(any(BugHistory.class)); } @DisplayName("해당 아이템이 존재하지 않으면 예외가 발생한다.") @@ -167,8 +167,6 @@ void success() { itemService.selectItem(memberId, itemId); // then - verify(inventorySearchRepository).findOne(memberId, itemId); - verify(inventorySearchRepository).findDefault(memberId, itemType); assertFalse(defaultInventory.isDefault()); assertTrue(inventory.isDefault()); } diff --git a/src/test/java/com/moabam/api/application/room/CertificationServiceTest.java b/src/test/java/com/moabam/api/application/room/CertificationServiceTest.java index 83c98f41..d15ecdf1 100644 --- a/src/test/java/com/moabam/api/application/room/CertificationServiceTest.java +++ b/src/test/java/com/moabam/api/application/room/CertificationServiceTest.java @@ -19,6 +19,7 @@ import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; +import com.moabam.api.application.bug.BugService; import com.moabam.api.application.image.ImageService; import com.moabam.api.application.member.MemberService; import com.moabam.api.application.room.mapper.CertificationsMapper; @@ -51,6 +52,9 @@ class CertificationServiceTest { @Mock private MemberService memberService; + @Mock + private BugService bugService; + @Mock private RoomRepository roomRepository; @@ -161,7 +165,7 @@ void already_certified_room_routine_success() { certificationService.certifyRoom(certifyInfo); // then - assertThat(member1.getBug().getMorningBug()).isEqualTo(12); + verify(bugService).reward(any(Member.class), any(BugType.class), anyInt()); } @DisplayName("인증되지 않은 방에서 루틴 인증 후 방의 인증 성공") @@ -184,11 +188,7 @@ void not_certified_room_routine_success() { certificationService.certifyRoom(certifyInfo); // then - assertThat(member1.getBug().getMorningBug()).isEqualTo(12); - assertThat(member2.getBug().getMorningBug()).isEqualTo(12); - assertThat(member3.getBug().getMorningBug()).isEqualTo(12); - assertThat(member3.getBug().getNightBug()).isEqualTo(20); - assertThat(member3.getBug().getGoldenBug()).isEqualTo(30); + verify(bugService, times(3)).reward(any(Member.class), any(BugType.class), anyInt()); assertThat(room.getExp()).isEqualTo(1); assertThat(room.getLevel()).isEqualTo(2); } diff --git a/src/test/java/com/moabam/api/presentation/ItemControllerTest.java b/src/test/java/com/moabam/api/presentation/ItemControllerTest.java index b637e8f7..3cdd53d7 100644 --- a/src/test/java/com/moabam/api/presentation/ItemControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/ItemControllerTest.java @@ -27,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional; import com.fasterxml.jackson.databind.ObjectMapper; +import com.moabam.api.application.bug.BugService; import com.moabam.api.application.item.ItemMapper; import com.moabam.api.application.member.MemberService; import com.moabam.api.domain.bug.BugType; @@ -54,6 +55,9 @@ class ItemControllerTest extends WithoutFilterSupporter { @MockBean MemberService memberService; + @MockBean + BugService bugService; + @Autowired ItemRepository itemRepository; From bec514405ef202cdcc4720124be638aebdac19c9 Mon Sep 17 00:00:00 2001 From: Kim Heebin Date: Tue, 28 Nov 2023 16:28:19 +0900 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20=EC=95=84=EC=9D=B4=ED=85=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=B2=84=EC=A0=84=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=EB=B0=A9=20=EB=B0=B0=EA=B2=BD=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20(#167)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 아이템 테이블에 awakeImage, sleepImage 컬럼 추가 * feat: 방 레벨업 시 이미지 업데이트 로직 추가 * chore: 코드 제거 * test: 테스트 검증 수정 * chore: 이미지 URL에 작은 따옴표 제거 --- .../api/application/item/ItemMapper.java | 2 +- .../api/application/member/MemberService.java | 1 + .../api/application/room/SearchService.java | 8 ++-- .../application/room/mapper/RoomMapper.java | 4 +- .../java/com/moabam/api/domain/item/Item.java | 15 +++++-- .../com/moabam/api/domain/item/ItemImage.java | 28 +++++++++++++ .../com/moabam/api/domain/member/Member.java | 5 +-- .../java/com/moabam/api/domain/room/Room.java | 40 +++++++++++++++---- .../application/member/MemberServiceTest.java | 6 +-- .../com/moabam/api/domain/room/RoomTest.java | 22 +++++++++- .../presentation/MemberControllerTest.java | 4 +- .../moabam/support/fixture/ItemFixture.java | 22 ++++++++-- 12 files changed, 127 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/moabam/api/domain/item/ItemImage.java 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 f91591df..f2cabfff 100644 --- a/src/main/java/com/moabam/api/application/item/ItemMapper.java +++ b/src/main/java/com/moabam/api/application/item/ItemMapper.java @@ -20,7 +20,7 @@ public static ItemResponse toItemResponse(Item item) { .type(item.getType().name()) .category(item.getCategory().name()) .name(item.getName()) - .image(item.getImage()) + .image(item.getAwakeImage()) .level(item.getUnlockLevel()) .bugPrice(item.getBugPrice()) .goldenBugPrice(item.getGoldenBugPrice()) diff --git a/src/main/java/com/moabam/api/application/member/MemberService.java b/src/main/java/com/moabam/api/application/member/MemberService.java index b6505ce3..fb0e8637 100644 --- a/src/main/java/com/moabam/api/application/member/MemberService.java +++ b/src/main/java/com/moabam/api/application/member/MemberService.java @@ -107,6 +107,7 @@ private void validateNickname(String nickname) { private Member signUp(Long socialId) { Member member = MemberMapper.toMember(socialId); + return memberRepository.save(member); } diff --git a/src/main/java/com/moabam/api/application/room/SearchService.java b/src/main/java/com/moabam/api/application/room/SearchService.java index 9e62b9d0..fafe30d0 100644 --- a/src/main/java/com/moabam/api/application/room/SearchService.java +++ b/src/main/java/com/moabam/api/application/room/SearchService.java @@ -299,8 +299,8 @@ private List completedMembers( .findAny() .orElseThrow(() -> new NotFoundException(INVENTORY_NOT_FOUND)); - String awakeImage = inventory.getItem().getImage(); - String sleepImage = inventory.getItem().getImage(); + String awakeImage = inventory.getItem().getAwakeImage(); + String sleepImage = inventory.getItem().getSleepImage(); int contributionPoint = calculateContributionPoint(member.getId(), participants, date); CertificationImagesResponse certificationImages = getCertificationImages(member.getId(), certifications); @@ -343,8 +343,8 @@ private List uncompletedMembers( .findAny() .orElseThrow(() -> new NotFoundException(INVENTORY_NOT_FOUND)); - String awakeImage = inventory.getItem().getImage(); - String sleepImage = inventory.getItem().getImage(); + String awakeImage = inventory.getItem().getAwakeImage(); + String sleepImage = inventory.getItem().getSleepImage(); int contributionPoint = calculateContributionPoint(memberId, participants, date); boolean isNotificationSent = knocks.contains(member.getId()); diff --git a/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java b/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java index 21e86124..f80eec07 100644 --- a/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java +++ b/src/main/java/com/moabam/api/application/room/mapper/RoomMapper.java @@ -164,8 +164,8 @@ public static UnJoinedRoomCertificateRankResponse toUnJoinedRoomCertificateRankR .rank(rank) .memberId(member.getId()) .nickname(member.getNickname()) - .awakeImage(inventory.getItem().getImage()) - .sleepImage(inventory.getItem().getImage()) + .awakeImage(inventory.getItem().getAwakeImage()) + .sleepImage(inventory.getItem().getSleepImage()) .build(); } } diff --git a/src/main/java/com/moabam/api/domain/item/Item.java b/src/main/java/com/moabam/api/domain/item/Item.java index ad7bbd0d..6fefd03e 100644 --- a/src/main/java/com/moabam/api/domain/item/Item.java +++ b/src/main/java/com/moabam/api/domain/item/Item.java @@ -10,6 +10,7 @@ import com.moabam.global.error.exception.BadRequestException; import jakarta.persistence.Column; +import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; @@ -44,8 +45,8 @@ public class Item extends BaseTimeEntity { @Column(name = "name", nullable = false) private String name; - @Column(name = "image", nullable = false) - private String image; + @Embedded + private ItemImage image; @Column(name = "bug_price", nullable = false) @ColumnDefault("0") @@ -60,7 +61,7 @@ public class Item extends BaseTimeEntity { private int unlockLevel; @Builder - private Item(ItemType type, ItemCategory category, String name, String image, int bugPrice, int goldenBugPrice, + private Item(ItemType type, ItemCategory category, String name, ItemImage image, int bugPrice, int goldenBugPrice, Integer unlockLevel) { this.type = requireNonNull(type); this.category = requireNonNull(category); @@ -107,4 +108,12 @@ private void validateBugTypeMatch(BugType bugType) { public int getPrice(BugType bugType) { return bugType.isGoldenBug() ? this.goldenBugPrice : this.bugPrice; } + + public String getAwakeImage() { + return this.getImage().getAwake(); + } + + public String getSleepImage() { + return this.getImage().getSleep(); + } } diff --git a/src/main/java/com/moabam/api/domain/item/ItemImage.java b/src/main/java/com/moabam/api/domain/item/ItemImage.java new file mode 100644 index 00000000..937a55b1 --- /dev/null +++ b/src/main/java/com/moabam/api/domain/item/ItemImage.java @@ -0,0 +1,28 @@ +package com.moabam.api.domain.item; + +import static java.util.Objects.*; + +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Embeddable +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class ItemImage { + + @Column(name = "awake_image", nullable = false) + private String awake; + + @Column(name = "sleep_image", nullable = false) + private String sleep; + + @Builder + public ItemImage(String awakeImage, String sleepImage) { + this.awake = requireNonNull(awakeImage); + this.sleep = requireNonNull(sleepImage); + } +} diff --git a/src/main/java/com/moabam/api/domain/member/Member.java b/src/main/java/com/moabam/api/domain/member/Member.java index 3cfc9f24..48486941 100644 --- a/src/main/java/com/moabam/api/domain/member/Member.java +++ b/src/main/java/com/moabam/api/domain/member/Member.java @@ -146,17 +146,16 @@ public void changeIntro(String intro) { public void changeProfileUri(String newProfileUri) { this.profileImage = requireNonNullElse(newProfileUri, profileImage); - this.profileImage = requireNonNullElse(newProfileUri, profileImage); } public void changeDefaultSkintUrl(Item item) throws NotFoundException { if (ItemType.MORNING.equals(item.getType())) { - this.morningImage = item.getImage(); + this.morningImage = item.getAwakeImage(); return; } if (ItemType.NIGHT.equals(item.getType())) { - this.nightImage = item.getImage(); + this.nightImage = item.getAwakeImage(); return; } diff --git a/src/main/java/com/moabam/api/domain/room/Room.java b/src/main/java/com/moabam/api/domain/room/Room.java index 8a3d3dbe..00a7ac42 100644 --- a/src/main/java/com/moabam/api/domain/room/Room.java +++ b/src/main/java/com/moabam/api/domain/room/Room.java @@ -28,9 +28,15 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Room extends BaseTimeEntity { - private static final String ROOM_LEVEL_0_IMAGE = "'temptemp'"; - private static final String ROOM_LEVEL_10_IMAGE = "'temp'"; - private static final String ROOM_LEVEL_20_IMAGE = "'tempp'"; + private static final int LEVEL_5 = 5; + private static final int LEVEL_10 = 10; + private static final int LEVEL_20 = 20; + private static final int LEVEL_30 = 30; + private static final String ROOM_LEVEL_0_IMAGE = "https://image.moabam.com/moabam/default/room-level-00.png"; + private static final String ROOM_LEVEL_5_IMAGE = "https://image.moabam.com/moabam/default/room-level-05.png"; + private static final String ROOM_LEVEL_10_IMAGE = "https://image.moabam.com/moabam/default/room-level-10.png"; + private static final String ROOM_LEVEL_20_IMAGE = "https://image.moabam.com/moabam/default/room-level-20.png"; + private static final String ROOM_LEVEL_30_IMAGE = "https://image.moabam.com/moabam/default/room-level-30.png"; private static final int MORNING_START_TIME = 4; private static final int MORNING_END_TIME = 10; private static final int NIGHT_START_TIME = 20; @@ -72,7 +78,7 @@ public class Room extends BaseTimeEntity { @Column(name = "announcement", length = 100) private String announcement; - @ColumnDefault(ROOM_LEVEL_0_IMAGE) + @ColumnDefault("'" + ROOM_LEVEL_0_IMAGE + "'") @Column(name = "room_image", length = 500) private String roomImage; @@ -96,6 +102,28 @@ private Room(Long id, String title, String password, RoomType roomType, int cert public void levelUp() { this.level += 1; this.exp = 0; + upgradeRoomImage(this.level); + } + + public void upgradeRoomImage(int level) { + if (level == LEVEL_5) { + this.roomImage = ROOM_LEVEL_5_IMAGE; + return; + } + + if (level == LEVEL_10) { + this.roomImage = ROOM_LEVEL_10_IMAGE; + return; + } + + if (level == LEVEL_20) { + this.roomImage = ROOM_LEVEL_20_IMAGE; + return; + } + + if (level == LEVEL_30) { + this.roomImage = ROOM_LEVEL_30_IMAGE; + } } public void gainExp() { @@ -134,10 +162,6 @@ public void decreaseCurrentUserCount() { this.currentUserCount -= 1; } - public void upgradeRoomImage(String roomImage) { - this.roomImage = roomImage; - } - public void changeCertifyTime(int certifyTime) { this.certifyTime = validateCertifyTime(this.roomType, certifyTime); } diff --git a/src/test/java/com/moabam/api/application/member/MemberServiceTest.java b/src/test/java/com/moabam/api/application/member/MemberServiceTest.java index 3271f6f1..7a03c38d 100644 --- a/src/test/java/com/moabam/api/application/member/MemberServiceTest.java +++ b/src/test/java/com/moabam/api/application/member/MemberServiceTest.java @@ -181,7 +181,7 @@ void success(@WithMember AuthMember authMember) { Inventory morningSkin = InventoryFixture.inventory(searchId, morning); Inventory nightSkin = InventoryFixture.inventory(searchId, night); List memberInfos = MemberInfoSearchFixture - .myInfo(morningSkin.getItem().getImage(), nightSkin.getItem().getImage()); + .myInfo(morningSkin.getItem().getAwakeImage(), nightSkin.getItem().getAwakeImage()); given(memberSearchRepository.findMemberAndBadges(anyLong(), anyBoolean())) .willReturn(memberInfos); @@ -190,8 +190,8 @@ void success(@WithMember AuthMember authMember) { MemberInfoResponse memberInfoResponse = memberService.searchInfo(authMember, null); // then - assertThat(memberInfoResponse.birds()).containsEntry("MORNING", morningSkin.getItem().getImage()); - assertThat(memberInfoResponse.birds()).containsEntry("NIGHT", nightSkin.getItem().getImage()); + assertThat(memberInfoResponse.birds()).containsEntry("MORNING", morningSkin.getItem().getAwakeImage()); + assertThat(memberInfoResponse.birds()).containsEntry("NIGHT", nightSkin.getItem().getAwakeImage()); } } diff --git a/src/test/java/com/moabam/api/domain/room/RoomTest.java b/src/test/java/com/moabam/api/domain/room/RoomTest.java index 21889ac3..59a13a61 100644 --- a/src/test/java/com/moabam/api/domain/room/RoomTest.java +++ b/src/test/java/com/moabam/api/domain/room/RoomTest.java @@ -9,6 +9,7 @@ import com.moabam.global.error.exception.BadRequestException; import com.moabam.global.error.model.ErrorMessage; +import com.moabam.support.fixture.RoomFixture; class RoomTest { @@ -25,7 +26,7 @@ void create_room_without_password_success() { // then assertThat(room.getPassword()).isNull(); - assertThat(room.getRoomImage()).isEqualTo("'temptemp'"); + assertThat(room.getRoomImage()).isEqualTo("https://image.moabam.com/moabam/default/room-level-00.png"); assertThat(room.getRoomType()).isEqualTo(RoomType.MORNING); assertThat(room.getCertifyTime()).isEqualTo(10); assertThat(room.getMaxUserCount()).isEqualTo(9); @@ -88,4 +89,23 @@ void night_time_validate_exception(int certifyTime) { .isInstanceOf(BadRequestException.class) .hasMessage(ErrorMessage.INVALID_REQUEST_FIELD.getMessage()); } + + @DisplayName("레벨에 따른 이미지 업데이트") + @ParameterizedTest + @CsvSource({ + "5, https://image.moabam.com/moabam/default/room-level-05.png", + "10, https://image.moabam.com/moabam/default/room-level-10.png", + "20, https://image.moabam.com/moabam/default/room-level-20.png", + "30, https://image.moabam.com/moabam/default/room-level-30.png", + }) + void update_room_image_success(int level, String image) { + // given + Room room = RoomFixture.room(); + + // when + room.upgradeRoomImage(level); + + // then + assertThat(room.getRoomImage()).isEqualTo(image); + } } diff --git a/src/test/java/com/moabam/api/presentation/MemberControllerTest.java b/src/test/java/com/moabam/api/presentation/MemberControllerTest.java index fb4b4b9e..a2b7fd16 100644 --- a/src/test/java/com/moabam/api/presentation/MemberControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/MemberControllerTest.java @@ -386,8 +386,8 @@ void search_friend_info_success() throws Exception { MockMvcResultMatchers.jsonPath("$.level").value(friend.getTotalCertifyCount() / LEVEL_DIVISOR), MockMvcResultMatchers.jsonPath("$.exp").value(friend.getTotalCertifyCount() % LEVEL_DIVISOR), - MockMvcResultMatchers.jsonPath("$.birds.MORNING").value(morningInven.getItem().getImage()), - MockMvcResultMatchers.jsonPath("$.birds.NIGHT").value(nightInven.getItem().getImage()), + MockMvcResultMatchers.jsonPath("$.birds.MORNING").value(morningInven.getItem().getAwakeImage()), + MockMvcResultMatchers.jsonPath("$.birds.NIGHT").value(nightInven.getItem().getAwakeImage()), MockMvcResultMatchers.jsonPath("$.badges[0].badge").value("MORNING_BIRTH"), MockMvcResultMatchers.jsonPath("$.badges[0].unlock").value(true), diff --git a/src/test/java/com/moabam/support/fixture/ItemFixture.java b/src/test/java/com/moabam/support/fixture/ItemFixture.java index c45d535d..3e65477a 100644 --- a/src/test/java/com/moabam/support/fixture/ItemFixture.java +++ b/src/test/java/com/moabam/support/fixture/ItemFixture.java @@ -4,6 +4,7 @@ import com.moabam.api.domain.item.Item; import com.moabam.api.domain.item.ItemCategory; +import com.moabam.api.domain.item.ItemImage; import com.moabam.api.domain.item.ItemType; public class ItemFixture { @@ -16,27 +17,42 @@ public class ItemFixture { public static final String NIGHT_MAGE_SKIN_IMAGE = IMAGE_DOMAIN + "item/night_mage.png"; public static Item.ItemBuilder morningSantaSkin() { + ItemImage image = ItemImage.builder() + .awakeImage(MORNING_SANTA_SKIN_IMAGE) + .sleepImage(MORNING_SANTA_SKIN_IMAGE) + .build(); + return Item.builder() .type(ItemType.MORNING) .category(ItemCategory.SKIN) .name(MORNING_SANTA_SKIN_NAME) - .image(MORNING_SANTA_SKIN_IMAGE); + .image(image); } public static Item.ItemBuilder morningKillerSkin() { + ItemImage image = ItemImage.builder() + .awakeImage(MORNING_KILLER_SKIN_IMAGE) + .sleepImage(MORNING_KILLER_SKIN_IMAGE) + .build(); + return Item.builder() .type(ItemType.MORNING) .category(ItemCategory.SKIN) .name(MORNING_KILLER_SKIN_NAME) - .image(MORNING_KILLER_SKIN_IMAGE); + .image(image); } public static Item nightMageSkin() { + ItemImage image = ItemImage.builder() + .awakeImage(NIGHT_MAGE_SKIN_IMAGE) + .sleepImage(NIGHT_MAGE_SKIN_IMAGE) + .build(); + return Item.builder() .type(ItemType.NIGHT) .category(ItemCategory.SKIN) .name(NIGHT_MAGE_SKIN_NAME) - .image(NIGHT_MAGE_SKIN_IMAGE) + .image(image) .build(); } } From 448dc4535ee880b4891de8c5f3fed45e5a2256e6 Mon Sep 17 00:00:00 2001 From: Park Seyeon Date: Tue, 28 Nov 2023 16:52:43 +0900 Subject: [PATCH 3/7] =?UTF-8?q?fix:=20no=20skin=20image=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=ED=95=B4=EA=B2=B0=20(#168)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 회원 로그인 시 기본 부엉이, 오목눈이 생성 기능 추가 및 테스트 코드 변경 * fix: 테스트 코드 변경 * refacotr: config 수정 * test: @BeforeAll Transaction적용 실패로 인한 merge 테스트 추가 * feat: 서비스 추가 * test: 기본 URL 변경 및 테스트 코드 수정 * style: 중복 코드 제거 --- .../api/application/member/MemberService.java | 4 +++- .../moabam/global/common/util/BaseImageUrl.java | 6 +++--- .../application/member/MemberServiceTest.java | 3 ++- .../api/presentation/MemberControllerTest.java | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/moabam/api/application/member/MemberService.java b/src/main/java/com/moabam/api/application/member/MemberService.java index fb0e8637..295a6186 100644 --- a/src/main/java/com/moabam/api/application/member/MemberService.java +++ b/src/main/java/com/moabam/api/application/member/MemberService.java @@ -107,8 +107,10 @@ private void validateNickname(String nickname) { private Member signUp(Long socialId) { Member member = MemberMapper.toMember(socialId); + Member savedMember = memberRepository.save(member); + saveMyEgg(savedMember); - return memberRepository.save(member); + return savedMember; } private void saveMyEgg(Member member) { diff --git a/src/main/java/com/moabam/global/common/util/BaseImageUrl.java b/src/main/java/com/moabam/global/common/util/BaseImageUrl.java index ac66f717..c430933a 100644 --- a/src/main/java/com/moabam/global/common/util/BaseImageUrl.java +++ b/src/main/java/com/moabam/global/common/util/BaseImageUrl.java @@ -14,7 +14,7 @@ public class BaseImageUrl { public static final String DEFAULT_NIGHT_AWAKE_SKIN_URL = ""; public static final String DEFAULT_NIGHT_SLEEP_SKIN_URL = ""; - public static final String DEFAULT_MORNING_EGG_URL = "moabam/skins/오목눈이/기본/오목눈이알.png"; - public static final String DEFAULT_NIGHT_EGG_URL = "moabam/skins/부엉이/기본/부엉이알.png"; - public static final String MEMBER_PROFILE_URL = "moabam/default/기본회원프로필.png"; + public static final String DEFAULT_MORNING_EGG_URL = "moabam/skins/omok/default/egg.png"; + public static final String DEFAULT_NIGHT_EGG_URL = "moabam/skins/owl/default/egg.png"; + public static final String MEMBER_PROFILE_URL = "moabam/default/member-profile.png"; } diff --git a/src/test/java/com/moabam/api/application/member/MemberServiceTest.java b/src/test/java/com/moabam/api/application/member/MemberServiceTest.java index 7a03c38d..a7959641 100644 --- a/src/test/java/com/moabam/api/application/member/MemberServiceTest.java +++ b/src/test/java/com/moabam/api/application/member/MemberServiceTest.java @@ -97,6 +97,8 @@ void signUp_success() { given(member.getId()).willReturn(1L); willReturn(member) .given(memberRepository).save(any(Member.class)); + willReturn(List.of(ItemFixture.morningSantaSkin().build(), ItemFixture.nightMageSkin())) + .given(itemRepository).findAllById(any()); // when LoginResponse result = memberService.login(authorizationTokenInfoResponse); @@ -213,5 +215,4 @@ void modify_success_test(@WithMember AuthMember authMember) { () -> assertThat(member.getProfileImage()).isEqualTo("/main") ); } - } diff --git a/src/test/java/com/moabam/api/presentation/MemberControllerTest.java b/src/test/java/com/moabam/api/presentation/MemberControllerTest.java index a2b7fd16..4c19555c 100644 --- a/src/test/java/com/moabam/api/presentation/MemberControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/MemberControllerTest.java @@ -76,6 +76,8 @@ import com.moabam.support.fixture.RoomFixture; import com.moabam.support.fixture.TokenSaveValueFixture; +import jakarta.persistence.EntityManager; + @Transactional @SpringBootTest @AutoConfigureMockMvc @@ -128,6 +130,9 @@ class MemberControllerTest extends WithoutFilterSupporter { Member member; + @Autowired + EntityManager entityManager; + @BeforeAll void allSetUp() { restTemplateBuilder = new RestTemplateBuilder() @@ -143,6 +148,7 @@ void setUp() { RestTemplate restTemplate = restTemplateBuilder.build(); ReflectionTestUtils.setField(oAuth2AuthorizationServerRequestService, "restTemplate", restTemplate); mockRestServiceServer = MockRestServiceServer.createServer(restTemplate); + member = entityManager.merge(member); } @DisplayName("로그아웃 성공 테스트") @@ -270,6 +276,7 @@ void search_my_info_success() throws Exception { member.changeDefaultSkintUrl(night); member.changeDefaultSkintUrl(morning); + memberRepository.flush(); // expected mockMvc.perform(get("/members")) @@ -317,6 +324,11 @@ void search_my_info_with_no_badge_success() throws Exception { Inventory killerInven = InventoryFixture.inventory(member.getId(), killer); inventoryRepository.saveAll(List.of(nightInven, morningInven, killerInven)); + member.changeDefaultSkintUrl(night); + member.changeDefaultSkintUrl(morning); + + memberRepository.flush(); + // expected mockMvc.perform(get("/members")) .andExpect(status().isOk()) @@ -376,6 +388,10 @@ void search_friend_info_success() throws Exception { memberRepository.flush(); inventoryRepository.saveAll(List.of(nightInven, morningInven, killerInven)); + friend.changeDefaultSkintUrl(morning); + friend.changeDefaultSkintUrl(night); + memberRepository.flush(); + // expected mockMvc.perform(get("/members/{memberId}", friend.getId())) .andExpect(status().isOk()) From e144759c62e7073c68e815ffcc557894b8cc9918 Mon Sep 17 00:00:00 2001 From: Dev Uni Date: Tue, 28 Nov 2023 16:54:11 +0900 Subject: [PATCH 4/7] =?UTF-8?q?hotfix:=20schema,=20item=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/sql/data.sql | 39 +++++ src/main/resources/sql/schema.sql | 247 ++++++++++++++++++++++++++++++ 2 files changed, 286 insertions(+) create mode 100644 src/main/resources/sql/data.sql create mode 100644 src/main/resources/sql/schema.sql diff --git a/src/main/resources/sql/data.sql b/src/main/resources/sql/data.sql new file mode 100644 index 00000000..dfaec72c --- /dev/null +++ b/src/main/resources/sql/data.sql @@ -0,0 +1,39 @@ +insert into item (type, category, name, awake_image, sleep_image, unlock_level, created_at) +values ('MORNING', 'SKIN', '오목눈이알', 'https://image.moabam.com/moabam/skins/omok/default/egg.png', + 'https://image.moabam.com/moabam/skins/omok/default/egg.png', 0, current_time()); + +insert into item (type, category, name, awake_image, sleep_image, unlock_level, created_at) +values ('NIGHT', 'SKIN', '부엉이알', 'https://image.moabam.com/moabam/skins/owl/default/egg.png', + 'https://image.moabam.com/moabam/skins/owl/default/egg.png', 0, current_time()); + +insert into item (type, category, name, awake_image, sleep_image, unlock_level, created_at) +values ('MORNING', 'SKIN', '오목눈이', 'https://image.moabam.com/moabam/skins/omok/default/eyes-opened.png', + 'https://image.moabam.com/moabam/skins/omok/default/eyes-closed.png', 1, current_time()); + +insert into item (type, category, name, awake_image, sleep_image, unlock_level, created_at) +values ('MORNING', 'SKIN', '부엉이', 'https://image.moabam.com/moabam/skins/owl/default/eyes-opened.png', + 'https://image.moabam.com/moabam/skins/owl/default/eyes-closed.png', 1, current_time()); + +insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) +values ('MORNING', 'SKIN', '안경 오목눈이', 'https://image.moabam.com/moabam/skins/omok/glasses/eyes-opened.png', + 'https://image.moabam.com/moabam/skins/omok/glasses/eyes-closed', 10, 5, 5, current_time()); + +insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) +values ('MORNING', 'SKIN', '안경 부엉이', 'https://image.moabam.com/moabam/skins/owl/glasses/eyes-opened.png', + 'https://image.moabam.com/moabam/skins/owl/glasses/eyes-closed', 10, 5, 5, current_time()); + +insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) +values ('MORNING', 'SKIN', '목도리 오목눈이', 'https://image.moabam.com/moabam/skins/omok/scarf/eyes-opened.png', + 'https://image.moabam.com/moabam/skins/omok/scarf/eyes-closed', 20, 10, 10, current_time()); + +insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) +values ('MORNING', 'SKIN', '목도리 부엉이', 'https://image.moabam.com/moabam/skins/owl/scarf/eyes-opened.png', + 'https://image.moabam.com/moabam/skins/owl/scarf/eyes-closed', 20, 10, 10, current_time()); + +insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) +values ('MORNING', 'SKIN', '산타 오목눈이', 'https://image.moabam.com/moabam/skins/omok/scarf/eyes-opened.png', + 'https://image.moabam.com/moabam/skins/omok/scarf/eyes-closed', 30, 15, 15, current_time()); + +insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) +values ('MORNING', 'SKIN', '산타 부엉이', 'https://image.moabam.com/moabam/skins/owl/santa/eyes-opened.png', + 'https://image.moabam.com/moabam/skins/owl/santa/eyes-closed', 30, 15, 15, current_time()); diff --git a/src/main/resources/sql/schema.sql b/src/main/resources/sql/schema.sql new file mode 100644 index 00000000..1c78b007 --- /dev/null +++ b/src/main/resources/sql/schema.sql @@ -0,0 +1,247 @@ +use moabam; + +create table badge +( + id bigint not null auto_increment, + member_id bigint not null, + type enum ('MORNING_ADULT','MORNING_BIRTH','NIGHT_ADULT','NIGHT_BIRTH') not null, + created_at datetime(6) not null, + primary key (id) +); + +create table bug_history +( + id bigint not null auto_increment, + member_id bigint not null, + payment_id bigint, + bug_type enum ('GOLDEN','MORNING','NIGHT') not null, + action_type enum ('CHARGE','COUPON','REFUND','REWARD','USE') not null, + quantity integer not null, + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id) +); + +create table certification +( + id bigint not null auto_increment, + routine_id bigint not null, + member_id bigint not null, + image varchar(255) not null, + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id) +); + +create table coupon +( + id bigint not null auto_increment, + name varchar(20) not null unique, + point integer default 1 not null, + description varchar(50) default '', + type enum ('DISCOUNT','GOLDEN','MORNING','NIGHT') not null, + stock integer default 1 not null, + start_at date not null unique, + open_at date not null, + admin_id bigint not null, + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id) +); + +create table coupon_wallet +( + id bigint not null auto_increment, + member_id bigint not null, + coupon_id bigint not null, + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id) +); + +create table daily_member_certification +( + id bigint not null auto_increment, + member_id bigint not null, + room_id bigint not null, + participant_id bigint, + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id) +); + +create table daily_room_certification +( + id bigint not null auto_increment, + room_id bigint not null, + certified_at date not null, + primary key (id) +); + +create table inventory +( + id bigint not null auto_increment, + member_id bigint not null, + item_id bigint not null, + is_default bit default false not null, + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id), + index idx_member_id (member_id) +); + +create table item +( + id bigint not null auto_increment, + type enum ('MORNING','NIGHT') not null, + category enum ('SKIN') not null, + name varchar(255) not null, + awake_image varchar(255) not null, + sleep_image varchar(255) not null, + bug_price integer default 0 not null, + golden_bug_price integer default 0 not null, + unlock_level integer default 1 not null, + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id) +); + +create table member +( + id bigint not null auto_increment, + social_id varchar(255) not null unique, + nickname varchar(255) not null unique, + intro varchar(30), + profile_image varchar(255) not null, + morning_image varchar(255) not null, + night_image varchar(255) not null, + total_certify_count bigint default 0 not null, + report_count integer default 0 not null, + current_morning_count integer default 0 not null, + current_night_count integer default 0 not null, + morning_bug integer default 0 not null, + night_bug integer default 0 not null, + golden_bug integer default 0 not null, + role enum ('ADMIN','BLACK','USER') default 'USER' not null, + deleted_at datetime(6), + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id) +); + +create table participant +( + id bigint not null auto_increment, + room_id bigint, + member_id bigint not null, + is_manager bit, + certify_count integer, + deleted_at datetime(6), + deleted_room_title varchar(30), + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id) +); + +create table payment +( + id bigint not null auto_increment, + member_id bigint not null, + product_id bigint not null, + coupon_wallet_id bigint, + order_id varchar(255), + order_name varchar(255) not null, + total_amount integer not null, + discount_amount integer not null, + payment_key varchar(255), + status enum ('ABORTED','CANCELED','DONE','EXPIRED','IN_PROGRESS','READY') not null, + created_at datetime(6) not null, + requested_at datetime(6), + approved_at datetime(6), + primary key (id), + index idx_order_id (order_id) +); + +create table product +( + id bigint not null auto_increment, + type enum ('BUG') default 'BUG' not null, + name varchar(255) not null, + price integer not null, + quantity integer default 1 not null, + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id) +); + +create table report +( + id bigint not null auto_increment, + reporter_id bigint not null, + reported_member_id bigint not null, + room_id bigint, + certification_id bigint, + description varchar(255), + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id) +); + +create table room +( + id bigint not null auto_increment, + title varchar(20) not null, + password varchar(8), + level integer default 0 not null, + exp integer default 0 not null, + room_type enum ('MORNING','NIGHT'), + certify_time integer not null, + current_user_count integer not null, + max_user_count integer not null, + announcement varchar(100), + room_image varchar(500), + manager_nickname varchar(30), + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id) +); + +create table routine +( + id bigint not null auto_increment, + room_id bigint, + content varchar(20) not null, + created_at datetime(6) not null, + updated_at datetime(6), + primary key (id) +); + +alter table bug_history + add foreign key (payment_id) references payment (id); + +alter table certification + add foreign key (routine_id) references routine (id); + +alter table coupon_wallet + add foreign key (coupon_id) references coupon (id); + +alter table daily_member_certification + add foreign key (participant_id) references participant (id); + +alter table inventory + add foreign key (item_id) references item (id); + +alter table participant + add foreign key (room_id) references room (id); + +alter table payment + add foreign key (product_id) references product (id); + +alter table report + add foreign key (certification_id) references certification (id); + +alter table report + add foreign key (room_id) references room (id); + +alter table routine + add foreign key (room_id) references room (id); From 0326137b5496f3849c27ffcf9c29cc91f7c356de Mon Sep 17 00:00:00 2001 From: Dev Uni Date: Tue, 28 Nov 2023 17:03:01 +0900 Subject: [PATCH 5/7] =?UTF-8?q?hotfix:=20config=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/config b/src/main/resources/config index ea25d857..0f4c27e5 160000 --- a/src/main/resources/config +++ b/src/main/resources/config @@ -1 +1 @@ -Subproject commit ea25d85744c2e6fcedbdb66b34c08837d382814d +Subproject commit 0f4c27e5bb593650ad4733c98f5c27b54eebc3c2 From ecd65d21a9e67f5d908328ec30e4cb65a1a3edec Mon Sep 17 00:00:00 2001 From: Dev Uni Date: Tue, 28 Nov 2023 17:13:32 +0900 Subject: [PATCH 6/7] =?UTF-8?q?hotfix:=20sql=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/sql/schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/sql/schema.sql b/src/main/resources/sql/schema.sql index 1c78b007..8f1f8cc4 100644 --- a/src/main/resources/sql/schema.sql +++ b/src/main/resources/sql/schema.sql @@ -1,4 +1,4 @@ -use moabam; +use moabam_dev; create table badge ( From eeda75115cb1b655f06c98415932e53ab885b74d Mon Sep 17 00:00:00 2001 From: Dev Uni Date: Tue, 28 Nov 2023 18:07:00 +0900 Subject: [PATCH 7/7] =?UTF-8?q?hotfix:=20item=20inventory=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/coupon/CouponManageService.java | 3 +-- .../item/repository/ItemSearchRepository.java | 16 ++++++---------- src/main/resources/sql/data.sql | 8 ++++---- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/moabam/api/application/coupon/CouponManageService.java b/src/main/java/com/moabam/api/application/coupon/CouponManageService.java index f4d1ef92..d4a070fc 100644 --- a/src/main/java/com/moabam/api/application/coupon/CouponManageService.java +++ b/src/main/java/com/moabam/api/application/coupon/CouponManageService.java @@ -4,7 +4,6 @@ import java.util.Optional; import java.util.Set; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import com.moabam.api.domain.coupon.Coupon; @@ -33,7 +32,7 @@ public class CouponManageService { private final CouponManageRepository couponManageRepository; private final CouponWalletRepository couponWalletRepository; - @Scheduled(fixedDelay = 1000) + // @Scheduled(fixedDelay = 1000) public void issue() { LocalDate now = clockHolder.date(); Optional isCoupon = couponRepository.findByStartAt(now); diff --git a/src/main/java/com/moabam/api/domain/item/repository/ItemSearchRepository.java b/src/main/java/com/moabam/api/domain/item/repository/ItemSearchRepository.java index f2b0f150..14a62b7e 100644 --- a/src/main/java/com/moabam/api/domain/item/repository/ItemSearchRepository.java +++ b/src/main/java/com/moabam/api/domain/item/repository/ItemSearchRepository.java @@ -1,7 +1,7 @@ package com.moabam.api.domain.item.repository; -import static com.moabam.api.domain.item.QInventory.*; -import static com.moabam.api.domain.item.QItem.*; +import static com.moabam.api.domain.item.QInventory.inventory; +import static com.moabam.api.domain.item.QItem.item; import java.util.List; @@ -10,7 +10,6 @@ import com.moabam.api.domain.item.Item; import com.moabam.api.domain.item.ItemType; import com.moabam.global.common.util.DynamicQuery; -import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; @@ -24,10 +23,12 @@ public class ItemSearchRepository { public List findNotPurchasedItems(Long memberId, ItemType type) { return jpaQueryFactory.selectFrom(item) .leftJoin(inventory) - .on(inventory.item.id.eq(item.id)) + .on(inventory.item.id.eq(item.id) + .and(inventory.memberId.eq(memberId))) .where( DynamicQuery.generateEq(type, item.type::eq), - DynamicQuery.generateEq(memberId, this::filterByMemberId)) + inventory.memberId.isNull() + ) .orderBy( item.unlockLevel.asc(), item.bugPrice.asc(), @@ -35,9 +36,4 @@ public List findNotPurchasedItems(Long memberId, ItemType type) { item.name.asc()) .fetch(); } - - private BooleanExpression filterByMemberId(Long memberId) { - return inventory.memberId.isNull() - .or(inventory.memberId.ne(memberId)); - } } diff --git a/src/main/resources/sql/data.sql b/src/main/resources/sql/data.sql index dfaec72c..7ed20150 100644 --- a/src/main/resources/sql/data.sql +++ b/src/main/resources/sql/data.sql @@ -11,7 +11,7 @@ values ('MORNING', 'SKIN', '오목눈이', 'https://image.moabam.com/moabam/skin 'https://image.moabam.com/moabam/skins/omok/default/eyes-closed.png', 1, current_time()); insert into item (type, category, name, awake_image, sleep_image, unlock_level, created_at) -values ('MORNING', 'SKIN', '부엉이', 'https://image.moabam.com/moabam/skins/owl/default/eyes-opened.png', +values ('NIGHT', 'SKIN', '부엉이', 'https://image.moabam.com/moabam/skins/owl/default/eyes-opened.png', 'https://image.moabam.com/moabam/skins/owl/default/eyes-closed.png', 1, current_time()); insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) @@ -19,7 +19,7 @@ values ('MORNING', 'SKIN', '안경 오목눈이', 'https://image.moabam.com/moab 'https://image.moabam.com/moabam/skins/omok/glasses/eyes-closed', 10, 5, 5, current_time()); insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) -values ('MORNING', 'SKIN', '안경 부엉이', 'https://image.moabam.com/moabam/skins/owl/glasses/eyes-opened.png', +values ('NIGHT', 'SKIN', '안경 부엉이', 'https://image.moabam.com/moabam/skins/owl/glasses/eyes-opened.png', 'https://image.moabam.com/moabam/skins/owl/glasses/eyes-closed', 10, 5, 5, current_time()); insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) @@ -27,7 +27,7 @@ values ('MORNING', 'SKIN', '목도리 오목눈이', 'https://image.moabam.com/m 'https://image.moabam.com/moabam/skins/omok/scarf/eyes-closed', 20, 10, 10, current_time()); insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) -values ('MORNING', 'SKIN', '목도리 부엉이', 'https://image.moabam.com/moabam/skins/owl/scarf/eyes-opened.png', +values ('NIGHT', 'SKIN', '목도리 부엉이', 'https://image.moabam.com/moabam/skins/owl/scarf/eyes-opened.png', 'https://image.moabam.com/moabam/skins/owl/scarf/eyes-closed', 20, 10, 10, current_time()); insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) @@ -35,5 +35,5 @@ values ('MORNING', 'SKIN', '산타 오목눈이', 'https://image.moabam.com/moab 'https://image.moabam.com/moabam/skins/omok/scarf/eyes-closed', 30, 15, 15, current_time()); insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) -values ('MORNING', 'SKIN', '산타 부엉이', 'https://image.moabam.com/moabam/skins/owl/santa/eyes-opened.png', +values ('NIGHT', 'SKIN', '산타 부엉이', 'https://image.moabam.com/moabam/skins/owl/santa/eyes-opened.png', 'https://image.moabam.com/moabam/skins/owl/santa/eyes-closed', 30, 15, 15, current_time());