generated from pricelees/issue-pr-template
refactor: 기존의 예약 entity를 새로 정의한 entity로 대체
This commit is contained in:
parent
485f8bd3f2
commit
85c8db1866
@ -1,68 +1,36 @@
|
|||||||
package roomescape.reservation.infrastructure.persistence
|
package roomescape.reservation.infrastructure.persistence
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
import jakarta.persistence.Entity
|
||||||
import jakarta.persistence.*
|
import jakarta.persistence.EnumType
|
||||||
import roomescape.common.entity.BaseEntity
|
import jakarta.persistence.Enumerated
|
||||||
import roomescape.member.infrastructure.persistence.MemberEntity
|
import jakarta.persistence.Table
|
||||||
import roomescape.theme.infrastructure.persistence.ThemeEntity
|
import roomescape.common.entity.AuditingBaseEntity
|
||||||
import roomescape.time.infrastructure.persistence.TimeEntity
|
|
||||||
import java.time.LocalDate
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "reservations")
|
@Table(name = "reservation")
|
||||||
class ReservationEntity(
|
class ReservationEntity(
|
||||||
@Id
|
id: Long,
|
||||||
@Column(name = "reservation_id")
|
|
||||||
private var _id: Long?,
|
|
||||||
|
|
||||||
@Column(name = "date", nullable = false)
|
val memberId: Long,
|
||||||
var date: LocalDate,
|
val scheduleId: Long,
|
||||||
|
val reserverName: String,
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
val reserverContact: String,
|
||||||
@JoinColumn(name = "time_id", nullable = false)
|
val participantCount: Short,
|
||||||
var time: TimeEntity,
|
val requirement: String,
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
|
||||||
@JoinColumn(name = "theme_id", nullable = false)
|
|
||||||
var theme: ThemeEntity,
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
|
||||||
@JoinColumn(name = "member_id", nullable = false)
|
|
||||||
var member: MemberEntity,
|
|
||||||
|
|
||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
@Column(name = "status", nullable = false, length = 30)
|
|
||||||
var status: ReservationStatus,
|
var status: ReservationStatus,
|
||||||
): BaseEntity() {
|
|
||||||
override fun getId(): Long? = _id
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
fun isWaiting(): Boolean = status == ReservationStatus.WAITING
|
|
||||||
|
|
||||||
@JsonIgnore
|
|
||||||
fun isReservedBy(memberId: Long): Boolean {
|
|
||||||
return this.member.id == memberId
|
|
||||||
}
|
|
||||||
|
|
||||||
fun cancelByUser() {
|
|
||||||
this.status = ReservationStatus.CANCELED_BY_USER
|
|
||||||
}
|
|
||||||
|
|
||||||
|
) : AuditingBaseEntity(id) {
|
||||||
fun confirm() {
|
fun confirm() {
|
||||||
this.status = ReservationStatus.CONFIRMED
|
this.status = ReservationStatus.CONFIRMED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun cancel() {
|
||||||
|
this.status = ReservationStatus.CANCELED
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class ReservationStatus {
|
enum class ReservationStatus {
|
||||||
CONFIRMED,
|
PENDING, CONFIRMED, CANCELED, FAILED, EXPIRED
|
||||||
CONFIRMED_PAYMENT_REQUIRED,
|
|
||||||
PENDING,
|
|
||||||
WAITING,
|
|
||||||
CANCELED_BY_USER,
|
|
||||||
AUTOMATICALLY_CANCELED,
|
|
||||||
;
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun confirmedStatus(): Array<ReservationStatus> = arrayOf(CONFIRMED, CONFIRMED_PAYMENT_REQUIRED)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user