generated from pricelees/issue-pr-template
refactor: CanceledPaymentEntity 코틀린 전환 및 validation 테스트 제거
This commit is contained in:
parent
a92339f7d4
commit
2c61d9ff2b
@ -44,7 +44,7 @@ public class PaymentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void saveCanceledPayment(PaymentCancel.Response cancelInfo, OffsetDateTime approvedAt, String paymentKey) {
|
public void saveCanceledPayment(PaymentCancel.Response cancelInfo, OffsetDateTime approvedAt, String paymentKey) {
|
||||||
canceledPaymentRepository.save(new CanceledPaymentEntity(
|
canceledPaymentRepository.save(new CanceledPaymentEntity(null,
|
||||||
paymentKey, cancelInfo.cancelReason, cancelInfo.cancelAmount, approvedAt, cancelInfo.canceledAt));
|
paymentKey, cancelInfo.cancelReason, cancelInfo.cancelAmount, approvedAt, cancelInfo.canceledAt));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ public class PaymentService {
|
|||||||
.orElseThrow(() -> throwPaymentNotFoundByPaymentKey(paymentKey));
|
.orElseThrow(() -> throwPaymentNotFoundByPaymentKey(paymentKey));
|
||||||
paymentRepository.delete(paymentEntity);
|
paymentRepository.delete(paymentEntity);
|
||||||
|
|
||||||
return canceledPaymentRepository.save(new CanceledPaymentEntity(paymentKey, cancelReason, paymentEntity.getTotalAmount(),
|
return canceledPaymentRepository.save(new CanceledPaymentEntity(null, paymentKey, cancelReason, paymentEntity.getTotalAmount(),
|
||||||
paymentEntity.getApprovedAt(), canceledAt));
|
paymentEntity.getApprovedAt(), canceledAt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,67 +1,18 @@
|
|||||||
package roomescape.payment.infrastructure.persistence;
|
package roomescape.payment.infrastructure.persistence
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import jakarta.persistence.*
|
||||||
|
import java.time.OffsetDateTime
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.GenerationType;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import roomescape.common.exception.ErrorType;
|
|
||||||
import roomescape.common.exception.RoomescapeException;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class CanceledPaymentEntity {
|
@Table(name = "canceled_payment")
|
||||||
|
class CanceledPaymentEntity(
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
var id: Long? = null,
|
||||||
|
|
||||||
@Id
|
var paymentKey: String,
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
var cancelReason: String,
|
||||||
private Long id;
|
var cancelAmount: Long,
|
||||||
|
var approvedAt: OffsetDateTime,
|
||||||
private String paymentKey;
|
var canceledAt: OffsetDateTime,
|
||||||
private String cancelReason;
|
)
|
||||||
private Long cancelAmount;
|
|
||||||
private OffsetDateTime approvedAt;
|
|
||||||
private OffsetDateTime canceledAt;
|
|
||||||
|
|
||||||
protected CanceledPaymentEntity() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public CanceledPaymentEntity(String paymentKey, String cancelReason, Long cancelAmount, OffsetDateTime approvedAt,
|
|
||||||
OffsetDateTime canceledAt) {
|
|
||||||
validateDate(approvedAt, canceledAt);
|
|
||||||
this.paymentKey = paymentKey;
|
|
||||||
this.cancelReason = cancelReason;
|
|
||||||
this.cancelAmount = cancelAmount;
|
|
||||||
this.approvedAt = approvedAt;
|
|
||||||
this.canceledAt = canceledAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateDate(OffsetDateTime approvedAt, OffsetDateTime canceledAt) {
|
|
||||||
if (canceledAt.isBefore(approvedAt)) {
|
|
||||||
throw new RoomescapeException(ErrorType.CANCELED_BEFORE_PAYMENT,
|
|
||||||
String.format("[approvedAt: %s, canceledAt: %s]", approvedAt, canceledAt),
|
|
||||||
HttpStatus.CONFLICT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCancelReason() {
|
|
||||||
return cancelReason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getCancelAmount() {
|
|
||||||
return cancelAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OffsetDateTime getApprovedAt() {
|
|
||||||
return approvedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OffsetDateTime getCanceledAt() {
|
|
||||||
return canceledAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCanceledAt(OffsetDateTime canceledAt) {
|
|
||||||
this.canceledAt = canceledAt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
package roomescape.payment.infrastructure.persistence;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import roomescape.common.exception.RoomescapeException;
|
|
||||||
|
|
||||||
class CanceledPaymentEntityTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("취소 날짜가 승인 날짜 이전이면 예외가 발생한다")
|
|
||||||
void invalidDate() {
|
|
||||||
OffsetDateTime approvedAt = OffsetDateTime.now();
|
|
||||||
OffsetDateTime canceledAt = approvedAt.minusMinutes(1L);
|
|
||||||
assertThatThrownBy(() -> new CanceledPaymentEntity("payment-key", "reason", 10000L, approvedAt, canceledAt))
|
|
||||||
.isInstanceOf(RoomescapeException.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user