Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Defelo committed Feb 4, 2025
1 parent 82170fc commit 3d58d2c
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
84 changes: 84 additions & 0 deletions academy_models/src/course.rs
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)));
1 change: 1 addition & 0 deletions academy_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
pub mod auth;
pub mod coin;
pub mod contact;
pub mod course;
pub mod email_address;
pub mod heart;
mod macros;
Expand Down
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;
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
);

0 comments on commit 3d58d2c

Please sign in to comment.