This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
[#25] 결제관련 entity 생성 및 설계 #38
Open
jjeda
wants to merge
7
commits into
feature/13
Choose a base branch
from
feature/25
base: feature/13
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4805aea
[#25] 결제관련 entity 생성 및 설계
jjeda 11dc401
[#25] 결제관련 서비스레이어 추상화를 위한 클래스 생성
jjeda 6b9f7ea
[#25] 결제관련 수정
jjeda ce0de2e
[#25] DTO 상속 및 현금 결제 비즈니스 로직
jjeda 5b88e12
[#25] 결제수단별 공통로직 사용을 위한 메서드 추출
jjeda 1c4a741
[#39] 결제완료에 대한 테스트 코드추가
jjeda 93913f5
Merge pull request #43 from f-lab-edu/feature/39
jjeda 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
31 changes: 31 additions & 0 deletions
31
src/main/java/me/jjeda/mall/orders/controller/PaymentController.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,31 @@ | ||
package me.jjeda.mall.orders.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import me.jjeda.mall.orders.domain.PaymentFactory; | ||
import me.jjeda.mall.orders.domain.PaymentType; | ||
import me.jjeda.mall.orders.dto.PaymentDto; | ||
import me.jjeda.mall.orders.service.PaymentService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@Controller | ||
@RequestMapping("/api/orders/payment") | ||
@RequiredArgsConstructor | ||
public class PaymentController { | ||
|
||
private final PaymentFactory paymentFactory; | ||
|
||
@PostMapping(value = "/{orderId}") | ||
public ResponseEntity payForOrder(@RequestBody PaymentDto paymentDto, @PathVariable Long orderId) { | ||
|
||
final PaymentService paymentService = paymentFactory.getType(paymentDto.getPaymentType()); | ||
|
||
return ResponseEntity.ok(paymentService.payForOrder(paymentDto, orderId)); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/me/jjeda/mall/orders/domain/CashPayment.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,36 @@ | ||
package me.jjeda.mall.orders.domain; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.OneToOne; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class CashPayment { | ||
|
||
@Id | ||
@GeneratedValue | ||
@Column(name = "cash_payment_id") | ||
private Long id; | ||
|
||
private String bank; | ||
|
||
private String bankAccount; | ||
|
||
private String name; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
private Payment payment; | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/me/jjeda/mall/orders/domain/CreditPayment.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,37 @@ | ||
package me.jjeda.mall.orders.domain; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.OneToOne; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class CreditPayment { | ||
|
||
@Id | ||
@GeneratedValue | ||
@Column(name = "credit_payment_id") | ||
private Long id; | ||
|
||
private String bank; | ||
|
||
private String cardNumber; | ||
|
||
private String name; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
private Payment payment; | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/me/jjeda/mall/orders/domain/MobilePayment.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,37 @@ | ||
package me.jjeda.mall.orders.domain; | ||
|
||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.OneToOne; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class MobilePayment { | ||
|
||
@Id | ||
@GeneratedValue | ||
@Column(name = "mobile_payment_id") | ||
private Long id; | ||
|
||
private String phone; | ||
|
||
private String telco; | ||
|
||
private String name; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
private Payment payment; | ||
} |
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,42 @@ | ||
package me.jjeda.mall.orders.domain; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Payment { | ||
|
||
@Id | ||
@GeneratedValue | ||
@Column(name = "payment_id") | ||
private Long id; | ||
|
||
private int price; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private PaymentStatus paymentStatus; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private PaymentType paymentType; | ||
|
||
private LocalDateTime createdAt; | ||
|
||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/me/jjeda/mall/orders/domain/PaymentFactory.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,36 @@ | ||
package me.jjeda.mall.orders.domain; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import me.jjeda.mall.orders.service.CashPaymentService; | ||
import me.jjeda.mall.orders.service.CreditPaymentService; | ||
import me.jjeda.mall.orders.service.MobilePaymentService; | ||
import me.jjeda.mall.orders.service.PaymentService; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class PaymentFactory { | ||
|
||
private final CashPaymentService cashPaymentService; | ||
private final CreditPaymentService creditPaymentService; | ||
private final MobilePaymentService mobilePaymentService; | ||
|
||
public PaymentService getType(PaymentType paymentType) { | ||
final PaymentService paymentService; | ||
|
||
switch (paymentType) { | ||
case CASH: | ||
paymentService = cashPaymentService; | ||
break; | ||
case CREDIT: | ||
paymentService = creditPaymentService; | ||
break; | ||
case MOBILE: | ||
paymentService = mobilePaymentService; | ||
break; | ||
default: | ||
throw new IllegalArgumentException(); | ||
} | ||
return paymentService; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/me/jjeda/mall/orders/domain/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,12 @@ | ||
package me.jjeda.mall.orders.domain; | ||
|
||
/** | ||
* 결제상태를 나타내는 enum | ||
* READY : 결제전 | ||
* COMP :결제완료 | ||
* CANCEL : 결제취소 | ||
* REFUND : 환불 | ||
*/ | ||
public enum PaymentStatus { | ||
READY, COMP, CANCEL, REFUND | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/me/jjeda/mall/orders/domain/PaymentType.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,11 @@ | ||
package me.jjeda.mall.orders.domain; | ||
|
||
/** | ||
* 결제 수단 | ||
* CREDIT : (신용)카드 | ||
* CASH : 계좌이체 | ||
* MOBILE : 모바일 | ||
*/ | ||
public enum PaymentType { | ||
CREDIT, CASH, MOBILE | ||
} |
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,26 @@ | ||
package me.jjeda.mall.orders.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import me.jjeda.mall.orders.domain.Payment; | ||
import me.jjeda.mall.orders.domain.PaymentStatus; | ||
import me.jjeda.mall.orders.domain.PaymentType; | ||
|
||
@Builder | ||
@Getter | ||
public class PaymentDto { | ||
|
||
private Long id; | ||
|
||
private int price; | ||
|
||
private PaymentStatus paymentStatus; | ||
|
||
private PaymentType paymentType; | ||
|
||
public static Payment toReadyEntity() { | ||
return Payment.builder() | ||
.paymentStatus(PaymentStatus.READY) | ||
.build(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/jjeda/mall/orders/repository/CashPaymentRepository.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,7 @@ | ||
package me.jjeda.mall.orders.repository; | ||
|
||
import me.jjeda.mall.orders.domain.CashPayment; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CashPaymentRepository extends JpaRepository<CashPayment, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/me/jjeda/mall/orders/repository/CreditPaymentRepository.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,8 @@ | ||
package me.jjeda.mall.orders.repository; | ||
|
||
import me.jjeda.mall.orders.domain.CreditPayment; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CreditPaymentRepository extends JpaRepository<CreditPayment, Long> { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/jjeda/mall/orders/repository/MobilePaymentRepository.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,7 @@ | ||
package me.jjeda.mall.orders.repository; | ||
|
||
import me.jjeda.mall.orders.domain.MobilePayment; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MobilePaymentRepository extends JpaRepository<MobilePayment, Long> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/jjeda/mall/orders/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,7 @@ | ||
package me.jjeda.mall.orders.repository; | ||
|
||
import me.jjeda.mall.orders.domain.Payment; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PaymentRepository extends JpaRepository<Payment, Long> { | ||
} |
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.
Type을 가져오는게 아니라 Service를 가져오는것이므로 이름을 적절하게 바꿔주면 좋을 것 같습니다~