refactor: Payment -> PaymentEntity 클래스명 변경

This commit is contained in:
이상진 2025-07-16 13:05:35 +09:00
parent 313d9850d1
commit 1f0ac0b550
6 changed files with 28 additions and 26 deletions

View File

@ -11,8 +11,9 @@ 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.CanceledPayment;
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository; import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
import roomescape.payment.infrastructure.persistence.Payment; import roomescape.payment.infrastructure.persistence.PaymentEntity;
import roomescape.payment.infrastructure.persistence.PaymentRepository; import roomescape.payment.infrastructure.persistence.PaymentRepository;
import roomescape.payment.web.PaymentApprove;
import roomescape.payment.web.PaymentCancel; import roomescape.payment.web.PaymentCancel;
import roomescape.payment.web.ReservationPaymentResponse; import roomescape.payment.web.ReservationPaymentResponse;
import roomescape.reservation.domain.Reservation; import roomescape.reservation.domain.Reservation;
@ -29,16 +30,16 @@ public class PaymentService {
this.canceledPaymentRepository = canceledPaymentRepository; this.canceledPaymentRepository = canceledPaymentRepository;
} }
public ReservationPaymentResponse savePayment(roomescape.payment.web.PaymentApprove.Response paymentResponse, public ReservationPaymentResponse savePayment(PaymentApprove.Response paymentResponse,
Reservation reservation) { Reservation reservation) {
Payment payment = new Payment(paymentResponse.orderId, paymentResponse.paymentKey, PaymentEntity paymentEntity = new PaymentEntity(paymentResponse.orderId, paymentResponse.paymentKey,
paymentResponse.totalAmount, reservation, paymentResponse.approvedAt); paymentResponse.totalAmount, reservation, paymentResponse.approvedAt);
Payment saved = paymentRepository.save(payment); PaymentEntity saved = paymentRepository.save(paymentEntity);
return ReservationPaymentResponse.from(saved); return ReservationPaymentResponse.from(saved);
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
public Optional<Payment> findPaymentByReservationId(Long reservationId) { public Optional<PaymentEntity> findPaymentByReservationId(Long reservationId) {
return paymentRepository.findByReservationId(reservationId); return paymentRepository.findByReservationId(reservationId);
} }
@ -59,12 +60,12 @@ public class PaymentService {
} }
private CanceledPayment cancelPayment(String paymentKey, String cancelReason, OffsetDateTime canceledAt) { private CanceledPayment cancelPayment(String paymentKey, String cancelReason, OffsetDateTime canceledAt) {
Payment payment = paymentRepository.findByPaymentKey(paymentKey) PaymentEntity paymentEntity = paymentRepository.findByPaymentKey(paymentKey)
.orElseThrow(() -> throwPaymentNotFoundByPaymentKey(paymentKey)); .orElseThrow(() -> throwPaymentNotFoundByPaymentKey(paymentKey));
paymentRepository.delete(payment); paymentRepository.delete(paymentEntity);
return canceledPaymentRepository.save(new CanceledPayment(paymentKey, cancelReason, payment.getTotalAmount(), return canceledPaymentRepository.save(new CanceledPayment(paymentKey, cancelReason, paymentEntity.getTotalAmount(),
payment.getApprovedAt(), canceledAt)); paymentEntity.getApprovedAt(), canceledAt));
} }
public void updateCanceledTime(String paymentKey, OffsetDateTime canceledAt) { public void updateCanceledTime(String paymentKey, OffsetDateTime canceledAt) {

View File

@ -17,7 +17,7 @@ import roomescape.common.exception.RoomescapeException;
import roomescape.reservation.domain.Reservation; import roomescape.reservation.domain.Reservation;
@Entity @Entity
public class Payment { public class PaymentEntity {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@ -39,10 +39,10 @@ public class Payment {
@Column(nullable = false) @Column(nullable = false)
private OffsetDateTime approvedAt; private OffsetDateTime approvedAt;
protected Payment() { protected PaymentEntity() {
} }
public Payment(String orderId, String paymentKey, Long totalAmount, Reservation reservation, public PaymentEntity(String orderId, String paymentKey, Long totalAmount, Reservation reservation,
OffsetDateTime approvedAt) { OffsetDateTime approvedAt) {
validate(orderId, paymentKey, totalAmount, reservation, approvedAt); validate(orderId, paymentKey, totalAmount, reservation, approvedAt);
this.orderId = orderId; this.orderId = orderId;

View File

@ -4,9 +4,9 @@ import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
public interface PaymentRepository extends JpaRepository<Payment, Long> { public interface PaymentRepository extends JpaRepository<PaymentEntity, Long> {
Optional<Payment> findByReservationId(Long reservationId); Optional<PaymentEntity> findByReservationId(Long reservationId);
Optional<Payment> findByPaymentKey(String paymentKey); Optional<PaymentEntity> findByPaymentKey(String paymentKey);
} }

View File

@ -3,6 +3,7 @@ package roomescape.payment.web
import com.fasterxml.jackson.annotation.JsonIgnoreProperties import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import roomescape.payment.infrastructure.client.PaymentCancelResponseDeserializer import roomescape.payment.infrastructure.client.PaymentCancelResponseDeserializer
import roomescape.payment.infrastructure.persistence.PaymentEntity
import roomescape.reservation.dto.response.ReservationResponse import roomescape.reservation.dto.response.ReservationResponse
import java.time.OffsetDateTime import java.time.OffsetDateTime
@ -55,7 +56,7 @@ data class ReservationPaymentResponse(
) { ) {
companion object { companion object {
@JvmStatic @JvmStatic
fun from(saved: roomescape.payment.infrastructure.persistence.Payment): ReservationPaymentResponse { fun from(saved: PaymentEntity): ReservationPaymentResponse {
return ReservationPaymentResponse( return ReservationPaymentResponse(
saved.id, saved.id,
saved.orderId, saved.orderId,

View File

@ -21,7 +21,7 @@ import roomescape.reservation.domain.ReservationStatus;
import roomescape.reservation.domain.ReservationTime; import roomescape.reservation.domain.ReservationTime;
import roomescape.theme.domain.Theme; import roomescape.theme.domain.Theme;
class PaymentTest { class PaymentEntityTest {
private Reservation reservation; private Reservation reservation;
@ -39,7 +39,7 @@ class PaymentTest {
@DisplayName("paymentKey가 null 또는 빈값이면 예외가 발생한다.") @DisplayName("paymentKey가 null 또는 빈값이면 예외가 발생한다.")
@NullAndEmptySource @NullAndEmptySource
void invalidPaymentKey(String paymentKey) { void invalidPaymentKey(String paymentKey) {
assertThatThrownBy(() -> new Payment("order-id", paymentKey, 10000L, reservation, OffsetDateTime.now())) assertThatThrownBy(() -> new PaymentEntity("order-id", paymentKey, 10000L, reservation, OffsetDateTime.now()))
.isInstanceOf(RoomescapeException.class); .isInstanceOf(RoomescapeException.class);
} }
@ -47,7 +47,7 @@ class PaymentTest {
@DisplayName("orderId가 null 또는 빈값이면 예외가 발생한다.") @DisplayName("orderId가 null 또는 빈값이면 예외가 발생한다.")
@NullAndEmptySource @NullAndEmptySource
void invalidOrderId(String orderId) { void invalidOrderId(String orderId) {
assertThatThrownBy(() -> new Payment(orderId, "payment-key", 10000L, reservation, OffsetDateTime.now())) assertThatThrownBy(() -> new PaymentEntity(orderId, "payment-key", 10000L, reservation, OffsetDateTime.now()))
.isInstanceOf(RoomescapeException.class); .isInstanceOf(RoomescapeException.class);
} }
@ -56,7 +56,7 @@ class PaymentTest {
@CsvSource(value = {"null", "-1"}, nullValues = {"null"}) @CsvSource(value = {"null", "-1"}, nullValues = {"null"})
void invalidOrderId(Long totalAmount) { void invalidOrderId(Long totalAmount) {
assertThatThrownBy( assertThatThrownBy(
() -> new Payment("orderId", "payment-key", totalAmount, reservation, OffsetDateTime.now())) () -> new PaymentEntity("orderId", "payment-key", totalAmount, reservation, OffsetDateTime.now()))
.isInstanceOf(RoomescapeException.class); .isInstanceOf(RoomescapeException.class);
} }
@ -64,7 +64,7 @@ class PaymentTest {
@DisplayName("Reservation이 null이면 예외가 발생한다.") @DisplayName("Reservation이 null이면 예외가 발생한다.")
@NullSource @NullSource
void invalidReservation(Reservation reservation) { void invalidReservation(Reservation reservation) {
assertThatThrownBy(() -> new Payment("orderId", "payment-key", 10000L, reservation, OffsetDateTime.now())) assertThatThrownBy(() -> new PaymentEntity("orderId", "payment-key", 10000L, reservation, OffsetDateTime.now()))
.isInstanceOf(RoomescapeException.class); .isInstanceOf(RoomescapeException.class);
} }
@ -72,7 +72,7 @@ class PaymentTest {
@DisplayName("승인 날짜가 null이면 예외가 발생한다.") @DisplayName("승인 날짜가 null이면 예외가 발생한다.")
@NullSource @NullSource
void invalidApprovedAt(OffsetDateTime approvedAt) { void invalidApprovedAt(OffsetDateTime approvedAt) {
assertThatThrownBy(() -> new Payment("orderId", "payment-key", 10000L, reservation, approvedAt)) assertThatThrownBy(() -> new PaymentEntity("orderId", "payment-key", 10000L, reservation, approvedAt))
.isInstanceOf(RoomescapeException.class); .isInstanceOf(RoomescapeException.class);
} }
} }

View File

@ -39,7 +39,7 @@ 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.CanceledPayment;
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository; import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository;
import roomescape.payment.infrastructure.persistence.Payment; import roomescape.payment.infrastructure.persistence.PaymentEntity;
import roomescape.payment.infrastructure.persistence.PaymentRepository; import roomescape.payment.infrastructure.persistence.PaymentRepository;
import roomescape.payment.web.PaymentApprove; import roomescape.payment.web.PaymentApprove;
import roomescape.payment.web.PaymentCancel; import roomescape.payment.web.PaymentCancel;
@ -398,12 +398,12 @@ public class ReservationControllerTest {
Reservation saved = reservationRepository.save( Reservation saved = reservationRepository.save(
new Reservation(date, time, theme, member, ReservationStatus.CONFIRMED)); new Reservation(date, time, theme, member, ReservationStatus.CONFIRMED));
Payment savedPayment = paymentRepository.save( PaymentEntity savedPaymentEntity = paymentRepository.save(
new Payment("pk", "oi", 1000L, saved, OffsetDateTime.now().minusHours(1L))); new PaymentEntity("pk", "oi", 1000L, saved, OffsetDateTime.now().minusHours(1L)));
// when // when
when(paymentClient.cancelPayment(any(PaymentCancel.Request.class))) when(paymentClient.cancelPayment(any(PaymentCancel.Request.class)))
.thenReturn(new PaymentCancel.Response("pk", "고객 요청", savedPayment.getTotalAmount(), .thenReturn(new PaymentCancel.Response("pk", "고객 요청", savedPaymentEntity.getTotalAmount(),
OffsetDateTime.now())); OffsetDateTime.now()));
// then // then