|
| 1 | +use std::time::Duration; |
| 2 | + |
| 3 | +use chrono::{DateTime, Utc}; |
| 4 | + |
| 5 | +use crate::{macros::id, nutype_string, url::Url}; |
| 6 | + |
| 7 | +id!(CourseId); |
| 8 | +id!(CourseAuthorId); |
| 9 | +id!(CourseSectionId); |
| 10 | +id!(CourseLessonId); |
| 11 | + |
| 12 | +#[derive(Debug, Clone)] |
| 13 | +pub struct Course { |
| 14 | + pub id: CourseId, |
| 15 | + pub title: CourseTitle, |
| 16 | + pub description: Option<CourseDescription>, |
| 17 | + pub updated_at: DateTime<Utc>, |
| 18 | + pub language: Option<CourseLanguage>, |
| 19 | + pub image: Option<Url>, |
| 20 | + pub price: u32, |
| 21 | +} |
| 22 | + |
| 23 | +nutype_string!(CourseTitle(validate(not_empty, len_char_max = 64))); |
| 24 | +nutype_string!(CourseDescription(validate(not_empty, len_char_max = 4096))); |
| 25 | + |
| 26 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 27 | +pub enum CourseLanguage { |
| 28 | + English, |
| 29 | + German, |
| 30 | +} |
| 31 | + |
| 32 | +#[derive(Debug, Clone)] |
| 33 | +pub struct CourseAuthor { |
| 34 | + pub id: CourseAuthorId, |
| 35 | + pub name: CourseAuthorName, |
| 36 | + pub url: Option<Url>, |
| 37 | +} |
| 38 | + |
| 39 | +nutype_string!(CourseAuthorName(validate(not_empty, len_char_max = 64))); |
| 40 | + |
| 41 | +#[derive(Debug, Clone)] |
| 42 | +pub struct CourseSection { |
| 43 | + pub id: CourseSectionId, |
| 44 | + pub course_id: CourseId, |
| 45 | + pub title: CourseSectionTitle, |
| 46 | + pub description: Option<CourseSectionDescription>, |
| 47 | + pub sort_key: u32, |
| 48 | +} |
| 49 | + |
| 50 | +nutype_string!(CourseSectionTitle(validate(not_empty, len_char_max = 64))); |
| 51 | +nutype_string!(CourseSectionDescription(validate( |
| 52 | + not_empty, |
| 53 | + len_char_max = 4096 |
| 54 | +))); |
| 55 | + |
| 56 | +#[derive(Debug, Clone)] |
| 57 | +pub struct CourseLesson { |
| 58 | + pub id: CourseLessonId, |
| 59 | + pub section_id: CourseSectionId, |
| 60 | + pub title: CourseLessonTitle, |
| 61 | + pub description: Option<CourseLessonDescription>, |
| 62 | + pub duration: Duration, |
| 63 | + pub sort_key: u32, |
| 64 | + pub variant: CourseLessonVariant, |
| 65 | +} |
| 66 | + |
| 67 | +nutype_string!(CourseLessonTitle(validate(not_empty, len_char_max = 64))); |
| 68 | +nutype_string!(CourseLessonDescription(validate( |
| 69 | + not_empty, |
| 70 | + len_char_max = 4096 |
| 71 | +))); |
| 72 | + |
| 73 | +#[derive(Debug, Clone)] |
| 74 | +pub enum CourseLessonVariant { |
| 75 | + Youtube(CourseYoutubeLesson), |
| 76 | + Mp4, |
| 77 | +} |
| 78 | + |
| 79 | +#[derive(Debug, Clone)] |
| 80 | +pub struct CourseYoutubeLesson { |
| 81 | + pub video_id: YoutubeVideoId, |
| 82 | +} |
| 83 | + |
| 84 | +nutype_string!(YoutubeVideoId(validate(not_empty, len_char_max = 16))); |
0 commit comments