generated from pricelees/issue-pr-template
[#39] '시간' -> '일정' 스키마 변경으로 테마별 시간 지정 #40
@ -0,0 +1,36 @@
|
|||||||
|
package roomescape.schedule.infrastructure.persistence
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity
|
||||||
|
import jakarta.persistence.EnumType
|
||||||
|
import jakarta.persistence.Enumerated
|
||||||
|
import jakarta.persistence.Table
|
||||||
|
import jakarta.persistence.UniqueConstraint
|
||||||
|
import roomescape.common.entity.AuditingBaseEntity
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.LocalTime
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "schedule", uniqueConstraints = [UniqueConstraint(columnNames = ["date", "time", "theme_id"])])
|
||||||
|
class ScheduleEntity(
|
||||||
|
id: Long,
|
||||||
|
|
||||||
|
var date: LocalDate,
|
||||||
|
var time: LocalTime,
|
||||||
|
var themeId: Long,
|
||||||
|
|
||||||
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
var status: ScheduleStatus
|
||||||
|
) : AuditingBaseEntity(id) {
|
||||||
|
|
||||||
|
fun modifyIfNotNull(
|
||||||
|
time: LocalTime?,
|
||||||
|
status: ScheduleStatus?
|
||||||
|
) {
|
||||||
|
time?.let { this.time = it }
|
||||||
|
status?.let { this.status = it }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class ScheduleStatus {
|
||||||
|
AVAILABLE, PENDING, RESERVED, BLOCKED
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package roomescape.schedule.infrastructure.persistence
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.time.LocalTime
|
||||||
|
|
||||||
|
interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
|
||||||
|
|
||||||
|
fun findAllByDate(date: LocalDate): List<ScheduleEntity>
|
||||||
|
|
||||||
|
fun findAllByDateAndThemeId(date: LocalDate, themeId: Long): List<ScheduleEntity>
|
||||||
|
|
||||||
|
fun existsByDateAndThemeIdAndTime(date: LocalDate, themeId: Long, time: LocalTime): Boolean
|
||||||
|
}
|
||||||
@ -49,6 +49,23 @@ create table if not exists theme (
|
|||||||
constraint fk_theme__updated_by foreign key (updated_by) references members (member_id)
|
constraint fk_theme__updated_by foreign key (updated_by) references members (member_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
create table if not exists schedule (
|
||||||
|
id bigint primary key,
|
||||||
|
date date not null,
|
||||||
|
time time not null,
|
||||||
|
theme_id bigint not null,
|
||||||
|
status varchar(30) not null,
|
||||||
|
created_at timestamp not null,
|
||||||
|
created_by bigint not null,
|
||||||
|
updated_at timestamp not null,
|
||||||
|
updated_by bigint not null,
|
||||||
|
|
||||||
|
constraint uk_schedule__date_time_theme_id unique (date, time, theme_id),
|
||||||
|
constraint fk_schedule__created_by foreign key (created_by) references members (member_id),
|
||||||
|
constraint fk_schedule__updated_by foreign key (updated_by) references members (member_id),
|
||||||
|
constraint fk_schedule__theme_id foreign key (theme_id) references theme (id)
|
||||||
|
);
|
||||||
|
|
||||||
create table if not exists times (
|
create table if not exists times (
|
||||||
time_id bigint primary key,
|
time_id bigint primary key,
|
||||||
start_at time not null,
|
start_at time not null,
|
||||||
|
|||||||
@ -51,6 +51,23 @@ create table if not exists theme (
|
|||||||
constraint fk_theme__updated_by foreign key (updated_by) references members (member_id)
|
constraint fk_theme__updated_by foreign key (updated_by) references members (member_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
create table if not exists schedule (
|
||||||
|
id bigint primary key,
|
||||||
|
date date not null,
|
||||||
|
time time not null,
|
||||||
|
theme_id bigint not null,
|
||||||
|
status varchar(30) not null,
|
||||||
|
created_at datetime(6) not null,
|
||||||
|
created_by bigint not null,
|
||||||
|
updated_at datetime(6) not null,
|
||||||
|
updated_by bigint not null,
|
||||||
|
|
||||||
|
constraint uk_schedule__date_time_theme_id unique (date, time, theme_id),
|
||||||
|
constraint fk_schedule__created_by foreign key (created_by) references members (member_id),
|
||||||
|
constraint fk_schedule__updated_by foreign key (updated_by) references members (member_id),
|
||||||
|
constraint fk_schedule__theme_id foreign key (theme_id) references theme (id)
|
||||||
|
);
|
||||||
|
|
||||||
create table if not exists times
|
create table if not exists times
|
||||||
(
|
(
|
||||||
time_id bigint primary key,
|
time_id bigint primary key,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user