docs + locations

This commit is contained in:
JMARyA 2024-09-02 18:40:02 +02:00
parent e1618b40ef
commit 48f00d8f6f
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
17 changed files with 390 additions and 33 deletions

View file

@ -0,0 +1,26 @@
use mongod::ToAPI;
use rocket::{get, State};
use crate::{
json_store::JSONStore,
location::Location,
routes::{api_error, FallibleApiResponse},
};
#[get("/location/<id>")]
pub async fn location_info(
id: &str,
locations: &State<JSONStore<Location>>,
) -> FallibleApiResponse {
let loc = locations
.get(id)
.ok_or_else(|| api_error("No location with that ID"))?;
Ok(loc.api().await)
}
#[get("/locations")]
pub async fn locations_info(locations: &State<JSONStore<Location>>) -> FallibleApiResponse {
// todo : recursive location map
unimplemented!()
}

View file

@ -1,9 +1,11 @@
mod demand;
mod error;
mod location;
mod supply;
pub use demand::*;
pub use error::*;
pub use location::*;
use mongod::Model;
use mongod::ToAPI;
pub use supply::*;

View file

@ -16,6 +16,7 @@ pub struct SupplyForm {
variant: String,
price: String,
origin: Option<String>,
location: Option<String>,
}
/// Route for supply action. Creates a new Transaction for the specified Item Variant.
@ -35,6 +36,7 @@ pub async fn supply_route(form: Json<SupplyForm>, itemdb: &State<ItemDB>) -> Fal
.try_into()
.map_err(|()| api_error("Price malformed"))?,
form.origin.as_deref(),
form.location.as_deref(),
)
.await;