use rocket::{http::Status, serde::json::Json};

use crate::json_result::JsonResult;

use self::session::ensure_session;

pub mod create_user;
pub mod get_courses;
pub mod get_expiration_date;
pub mod register_course;
mod session;
pub mod update_expiration_date;
pub mod user;

/// Tries to connect to the online classroom, and get a session cookie
#[get("/classroom/connect")]
pub async fn connection() -> (Status, Json<JsonResult<()>>) {
    match ensure_session().await {
        Ok(_) => (Status::Ok, JsonResult::ok(())),
        Err(err) => (Status::Ok, JsonResult::err(err)),
    }
}
