-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use std::time::Duration; | ||
|
||
use chrono::{DateTime, Utc}; | ||
|
||
use crate::{macros::id, nutype_string, url::Url}; | ||
|
||
id!(CourseId); | ||
id!(CourseAuthorId); | ||
id!(CourseSectionId); | ||
id!(CourseLessonId); | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Course { | ||
pub id: CourseId, | ||
pub title: CourseTitle, | ||
pub description: Option<CourseDescription>, | ||
pub updated_at: DateTime<Utc>, | ||
pub language: Option<CourseLanguage>, | ||
pub image: Option<Url>, | ||
pub price: u32, | ||
} | ||
|
||
nutype_string!(CourseTitle(validate(not_empty, len_char_max = 64))); | ||
nutype_string!(CourseDescription(validate(not_empty, len_char_max = 4096))); | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub enum CourseLanguage { | ||
English, | ||
German, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct CourseAuthor { | ||
pub id: CourseAuthorId, | ||
pub name: CourseAuthorName, | ||
pub url: Option<Url>, | ||
} | ||
|
||
nutype_string!(CourseAuthorName(validate(not_empty, len_char_max = 64))); | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct CourseSection { | ||
pub id: CourseSectionId, | ||
pub course_id: CourseId, | ||
pub title: CourseSectionTitle, | ||
pub description: Option<CourseSectionDescription>, | ||
pub sort_key: u32, | ||
} | ||
|
||
nutype_string!(CourseSectionTitle(validate(not_empty, len_char_max = 64))); | ||
nutype_string!(CourseSectionDescription(validate( | ||
not_empty, | ||
len_char_max = 4096 | ||
))); | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct CourseLesson { | ||
pub id: CourseLessonId, | ||
pub section_id: CourseSectionId, | ||
pub title: CourseLessonTitle, | ||
pub description: Option<CourseLessonDescription>, | ||
pub duration: Duration, | ||
pub sort_key: u32, | ||
pub variant: CourseLessonVariant, | ||
} | ||
|
||
nutype_string!(CourseLessonTitle(validate(not_empty, len_char_max = 64))); | ||
nutype_string!(CourseLessonDescription(validate( | ||
not_empty, | ||
len_char_max = 4096 | ||
))); | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum CourseLessonVariant { | ||
Youtube(CourseYoutubeLesson), | ||
Mp4, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct CourseYoutubeLesson { | ||
pub video_id: YoutubeVideoId, | ||
} | ||
|
||
nutype_string!(YoutubeVideoId(validate(not_empty, len_char_max = 16))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
academy_persistence/postgres/migrations/2025-02-04-233403_create_course_tables/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
drop table course_lessons, course_youtube_lessons, course_mp4_lessons; | ||
drop table course_sections; | ||
drop table courses, course_authors, course_author_courses; | ||
drop type course_language; |
53 changes: 53 additions & 0 deletions
53
academy_persistence/postgres/migrations/2025-02-04-233403_create_course_tables/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
create type course_language as enum ('de', 'en'); | ||
|
||
create table courses ( | ||
id uuid primary key, | ||
title text not null, | ||
description text, | ||
updated_at timestamp with time zone not null, | ||
language course_language, | ||
image text, | ||
price integer not null check (price >= 0) | ||
); | ||
create unique index courses_title_idx on courses (lower(title)); | ||
|
||
create table course_authors ( | ||
id uuid primary key, | ||
name text not null, | ||
url text | ||
); | ||
create unique index course_authors_name_idx on course_authors (lower(name)); | ||
|
||
create table course_author_courses ( | ||
course_id uuid not null references courses(id) on delete cascade, | ||
course_author_id uuid not null references course_authors(id) on delete cascade, | ||
primary key (course_id, course_author_id) | ||
); | ||
|
||
create table course_sections ( | ||
id uuid primary key, | ||
course_id uuid not null references courses(id) on delete cascade, | ||
title text not null, | ||
description text, | ||
sort_key integer unique not null check (sort_key >= 0) | ||
); | ||
create unique index course_sections_title_idx on course_sections (lower(title)); | ||
|
||
create table course_lessons ( | ||
id uuid primary key, | ||
section_id uuid not null references course_sections(id) on delete cascade, | ||
title text not null, | ||
description text, | ||
duration interval not null, | ||
sort_key integer unique not null check (sort_key >= 0) | ||
); | ||
create unique index course_lessons_title_idx on course_lessons (lower(title)); | ||
|
||
create table course_youtube_lessons ( | ||
id uuid primary key references course_lessons (id) on delete cascade, | ||
video_id text not null | ||
); | ||
|
||
create table course_mp4_lessons ( | ||
id uuid primary key references course_lessons (id) on delete cascade | ||
); |