This commit is contained in:
JMARyA 2024-09-12 11:54:52 +02:00
parent 02966c0605
commit fb6a96ff55
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 15 additions and 37 deletions

View file

@ -1,6 +1,6 @@
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Default, Clone, Deserialize)]
pub struct Config {
/// Allowed tokens for access
pub allowed_tokens: Vec<String>,
@ -8,15 +8,6 @@ pub struct Config {
pub webhook: Option<Webhook>,
}
impl Default for Config {
fn default() -> Self {
Self {
allowed_tokens: Vec::new(),
webhook: None,
}
}
}
pub fn get_config() -> Config {
if let Ok(content) = std::fs::read_to_string("./config.toml") {
return toml::from_str(&content).unwrap();

View file

@ -1,5 +1,3 @@
use std::ops::{Deref, DerefMut};
use flow::FlowInfo;
use json_store::JSONStore;
use location::Location;
@ -52,13 +50,13 @@ async fn rocket() -> _ {
let itemdb = db::ItemDB::new("./itemdb").await;
let mut locations: JSONStore<Location> = JSONStore::new("./locations");
for location in locations.deref_mut() {
for location in &mut *locations {
location.1.add(location.0).await;
}
let mut flows: JSONStore<FlowInfo> = JSONStore::new("./flows");
for flow in flows.deref_mut() {
for flow in &mut *flows {
flow.1.add(flow.0).await;
}

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
use mongod::{vec_to_api, ToAPI};
use mongod::ToAPI;
use rocket::{get, State};
use serde_json::json;
@ -9,9 +9,7 @@ use crate::{
config::Config,
flow::FlowInfo,
json_store::JSONStore,
location::Location,
routes::{api_error, FallibleApiResponse, Token},
transaction::Transaction,
};
#[get("/flow/<id>/info")]

View file

@ -1,4 +1,4 @@
use std::{collections::HashMap, ops::Deref};
use std::collections::HashMap;
use mongod::{vec_to_api, ToAPI};
use rocket::{get, State};
@ -42,7 +42,7 @@ async fn location_api_resolve(
if parent == id {
sub_l.insert(
sub_loc.0.clone(),
Box::pin(location_api_resolve(&sub_loc.0, &sub_loc.1, locations)).await,
Box::pin(location_api_resolve(sub_loc.0, sub_loc.1, locations)).await,
);
}
}
@ -52,7 +52,7 @@ async fn location_api_resolve(
.as_object_mut()
.unwrap()
.insert("sub".to_string(), serde_json::to_value(sub_l).unwrap());
return loc_api;
loc_api
}
#[get("/locations")]
@ -82,7 +82,7 @@ pub async fn locations_info(
let mut root_locations = HashMap::new();
for loc in locations.inner().deref() {
for loc in &**locations.inner() {
if loc.1.parent.is_none() {
root_locations.insert(loc.0, loc.1);
}
@ -109,15 +109,10 @@ pub async fn location_inventory(
) -> FallibleApiResponse {
check_auth!(t, c);
if let Some(rec) = recursive {
match rec {
"true" | "yes" | "1" => {
return Ok(json!(
vec_to_api(&Transaction::in_location_recursive(location).await).await
));
}
_ => {}
}
if let Some("true" | "yes" | "1") = recursive {
return Ok(json!(
vec_to_api(&Transaction::in_location_recursive(location).await).await
));
}
Ok(json!(

View file

@ -127,7 +127,7 @@ pub async fn min_items_route(
) -> FallibleApiResponse {
check_auth!(t, c);
let t: Vec<_> = get_items_without_min_satisfied(&itemdb)
let t: Vec<_> = get_items_without_min_satisfied(itemdb)
.await
.into_iter()
.map(|x| {

View file

@ -103,11 +103,7 @@ impl Transaction {
let expiration_ts = expiry * 24 * 60 * 60;
if (date_added + expiration_ts) < current_time {
return true;
} else {
return false;
}
return (date_added + expiration_ts) < current_time;
}
false
@ -128,7 +124,7 @@ impl Transaction {
Self::find(doc! { "location": loc.id() }, None, None)
.await
.unwrap(),
)
);
}
transactions