Skip to content

Commit

Permalink
provide whitelist information on /Whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
harryob committed Oct 30, 2024
1 parent 76ca0dc commit 2610823
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod logging;
mod player;
mod stickyban;
mod ticket;
mod whitelist;

#[rocket::async_trait]
impl Fairing for CORS {
Expand Down Expand Up @@ -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],
)
}
27 changes: 27 additions & 0 deletions src/whitelist.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
whitelist_status: Option<String>,
}

#[get("/")]
pub async fn get_all_whitelistees(mut db: Connection<Cmdb>) -> Json<Vec<WhitelistPlayer>> {
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()),
}
}

0 comments on commit 2610823

Please sign in to comment.