feat(schedule)!: move schedule parser, downloader, and updater to external library

This can be used to support more schedule formats in the future.
This commit is contained in:
2025-09-02 08:54:22 +04:00
parent 7c973bfda0
commit 5e39fc9acc
37 changed files with 1364 additions and 1271 deletions

View File

@@ -18,8 +18,9 @@ async fn sign_up_combined(
}
if !app_state
.get_schedule_snapshot()
.get_schedule_snapshot("eng_polytechnic")
.await
.unwrap()
.data
.groups
.contains_key(&data.group)

View File

@@ -40,8 +40,9 @@ pub async fn telegram_complete(
// проверка на существование группы
if !app_state
.get_schedule_snapshot()
.get_schedule_snapshot("eng_polytechnic")
.await
.unwrap()
.data
.groups
.contains_key(&data.group)

View File

@@ -31,8 +31,9 @@ pub async fn group(user: AsyncExtractor<User>, app_state: web::Data<AppState>) -
None => Err(ErrorCode::SignUpNotCompleted),
Some(group) => match app_state
.get_schedule_snapshot()
.get_schedule_snapshot("eng_polytechnic")
.await
.unwrap()
.data
.groups
.get(group)

View File

@@ -6,8 +6,9 @@ use actix_web::{get, web};
#[get("/group-names")]
pub async fn group_names(app_state: web::Data<AppState>) -> Response {
let mut names: Vec<String> = app_state
.get_schedule_snapshot()
.get_schedule_snapshot("eng_polytechnic")
.await
.unwrap()
.data
.groups
.keys()

View File

@@ -1,7 +1,7 @@
use crate::state::{AppState, ScheduleSnapshot};
use crate::state::AppState;
use actix_macros::{OkResponse, ResponderJson};
use actix_web::web;
use schedule_parser::schema::ScheduleEntry;
use providers::base::{ScheduleEntry, ScheduleSnapshot};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::ops::Deref;
@@ -32,7 +32,12 @@ impl From<ScheduleEntry> for ScheduleEntryResponse {
impl ScheduleView {
pub async fn from(app_state: &web::Data<AppState>) -> Self {
let schedule = app_state.get_schedule_snapshot().await.clone();
let schedule = app_state
.get_schedule_snapshot("eng_polytechnic")
.await
.unwrap()
.deref()
.clone();
Self {
url: schedule.url,
@@ -60,7 +65,13 @@ pub struct CacheStatus {
impl CacheStatus {
pub async fn from(value: &web::Data<AppState>) -> Self {
From::<&ScheduleSnapshot>::from(value.get_schedule_snapshot().await.deref())
From::<&ScheduleSnapshot>::from(
value
.get_schedule_snapshot("eng_polytechnic")
.await
.unwrap()
.deref(),
)
}
}

View File

@@ -2,7 +2,7 @@ use self::schema::*;
use crate::AppState;
use crate::routes::schema::ResponseError;
use actix_web::{get, web};
use schedule_parser::schema::ScheduleEntry;
use providers::base::ScheduleEntry;
#[utoipa::path(responses(
(status = OK, body = ScheduleEntry),
@@ -18,8 +18,9 @@ use schedule_parser::schema::ScheduleEntry;
#[get("/teacher/{name}")]
pub async fn teacher(name: web::Path<String>, app_state: web::Data<AppState>) -> ServiceResponse {
match app_state
.get_schedule_snapshot()
.get_schedule_snapshot("eng_polytechnic")
.await
.unwrap()
.data
.teachers
.get(&name.into_inner())

View File

@@ -6,8 +6,9 @@ use actix_web::{get, web};
#[get("/teacher-names")]
pub async fn teacher_names(app_state: web::Data<AppState>) -> Response {
let mut names: Vec<String> = app_state
.get_schedule_snapshot()
.get_schedule_snapshot("eng_polytechnic")
.await
.unwrap()
.data
.teachers
.keys()

View File

@@ -19,8 +19,9 @@ pub async fn change_group(
}
if !app_state
.get_schedule_snapshot()
.get_schedule_snapshot("eng_polytechnic")
.await
.unwrap()
.data
.groups
.contains_key(&data.group)