diff --git a/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PaymentAttemptEntity.kt b/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PaymentAttemptEntity.kt new file mode 100644 index 00000000..26de715c --- /dev/null +++ b/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PaymentAttemptEntity.kt @@ -0,0 +1,38 @@ +package com.sangdol.roomescape.order.infrastructure.persistence + +import com.sangdol.common.persistence.PersistableBaseEntity +import jakarta.persistence.* +import org.springframework.data.annotation.CreatedBy +import org.springframework.data.annotation.CreatedDate +import org.springframework.data.jpa.domain.support.AuditingEntityListener +import java.time.Instant + +@Entity +@EntityListeners(AuditingEntityListener::class) +@Table(name = "payment_attempts") +class PaymentAttemptEntity( + id: Long, + + val reservationId: Long, + + @Enumerated(value = EnumType.STRING) + val result: AttemptResult, + + @Column(columnDefinition = "VARCHAR(50)") + val errorCode: String? = null, + + @Column(columnDefinition = "TEXT") + val message: String? = null, +) : PersistableBaseEntity(id) { + @Column(updatable = false) + @CreatedDate + lateinit var createdAt: Instant + + @Column(updatable = false) + @CreatedBy + var createdBy: Long = 0L +} + +enum class AttemptResult { + SUCCESS, FAILED +} \ No newline at end of file diff --git a/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskEntity.kt b/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskEntity.kt new file mode 100644 index 00000000..730ca5c8 --- /dev/null +++ b/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskEntity.kt @@ -0,0 +1,16 @@ +package com.sangdol.roomescape.order.infrastructure.persistence + +import com.sangdol.common.persistence.PersistableBaseEntity +import jakarta.persistence.Entity +import jakarta.persistence.Table +import java.time.Instant + +@Entity +@Table(name = "post_order_tasks") +class PostOrderTaskEntity( + id: Long, + val reservationId: Long, + val paymentKey: String, + val trial: Int, + val nextRetryAt: Instant +) : PersistableBaseEntity(id) \ No newline at end of file diff --git a/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskRepository.kt b/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskRepository.kt new file mode 100644 index 00000000..356215e8 --- /dev/null +++ b/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskRepository.kt @@ -0,0 +1,6 @@ +package com.sangdol.roomescape.order.infrastructure.persistence + +import org.springframework.data.jpa.repository.JpaRepository + +interface PostOrderTaskRepository : JpaRepository { +} \ No newline at end of file diff --git a/service/src/main/resources/schema/schema-mysql.sql b/service/src/main/resources/schema/schema-mysql.sql index c3a4ab47..6c281116 100644 --- a/service/src/main/resources/schema/schema-mysql.sql +++ b/service/src/main/resources/schema/schema-mysql.sql @@ -238,3 +238,26 @@ create table if not exists canceled_payment( constraint uk_canceled_payment__paymentId unique (payment_id), constraint fk_canceled_payment__paymentId foreign key (payment_id) references payment(id) ); + +create table if not exists payment_attempts( + id bigint primary key, + reservation_id bigint not null, + result varchar(20) not null, + error_code varchar(50) null, + message text null, + created_at datetime(6) not null, + created_by bigint not null, + + constraint fk_payment_attempts__reservation_id foreign key (reservation_id) references reservation (id), + index idx_payment_attempts__reservation_id_result (reservation_id, result) +); + +create table if not exists post_order_tasks( + id bigint primary key, + reservation_id bigint not null, + payment_key varchar(255) not null, + trial int not null, + next_retry_at datetime(6) not null, + + constraint uk_post_order_tasks__reservation_id unique (reservation_id) +);