diff --git a/src/config.rs b/src/config.rs index 5878568..58d1fcb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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, @@ -8,15 +8,6 @@ pub struct Config { pub webhook: Option, } -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(); diff --git a/src/main.rs b/src/main.rs index aae6333..38510de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 = JSONStore::new("./locations"); - for location in locations.deref_mut() { + for location in &mut *locations { location.1.add(location.0).await; } let mut flows: JSONStore = JSONStore::new("./flows"); - for flow in flows.deref_mut() { + for flow in &mut *flows { flow.1.add(flow.0).await; } diff --git a/src/routes/flow.rs b/src/routes/flow.rs index 7b698f6..069aab0 100644 --- a/src/routes/flow.rs +++ b/src/routes/flow.rs @@ -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//info")] diff --git a/src/routes/item/location.rs b/src/routes/item/location.rs index 0bcca4f..b1be02f 100644 --- a/src/routes/item/location.rs +++ b/src/routes/item/location.rs @@ -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!( diff --git a/src/routes/item/mod.rs b/src/routes/item/mod.rs index 004006a..a05ddea 100644 --- a/src/routes/item/mod.rs +++ b/src/routes/item/mod.rs @@ -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| { diff --git a/src/transaction.rs b/src/transaction.rs index 64e9bf7..4a58772 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -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