generated from pricelees/issue-pr-template
refactor: CanceledPayment -> CanceledPaymentEntity 클래스명 변경
This commit is contained in:
parent
1f0ac0b550
commit
a693406f32
@ -9,7 +9,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import roomescape.common.exception.ErrorType;
|
||||
import roomescape.common.exception.RoomescapeException;
|
||||
import roomescape.payment.infrastructure.persistence.CanceledPayment;
|
||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentEntity;
|
||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
|
||||
import roomescape.payment.infrastructure.persistence.PaymentEntity;
|
||||
import roomescape.payment.infrastructure.persistence.PaymentRepository;
|
||||
@ -44,7 +44,7 @@ public class PaymentService {
|
||||
}
|
||||
|
||||
public void saveCanceledPayment(PaymentCancel.Response cancelInfo, OffsetDateTime approvedAt, String paymentKey) {
|
||||
canceledPaymentRepository.save(new CanceledPayment(
|
||||
canceledPaymentRepository.save(new CanceledPaymentEntity(
|
||||
paymentKey, cancelInfo.cancelReason, cancelInfo.cancelAmount, approvedAt, cancelInfo.canceledAt));
|
||||
}
|
||||
|
||||
@ -54,22 +54,22 @@ public class PaymentService {
|
||||
String.format("[reservationId: %d]", reservationId), HttpStatus.NOT_FOUND))
|
||||
.getPaymentKey();
|
||||
// 취소 시간은 현재 시간으로 일단 생성한 뒤, 결제 취소 완료 후 해당 시간으로 변경합니다.
|
||||
CanceledPayment canceled = cancelPayment(paymentKey, "고객 요청", OffsetDateTime.now());
|
||||
CanceledPaymentEntity canceled = cancelPayment(paymentKey, "고객 요청", OffsetDateTime.now());
|
||||
|
||||
return new PaymentCancel.Request(paymentKey, canceled.getCancelAmount(), canceled.getCancelReason());
|
||||
}
|
||||
|
||||
private CanceledPayment cancelPayment(String paymentKey, String cancelReason, OffsetDateTime canceledAt) {
|
||||
private CanceledPaymentEntity cancelPayment(String paymentKey, String cancelReason, OffsetDateTime canceledAt) {
|
||||
PaymentEntity paymentEntity = paymentRepository.findByPaymentKey(paymentKey)
|
||||
.orElseThrow(() -> throwPaymentNotFoundByPaymentKey(paymentKey));
|
||||
paymentRepository.delete(paymentEntity);
|
||||
|
||||
return canceledPaymentRepository.save(new CanceledPayment(paymentKey, cancelReason, paymentEntity.getTotalAmount(),
|
||||
return canceledPaymentRepository.save(new CanceledPaymentEntity(paymentKey, cancelReason, paymentEntity.getTotalAmount(),
|
||||
paymentEntity.getApprovedAt(), canceledAt));
|
||||
}
|
||||
|
||||
public void updateCanceledTime(String paymentKey, OffsetDateTime canceledAt) {
|
||||
CanceledPayment canceledPayment = canceledPaymentRepository.findByPaymentKey(paymentKey)
|
||||
CanceledPaymentEntity canceledPayment = canceledPaymentRepository.findByPaymentKey(paymentKey)
|
||||
.orElseThrow(() -> throwPaymentNotFoundByPaymentKey(paymentKey));
|
||||
canceledPayment.setCanceledAt(canceledAt);
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ import roomescape.common.exception.ErrorType;
|
||||
import roomescape.common.exception.RoomescapeException;
|
||||
|
||||
@Entity
|
||||
public class CanceledPayment {
|
||||
public class CanceledPaymentEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@ -24,10 +24,10 @@ public class CanceledPayment {
|
||||
private OffsetDateTime approvedAt;
|
||||
private OffsetDateTime canceledAt;
|
||||
|
||||
protected CanceledPayment() {
|
||||
protected CanceledPaymentEntity() {
|
||||
}
|
||||
|
||||
public CanceledPayment(String paymentKey, String cancelReason, Long cancelAmount, OffsetDateTime approvedAt,
|
||||
public CanceledPaymentEntity(String paymentKey, String cancelReason, Long cancelAmount, OffsetDateTime approvedAt,
|
||||
OffsetDateTime canceledAt) {
|
||||
validateDate(approvedAt, canceledAt);
|
||||
this.paymentKey = paymentKey;
|
||||
@ -4,7 +4,7 @@ import java.util.Optional;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface CanceledPaymentRepository extends JpaRepository<CanceledPayment, Long> {
|
||||
public interface CanceledPaymentRepository extends JpaRepository<CanceledPaymentEntity, Long> {
|
||||
|
||||
Optional<CanceledPayment> findByPaymentKey(String paymentKey);
|
||||
Optional<CanceledPaymentEntity> findByPaymentKey(String paymentKey);
|
||||
}
|
||||
|
||||
@ -9,14 +9,14 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import roomescape.common.exception.RoomescapeException;
|
||||
|
||||
class CanceledPaymentTest {
|
||||
class CanceledPaymentEntityTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("취소 날짜가 승인 날짜 이전이면 예외가 발생한다")
|
||||
void invalidDate() {
|
||||
OffsetDateTime approvedAt = OffsetDateTime.now();
|
||||
OffsetDateTime canceledAt = approvedAt.minusMinutes(1L);
|
||||
assertThatThrownBy(() -> new CanceledPayment("payment-key", "reason", 10000L, approvedAt, canceledAt))
|
||||
assertThatThrownBy(() -> new CanceledPaymentEntity("payment-key", "reason", 10000L, approvedAt, canceledAt))
|
||||
.isInstanceOf(RoomescapeException.class);
|
||||
}
|
||||
}
|
||||
@ -37,7 +37,7 @@ import roomescape.member.infrastructure.persistence.Member;
|
||||
import roomescape.member.infrastructure.persistence.MemberRepository;
|
||||
import roomescape.member.infrastructure.persistence.Role;
|
||||
import roomescape.payment.infrastructure.client.TossPaymentClient;
|
||||
import roomescape.payment.infrastructure.persistence.CanceledPayment;
|
||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentEntity;
|
||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
|
||||
import roomescape.payment.infrastructure.persistence.PaymentEntity;
|
||||
import roomescape.payment.infrastructure.persistence.PaymentRepository;
|
||||
@ -447,7 +447,8 @@ public class ReservationControllerTest {
|
||||
.statusCode(400);
|
||||
|
||||
// then
|
||||
Optional<CanceledPayment> canceledPaymentOptional = canceledPaymentRepository.findByPaymentKey(paymentKey);
|
||||
Optional<CanceledPaymentEntity> canceledPaymentOptional = canceledPaymentRepository.findByPaymentKey(
|
||||
paymentKey);
|
||||
assertThat(canceledPaymentOptional).isNotNull();
|
||||
assertThat(canceledPaymentOptional.get().getCanceledAt()).isEqualTo(canceledAt);
|
||||
assertThat(canceledPaymentOptional.get().getCancelReason()).isEqualTo("고객 요청");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user