feat: Add all and remove test
This commit is contained in:
5
src/all.rs
Normal file
5
src/all.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
use crate::{api::fetch_api, ApiResponse, SuplError};
|
||||||
|
|
||||||
|
pub fn get_all_impl(provider_url: &str) -> Result<ApiResponse, SuplError> {
|
||||||
|
fetch_api(provider_url)
|
||||||
|
}
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
use jecna_supl_client::{AbsenceEntry, JecnaSuplClient};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let client = JecnaSuplClient::new();
|
|
||||||
|
|
||||||
println!("Fetching schedule for E4...");
|
|
||||||
match client.get_schedule("E4".to_string()) {
|
|
||||||
Ok(result) => {
|
|
||||||
println!("Last updated: {}", result.status.last_updated);
|
|
||||||
|
|
||||||
if result.schedule.is_empty() {
|
|
||||||
println!("No substitution schedule found for the upcoming days.");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (date, day) in result.schedule {
|
|
||||||
println!("\nDate: {}", date);
|
|
||||||
println!("In work: {}", day.info.in_work);
|
|
||||||
if !day.takes_place.is_empty() {
|
|
||||||
println!("Extra info: {}", day.takes_place);
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Changes:");
|
|
||||||
for (i, change) in day.changes.iter().enumerate() {
|
|
||||||
if let Some(c) = change {
|
|
||||||
println!(" Lesson {}: {}", i + 1, c.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Absences:");
|
|
||||||
for entry in day.absence {
|
|
||||||
print_absence(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => eprintln!("Error fetching schedule: {:?}", e),
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("\nFetching all teacher absences...");
|
|
||||||
match client.get_teacher_absence() {
|
|
||||||
Ok(result) => {
|
|
||||||
for (date, entries) in result.absences {
|
|
||||||
println!("\nDate: {}", date);
|
|
||||||
for entry in entries {
|
|
||||||
print_absence(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => eprintln!("Error fetching teacher absences: {:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_absence(entry: AbsenceEntry) {
|
|
||||||
match entry {
|
|
||||||
AbsenceEntry::WholeDay {
|
|
||||||
teacher,
|
|
||||||
teacher_code,
|
|
||||||
} => {
|
|
||||||
println!(" {} ({}): Whole day", teacher, teacher_code);
|
|
||||||
}
|
|
||||||
AbsenceEntry::Single {
|
|
||||||
teacher,
|
|
||||||
teacher_code,
|
|
||||||
hours,
|
|
||||||
} => {
|
|
||||||
println!(" {} ({}): Lesson {}", teacher, teacher_code, hours);
|
|
||||||
}
|
|
||||||
AbsenceEntry::Range {
|
|
||||||
teacher,
|
|
||||||
teacher_code,
|
|
||||||
hours,
|
|
||||||
} => {
|
|
||||||
println!(
|
|
||||||
" {} ({}): Lessons {}-{}",
|
|
||||||
teacher, teacher_code, hours.from, hours.to
|
|
||||||
);
|
|
||||||
}
|
|
||||||
AbsenceEntry::Exkurze {
|
|
||||||
teacher,
|
|
||||||
teacher_code,
|
|
||||||
} => {
|
|
||||||
println!(" {} ({}): Excursion", teacher, teacher_code);
|
|
||||||
}
|
|
||||||
AbsenceEntry::Zastoupen {
|
|
||||||
teacher,
|
|
||||||
teacher_code,
|
|
||||||
zastupuje,
|
|
||||||
} => {
|
|
||||||
println!(
|
|
||||||
" {} ({}): Represented by {} ({})",
|
|
||||||
teacher, teacher_code, zastupuje.teacher, zastupuje.teacher_code
|
|
||||||
);
|
|
||||||
}
|
|
||||||
AbsenceEntry::Invalid { original } => {
|
|
||||||
println!(" Invalid entry: {}", original);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ mod api;
|
|||||||
mod models;
|
mod models;
|
||||||
mod schedule;
|
mod schedule;
|
||||||
mod teacher_absence;
|
mod teacher_absence;
|
||||||
|
mod all;
|
||||||
|
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
@@ -37,4 +38,9 @@ impl JecnaSuplClient {
|
|||||||
let provider = self.provider_url.read().unwrap();
|
let provider = self.provider_url.read().unwrap();
|
||||||
teacher_absence::get_teacher_absence_impl(&provider)
|
teacher_absence::get_teacher_absence_impl(&provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_all(&self) -> Result<ApiResponse, SuplError> {
|
||||||
|
let provider = self.provider_url.read().unwrap();
|
||||||
|
all::get_all_impl(&provider)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,17 +71,19 @@ pub struct ChangeEntry {
|
|||||||
pub text: String,
|
pub text: String,
|
||||||
#[serde(rename = "backgroundColor")]
|
#[serde(rename = "backgroundColor")]
|
||||||
pub background_color: Option<String>,
|
pub background_color: Option<String>,
|
||||||
|
#[serde(rename = "foregroundColor")]
|
||||||
|
pub foreground_color: Option<String>,
|
||||||
#[serde(rename = "willBeSpecified")]
|
#[serde(rename = "willBeSpecified")]
|
||||||
pub will_be_specified: Option<bool>,
|
pub will_be_specified: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, Debug, uniffi::Record)]
|
||||||
pub struct ApiResponse {
|
pub struct ApiResponse {
|
||||||
pub status: Status,
|
pub status: Status,
|
||||||
pub schedule: HashMap<String, DailyData>,
|
pub schedule: HashMap<String, DailyData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone)]
|
#[derive(Deserialize, Clone, Debug, uniffi::Record)]
|
||||||
pub struct DailyData {
|
pub struct DailyData {
|
||||||
pub info: DayInfo,
|
pub info: DayInfo,
|
||||||
pub changes: HashMap<String, Vec<Option<ChangeEntry>>>,
|
pub changes: HashMap<String, Vec<Option<ChangeEntry>>>,
|
||||||
|
|||||||
Reference in New Issue
Block a user