|
| 1 | +use academy_models::{ |
| 2 | + course::{ |
| 3 | + CourseAuthor, CourseAuthorName, CourseDescription, CourseId, CourseLectureTitle, |
| 4 | + CourseLectureUserSummary, CourseSectionTitle, CourseSectionUserSummary, CourseTitle, |
| 5 | + CourseUserSummary, |
| 6 | + }, |
| 7 | + url::Url, |
| 8 | +}; |
| 9 | +use schemars::JsonSchema; |
| 10 | +use serde::Serialize; |
| 11 | + |
| 12 | +#[derive(Debug, Clone, PartialEq, Eq, Serialize, JsonSchema)] |
| 13 | +pub struct ApiCourseUserSummary { |
| 14 | + pub id: CourseId, |
| 15 | + pub title: CourseTitle, |
| 16 | + pub description: CourseDescription, |
| 17 | + pub category: Option<String>, |
| 18 | + pub language: Option<&'static str>, |
| 19 | + pub image: Option<Url>, |
| 20 | + pub authors: Vec<ApiCourseAuthor>, |
| 21 | + pub price: u64, |
| 22 | + pub learnings_goals: Vec<String>, |
| 23 | + pub requirements: Vec<String>, |
| 24 | + pub last_update: i64, |
| 25 | + pub sections: Vec<ApiCourseSectionUserSummary>, |
| 26 | + pub completed: Option<bool>, |
| 27 | +} |
| 28 | + |
| 29 | +#[derive(Debug, Clone, PartialEq, Eq, Serialize, JsonSchema)] |
| 30 | +pub struct ApiCourseAuthor { |
| 31 | + pub name: CourseAuthorName, |
| 32 | + pub url: Option<Url>, |
| 33 | +} |
| 34 | + |
| 35 | +#[derive(Debug, Clone, PartialEq, Eq, Serialize, JsonSchema)] |
| 36 | +pub struct ApiCourseSectionUserSummary { |
| 37 | + pub title: CourseSectionTitle, |
| 38 | + pub lectures: Vec<ApiCourseLectureUserSummary>, |
| 39 | + pub completed: Option<bool>, |
| 40 | +} |
| 41 | + |
| 42 | +#[derive(Debug, Clone, PartialEq, Eq, Serialize, JsonSchema)] |
| 43 | +pub struct ApiCourseLectureUserSummary { |
| 44 | + pub title: CourseLectureTitle, |
| 45 | + pub duration: u64, |
| 46 | + pub completed: Option<bool>, |
| 47 | +} |
| 48 | + |
| 49 | +impl From<CourseUserSummary> for ApiCourseUserSummary { |
| 50 | + fn from(value: CourseUserSummary) -> Self { |
| 51 | + Self { |
| 52 | + id: value.base.id, |
| 53 | + title: value.base.title, |
| 54 | + description: value.base.description, |
| 55 | + category: None, |
| 56 | + language: Some("de"), |
| 57 | + image: value.base.image_url, |
| 58 | + authors: value.base.authors.into_iter().map(Into::into).collect(), |
| 59 | + price: value.base.price, |
| 60 | + learnings_goals: vec![], |
| 61 | + requirements: vec![], |
| 62 | + last_update: value.base.last_update.timestamp(), |
| 63 | + sections: value.sections.into_iter().map(Into::into).collect(), |
| 64 | + completed: value.completed, |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +impl From<CourseAuthor> for ApiCourseAuthor { |
| 70 | + fn from(value: CourseAuthor) -> Self { |
| 71 | + Self { |
| 72 | + name: value.name, |
| 73 | + url: value.url, |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +impl From<CourseSectionUserSummary> for ApiCourseSectionUserSummary { |
| 79 | + fn from(value: CourseSectionUserSummary) -> Self { |
| 80 | + Self { |
| 81 | + title: value.title, |
| 82 | + lectures: value.lectures.into_iter().map(Into::into).collect(), |
| 83 | + completed: value.completed, |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +impl From<CourseLectureUserSummary> for ApiCourseLectureUserSummary { |
| 89 | + fn from(value: CourseLectureUserSummary) -> Self { |
| 90 | + Self { |
| 91 | + title: value.title, |
| 92 | + duration: value.duration.as_secs(), |
| 93 | + completed: value.completed, |
| 94 | + } |
| 95 | + } |
| 96 | +} |
0 commit comments