refactor: CanceledPayment -> CanceledPaymentEntity 클래스명 변경

This commit is contained in:
이상진 2025-07-16 13:06:27 +09:00
parent 1f0ac0b550
commit a693406f32
5 changed files with 16 additions and 15 deletions

View File

@ -9,7 +9,7 @@ import org.springframework.transaction.annotation.Transactional;
import roomescape.common.exception.ErrorType; import roomescape.common.exception.ErrorType;
import roomescape.common.exception.RoomescapeException; 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.CanceledPaymentRepository;
import roomescape.payment.infrastructure.persistence.PaymentEntity; import roomescape.payment.infrastructure.persistence.PaymentEntity;
import roomescape.payment.infrastructure.persistence.PaymentRepository; import roomescape.payment.infrastructure.persistence.PaymentRepository;
@ -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 CanceledPayment( canceledPaymentRepository.save(new CanceledPaymentEntity(
paymentKey, cancelInfo.cancelReason, cancelInfo.cancelAmount, approvedAt, cancelInfo.canceledAt)); paymentKey, cancelInfo.cancelReason, cancelInfo.cancelAmount, approvedAt, cancelInfo.canceledAt));
} }
@ -54,22 +54,22 @@ public class PaymentService {
String.format("[reservationId: %d]", reservationId), HttpStatus.NOT_FOUND)) String.format("[reservationId: %d]", reservationId), HttpStatus.NOT_FOUND))
.getPaymentKey(); .getPaymentKey();
// 취소 시간은 현재 시간으로 일단 생성한 , 결제 취소 완료 해당 시간으로 변경합니다. // 취소 시간은 현재 시간으로 일단 생성한 , 결제 취소 완료 해당 시간으로 변경합니다.
CanceledPayment canceled = cancelPayment(paymentKey, "고객 요청", OffsetDateTime.now()); CanceledPaymentEntity canceled = cancelPayment(paymentKey, "고객 요청", OffsetDateTime.now());
return new PaymentCancel.Request(paymentKey, canceled.getCancelAmount(), canceled.getCancelReason()); 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) PaymentEntity paymentEntity = paymentRepository.findByPaymentKey(paymentKey)
.orElseThrow(() -> throwPaymentNotFoundByPaymentKey(paymentKey)); .orElseThrow(() -> throwPaymentNotFoundByPaymentKey(paymentKey));
paymentRepository.delete(paymentEntity); paymentRepository.delete(paymentEntity);
return canceledPaymentRepository.save(new CanceledPayment(paymentKey, cancelReason, paymentEntity.getTotalAmount(), return canceledPaymentRepository.save(new CanceledPaymentEntity(paymentKey, cancelReason, paymentEntity.getTotalAmount(),
paymentEntity.getApprovedAt(), canceledAt)); paymentEntity.getApprovedAt(), canceledAt));
} }
public void updateCanceledTime(String paymentKey, OffsetDateTime canceledAt) { public void updateCanceledTime(String paymentKey, OffsetDateTime canceledAt) {
CanceledPayment canceledPayment = canceledPaymentRepository.findByPaymentKey(paymentKey) CanceledPaymentEntity canceledPayment = canceledPaymentRepository.findByPaymentKey(paymentKey)
.orElseThrow(() -> throwPaymentNotFoundByPaymentKey(paymentKey)); .orElseThrow(() -> throwPaymentNotFoundByPaymentKey(paymentKey));
canceledPayment.setCanceledAt(canceledAt); canceledPayment.setCanceledAt(canceledAt);
} }

View File

@ -12,7 +12,7 @@ import roomescape.common.exception.ErrorType;
import roomescape.common.exception.RoomescapeException; import roomescape.common.exception.RoomescapeException;
@Entity @Entity
public class CanceledPayment { public class CanceledPaymentEntity {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@ -24,10 +24,10 @@ public class CanceledPayment {
private OffsetDateTime approvedAt; private OffsetDateTime approvedAt;
private OffsetDateTime canceledAt; 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) { OffsetDateTime canceledAt) {
validateDate(approvedAt, canceledAt); validateDate(approvedAt, canceledAt);
this.paymentKey = paymentKey; this.paymentKey = paymentKey;

View File

@ -4,7 +4,7 @@ import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository; 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);
} }

View File

@ -9,14 +9,14 @@ import org.junit.jupiter.api.Test;
import roomescape.common.exception.RoomescapeException; import roomescape.common.exception.RoomescapeException;
class CanceledPaymentTest { class CanceledPaymentEntityTest {
@Test @Test
@DisplayName("취소 날짜가 승인 날짜 이전이면 예외가 발생한다") @DisplayName("취소 날짜가 승인 날짜 이전이면 예외가 발생한다")
void invalidDate() { void invalidDate() {
OffsetDateTime approvedAt = OffsetDateTime.now(); OffsetDateTime approvedAt = OffsetDateTime.now();
OffsetDateTime canceledAt = approvedAt.minusMinutes(1L); 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); .isInstanceOf(RoomescapeException.class);
} }
} }

View File

@ -37,7 +37,7 @@ import roomescape.member.infrastructure.persistence.Member;
import roomescape.member.infrastructure.persistence.MemberRepository; import roomescape.member.infrastructure.persistence.MemberRepository;
import roomescape.member.infrastructure.persistence.Role; import roomescape.member.infrastructure.persistence.Role;
import roomescape.payment.infrastructure.client.TossPaymentClient; 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.CanceledPaymentRepository;
import roomescape.payment.infrastructure.persistence.PaymentEntity; import roomescape.payment.infrastructure.persistence.PaymentEntity;
import roomescape.payment.infrastructure.persistence.PaymentRepository; import roomescape.payment.infrastructure.persistence.PaymentRepository;
@ -447,7 +447,8 @@ public class ReservationControllerTest {
.statusCode(400); .statusCode(400);
// then // then
Optional<CanceledPayment> canceledPaymentOptional = canceledPaymentRepository.findByPaymentKey(paymentKey); Optional<CanceledPaymentEntity> canceledPaymentOptional = canceledPaymentRepository.findByPaymentKey(
paymentKey);
assertThat(canceledPaymentOptional).isNotNull(); assertThat(canceledPaymentOptional).isNotNull();
assertThat(canceledPaymentOptional.get().getCanceledAt()).isEqualTo(canceledAt); assertThat(canceledPaymentOptional.get().getCanceledAt()).isEqualTo(canceledAt);
assertThat(canceledPaymentOptional.get().getCancelReason()).isEqualTo("고객 요청"); assertThat(canceledPaymentOptional.get().getCancelReason()).isEqualTo("고객 요청");