diff --git a/Cargo.lock b/Cargo.lock index 80f48b3..dc86895 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1282,7 +1282,7 @@ dependencies = [ [[package]] name = "mongod" version = "0.2.2" -source = "git+https://git.hydrar.de/jmarya/mongod#b0bae64efcfdc833c3b9e8508bf228c9299c1d21" +source = "git+https://git.hydrar.de/jmarya/mongod#58150002e60802d7b00fe0537e4a2e8c4e389a4a" dependencies = [ "chrono", "futures", @@ -1298,7 +1298,7 @@ dependencies = [ [[package]] name = "mongod_derive" version = "0.1.0" -source = "git+https://git.hydrar.de/jmarya/mongod#b0bae64efcfdc833c3b9e8508bf228c9299c1d21" +source = "git+https://git.hydrar.de/jmarya/mongod#58150002e60802d7b00fe0537e4a2e8c4e389a4a" dependencies = [ "case", "proc-macro2", diff --git a/src/main.rs b/src/main.rs index fd01f4f..370c984 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,7 +89,8 @@ async fn rocket() -> _ { routes::item::variant_price_history_by_origin, routes::flow::end_flow_route, routes::flow::continue_flow_route, - routes::flow::create_flow_route + routes::flow::create_flow_route, + routes::item::move_transaction_route ], ) .manage(itemdb) diff --git a/src/routes/item/mod.rs b/src/routes/item/mod.rs index f94aa01..f8ff454 100644 --- a/src/routes/item/mod.rs +++ b/src/routes/item/mod.rs @@ -7,8 +7,13 @@ mod supply; pub use demand::*; pub use error::*; pub use location::*; +use mongod::reference_of; use mongod::Model; use mongod::ToAPI; +use rocket::post; +use rocket::serde::json::Json; +use serde::Deserialize; +use serde::Serialize; pub use stat::*; pub use supply::*; @@ -20,6 +25,7 @@ use crate::check_auth; use crate::config::Config; use crate::db::get_items_without_min_satisfied; use crate::db::ItemDB; +use crate::location::Location; use crate::routes::Token; use crate::transaction::Transaction; @@ -143,3 +149,25 @@ pub async fn min_items_route( Ok(json!(t)) } + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct MoveTransaction { + pub to: String, +} + +#[post("/transaction//move", data = "
")] +pub async fn move_transaction_route(id: &str, form: Json) -> FallibleApiResponse { + let new_loc = &form.to; + Transaction::get(id) + .await + .ok_or_else(|| api_error("No such transaction"))? + .change() + .location(Some( + reference_of!(Location, new_loc).ok_or_else(|| api_error("No such location"))?, + )) + .update() + .await + .unwrap(); + + Ok(json!({"ok": 1 })) +}