-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 벌레 상품 구매 기능 구현 #107
Merged
Merged
feat: 벌레 상품 구매 기능 구현 #107
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
67b97c2
feat: 결제 엔티티 생성
kmebin 681919f
feat: 벌레 상품 구매 API 구현
kmebin cb5b7ed
Merge branch 'develop' into feature/#55-purchase-bug-product
kmebin 03e02ed
test: 벌레 상품 구매 통합 테스트
kmebin d77ed1d
test: 벌레 상품 구매 서비스 테스트
kmebin 8612c77
test: 결제 쿠폰 적용 테스트
kmebin 72776a4
test: 주문 생성 및 금액 할인 테스트
kmebin b97ce47
test: 벌레 사용 및 증가 로직 검증 방식 수정
kmebin be0a1d3
chore: config 업데이트
kmebin 07388bd
fix: 상품 구매 Response에 주문 id 제거
kmebin 663257f
feat: 상품 구매 Response에 결제 id 추가
kmebin afb2bde
fix: Transactional 적용
kmebin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: Payment와 Order의 합의점을 찾지 못해서 toEntity가 되어버린걸까요!? |
||
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
Submodule config
updated
from b960de to 2b7212
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A: 오호! 만들어지면 알려드리겠습니다..!