add transaction move
This commit is contained in:
parent
e26c8b3469
commit
0d4ed15460
3 changed files with 32 additions and 3 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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/<id>/move", data = "<form>")]
|
||||
pub async fn move_transaction_route(id: &str, form: Json<MoveTransaction>) -> 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 }))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue