From 4d5436bca9c73bd6af15dd0b01dbe97dd8b819c9 Mon Sep 17 00:00:00 2001 From: BloxerHD018 Date: Thu, 23 Apr 2026 17:19:49 +0100 Subject: [PATCH] Add get_wup Admin API routes --- Cargo.toml | 2 +- src/api/get_files_wup.rs | 50 ++++++++++++++++++++++++++++++++++++++++ src/api/mod.rs | 1 + src/main.rs | 2 ++ src/models/file_wup.rs | 4 ++-- 5 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/api/get_files_wup.rs diff --git a/Cargo.toml b/Cargo.toml index d1e82ce..2c0be67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ sqlx = { version = "0.8.3", features = [ "postgres", "runtime-tokio", "macros", serde = { version = "1.0", features = [ "derive" ] } serde_json = "1" quick-xml = { version = "0.31", features = [ "serialize" ] } -chrono = "0.4" +chrono = { version = "0.4", features = [ "serde" ] } sha1 = "0.10" sha2 = "0.10" hex = "0.4" diff --git a/src/api/get_files_wup.rs b/src/api/get_files_wup.rs new file mode 100644 index 0000000..6001b12 --- /dev/null +++ b/src/api/get_files_wup.rs @@ -0,0 +1,50 @@ +use rocket::{State, http::Status, serde::json::Json}; +use serde::Deserialize; +use crate::Pool; +use crate::auth::Auth; +use crate::database::{get_wup_task_file_by_data_id, get_wup_task_files}; +use crate::models::file_wup::FileWUP; + +#[derive(Deserialize)] +pub struct GetFilesWUPOptions { + pub allow_deleted: bool, + pub boss_app_id: String, + pub task_id: String, + pub country: Option, + pub language: Option, + pub any: Option, +} + +#[rocket::get("/api/v1/get_wup", data = "")] +pub async fn get_files_wup( + pool: &State, + input: Json, + _auth: Auth, +) -> Json> { + let data = input.into_inner(); + + let files = get_wup_task_files( + pool, + data.allow_deleted, + data.boss_app_id, + data.task_id, + data.country, + data.language, + data.any, + ).await; + + return Json(files); +} + +#[rocket::get("/api/v1/get_wup/")] +pub async fn get_file_wup_by_data_id( + pool: &State, + id: i64, + _auth: Auth, +) -> Result, Status> { + if let Some(file) = get_wup_task_file_by_data_id(pool, id).await { + return Ok(Json(file)); + } else { + return Err(Status::NotFound); + } +} diff --git a/src/api/mod.rs b/src/api/mod.rs index 1edcd91..03f59e6 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,2 +1,3 @@ pub mod upload_file_wup; +pub mod get_files_wup; pub mod add_task; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 79f05b2..1d63615 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,6 +82,8 @@ async fn launch() -> _ { services::npdi::data, api::upload_file_wup::upload_file_wup, api::add_task::add_task, + api::get_files_wup::get_files_wup, + api::get_files_wup::get_file_wup_by_data_id, ]) .register("/", catchers![not_found]) } \ No newline at end of file diff --git a/src/models/file_wup.rs b/src/models/file_wup.rs index 466b08c..0627d84 100644 --- a/src/models/file_wup.rs +++ b/src/models/file_wup.rs @@ -71,7 +71,7 @@ pub struct FileWUPAttributes { pub description: String, } -#[derive(FromRow, Clone)] +#[derive(FromRow, Clone, Serialize)] pub struct FileWUP { pub deleted: bool, pub file_key: String, @@ -92,4 +92,4 @@ pub struct FileWUP { pub auto_delete: bool, pub created: NaiveDateTime, pub updated: NaiveDateTime, -} \ No newline at end of file +}