From 55b318b2f17b6c74caac16eb1b22b3ee7c690202 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Mon, 7 Oct 2024 21:15:57 +0200 Subject: [PATCH] fix --- src/location.rs | 6 ++++-- src/main.rs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/location.rs b/src/location.rs index 81bd6fe..dafb65d 100644 --- a/src/location.rs +++ b/src/location.rs @@ -50,8 +50,10 @@ impl Location { let locations = get_locations!(); for loc in locations.keys() { let loc = locations.get(loc).unwrap(); - if *loc.parent.as_ref().unwrap_or(&String::new()) == self.id { - ret.push(loc.clone()); + if let Some(parent) = &loc.parent { + if *parent == self.id { + ret.push(loc.clone()); + } } } diff --git a/src/main.rs b/src/main.rs index a14eed9..bdcfa6e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,7 +59,15 @@ macro_rules! get_locations { if let Some(client) = $crate::LOCATIONS.get() { client } else { - let locations = $crate::JSONStore::new("./locations"); + let mut locations: $crate::json_store::JSONStore<$crate::location::Location> = + $crate::JSONStore::new("./locations"); + + let loc_keys: Vec<_> = locations.keys().cloned().collect(); + for loc in loc_keys { + let location = locations.get_mut(&loc).unwrap(); + location.id = loc.clone(); + } + $crate::LOCATIONS.set(locations).unwrap(); $crate::LOCATIONS.get().unwrap() } @@ -98,6 +106,10 @@ async fn rocket() -> _ { .to_cors() .expect("error creating CORS options"); + let pg = get_pg!(); + + sqlx::migrate!("./migrations").run(pg).await.unwrap(); + let config = config::get_config(); let itemdb = get_itemdb!().clone(); let locations = get_locations!().clone();