headless_lms_server/domain/langs/
convert.rs1use headless_lms_models::{
4 course_instances::CourseInstanceWithCourseInfo, exercise_tasks::CourseMaterialExerciseTask,
5 exercises::GradingProgress,
6};
7use mooc_langs_api as api;
8
9pub trait Convert<T> {
10 fn convert(self) -> T;
11}
12
13impl<T, U> Convert<Vec<T>> for Vec<U>
14where
15 U: Convert<T>,
16{
17 fn convert(self) -> Vec<T> {
18 self.into_iter().map(Convert::convert).collect()
19 }
20}
21
22impl Convert<api::CourseInstance> for CourseInstanceWithCourseInfo {
23 fn convert(self) -> api::CourseInstance {
24 api::CourseInstance {
25 course_id: self.course_id,
26 course_slug: self.course_slug,
27 course_name: self.course_name,
28 course_description: self.course_description,
29 id: self.course_instance_id,
30 instance_name: self.course_instance_name,
31 instance_description: self.course_instance_description,
32 organization_name: self.organization_name,
33 }
34 }
35}
36
37impl Convert<api::ExerciseTask> for CourseMaterialExerciseTask {
38 fn convert(self) -> api::ExerciseTask {
39 api::ExerciseTask {
40 task_id: self.id,
41 order_number: self.order_number,
42 assignment: self.assignment,
43 public_spec: self.public_spec,
44 model_solution_spec: self.model_solution_spec,
45 exercise_service_slug: self.exercise_service_slug,
46 }
47 }
48}
49
50impl Convert<api::GradingProgress> for GradingProgress {
51 fn convert(self) -> api::GradingProgress {
52 match self {
53 Self::Failed => api::GradingProgress::Failed,
54 Self::NotReady => api::GradingProgress::NotReady,
55 Self::PendingManual => api::GradingProgress::PendingManual,
56 Self::Pending => api::GradingProgress::Pending,
57 Self::FullyGraded => api::GradingProgress::FullyGraded,
58 }
59 }
60}