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 64babb43..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,15 +1,15 @@ package com.moabam.api.application.bug; import java.util.List; -import java.util.Optional; +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.domain.item.repository.BugHistoryDto; 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; @@ -37,27 +37,18 @@ public static BugResponse toBugResponse(Bug bug) { .build(); } - public static BugHistoryItemResponse toBugHistoryItemResponse(BugHistoryDto dto) { - BugHistoryItemResponse.PaymentResponse payment = Optional.ofNullable(dto.payment()) - .map(p -> BugHistoryItemResponse.PaymentResponse.builder() - .id(p.getId()) - .orderName(p.getOrder().getName()) - .discountAmount(p.getDiscountAmount()) - .totalAmount(p.getTotalAmount()) - .build()) - .orElse(null); - + 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(payment) + .payment(PaymentMapper.toPaymentResponse(dto.payment())) .build(); } - public static BugHistoryResponse toBugHistoryResponse(List dtoList) { + 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 3e0ade7b..3e6c1295 100644 --- a/src/main/java/com/moabam/api/application/bug/BugService.java +++ b/src/main/java/com/moabam/api/application/bug/BugService.java @@ -17,12 +17,12 @@ 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.item.repository.BugHistoryDto; 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; @@ -50,7 +50,7 @@ public BugResponse getBug(Long memberId) { } public BugHistoryResponse getBugHistory(Long memberId) { - List history = bugHistorySearchRepository.findByMemberIdWithPayment(memberId); + List history = bugHistorySearchRepository.findByMemberIdWithPayment(memberId); return BugMapper.toBugHistoryResponse(history); } 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/repository/BugHistorySearchRepository.java b/src/main/java/com/moabam/api/domain/bug/repository/BugHistorySearchRepository.java index 5eb17a50..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 @@ -7,7 +7,7 @@ import org.springframework.stereotype.Repository; -import com.moabam.api.domain.item.repository.BugHistoryDto; +import com.moabam.api.dto.bug.BugHistoryWithPayment; import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -19,9 +19,9 @@ public class BugHistorySearchRepository { private final JPAQueryFactory jpaQueryFactory; - public List findByMemberIdWithPayment(Long memberId) { + public List findByMemberIdWithPayment(Long memberId) { return jpaQueryFactory.select(Projections.constructor( - BugHistoryDto.class, + BugHistoryWithPayment.class, bugHistory.id, bugHistory.bugType, bugHistory.actionType, diff --git a/src/main/java/com/moabam/api/dto/bug/BugHistoryItemResponse.java b/src/main/java/com/moabam/api/dto/bug/BugHistoryItemResponse.java index 5bcefc63..8d2703ac 100644 --- a/src/main/java/com/moabam/api/dto/bug/BugHistoryItemResponse.java +++ b/src/main/java/com/moabam/api/dto/bug/BugHistoryItemResponse.java @@ -5,6 +5,7 @@ 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; @@ -16,16 +17,6 @@ public record BugHistoryItemResponse( int quantity, String date, @JsonInclude(NON_NULL) PaymentResponse payment - ) { - @Builder - public record PaymentResponse( - Long id, - String orderName, - int discountAmount, - int totalAmount - ) { - - } } diff --git a/src/main/java/com/moabam/api/domain/item/repository/BugHistoryDto.java b/src/main/java/com/moabam/api/dto/bug/BugHistoryWithPayment.java similarity index 80% rename from src/main/java/com/moabam/api/domain/item/repository/BugHistoryDto.java rename to src/main/java/com/moabam/api/dto/bug/BugHistoryWithPayment.java index a6ae6101..30b2ef78 100644 --- a/src/main/java/com/moabam/api/domain/item/repository/BugHistoryDto.java +++ b/src/main/java/com/moabam/api/dto/bug/BugHistoryWithPayment.java @@ -1,4 +1,4 @@ -package com.moabam.api.domain.item.repository; +package com.moabam.api.dto.bug; import java.time.LocalDateTime; @@ -9,14 +9,13 @@ import lombok.Builder; @Builder -public record BugHistoryDto( +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 +) { + +}