[BE][Classroom] Parse & send courseid in the user courses list
This commit is contained in:
parent
815db6d7ed
commit
54c61b8b2a
23
backend/Cargo.lock
generated
23
backend/Cargo.lock
generated
@ -159,6 +159,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"log",
|
||||
"once_cell",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"rocket",
|
||||
"scraper",
|
||||
@ -1577,9 +1578,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
version = "2.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
@ -2335,14 +2336,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.9.3"
|
||||
version = "1.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a"
|
||||
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata 0.3.6",
|
||||
"regex-syntax 0.7.4",
|
||||
"regex-automata 0.4.3",
|
||||
"regex-syntax 0.8.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2356,13 +2357,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.3.6"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69"
|
||||
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax 0.7.4",
|
||||
"regex-syntax 0.8.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2373,9 +2374,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.7.4"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2"
|
||||
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
|
@ -22,5 +22,6 @@ env_logger = "0.10.0"
|
||||
bardecoder = "0.5.0"
|
||||
image = "0.24.7"
|
||||
imageproc = "0.23.0"
|
||||
regex = "1.10.2"
|
||||
|
||||
|
||||
|
@ -4,7 +4,6 @@ use log::{error, info};
|
||||
use reqwest::Client;
|
||||
use rocket::http::Status;
|
||||
use rocket::serde::json::Json;
|
||||
use sqlx::Connection;
|
||||
|
||||
use crate::json_result::JsonResult;
|
||||
use crate::model::person::{PersonCreate, PersonLink};
|
||||
|
@ -1,9 +1,7 @@
|
||||
use cors::Cors;
|
||||
use once_cell::sync::OnceCell;
|
||||
use sqlx::mysql::MySqlPoolOptions;
|
||||
use sqlx::Connection;
|
||||
use sqlx::MySql;
|
||||
use sqlx::MySqlConnection;
|
||||
use sqlx::Pool;
|
||||
use std::env;
|
||||
use std::time::Instant;
|
||||
|
0
backend/src/online_classroom/course_disenroll.rs
Normal file
0
backend/src/online_classroom/course_disenroll.rs
Normal file
@ -1,10 +1,12 @@
|
||||
use super::session::request;
|
||||
use regex::Regex;
|
||||
use scraper::{Html, Selector};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct ClassroomCourse {
|
||||
name: String,
|
||||
course_id: i32,
|
||||
}
|
||||
|
||||
/// Returns all the courses the user is enrolled in
|
||||
@ -59,7 +61,62 @@ pub async fn get_courses(user_id: i32) -> Result<Vec<ClassroomCourse>, String> {
|
||||
}
|
||||
|
||||
let course_name = td_els[1].inner_html();
|
||||
courses.push(ClassroomCourse { name: course_name })
|
||||
|
||||
let course_actions_container = td_els[5];
|
||||
let anchor_container_children = course_actions_container.children().collect::<Vec<_>>();
|
||||
let delete_anchor = anchor_container_children.get(5);
|
||||
|
||||
let delete_anchor = match delete_anchor {
|
||||
Some(anchor) => anchor,
|
||||
None => {
|
||||
return Err(format!(
|
||||
"Error parsing tr: delete anchor not found in td[5] inner html: {}",
|
||||
course_name
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
// user_information.php?action=unsubscribe&course_id=14&user_id=2421
|
||||
let delete_anchor_href = match delete_anchor.value().as_element().unwrap().attr("href") {
|
||||
Some(href) => href,
|
||||
None => {
|
||||
return Err(format!(
|
||||
"Error parsing tr: delete anchor href not found: {}",
|
||||
course_name
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let re = Regex::new(r"course_id=(\d+)").unwrap();
|
||||
let captures = match re.captures(delete_anchor_href) {
|
||||
Some(c) => c,
|
||||
None => {
|
||||
log::info!("course_href: {}", delete_anchor_href);
|
||||
return Err(format!(
|
||||
"Error parsing tr: link course id not found. course: {}",
|
||||
course_name
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let course_id_str = captures.get(1).unwrap().as_str();
|
||||
|
||||
let course_id_result = course_id_str.parse::<i32>();
|
||||
let course_id = match course_id_result {
|
||||
Ok(id) => id,
|
||||
Err(_) => {
|
||||
log::info!("matched course_id: {}", course_id_str);
|
||||
return Err(format!(
|
||||
"Error parsing course_id: not a number. course: {}",
|
||||
course_name
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
courses.push(ClassroomCourse {
|
||||
name: course_name,
|
||||
course_id,
|
||||
})
|
||||
}
|
||||
|
||||
Ok(courses)
|
||||
|
@ -11,6 +11,7 @@ pub mod register_course;
|
||||
mod session;
|
||||
pub mod update_expiration_date;
|
||||
pub mod user;
|
||||
pub mod course_disenroll;
|
||||
|
||||
/// Tries to connect to the online classroom, and gets a session cookie
|
||||
/// if neccesary.
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { For, Show, createEffect, onMount } from "solid-js";
|
||||
import { For, Show, createEffect } from "solid-js";
|
||||
import { LoadingStatus, backend, useLoading, wait } from "../../utils/functions";
|
||||
import { JsonResult } from "../../types/JsonResult";
|
||||
import { ClassroomCourse } from "../../types/ClassroomCourse";
|
||||
@ -8,8 +8,7 @@ import { XIcon } from "../../icons/XIcon";
|
||||
import { QuestionIcon } from "../../icons/QuestionIcon";
|
||||
|
||||
export function CoursesList(props: {userid: number, updateSignal: number, courses: Array<ClassroomCourse>, setCourses: (c: Array<ClassroomCourse>) => void}) {
|
||||
|
||||
const {setError, status, setStatus} = useLoading();
|
||||
const {error, setError, status, setStatus} = useLoading();
|
||||
|
||||
const loadCourses = async() => {
|
||||
setStatus(LoadingStatus.Loading);
|
||||
@ -30,7 +29,7 @@ export function CoursesList(props: {userid: number, updateSignal: number, course
|
||||
});
|
||||
};
|
||||
|
||||
onMount(loadCourses);
|
||||
// onMount(loadCourses);
|
||||
|
||||
createEffect(() => {
|
||||
// Update courses when updateSignal changes
|
||||
@ -61,6 +60,13 @@ export function CoursesList(props: {userid: number, updateSignal: number, course
|
||||
<For each={props.courses}>
|
||||
{(c) => <Course course={c} />}
|
||||
</For>
|
||||
|
||||
<Show when={error() !== ""}>
|
||||
<p class="text-c-error">
|
||||
Error recuperando cursos: {error()}
|
||||
</p>
|
||||
</Show>
|
||||
|
||||
<Show when={status() === LoadingStatus.Ok && props.courses.length === 0}>
|
||||
<div class="px-4 pb-2 text-center">
|
||||
<div class="text-center pt-6 pb-4">
|
||||
|
@ -1,5 +1,6 @@
|
||||
export type ClassroomCourse = {
|
||||
name: string
|
||||
name: string,
|
||||
course_id: number,
|
||||
}
|
||||
|
||||
export type ClassroomCourseValue =
|
||||
|
Loading…
Reference in New Issue
Block a user