Skip to main content

librus_rs/structs/
lessons.rs

1//! Lesson and attendance data types.
2
3use serde::Deserialize;
4
5/// A lesson linking a teacher, subject, and class.
6#[derive(Debug, Deserialize)]
7#[serde(rename_all = "PascalCase")]
8pub struct Lesson {
9    /// Unique lesson identifier.
10    pub id: i32,
11    /// Reference to the teacher.
12    pub teacher: LessonClass,
13    /// Reference to the subject.
14    pub subject: LessonClass,
15    /// Reference to the class.
16    pub class: LessonClass,
17}
18
19/// A reference to a lesson-related resource.
20#[derive(Debug, Deserialize)]
21#[serde(rename_all = "PascalCase")]
22pub struct LessonClass {
23    /// Resource ID.
24    pub id: i32,
25    /// API URL to fetch the resource.
26    pub url: String,
27}
28
29#[derive(Debug, Deserialize)]
30pub struct LessonResources {
31    #[serde(rename = "..")]
32    pub root: LessonUrl,
33}
34
35#[derive(Debug, Deserialize)]
36#[serde(rename_all = "PascalCase")]
37pub struct LessonUrl {
38    pub url: String,
39}
40
41/// Response containing a single lesson.
42#[derive(Debug, Deserialize)]
43#[serde(rename_all = "PascalCase")]
44pub struct ResponseLesson {
45    /// The lesson data.
46    pub lesson: Lesson,
47    /// Related API resources.
48    pub resources: LessonResources,
49    /// API URL for this response.
50    pub url: String,
51}
52
53/// An academic subject.
54#[derive(Debug, Deserialize)]
55#[serde(rename_all = "PascalCase")]
56pub struct LessonSubject {
57    /// Unique subject identifier.
58    pub id: i32,
59    /// Full subject name (e.g., "Mathematics").
60    pub name: String,
61    /// Subject number in the curriculum.
62    #[serde(rename = "No")]
63    pub num: i32,
64    /// Short subject code (e.g., "MAT").
65    pub short: String,
66    /// Whether this is an extracurricular subject.
67    pub is_extra_curricular: Option<bool>,
68    /// Whether this is a block lesson.
69    pub is_block_lesson: Option<bool>,
70}
71
72/// Response containing a single subject.
73#[derive(Debug, Deserialize)]
74#[serde(rename_all = "PascalCase")]
75pub struct ResponseLessonSubject {
76    /// The subject data, if found.
77    pub subject: Option<LessonSubject>,
78    /// Related API resources.
79    pub resources: LessonResources,
80    /// API URL for this response.
81    pub url: String,
82}
83
84/// A student's attendance record for a lesson.
85#[derive(Debug, Deserialize)]
86#[serde(rename_all = "PascalCase")]
87pub struct Attendance {
88    /// Unique attendance record identifier.
89    pub id: AttendanceId,
90    /// Reference to the lesson.
91    pub lesson: AttendanceAddedBy,
92    /// Reference to the student.
93    pub student: AttendanceAddedBy,
94    /// Date of the lesson.
95    pub date: String,
96    /// Date when the record was added.
97    pub add_date: String,
98    /// Lesson number in the day (1-8+).
99    pub lesson_no: i32,
100    /// Semester number (1 or 2).
101    pub semester: i32,
102    /// Reference to the attendance type.
103    #[serde(rename = "Type")]
104    pub attendance_type: AttendanceAddedBy,
105    /// Reference to the teacher who recorded attendance.
106    pub added_by: AttendanceAddedBy,
107    /// Reference to a school trip, if applicable.
108    pub trip: Option<AttendanceAddedBy>,
109}
110
111/// A reference to an attendance-related resource.
112#[derive(Debug, Deserialize)]
113#[serde(rename_all = "PascalCase")]
114pub struct AttendanceAddedBy {
115    /// Resource ID.
116    pub id: i32,
117    /// API URL to fetch the resource.
118    pub url: String,
119}
120
121/// Attendance record ID which can be numeric or string.
122#[derive(Debug, Deserialize)]
123#[serde(untagged)]
124pub enum AttendanceId {
125    /// Numeric ID.
126    Integer(i32),
127    /// String ID.
128    String(String),
129}
130
131#[derive(Debug, Deserialize)]
132pub struct AttendanceResources {
133    #[serde(rename = "Attendances\\Types")]
134    pub attendances_types: LessonUrl,
135    #[serde(rename = "Attendances\\LessonsStatistics")]
136    pub attendances_lessons_statistics: LessonUrl,
137    #[serde(rename = "Attendances\\FilledByTeacher")]
138    pub attendances_filled_by_teacher: LessonUrl,
139    #[serde(rename = "..")]
140    pub empty: LessonUrl,
141}
142
143/// Response containing all attendances.
144#[derive(Debug, Deserialize)]
145#[serde(rename_all = "PascalCase")]
146pub struct ResponseAttendances {
147    /// List of attendance records.
148    pub attendances: Vec<Attendance>,
149    /// Related API resources.
150    pub resources: AttendanceResources,
151    /// API URL for this response.
152    pub url: String,
153}
154
155/// A type of attendance (present, absent, late, etc.).
156#[derive(Debug, Deserialize)]
157#[serde(rename_all = "PascalCase")]
158pub struct AttendanceType {
159    /// Unique type identifier.
160    pub id: i32,
161    /// Full name (e.g., "Present", "Absent", "Late").
162    pub name: String,
163    /// Short code (e.g., "P", "A", "L").
164    pub short: String,
165    /// Whether this is a standard type.
166    pub standard: bool,
167    /// RGB color for display (e.g., "00FF00").
168    #[serde(rename = "ColorRGB")]
169    pub color_rgb: Option<String>,
170    /// Whether this type counts as present.
171    pub is_presence_kind: bool,
172    /// Display order.
173    pub order: i32,
174    /// System identifier.
175    pub identifier: String,
176    /// Reference to a standard type.
177    pub standard_type: Option<AttendanceColor>,
178    /// Reference to the color.
179    pub color: Option<AttendanceColor>,
180}
181
182#[derive(Debug, Deserialize)]
183#[serde(rename_all = "PascalCase")]
184pub struct AttendanceColor {
185    pub id: i32,
186    pub url: String,
187}
188
189/// Response containing all attendance types.
190#[derive(Debug, Deserialize)]
191#[serde(rename_all = "PascalCase")]
192pub struct ResponseAttendancesType {
193    /// List of attendance types.
194    pub types: Vec<AttendanceType>,
195    /// Related API resources.
196    pub resources: LessonResources,
197    /// API URL for this response.
198    pub url: String,
199}