From cff25860f4728ca9edd9129a5d1dee63dbfcfeea Mon Sep 17 00:00:00 2001 From: Kim Heebin Date: Mon, 27 Nov 2023 14:51:40 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=B2=8C=EB=A0=88=20=EB=82=B4=EC=97=AD?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=20(#155)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 벌레 내역 조회 API 구현 * refactor: 결제 테이블 coupon_id 컬럼을 discount_amount로 변경 * test: 벌레 내역 조회 컨트롤러 통합 테스트 * fix: 테스트 오류 수정 * chore: 사용하지 않는 메서드 제거 * refactor: Response 분리 * style: 줄바꿈 제거 --- .../moabam/api/application/bug/BugMapper.java | 37 +++++++++-- .../api/application/bug/BugService.java | 10 +++ .../api/application/coupon/CouponService.java | 2 - .../application/payment/PaymentMapper.java | 14 ++++ .../com/moabam/api/domain/bug/BugHistory.java | 11 +++- .../BugHistorySearchRepository.java | 33 +++++----- .../repository/CouponWalletRepository.java | 3 + .../api/dto/bug/BugHistoryItemResponse.java | 22 +++++++ .../api/dto/bug/BugHistoryResponse.java | 12 ++++ .../api/dto/bug/BugHistoryWithPayment.java | 21 ++++++ .../api/dto/payment/PaymentResponse.java | 13 ++++ .../api/presentation/BugController.java | 7 ++ .../moabam/global/common/util/DateUtils.java | 17 +++++ .../com/moabam/api/domain/bug/BugTest.java | 1 - .../api/presentation/BugControllerTest.java | 65 +++++++++++++++++++ .../moabam/support/fixture/BugFixture.java | 26 ++++++++ 16 files changed, 267 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/moabam/api/dto/bug/BugHistoryItemResponse.java create mode 100644 src/main/java/com/moabam/api/dto/bug/BugHistoryResponse.java create mode 100644 src/main/java/com/moabam/api/dto/bug/BugHistoryWithPayment.java create mode 100644 src/main/java/com/moabam/api/dto/payment/PaymentResponse.java create mode 100644 src/main/java/com/moabam/global/common/util/DateUtils.java 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 9f217971..cf40d215 100644 --- a/src/main/java/com/moabam/api/application/bug/BugMapper.java +++ b/src/main/java/com/moabam/api/application/bug/BugMapper.java @@ -1,10 +1,18 @@ package com.moabam.api.application.bug; +import java.util.List; + +import com.moabam.api.application.payment.PaymentMapper; import com.moabam.api.domain.bug.Bug; 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.bug.BugHistoryItemResponse; +import com.moabam.api.dto.bug.BugHistoryResponse; +import com.moabam.api.dto.bug.BugHistoryWithPayment; import com.moabam.api.dto.bug.BugResponse; +import com.moabam.global.common.util.DateUtils; +import com.moabam.global.common.util.StreamUtils; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -12,6 +20,15 @@ @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()) @@ -20,12 +37,20 @@ public static BugResponse toBugResponse(Bug bug) { .build(); } - public static BugHistory toUseBugHistory(Long memberId, BugType bugType, int quantity) { - return BugHistory.builder() - .memberId(memberId) - .bugType(bugType) - .actionType(BugActionType.USE) - .quantity(quantity) + public static BugHistoryItemResponse toBugHistoryItemResponse(BugHistoryWithPayment dto) { + return BugHistoryItemResponse.builder() + .id(dto.id()) + .bugType(dto.bugType()) + .actionType(dto.actionType()) + .quantity(dto.quantity()) + .date(DateUtils.format(dto.createdAt())) + .payment(PaymentMapper.toPaymentResponse(dto.payment())) + .build(); + } + + public static BugHistoryResponse toBugHistoryResponse(List dtoList) { + return BugHistoryResponse.builder() + .history(StreamUtils.map(dtoList, BugMapper::toBugHistoryItemResponse)) .build(); } 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 18d2a7a2..3e6c1295 100644 --- a/src/main/java/com/moabam/api/application/bug/BugService.java +++ b/src/main/java/com/moabam/api/application/bug/BugService.java @@ -15,11 +15,14 @@ import com.moabam.api.application.product.ProductMapper; import com.moabam.api.domain.bug.Bug; import com.moabam.api.domain.bug.repository.BugHistoryRepository; +import com.moabam.api.domain.bug.repository.BugHistorySearchRepository; import com.moabam.api.domain.coupon.Coupon; import com.moabam.api.domain.payment.Payment; import com.moabam.api.domain.payment.repository.PaymentRepository; import com.moabam.api.domain.product.Product; import com.moabam.api.domain.product.repository.ProductRepository; +import com.moabam.api.dto.bug.BugHistoryResponse; +import com.moabam.api.dto.bug.BugHistoryWithPayment; import com.moabam.api.dto.bug.BugResponse; import com.moabam.api.dto.product.ProductsResponse; import com.moabam.api.dto.product.PurchaseProductRequest; @@ -36,6 +39,7 @@ public class BugService { private final MemberService memberService; private final CouponService couponService; private final BugHistoryRepository bugHistoryRepository; + private final BugHistorySearchRepository bugHistorySearchRepository; private final ProductRepository productRepository; private final PaymentRepository paymentRepository; @@ -45,6 +49,12 @@ public BugResponse getBug(Long memberId) { return BugMapper.toBugResponse(bug); } + public BugHistoryResponse getBugHistory(Long memberId) { + List history = bugHistorySearchRepository.findByMemberIdWithPayment(memberId); + + return BugMapper.toBugHistoryResponse(history); + } + public ProductsResponse getBugProducts() { List products = productRepository.findAllByType(BUG); 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 ec96458a..598e0c27 100644 --- a/src/main/java/com/moabam/api/application/coupon/CouponService.java +++ b/src/main/java/com/moabam/api/application/coupon/CouponService.java @@ -10,7 +10,6 @@ import com.moabam.api.domain.coupon.CouponWallet; import com.moabam.api.domain.coupon.repository.CouponRepository; 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.Role; import com.moabam.api.dto.coupon.CouponResponse; @@ -35,7 +34,6 @@ public class CouponService { private final CouponManageService couponManageService; private final CouponRepository couponRepository; private final CouponSearchRepository couponSearchRepository; - private final CouponWalletRepository couponWalletRepository; private final CouponWalletSearchRepository couponWalletSearchRepository; @Transactional diff --git a/src/main/java/com/moabam/api/application/payment/PaymentMapper.java b/src/main/java/com/moabam/api/application/payment/PaymentMapper.java index 3495adad..322ce92a 100644 --- a/src/main/java/com/moabam/api/application/payment/PaymentMapper.java +++ b/src/main/java/com/moabam/api/application/payment/PaymentMapper.java @@ -1,8 +1,11 @@ package com.moabam.api.application.payment; +import java.util.Optional; + import com.moabam.api.domain.payment.Order; import com.moabam.api.domain.payment.Payment; import com.moabam.api.domain.product.Product; +import com.moabam.api.dto.payment.PaymentResponse; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -22,4 +25,15 @@ public static Payment toPayment(Long memberId, Product product) { .totalAmount(product.getPrice()) .build(); } + + public static PaymentResponse toPaymentResponse(Payment payment) { + return Optional.ofNullable(payment) + .map(p -> PaymentResponse.builder() + .id(p.getId()) + .orderName(p.getOrder().getName()) + .discountAmount(p.getDiscountAmount()) + .totalAmount(p.getTotalAmount()) + .build()) + .orElse(null); + } } diff --git a/src/main/java/com/moabam/api/domain/bug/BugHistory.java b/src/main/java/com/moabam/api/domain/bug/BugHistory.java index 072a16ec..9c08f4b4 100644 --- a/src/main/java/com/moabam/api/domain/bug/BugHistory.java +++ b/src/main/java/com/moabam/api/domain/bug/BugHistory.java @@ -3,6 +3,7 @@ import static com.moabam.global.error.model.ErrorMessage.*; import static java.util.Objects.*; +import com.moabam.api.domain.payment.Payment; import com.moabam.global.common.entity.BaseTimeEntity; import com.moabam.global.error.exception.BadRequestException; @@ -10,9 +11,12 @@ import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Builder; @@ -33,6 +37,10 @@ public class BugHistory extends BaseTimeEntity { @Column(name = "member_id", updatable = false, nullable = false) private Long memberId; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "payment_id") + private Payment payment; + @Enumerated(value = EnumType.STRING) @Column(name = "bug_type", nullable = false) private BugType bugType; @@ -45,8 +53,9 @@ public class BugHistory extends BaseTimeEntity { private int quantity; @Builder - private BugHistory(Long memberId, BugType bugType, BugActionType actionType, int quantity) { + private BugHistory(Long memberId, Payment payment, BugType bugType, BugActionType actionType, int quantity) { this.memberId = requireNonNull(memberId); + this.payment = payment; this.bugType = requireNonNull(bugType); this.actionType = requireNonNull(actionType); this.quantity = validateQuantity(quantity); diff --git a/src/main/java/com/moabam/api/domain/bug/repository/BugHistorySearchRepository.java b/src/main/java/com/moabam/api/domain/bug/repository/BugHistorySearchRepository.java index 82a9ae61..8c5f569a 100644 --- a/src/main/java/com/moabam/api/domain/bug/repository/BugHistorySearchRepository.java +++ b/src/main/java/com/moabam/api/domain/bug/repository/BugHistorySearchRepository.java @@ -1,16 +1,14 @@ package com.moabam.api.domain.bug.repository; import static com.moabam.api.domain.bug.QBugHistory.*; +import static com.moabam.api.domain.payment.QPayment.*; -import java.time.LocalDateTime; import java.util.List; import org.springframework.stereotype.Repository; -import com.moabam.api.domain.bug.BugActionType; -import com.moabam.api.domain.bug.BugHistory; -import com.moabam.global.common.util.DynamicQuery; -import com.querydsl.core.types.dsl.BooleanExpression; +import com.moabam.api.dto.bug.BugHistoryWithPayment; +import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; @@ -21,19 +19,20 @@ public class BugHistorySearchRepository { private final JPAQueryFactory jpaQueryFactory; - public List find(Long memberId, BugActionType actionType, LocalDateTime dateTime) { - return jpaQueryFactory.selectFrom(bugHistory) - .where( - DynamicQuery.generateEq(memberId, bugHistory.memberId::eq), - DynamicQuery.generateEq(actionType, bugHistory.actionType::eq), - DynamicQuery.generateEq(dateTime, this::equalDate) + public List findByMemberIdWithPayment(Long memberId) { + return jpaQueryFactory.select(Projections.constructor( + BugHistoryWithPayment.class, + bugHistory.id, + bugHistory.bugType, + bugHistory.actionType, + bugHistory.quantity, + bugHistory.createdAt, + payment) ) + .from(bugHistory) + .leftJoin(bugHistory.payment, payment) + .where(bugHistory.memberId.eq(memberId)) + .orderBy(bugHistory.createdAt.desc()) .fetch(); } - - private BooleanExpression equalDate(LocalDateTime dateTime) { - return bugHistory.createdAt.year().eq(dateTime.getYear()) - .and(bugHistory.createdAt.month().eq(dateTime.getMonthValue())) - .and(bugHistory.createdAt.dayOfMonth().eq(dateTime.getDayOfMonth())); - } } diff --git a/src/main/java/com/moabam/api/domain/coupon/repository/CouponWalletRepository.java b/src/main/java/com/moabam/api/domain/coupon/repository/CouponWalletRepository.java index 626512dc..48da8ca1 100644 --- a/src/main/java/com/moabam/api/domain/coupon/repository/CouponWalletRepository.java +++ b/src/main/java/com/moabam/api/domain/coupon/repository/CouponWalletRepository.java @@ -1,9 +1,12 @@ package com.moabam.api.domain.coupon.repository; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; import com.moabam.api.domain.coupon.CouponWallet; public interface CouponWalletRepository extends JpaRepository { + Optional findByIdAndMemberId(Long id, Long memberId); } diff --git a/src/main/java/com/moabam/api/dto/bug/BugHistoryItemResponse.java b/src/main/java/com/moabam/api/dto/bug/BugHistoryItemResponse.java new file mode 100644 index 00000000..8d2703ac --- /dev/null +++ b/src/main/java/com/moabam/api/dto/bug/BugHistoryItemResponse.java @@ -0,0 +1,22 @@ +package com.moabam.api.dto.bug; + +import static com.fasterxml.jackson.annotation.JsonInclude.Include.*; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.moabam.api.domain.bug.BugActionType; +import com.moabam.api.domain.bug.BugType; +import com.moabam.api.dto.payment.PaymentResponse; + +import lombok.Builder; + +@Builder +public record BugHistoryItemResponse( + Long id, + BugType bugType, + BugActionType actionType, + int quantity, + String date, + @JsonInclude(NON_NULL) PaymentResponse payment +) { + +} diff --git a/src/main/java/com/moabam/api/dto/bug/BugHistoryResponse.java b/src/main/java/com/moabam/api/dto/bug/BugHistoryResponse.java new file mode 100644 index 00000000..efbf3df3 --- /dev/null +++ b/src/main/java/com/moabam/api/dto/bug/BugHistoryResponse.java @@ -0,0 +1,12 @@ +package com.moabam.api.dto.bug; + +import java.util.List; + +import lombok.Builder; + +@Builder +public record BugHistoryResponse( + List history +) { + +} diff --git a/src/main/java/com/moabam/api/dto/bug/BugHistoryWithPayment.java b/src/main/java/com/moabam/api/dto/bug/BugHistoryWithPayment.java new file mode 100644 index 00000000..30b2ef78 --- /dev/null +++ b/src/main/java/com/moabam/api/dto/bug/BugHistoryWithPayment.java @@ -0,0 +1,21 @@ +package com.moabam.api.dto.bug; + +import java.time.LocalDateTime; + +import com.moabam.api.domain.bug.BugActionType; +import com.moabam.api.domain.bug.BugType; +import com.moabam.api.domain.payment.Payment; + +import lombok.Builder; + +@Builder +public record BugHistoryWithPayment( + Long id, + BugType bugType, + BugActionType actionType, + int quantity, + LocalDateTime createdAt, + Payment payment +) { + +} diff --git a/src/main/java/com/moabam/api/dto/payment/PaymentResponse.java b/src/main/java/com/moabam/api/dto/payment/PaymentResponse.java new file mode 100644 index 00000000..29e30af5 --- /dev/null +++ b/src/main/java/com/moabam/api/dto/payment/PaymentResponse.java @@ -0,0 +1,13 @@ +package com.moabam.api.dto.payment; + +import lombok.Builder; + +@Builder +public record PaymentResponse( + Long id, + String orderName, + int discountAmount, + int totalAmount +) { + +} diff --git a/src/main/java/com/moabam/api/presentation/BugController.java b/src/main/java/com/moabam/api/presentation/BugController.java index 41a56009..51246958 100644 --- a/src/main/java/com/moabam/api/presentation/BugController.java +++ b/src/main/java/com/moabam/api/presentation/BugController.java @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RestController; import com.moabam.api.application.bug.BugService; +import com.moabam.api.dto.bug.BugHistoryResponse; import com.moabam.api.dto.bug.BugResponse; import com.moabam.api.dto.product.ProductsResponse; import com.moabam.api.dto.product.PurchaseProductRequest; @@ -33,6 +34,12 @@ public BugResponse getBug(@Auth AuthMember member) { return bugService.getBug(member.id()); } + @GetMapping("/history") + @ResponseStatus(HttpStatus.OK) + public BugHistoryResponse getBugHistory(@Auth AuthMember member) { + return bugService.getBugHistory(member.id()); + } + @GetMapping("/products") @ResponseStatus(HttpStatus.OK) public ProductsResponse getBugProducts() { diff --git a/src/main/java/com/moabam/global/common/util/DateUtils.java b/src/main/java/com/moabam/global/common/util/DateUtils.java new file mode 100644 index 00000000..38fa97b4 --- /dev/null +++ b/src/main/java/com/moabam/global/common/util/DateUtils.java @@ -0,0 +1,17 @@ +package com.moabam.global.common.util; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class DateUtils { + + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + + public static String format(LocalDateTime dateTime) { + return dateTime.format(formatter); + } +} diff --git a/src/test/java/com/moabam/api/domain/bug/BugTest.java b/src/test/java/com/moabam/api/domain/bug/BugTest.java index 96609913..4fe62d0d 100644 --- a/src/test/java/com/moabam/api/domain/bug/BugTest.java +++ b/src/test/java/com/moabam/api/domain/bug/BugTest.java @@ -75,6 +75,5 @@ void increase_bug_success() { // then assertThat(bug.getMorningBug()).isEqualTo(MORNING_BUG + 5); assertThat(bug.getNightBug()).isEqualTo(NIGHT_BUG + 5); - assertThat(bug.getGoldenBug()).isEqualTo(GOLDEN_BUG + 5); } } diff --git a/src/test/java/com/moabam/api/presentation/BugControllerTest.java b/src/test/java/com/moabam/api/presentation/BugControllerTest.java index 34025882..0a8dcb3e 100644 --- a/src/test/java/com/moabam/api/presentation/BugControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/BugControllerTest.java @@ -3,6 +3,7 @@ import static com.moabam.global.auth.model.AuthorizationThreadLocal.*; import static com.moabam.support.fixture.BugFixture.*; import static com.moabam.support.fixture.MemberFixture.*; +import static com.moabam.support.fixture.PaymentFixture.*; import static com.moabam.support.fixture.ProductFixture.*; import static java.nio.charset.StandardCharsets.*; import static org.assertj.core.api.Assertions.*; @@ -15,6 +16,7 @@ import java.util.List; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -27,10 +29,15 @@ import com.moabam.api.application.bug.BugMapper; import com.moabam.api.application.member.MemberService; import com.moabam.api.application.product.ProductMapper; +import com.moabam.api.domain.bug.BugActionType; +import com.moabam.api.domain.bug.BugType; import com.moabam.api.domain.bug.repository.BugHistoryRepository; import com.moabam.api.domain.bug.repository.BugHistorySearchRepository; +import com.moabam.api.domain.payment.Payment; +import com.moabam.api.domain.payment.repository.PaymentRepository; import com.moabam.api.domain.product.Product; import com.moabam.api.domain.product.repository.ProductRepository; +import com.moabam.api.dto.bug.BugHistoryResponse; import com.moabam.api.dto.bug.BugResponse; import com.moabam.api.dto.product.ProductsResponse; import com.moabam.api.dto.product.PurchaseProductRequest; @@ -61,6 +68,9 @@ class BugControllerTest extends WithoutFilterSupporter { @Autowired ProductRepository productRepository; + @Autowired + PaymentRepository paymentRepository; + @DisplayName("벌레를 조회한다.") @WithMember @Test @@ -82,6 +92,61 @@ void get_bug_success() throws Exception { assertThat(actual).isEqualTo(expected); } + @DisplayName("벌레 내역을 조회한다.") + @Nested + class GetBugHistory { + + @DisplayName("성공한다.") + @WithMember + @Test + void success() throws Exception { + // given + Long memberId = getAuthMember().id(); + bugHistoryRepository.save(rewardMorningBugHistory(memberId)); + + // expected + String content = mockMvc.perform(get("/bugs/history") + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andDo(print()) + .andReturn() + .getResponse() + .getContentAsString(UTF_8); + BugHistoryResponse actual = objectMapper.readValue(content, BugHistoryResponse.class); + assertThat(actual.history().get(0).bugType()).isEqualTo(BugType.MORNING); + assertThat(actual.history().get(0).actionType()).isEqualTo(BugActionType.REWARD); + assertThat(actual.history().get(0).quantity()).isEqualTo(REWARD_MORNING_BUG); + assertThat(actual.history().get(0).payment()).isNull(); + } + + @DisplayName("벌레 충전 내역인 경우 결제 정보를 포함한다.") + @WithMember + @Test + void charge_success() throws Exception { + // given + Long memberId = getAuthMember().id(); + Product product = productRepository.save(bugProduct()); + Payment payment = paymentRepository.save(payment(product)); + bugHistoryRepository.save(chargeGoldenBugHistory(memberId, payment)); + + // expected + String content = mockMvc.perform(get("/bugs/history") + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andDo(print()) + .andReturn() + .getResponse() + .getContentAsString(UTF_8); + BugHistoryResponse actual = objectMapper.readValue(content, BugHistoryResponse.class); + assertThat(actual.history().get(0).bugType()).isEqualTo(BugType.GOLDEN); + assertThat(actual.history().get(0).actionType()).isEqualTo(BugActionType.CHARGE); + assertThat(actual.history().get(0).quantity()).isEqualTo(BUG_PRODUCT_QUANTITY); + assertThat(actual.history().get(0).payment().orderName()).isEqualTo(BUG_PRODUCT_NAME); + assertThat(actual.history().get(0).payment().totalAmount()).isEqualTo(BUG_PRODUCT_PRICE); + assertThat(actual.history().get(0).payment().discountAmount()).isZero(); + } + } + @DisplayName("벌레 상품 목록을 조회한다.") @Test void get_bug_products_success() throws Exception { diff --git a/src/test/java/com/moabam/support/fixture/BugFixture.java b/src/test/java/com/moabam/support/fixture/BugFixture.java index a2584bcd..a6578d40 100644 --- a/src/test/java/com/moabam/support/fixture/BugFixture.java +++ b/src/test/java/com/moabam/support/fixture/BugFixture.java @@ -1,12 +1,19 @@ package com.moabam.support.fixture; +import static com.moabam.support.fixture.ProductFixture.*; + import com.moabam.api.domain.bug.Bug; +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.domain.payment.Payment; public final class BugFixture { public static final int MORNING_BUG = 10; public static final int NIGHT_BUG = 20; public static final int GOLDEN_BUG = 30; + public static final int REWARD_MORNING_BUG = 3; public static Bug bug() { return Bug.builder() @@ -15,4 +22,23 @@ public static Bug bug() { .goldenBug(GOLDEN_BUG) .build(); } + + public static BugHistory rewardMorningBugHistory(Long memberId) { + return BugHistory.builder() + .memberId(memberId) + .bugType(BugType.MORNING) + .actionType(BugActionType.REWARD) + .quantity(REWARD_MORNING_BUG) + .build(); + } + + public static BugHistory chargeGoldenBugHistory(Long memberId, Payment payment) { + return BugHistory.builder() + .memberId(memberId) + .payment(payment) + .bugType(BugType.GOLDEN) + .actionType(BugActionType.CHARGE) + .quantity(BUG_PRODUCT_QUANTITY) + .build(); + } }