-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 결제 엔티티 생성 * feat: 벌레 상품 구매 API 구현 * test: 벌레 상품 구매 통합 테스트 * test: 벌레 상품 구매 서비스 테스트 * test: 결제 쿠폰 적용 테스트 * test: 주문 생성 및 금액 할인 테스트 * test: 벌레 사용 및 증가 로직 검증 방식 수정 * chore: config 업데이트 * fix: 상품 구매 Response에 주문 id 제거 * feat: 상품 구매 Response에 결제 id 추가 * fix: Transactional 적용
- Loading branch information
Showing
23 changed files
with
472 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/moabam/api/application/payment/PaymentMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.moabam.api.application.payment; | ||
|
||
import com.moabam.api.domain.payment.Order; | ||
import com.moabam.api.domain.payment.Payment; | ||
import com.moabam.api.domain.product.Product; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class PaymentMapper { | ||
|
||
public static Payment toEntity(Long memberId, Product product) { | ||
Order order = Order.builder() | ||
.name(product.getName()) | ||
.amount(product.getPrice()) | ||
.build(); | ||
|
||
return Payment.builder() | ||
.memberId(memberId) | ||
.product(product) | ||
.order(order) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.moabam.api.domain.payment; | ||
|
||
import static com.moabam.global.error.model.ErrorMessage.*; | ||
import static java.lang.Math.*; | ||
import static java.util.Objects.*; | ||
|
||
import com.moabam.global.error.exception.BadRequestException; | ||
|
||
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 Order { | ||
|
||
private static final int MIN_AMOUNT = 0; | ||
|
||
@Column(name = "order_id") | ||
private String id; | ||
|
||
@Column(name = "order_name", nullable = false) | ||
private String name; | ||
|
||
@Column(name = "amount", nullable = false) | ||
private int amount; | ||
|
||
@Builder | ||
private Order(String id, String name, int amount) { | ||
this.id = id; | ||
this.name = requireNonNull(name); | ||
this.amount = validateAmount(amount); | ||
} | ||
|
||
private int validateAmount(int amount) { | ||
if (amount < MIN_AMOUNT) { | ||
throw new BadRequestException(INVALID_ORDER_AMOUNT); | ||
} | ||
|
||
return amount; | ||
} | ||
|
||
public void discountAmount(int price) { | ||
this.amount = max(MIN_AMOUNT, amount - price); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.moabam.api.domain.payment; | ||
|
||
import static java.util.Objects.*; | ||
|
||
import com.moabam.api.domain.coupon.Coupon; | ||
import com.moabam.api.domain.product.Product; | ||
import com.moabam.global.common.entity.BaseTimeEntity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embedded; | ||
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; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@Table(name = "payment") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Payment extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private Long id; | ||
|
||
@Column(name = "member_id", updatable = false, nullable = false) | ||
private Long memberId; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "product_id", updatable = false, nullable = false) | ||
private Product product; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "coupon_id") | ||
private Coupon coupon; | ||
|
||
@Embedded | ||
private Order order; | ||
|
||
@Column(name = "payment_key") | ||
private String paymentKey; | ||
|
||
@Enumerated(value = EnumType.STRING) | ||
@Column(name = "status", nullable = false) | ||
private PaymentStatus status; | ||
|
||
@Builder | ||
public Payment(Long memberId, Product product, Coupon coupon, Order order, String paymentKey, | ||
PaymentStatus status) { | ||
this.memberId = requireNonNull(memberId); | ||
this.product = requireNonNull(product); | ||
this.coupon = coupon; | ||
this.order = requireNonNull(order); | ||
this.paymentKey = paymentKey; | ||
this.status = requireNonNullElse(status, PaymentStatus.REQUEST); | ||
} | ||
|
||
public void applyCoupon(Coupon coupon) { | ||
this.order.discountAmount(coupon.getPoint()); | ||
this.coupon = coupon; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/moabam/api/domain/payment/PaymentStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.moabam.api.domain.payment; | ||
|
||
public enum PaymentStatus { | ||
|
||
// 임시 | ||
REQUEST, | ||
DONE, | ||
FAIL, | ||
REFUND; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/moabam/api/domain/payment/repository/PaymentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.moabam.api.domain.payment.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.moabam.api.domain.payment.Payment; | ||
|
||
public interface PaymentRepository extends JpaRepository<Payment, Long> { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/moabam/api/dto/product/PurchaseProductRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.moabam.api.dto.product; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public record PurchaseProductRequest( | ||
@Nullable Long couponId | ||
) { | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/moabam/api/dto/product/PurchaseProductResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.moabam.api.dto.product; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record PurchaseProductResponse( | ||
Long paymentId, | ||
String orderName, | ||
int price | ||
) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.