feat: Add all and remove test

This commit is contained in:
2026-02-07 17:56:28 +01:00
parent a3cfcd52c5
commit c59b55c66b
4 changed files with 15 additions and 99 deletions

5
src/all.rs Normal file
View 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)
}

View File

@@ -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);
}
}
}

View File

@@ -2,6 +2,7 @@ mod api;
mod models;
mod schedule;
mod teacher_absence;
mod all;
use std::sync::RwLock;
@@ -37,4 +38,9 @@ impl JecnaSuplClient {
let provider = self.provider_url.read().unwrap();
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)
}
}

View File

@@ -71,17 +71,19 @@ pub struct ChangeEntry {
pub text: String,
#[serde(rename = "backgroundColor")]
pub background_color: Option<String>,
#[serde(rename = "foregroundColor")]
pub foreground_color: Option<String>,
#[serde(rename = "willBeSpecified")]
pub will_be_specified: Option<bool>,
}
#[derive(Deserialize)]
#[derive(Deserialize, Debug, uniffi::Record)]
pub struct ApiResponse {
pub status: Status,
pub schedule: HashMap<String, DailyData>,
}
#[derive(Deserialize, Clone)]
#[derive(Deserialize, Clone, Debug, uniffi::Record)]
pub struct DailyData {
pub info: DayInfo,
pub changes: HashMap<String, Vec<Option<ChangeEntry>>>,