From 894977663967a26ee436885da34d9b11ca085fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=90=91=E5=A4=9C?= Date: Tue, 10 Dec 2024 19:14:06 +0800 Subject: [PATCH] feat(contest): remove contest rank --- Cargo.lock | 2 +- src/models/contest.rs | 9 --------- src/routes/contest.rs | 21 +-------------------- src/utils/contest.rs | 34 +--------------------------------- 4 files changed, 3 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 77daefd..becf7f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,7 +71,7 @@ dependencies = [ [[package]] name = "algohub-server" -version = "0.1.15" +version = "0.1.16" dependencies = [ "anyhow", "chrono", diff --git a/src/models/contest.rs b/src/models/contest.rs index d5c50e0..c447ced 100644 --- a/src/models/contest.rs +++ b/src/models/contest.rs @@ -127,12 +127,3 @@ pub struct ContestProblem { pub submitted_count: u32, pub accepted_count: u32, } - -#[derive(Serialize, Deserialize, Debug)] -#[serde(rename_all = "camelCase")] -pub struct ContestRank { - name: String, - problem_id: String, - accepted: bool, - wrongs: u32, -} diff --git a/src/routes/contest.rs b/src/routes/contest.rs index e183f4f..43dc78e 100644 --- a/src/routes/contest.rs +++ b/src/routes/contest.rs @@ -3,7 +3,7 @@ use surrealdb::{engine::remote::ws::Client, sql::Thing, Surreal}; use crate::{ models::{ - contest::{AddProblems, ContestProblem, ContestRank, CreateContest, UserContest}, + contest::{AddProblems, ContestProblem, CreateContest, UserContest}, error::Error, response::{Empty, Response}, Credentials, OwnedId, @@ -117,25 +117,6 @@ pub async fn get( })) } -#[post("/rank/", data = "")] -pub async fn rank( - db: &State>, - id: &str, - auth: Json>, -) -> Result> { - if !session::verify(db, auth.id, auth.token).await { - return Err(Error::Unauthorized(Json("Invalid credentials".into()))); - } - - let rank = contest::rank(db, id).await?; - - Ok(Json(Response { - success: true, - message: "Contest rank retrieved successfully".into(), - data: Some(rank), - })) -} - pub fn routes() -> Vec { use rocket::routes; routes![create, get, add_problems, list_problems, list_all] diff --git a/src/utils/contest.rs b/src/utils/contest.rs index 54d13ca..70cd0a2 100644 --- a/src/utils/contest.rs +++ b/src/utils/contest.rs @@ -1,7 +1,7 @@ use anyhow::Result; use surrealdb::{engine::remote::ws::Client, sql::Thing, Surreal}; -use crate::models::contest::{Contest, ContestData, ContestProblem, ContestRank}; +use crate::models::contest::{Contest, ContestData, ContestProblem}; pub async fn create( db: &Surreal, @@ -105,35 +105,3 @@ pub async fn remove_problem( .await? .take(0)?) } - -const RANK_QUERY: &str = r#" -SELECT VALUE array::map((SELECT VALUE id FROM type::thing("contest", $id).problems), |$problem| { - LET $submissions = SELECT judge_result.status.type AS status, created_at - FROM submission WHERE problem.id == $problem AND $parent.id == creator ORDER BY created_at ASC; - LET $first_accepted = array::find_index($submissions, |$submission| { - RETURN $submission.status == "accepted" - }); - RETURN IF $first_accepted { - RETURN { - name: $problem.title, - problem_id: record::id($problem), - accepted: true, - wrongs: count($submissions) - $first_accepted - 1, - } - } ELSE { - RETURN { - name: $problem.title, - problem_id: record::id($problem), - accepted: false, - wrongs: count($submissions), - } - } -}) FROM array::distinct(SELECT VALUE creator FROM submission) -"#; -pub async fn rank(db: &Surreal, id: &str) -> Result> { - Ok(db - .query(RANK_QUERY) - .bind(("id", id.to_string())) - .await? - .take(0)?) -}