From 2610823824aeff928e227d66d24f66c3ad356b80 Mon Sep 17 00:00:00 2001 From: harryob <55142896+harryob@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:26:23 +0000 Subject: [PATCH] provide whitelist information on `/Whitelist` --- src/main.rs | 5 +++++ src/whitelist.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/whitelist.rs diff --git a/src/main.rs b/src/main.rs index ce2103d..0a506fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,7 @@ mod logging; mod player; mod stickyban; mod ticket; +mod whitelist; #[rocket::async_trait] impl Fairing for CORS { @@ -139,4 +140,8 @@ fn rocket() -> _ { format!("{}/Ticket", base_url), routes![ticket::get_tickets_by_round_id, ticket::get_tickets_by_user], ) + .mount( + format!("{base_url}/Whitelist"), + routes![whitelist::get_all_whitelistees], + ) } diff --git a/src/whitelist.rs b/src/whitelist.rs new file mode 100644 index 0000000..08d4f44 --- /dev/null +++ b/src/whitelist.rs @@ -0,0 +1,27 @@ +use rocket::serde::json::Json; +use rocket_db_pools::Connection; +use serde::Serialize; +use sqlx::{prelude::FromRow, query_as}; + +use crate::Cmdb; + +#[derive(Serialize, FromRow)] +#[serde(rename_all = "camelCase")] +pub struct WhitelistPlayer { + id: i64, + ckey: Option, + whitelist_status: Option, +} + +#[get("/")] +pub async fn get_all_whitelistees(mut db: Connection) -> Json> { + match query_as( + "SELECT id, ckey, whitelist_status FROM players WHERE (whitelist_status is not null AND LENGTH(whitelist_status) > 0)", + ) + .fetch_all(&mut **db) + .await + { + Ok(result) => Json(result), + Err(_) => Json(Vec::new()), + } +}