Fix grade fetching bugs

This commit is contained in:
lemonsh 2022-09-25 12:01:34 +02:00
parent 207aca6fcc
commit 70faf314d1
5 changed files with 46 additions and 33 deletions

35
Cargo.lock generated
View File

@ -395,14 +395,13 @@ dependencies = [
[[package]]
name = "iana-time-zone"
version = "0.1.48"
version = "0.1.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "237a0714f28b1ee39ccec0770ccb544eb02c9ef2c82bb096230eefcffa6468b0"
checksum = "fd911b35d940d2bd0bea0f9100068e5b97b51a1cbe13d13382f132e0365257a0"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"js-sys",
"once_cell",
"wasm-bindgen",
"winapi",
]
@ -541,9 +540,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.14.0"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0"
checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
[[package]]
name = "openssl"
@ -646,9 +645,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.43"
version = "1.0.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
checksum = "7bd7356a8122b6c4a24a82b278680c73357984ca2fc79a0f9fa6dea7dced7c58"
dependencies = [
"unicode-ident",
]
@ -693,9 +692,9 @@ dependencies = [
[[package]]
name = "reqwest"
version = "0.11.11"
version = "0.11.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92"
checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc"
dependencies = [
"base64",
"bytes",
@ -709,10 +708,10 @@ dependencies = [
"hyper-tls",
"ipnet",
"js-sys",
"lazy_static",
"log",
"mime",
"native-tls",
"once_cell",
"percent-encoding",
"pin-project-lite",
"serde",
@ -769,18 +768,18 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.144"
version = "1.0.145"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860"
checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.144"
version = "1.0.145"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00"
checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c"
dependencies = [
"proc-macro2",
"quote",
@ -898,18 +897,18 @@ checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16"
[[package]]
name = "thiserror"
version = "1.0.35"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85"
checksum = "0a99cb8c4b9a8ef0e7907cd3b617cc8dc04d571c4e73c8ae403d80ac160bb122"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.35"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783"
checksum = "3a891860d3c8d66fec8e73ddb3765f90082374dbaaa833407b904a94f1a7eb43"
dependencies = [
"proc-macro2",
"quote",

View File

@ -16,7 +16,6 @@ use openssl::x509::{X509NameBuilder, X509};
use reqwest::Client;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::collections::HashMap;
use uuid::Uuid;
/// API client containing the credentials
@ -219,13 +218,13 @@ pub struct Credentials {
}
async fn get_firebase_token(http: &Client) -> std::result::Result<String, reqwest::Error> {
// TODO: why is this a hashmap, was I drunk? this could easily be a const &[(&str, &str)]
let mut body = HashMap::with_capacity(5);
body.insert("sender", "987828170337");
body.insert("X-scope", "*");
body.insert("X-gmp_app_id", "1:987828170337:android:ac97431a0a4578c3");
body.insert("app", "pl.edu.vulcan.hebe");
body.insert("device", "4609707972546570896");
const FIREBASE_BODY: &[(&str, &str)] = &[
("sender", "987828170337"),
("X-scope", "*"),
("X-gmp_app_id", "1:987828170337:android:ac97431a0a4578c3"),
("app", "pl.edu.vulcan.hebe"),
("device", "4609707972546570896"),
];
let req = http
.post("https://android.clients.google.com/c2dm/register3")
@ -235,7 +234,7 @@ async fn get_firebase_token(http: &Client) -> std::result::Result<String, reqwes
)
.header("User-Agent", "Android-GCM/1.5")
.header("app", "pl.edu.vulcan.hebe")
.form(&body)
.form(FIREBASE_BODY)
.build()?;
Ok(http.execute(req).await?.text().await?)

View File

@ -13,7 +13,7 @@ pub struct UonetStatus {
#[serde(rename_all = "PascalCase")]
pub(crate) struct UonetResponse<T> {
pub status: UonetStatus,
pub envelope: T,
pub envelope: Option<T>,
}
#[derive(Debug, Deserialize)]

View File

@ -128,6 +128,8 @@ pub fn read_uonet_response<'a, T: Deserialize<'a>>(json: &'a str) -> Result<T, U
if resp.status.code != 0 {
Err(ErrorResponse(resp.status))
} else {
Ok(resp.envelope)
Ok(resp
.envelope
.ok_or_else(|| UonetError::IncompleteResponse(Some(json.to_string())))?)
}
}

View File

@ -2,7 +2,9 @@ use chrono::{NaiveDate, NaiveDateTime};
use serde::de::DeserializeOwned;
use crate::{
account::VulcanAccount, models::Student, request::read_uonet_response, Result, UonetError,
account::VulcanAccount,
request::{read_uonet_response, UonetRequest},
Result, UonetError,
};
pub enum FilterType {
@ -27,11 +29,17 @@ impl VulcanAccount {
query.push(("unitId", student.unit.id.to_string()));
query.push(("pupilId", student.pupil.id.to_string()));
query.push(("periodId", period.id.to_string()));
format!("api/mobile/{}/byPupil", endpoint)
format!(
"{}{}/api/mobile/{}/byPupil",
self.credentials.rest_url, student.unit.symbol, endpoint
)
}
FilterType::ByLoginId => {
query.push(("loginId", self.credentials.login_id.to_string()));
format!("api/mobile/{}", endpoint)
format!(
"{}{}/api/mobile/{}",
self.credentials.rest_url, student.unit.symbol, endpoint
)
}
};
if let Some(from) = from {
@ -47,7 +55,12 @@ impl VulcanAccount {
query.push(("lastId", "-2147483648".to_string()));
query.push(("lastSyncDate", last_sync));
let req = self.http.get(url).query(&query).build()?;
let req = self
.http
.get(&url)
.query(&query)
.envelope(&url, self, None)?
.build()?;
let resp = self.http.execute(req).await?.text().await?;
read_uonet_response(&resp)
}