mirror of
https://github.com/n08i40k/schedule-parser-rusted.git
synced 2025-12-06 17:57:47 +03:00
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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user