Fix internal call values
parent: tbd commit: 8e8ab90
Showing 5 changed files with 29 insertions and 18 deletions
giterated-daemon/src/database_backend/handler.rs
@@ -61,6 +61,7 @@ pub async fn repository_info( | ||
61 | 61 | backend: Arc<GiteratedStack>, |
62 | 62 | requester: Option<AuthenticatedUser>, |
63 | 63 | ) -> Result<RepositoryView, OperationError<RepositoryError>> { |
64 | info!("Called"); | |
64 | 65 | let mut object = backend |
65 | 66 | .get_object::<Repository>(&object.to_string(), &operation_state) |
66 | 67 | .await |
giterated-models/src/object.rs
@@ -83,7 +83,7 @@ impl< | ||
83 | 83 | .await |
84 | 84 | .unwrap(); |
85 | 85 | |
86 | Ok(serde_json::from_value(result).unwrap()) | |
86 | Ok(serde_json::from_slice(&result).unwrap()) | |
87 | 87 | } |
88 | 88 | |
89 | 89 | pub async fn get_setting<S: Setting + Send + Clone + Debug>( |
giterated-models/src/value.rs
@@ -20,7 +20,7 @@ impl<O: GiteratedObject + Send> GiteratedOperation<O> for GetValue { | ||
20 | 20 | fn operation_name() -> &'static str { |
21 | 21 | "get_value" |
22 | 22 | } |
23 | type Success = Value; | |
23 | type Success = Vec<u8>; | |
24 | 24 | type Failure = GetValueError; |
25 | 25 | } |
26 | 26 |
giterated-stack/src/meta/mod.rs
@@ -74,9 +74,6 @@ impl RuntimeMetadata { | ||
74 | 74 | >( |
75 | 75 | &mut self, |
76 | 76 | ) { |
77 | let _object_name = O::object_name().to_string(); | |
78 | let _value_name = V::value_name().to_string(); | |
79 | ||
80 | 77 | if self |
81 | 78 | .values |
82 | 79 | .insert(ObjectValuePair::from_types::<O, V>(), ValueMeta::new::<V>()) |
giterated-stack/src/stack.rs
@@ -17,7 +17,8 @@ use giterated_models::{ | ||
17 | 17 | operation::GiteratedOperation, |
18 | 18 | settings::{GetSetting, SetSetting}, |
19 | 19 | }; |
20 | use tracing::trace; | |
20 | use serde_json::Value; | |
21 | use tracing::{info, trace}; | |
21 | 22 | |
22 | 23 | use crate::handler::HandlerTree; |
23 | 24 | use crate::provider::MetadataProvider; |
@@ -305,6 +306,8 @@ impl GiteratedStack { | ||
305 | 306 | OperationError::Unhandled => OperationError::Unhandled, |
306 | 307 | }); |
307 | 308 | |
309 | let result = result.map(|r| serde_json::to_vec(&r).unwrap()); | |
310 | ||
308 | 311 | return result; |
309 | 312 | } else if message.operation == "get_setting" { |
310 | 313 | let operation: GetSetting = serde_json::from_slice(&message.payload.0).unwrap(); |
@@ -672,16 +675,19 @@ impl ObjectBackend<StackOperationState> for Arc<GiteratedStack> { | ||
672 | 675 | |
673 | 676 | // We need to hijack get_value, set_setting, and get_setting. |
674 | 677 | if operation_name == "get_value" { |
675 | let mut value_meta = None; | |
676 | for (_, meta) in self.metadata.values.iter() { | |
677 | if (meta.is_get_value_typed)(operation.clone()) { | |
678 | value_meta = Some(meta); | |
679 | break; | |
680 | } | |
681 | } | |
682 | ||
683 | let value_meta = value_meta.ok_or_else(|| OperationError::Unhandled)?; | |
678 | let get_value = operation | |
679 | .0 | |
680 | .downcast_ref::<GetValue>() | |
681 | .ok_or_else(|| OperationError::Unhandled)?; | |
684 | 682 | |
683 | let value_meta = self | |
684 | .metadata | |
685 | .values | |
686 | .get(&ObjectValuePair { | |
687 | object_kind: O::object_name(), | |
688 | value_kind: &get_value.value_name, | |
689 | }) | |
690 | .ok_or_else(|| OperationError::Unhandled)?; | |
685 | 691 | let value_name = value_meta.name.clone(); |
686 | 692 | |
687 | 693 | trace!( |
@@ -699,11 +705,20 @@ impl ObjectBackend<StackOperationState> for Arc<GiteratedStack> { | ||
699 | 705 | continue; |
700 | 706 | } |
701 | 707 | |
708 | trace!( | |
709 | "Calling handler for get_value {}::{}", | |
710 | O::object_name(), | |
711 | value_name | |
712 | ); | |
713 | ||
702 | 714 | return match getter |
703 | 715 | .handle((object.clone(),), operation_state.clone()) |
704 | 716 | .await |
705 | 717 | { |
706 | Ok(success) => Ok(success.0.downcast_ref::<D::Success>().unwrap().clone()), | |
718 | Ok(success) => Ok(*(Box::new((value_meta.serialize)(success).unwrap()) | |
719 | as Box<dyn Any>) | |
720 | .downcast() | |
721 | .unwrap()), | |
707 | 722 | Err(err) => Err(match err { |
708 | 723 | OperationError::Operation(failure) => OperationError::Operation( |
709 | 724 | failure.0.downcast_ref::<D::Failure>().unwrap().clone(), |
@@ -719,8 +734,6 @@ impl ObjectBackend<StackOperationState> for Arc<GiteratedStack> { | ||
719 | 734 | }), |
720 | 735 | }; |
721 | 736 | } |
722 | ||
723 | return Err(OperationError::Unhandled); | |
724 | 737 | } else if operation.0.is::<GetSetting>() { |
725 | 738 | let get_setting: &GetSetting = operation.0.downcast_ref().unwrap(); |
726 | 739 | let setting_name = get_setting.setting_name.clone(); |