diff --git a/giterated-daemon/src/database_backend/handler.rs b/giterated-daemon/src/database_backend/handler.rs index ac1f4c6..15f11e0 100644 --- a/giterated-daemon/src/database_backend/handler.rs +++ b/giterated-daemon/src/database_backend/handler.rs @@ -61,6 +61,7 @@ pub async fn repository_info( backend: Arc, requester: Option, ) -> Result> { + info!("Called"); let mut object = backend .get_object::(&object.to_string(), &operation_state) .await diff --git a/giterated-models/src/object.rs b/giterated-models/src/object.rs index cae9377..3eddac4 100644 --- a/giterated-models/src/object.rs +++ b/giterated-models/src/object.rs @@ -83,7 +83,7 @@ impl< .await .unwrap(); - Ok(serde_json::from_value(result).unwrap()) + Ok(serde_json::from_slice(&result).unwrap()) } pub async fn get_setting( diff --git a/giterated-models/src/value.rs b/giterated-models/src/value.rs index 5a566e9..888145f 100644 --- a/giterated-models/src/value.rs +++ b/giterated-models/src/value.rs @@ -20,7 +20,7 @@ impl GiteratedOperation for GetValue { fn operation_name() -> &'static str { "get_value" } - type Success = Value; + type Success = Vec; type Failure = GetValueError; } diff --git a/giterated-stack/src/meta/mod.rs b/giterated-stack/src/meta/mod.rs index f85ef5c..516f789 100644 --- a/giterated-stack/src/meta/mod.rs +++ b/giterated-stack/src/meta/mod.rs @@ -74,9 +74,6 @@ impl RuntimeMetadata { >( &mut self, ) { - let _object_name = O::object_name().to_string(); - let _value_name = V::value_name().to_string(); - if self .values .insert(ObjectValuePair::from_types::(), ValueMeta::new::()) diff --git a/giterated-stack/src/stack.rs b/giterated-stack/src/stack.rs index 4399df9..015343f 100644 --- a/giterated-stack/src/stack.rs +++ b/giterated-stack/src/stack.rs @@ -17,7 +17,8 @@ use giterated_models::{ operation::GiteratedOperation, settings::{GetSetting, SetSetting}, }; -use tracing::trace; +use serde_json::Value; +use tracing::{info, trace}; use crate::handler::HandlerTree; use crate::provider::MetadataProvider; @@ -305,6 +306,8 @@ impl GiteratedStack { OperationError::Unhandled => OperationError::Unhandled, }); + let result = result.map(|r| serde_json::to_vec(&r).unwrap()); + return result; } else if message.operation == "get_setting" { let operation: GetSetting = serde_json::from_slice(&message.payload.0).unwrap(); @@ -672,16 +675,19 @@ impl ObjectBackend for Arc { // We need to hijack get_value, set_setting, and get_setting. if operation_name == "get_value" { - let mut value_meta = None; - for (_, meta) in self.metadata.values.iter() { - if (meta.is_get_value_typed)(operation.clone()) { - value_meta = Some(meta); - break; - } - } - - let value_meta = value_meta.ok_or_else(|| OperationError::Unhandled)?; + let get_value = operation + .0 + .downcast_ref::() + .ok_or_else(|| OperationError::Unhandled)?; + let value_meta = self + .metadata + .values + .get(&ObjectValuePair { + object_kind: O::object_name(), + value_kind: &get_value.value_name, + }) + .ok_or_else(|| OperationError::Unhandled)?; let value_name = value_meta.name.clone(); trace!( @@ -699,11 +705,20 @@ impl ObjectBackend for Arc { continue; } + trace!( + "Calling handler for get_value {}::{}", + O::object_name(), + value_name + ); + return match getter .handle((object.clone(),), operation_state.clone()) .await { - Ok(success) => Ok(success.0.downcast_ref::().unwrap().clone()), + Ok(success) => Ok(*(Box::new((value_meta.serialize)(success).unwrap()) + as Box) + .downcast() + .unwrap()), Err(err) => Err(match err { OperationError::Operation(failure) => OperationError::Operation( failure.0.downcast_ref::().unwrap().clone(), @@ -719,8 +734,6 @@ impl ObjectBackend for Arc { }), }; } - - return Err(OperationError::Unhandled); } else if operation.0.is::() { let get_setting: &GetSetting = operation.0.downcast_ref().unwrap(); let setting_name = get_setting.setting_name.clone();