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

View File

@ -17,7 +17,7 @@ import roomescape.common.exception.RoomescapeException;
import roomescape.reservation.domain.Reservation;
@Entity
public class Payment {
public class PaymentEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -39,10 +39,10 @@ public class Payment {
@Column(nullable = false)
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) {
validate(orderId, paymentKey, totalAmount, reservation, approvedAt);
this.orderId = orderId;

View File

@ -4,9 +4,9 @@ import java.util.Optional;
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.databind.annotation.JsonDeserialize
import roomescape.payment.infrastructure.client.PaymentCancelResponseDeserializer
import roomescape.payment.infrastructure.persistence.PaymentEntity
import roomescape.reservation.dto.response.ReservationResponse
import java.time.OffsetDateTime
@ -55,7 +56,7 @@ data class ReservationPaymentResponse(
) {
companion object {
@JvmStatic
fun from(saved: roomescape.payment.infrastructure.persistence.Payment): ReservationPaymentResponse {
fun from(saved: PaymentEntity): ReservationPaymentResponse {
return ReservationPaymentResponse(
saved.id,
saved.orderId,

View File

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

View File

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