-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Refactor/#172/정산 생성 api
- Loading branch information
Showing
29 changed files
with
838 additions
and
97 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
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
25 changes: 25 additions & 0 deletions
25
src/main/java/space/space_spring/domain/pay/model/EqualSplitPayAmountPolicy.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 space.space_spring.domain.pay.model; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import space.space_spring.exception.CustomException; | ||
|
||
import java.util.List; | ||
|
||
import static space.space_spring.response.status.BaseExceptionResponseStatus.INVALID_EQUAL_SPLIT_AMOUNT; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class EqualSplitPayAmountPolicy implements PayAmountPolicy { | ||
|
||
@Override | ||
public void validatePayAmount(int totalAmount, List<Integer> targetAmounts) { | ||
int numberOfTarget = targetAmounts.size(); | ||
int expectedAmountPerTarget = totalAmount / numberOfTarget; | ||
|
||
for (Integer targetAmount : targetAmounts) { | ||
if (targetAmount != expectedAmountPerTarget) { | ||
throw new CustomException(INVALID_EQUAL_SPLIT_AMOUNT); | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/space/space_spring/domain/pay/model/IndividualPayAmountPolicy.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,23 @@ | ||
package space.space_spring.domain.pay.model; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import space.space_spring.exception.CustomException; | ||
|
||
import java.util.List; | ||
|
||
import static space.space_spring.response.status.BaseExceptionResponseStatus.INVALID_INDIVIDUAL_AMOUNT; | ||
|
||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class IndividualPayAmountPolicy implements PayAmountPolicy { | ||
|
||
@Override | ||
public void validatePayAmount(int totalAmount, List<Integer> targetAmounts) { | ||
int sumOfTargetAmounts = targetAmounts.stream().mapToInt(Integer::intValue).sum(); | ||
|
||
if (sumOfTargetAmounts != totalAmount) { | ||
throw new CustomException(INVALID_INDIVIDUAL_AMOUNT); | ||
} | ||
} | ||
} |
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 space.space_spring.domain.pay.model; | ||
|
||
public class Money { | ||
|
||
|
||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/space/space_spring/domain/pay/model/PayAmountPolicy.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 space.space_spring.domain.pay.model; | ||
|
||
import java.util.List; | ||
|
||
public interface PayAmountPolicy { | ||
|
||
void validatePayAmount(int totalAmount, List<Integer> targetAmounts); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/space/space_spring/domain/pay/model/PayCreateTargetInfo.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,20 @@ | ||
package space.space_spring.domain.pay.model; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class PayCreateTargetInfo { | ||
|
||
private Long targetUserId; | ||
|
||
private int requestedAmount; | ||
|
||
@Builder | ||
private PayCreateTargetInfo(Long targetUserId, int requestedAmount) { | ||
this.targetUserId = targetUserId; | ||
this.requestedAmount = requestedAmount; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/space/space_spring/domain/pay/model/PayCreateValidator.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,16 @@ | ||
package space.space_spring.domain.pay.model; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Component | ||
public class PayCreateValidator { | ||
|
||
public void validatePayAmount(PayType payType, int totalAmount, List<Integer> targetAmounts) { | ||
payType.getPayAmountPolicy().validatePayAmount(totalAmount, targetAmounts); | ||
} | ||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/space/space_spring/domain/pay/model/PayType.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,21 @@ | ||
package space.space_spring.domain.pay.model; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum PayType { | ||
/** | ||
* INDIVIDUAL : 정산 요청 금액을 직접 입력 | ||
* EQUAL_SPLIT : 정산 요청 금액을 1/n 분배 | ||
*/ | ||
|
||
INDIVIDUAL(new IndividualPayAmountPolicy()), | ||
EQUAL_SPLIT(new EqualSplitPayAmountPolicy()); | ||
|
||
private final PayAmountPolicy payAmountPolicy; | ||
|
||
PayType (PayAmountPolicy payAmountPolicy) { | ||
this.payAmountPolicy = payAmountPolicy; | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
src/main/java/space/space_spring/domain/pay/model/request/PayCreateRequest.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,61 @@ | ||
package space.space_spring.domain.pay.model.request; | ||
|
||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Positive; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import space.space_spring.domain.pay.model.PayCreateTargetInfo; | ||
import space.space_spring.domain.pay.model.PayType; | ||
import space.space_spring.global.common.EnumValidator; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class PayCreateRequest { | ||
|
||
/** | ||
* PayRequest 엔티티 생성 시 필요한 정보 | ||
*/ | ||
|
||
@NotNull(message = "총 정산 요청 금액은 공백일 수 없습니다.") | ||
@Positive(message = "총 정산 요청 금액은 양수이어야 합니다.") | ||
private int totalAmount; | ||
|
||
@NotBlank(message = "은행 이름은 공백일 수 없습니다.") | ||
private String bankName; | ||
|
||
@NotBlank(message = "은행 계좌 번호는 공백일 수 없습니다.") | ||
private String bankAccountNum; | ||
|
||
@Valid | ||
private List<TargetInfoRequest> targetInfoRequests; | ||
|
||
@EnumValidator(enumClass = PayType.class, message = "payType은 INDIVIDUAL 또는 EQUAL_SPLIT 이어야 합니다.") | ||
private String payType; | ||
|
||
|
||
@Builder | ||
private PayCreateRequest(int totalAmount, String bankName, String bankAccountNum, List<TargetInfoRequest> targetInfoRequests, String payType) { | ||
this.totalAmount = totalAmount; | ||
this.bankName = bankName; | ||
this.bankAccountNum = bankAccountNum; | ||
this.targetInfoRequests = targetInfoRequests; | ||
this.payType = payType; | ||
} | ||
|
||
public PayCreateServiceRequest toServiceRequest() { | ||
return PayCreateServiceRequest.builder() | ||
.totalAmount(totalAmount) | ||
.bankName(bankName) | ||
.bankAccountNum(bankAccountNum) | ||
.payCreateTargetInfos(targetInfoRequests.stream() | ||
.map(TargetInfoRequest::toPayCreateTargetInfo) | ||
.toList()) | ||
.payType(PayType.valueOf(payType)) | ||
.build(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/space/space_spring/domain/pay/model/request/PayCreateServiceRequest.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,34 @@ | ||
package space.space_spring.domain.pay.model.request; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import space.space_spring.domain.pay.model.PayCreateTargetInfo; | ||
import space.space_spring.domain.pay.model.PayType; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class PayCreateServiceRequest { | ||
|
||
private int totalAmount; | ||
|
||
private String bankName; | ||
|
||
private String bankAccountNum; | ||
|
||
private List<PayCreateTargetInfo> payCreateTargetInfos; | ||
|
||
private PayType payType; | ||
|
||
@Builder | ||
private PayCreateServiceRequest(int totalAmount, String bankName, String bankAccountNum, List<PayCreateTargetInfo> payCreateTargetInfos, PayType payType) { | ||
this.totalAmount = totalAmount; | ||
this.bankName = bankName; | ||
this.bankAccountNum = bankAccountNum; | ||
this.payCreateTargetInfos = payCreateTargetInfos; | ||
this.payType = payType; | ||
} | ||
|
||
} |
Oops, something went wrong.