diff --git a/aw-datastore/src/datastore.rs b/aw-datastore/src/datastore.rs index ae1d196b..2caa1c37 100644 --- a/aw-datastore/src/datastore.rs +++ b/aw-datastore/src/datastore.rs @@ -12,7 +12,6 @@ use serde_json::value::Value; use aw_models::Bucket; use aw_models::BucketMetadata; use aw_models::Event; -use aw_models::KeyValue; use rusqlite::params; use rusqlite::types::ToSql; @@ -897,7 +896,7 @@ impl DatastoreInstance { Ok(()) } - pub fn get_key_value(&self, conn: &Connection, key: &str) -> Result { + pub fn get_key_value(&self, conn: &Connection, key: &str) -> Result { let mut stmt = match conn.prepare( " SELECT * FROM key_value WHERE KEY = ?1", @@ -911,10 +910,7 @@ impl DatastoreInstance { }; match stmt.query_row([key], |row| { - Ok(KeyValue { - key: row.get(0)?, - value: row.get(1)?, - }) + Ok(row.get(1)?) }) { Ok(result) => Ok(result), Err(err) => match err { diff --git a/aw-datastore/src/worker.rs b/aw-datastore/src/worker.rs index 11fa5c0a..82541537 100644 --- a/aw-datastore/src/worker.rs +++ b/aw-datastore/src/worker.rs @@ -13,7 +13,6 @@ use rusqlite::TransactionBehavior; use aw_models::Bucket; use aw_models::Event; -use aw_models::KeyValue; use crate::DatastoreError; use crate::DatastoreInstance; @@ -51,7 +50,7 @@ pub enum Response { Event(Event), EventList(Vec), Count(i64), - KeyValue(KeyValue), + KeyValue(String), KeyValues(HashMap) } @@ -488,7 +487,7 @@ impl Datastore { } } - pub fn get_key_value(&self, key: &str) -> Result { + pub fn get_key_value(&self, key: &str) -> Result { let cmd = Command::GetKeyValue(key.to_string()); let receiver = self.requester.request(cmd).unwrap(); diff --git a/aw-models/src/key_value.rs b/aw-models/src/key_value.rs deleted file mode 100644 index 60d13a88..00000000 --- a/aw-models/src/key_value.rs +++ /dev/null @@ -1,28 +0,0 @@ -use chrono::{DateTime, Utc}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use serde_json::Value; - -#[derive(Serialize, Deserialize, JsonSchema)] -pub struct Key { - pub key: String, -} - -#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug, PartialEq)] -pub struct KeyValue { - pub key: String, - pub value: Value, -} - -impl KeyValue { - pub fn new, V: Into>( - key: K, - value: V, - timestamp: DateTime, - ) -> KeyValue { - KeyValue { - key: key.into(), - value: value.into(), - } - } -} diff --git a/aw-models/src/lib.rs b/aw-models/src/lib.rs index 6f227443..157f7cfc 100644 --- a/aw-models/src/lib.rs +++ b/aw-models/src/lib.rs @@ -20,7 +20,6 @@ mod bucket; mod duration; mod event; mod info; -mod key_value; mod query; mod timeinterval; mod tryvec; @@ -30,8 +29,6 @@ pub use self::bucket::BucketMetadata; pub use self::bucket::BucketsExport; pub use self::event::Event; pub use self::info::Info; -pub use self::key_value::Key; -pub use self::key_value::KeyValue; pub use self::query::Query; pub use self::timeinterval::TimeInterval; pub use self::tryvec::TryVec; diff --git a/aw-server/src/endpoints/settings.rs b/aw-server/src/endpoints/settings.rs index a40367b9..5babe9e8 100644 --- a/aw-server/src/endpoints/settings.rs +++ b/aw-server/src/endpoints/settings.rs @@ -1,5 +1,4 @@ use crate::endpoints::ServerState; -use aw_query::query; use rocket::http::Status; use rocket::serde::json::Json; use rocket::State; @@ -54,7 +53,7 @@ pub fn setting_get( let datastore = endpoints_get_lock!(state.datastore); match datastore.get_key_value(&setting_key) { - Ok(kv) => Ok(Json(kv.value)), + Ok(value) => Ok(Json(serde_json::from_str(&value).unwrap())), Err(err) => Err(err.into()), } } diff --git a/aw-server/tests/api.rs b/aw-server/tests/api.rs index 19e32d0f..bfdfda0b 100644 --- a/aw-server/tests/api.rs +++ b/aw-server/tests/api.rs @@ -11,14 +11,12 @@ mod api_tests { use std::path::PathBuf; use std::sync::Mutex; - use chrono::{DateTime, Utc}; use rocket::http::{ContentType, Header, Status}; use serde_json::{json, Value}; use aw_server::config; use aw_server::endpoints; - use aw_models::KeyValue; use aw_models::{Bucket, BucketsExport}; use rocket::local::blocking::Client;