From b8e9c38024af7209f0d3ba326e4ed1dea104ddae Mon Sep 17 00:00:00 2001 From: pricelees Date: Thu, 4 Sep 2025 11:33:21 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9D=BC=EC=A0=95(Schedule)=20?= =?UTF-8?q?=EC=8A=A4=ED=82=A4=EB=A7=88=20=EB=B0=8F=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/ScheduleEntity.kt | 36 +++++++++++++++++++ .../persistence/ScheduleRepository.kt | 14 ++++++++ src/main/resources/schema/schema-h2.sql | 17 +++++++++ src/main/resources/schema/schema-mysql.sql | 17 +++++++++ 4 files changed, 84 insertions(+) create mode 100644 src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleEntity.kt create mode 100644 src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt diff --git a/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleEntity.kt b/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleEntity.kt new file mode 100644 index 00000000..7da08a63 --- /dev/null +++ b/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleEntity.kt @@ -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 +} diff --git a/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt b/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt new file mode 100644 index 00000000..8bae9654 --- /dev/null +++ b/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt @@ -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 { + + fun findAllByDate(date: LocalDate): List + + fun findAllByDateAndThemeId(date: LocalDate, themeId: Long): List + + fun existsByDateAndThemeIdAndTime(date: LocalDate, themeId: Long, time: LocalTime): Boolean +} diff --git a/src/main/resources/schema/schema-h2.sql b/src/main/resources/schema/schema-h2.sql index 82d0965a..e24c5f78 100644 --- a/src/main/resources/schema/schema-h2.sql +++ b/src/main/resources/schema/schema-h2.sql @@ -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, diff --git a/src/main/resources/schema/schema-mysql.sql b/src/main/resources/schema/schema-mysql.sql index 4664f1dd..6e78453e 100644 --- a/src/main/resources/schema/schema-mysql.sql +++ b/src/main/resources/schema/schema-mysql.sql @@ -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,