feat: 일정(Schedule) 스키마 및 엔티티 정의

This commit is contained in:
이상진 2025-09-04 11:33:21 +09:00
parent 67728a7d7e
commit b8e9c38024
4 changed files with 84 additions and 0 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -49,6 +49,23 @@ create table if not exists theme (
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 (
time_id bigint primary key,
start_at time not null,

View File

@ -51,6 +51,23 @@ create table if not exists theme (
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
(
time_id bigint primary key,