diff --git a/giterated-daemon/src/database_backend/handler.rs b/giterated-daemon/src/database_backend/handler.rs index 33630f7..7a366a1 100644 --- a/giterated-daemon/src/database_backend/handler.rs +++ b/giterated-daemon/src/database_backend/handler.rs @@ -16,11 +16,12 @@ use giterated_models::{ RepositoryInfoRequest, RepositoryLastCommitOfFileRequest, RepositoryStatistics, RepositoryStatisticsRequest, RepositorySummary, RepositoryView, Visibility, }, - settings::{AnySetting, GetSetting, GetSettingError}, + settings::{GetSetting, GetSettingError}, user::{Bio, DisplayName, User, UserRepositoriesRequest}, value::{AnyValue, GetValueTyped}, }; use giterated_stack::{AuthenticatedUser, AuthorizedInstance, GiteratedStack, StackOperationState}; +use serde_json::Value; use super::DatabaseBackend; @@ -82,7 +83,7 @@ pub fn user_get_setting( object: &User, operation: GetSetting, state: DatabaseBackend, -) -> LocalBoxFuture<'static, Result>> { +) -> LocalBoxFuture<'static, Result>> { let object = object.clone(); async move { @@ -92,7 +93,7 @@ pub fn user_get_setting( .await .map_err(|e| OperationError::Internal(e.to_string()))?; - Ok(value) + Ok(value.0) } .boxed_local() } @@ -466,7 +467,7 @@ pub fn repository_get_setting( object: &Repository, operation: GetSetting, state: DatabaseBackend, -) -> LocalBoxFuture<'static, Result>> { +) -> LocalBoxFuture<'static, Result>> { let object = object.clone(); async move { @@ -476,7 +477,7 @@ pub fn repository_get_setting( .await .map_err(|e| OperationError::Internal(e.to_string()))?; - Ok(value) + Ok(value.0) } .boxed_local() } diff --git a/giterated-daemon/src/database_backend/mod.rs b/giterated-daemon/src/database_backend/mod.rs index 5c04d13..544134e 100644 --- a/giterated-daemon/src/database_backend/mod.rs +++ b/giterated-daemon/src/database_backend/mod.rs @@ -22,9 +22,9 @@ use self::handler::{ instance_registration_request, repository_commit_before, repository_commit_by_id, repository_diff, repository_diff_patch, repository_file_from_id, repository_file_from_path, repository_get_branches, repository_get_default_branch, repository_get_latest_commit, - repository_get_statistics, repository_get_value_description, repository_get_value_visibility, - repository_info, repository_last_commit_of_file, user_get_repositories, user_get_value_bio, - user_get_value_display_name, + repository_get_setting, repository_get_statistics, repository_get_value_description, + repository_get_value_visibility, repository_info, repository_last_commit_of_file, + user_get_repositories, user_get_setting, user_get_value_bio, user_get_value_display_name, }; #[derive(Clone, Debug)] @@ -79,7 +79,9 @@ impl DatabaseBackend { builder .object::() + .object_settings(repository_get_setting) .object::() + .object_settings(user_get_setting) .object::(); builder diff --git a/giterated-stack/src/handler.rs b/giterated-stack/src/handler.rs index 2f4dee3..9e56b23 100644 --- a/giterated-stack/src/handler.rs +++ b/giterated-stack/src/handler.rs @@ -14,7 +14,8 @@ use giterated_models::{ settings::{GetSetting, GetSettingError, SetSetting, Setting}, value::{AnyValue, GetValue, GetValueTyped, GiteratedObjectValue}, }; -use tracing::trace; +use serde_json::Value; +use tracing::{info, trace}; use crate::{ GiteratedOperationHandler, ObjectMeta, ObjectOperationPair, ObjectValuePair, OperationMeta, @@ -437,9 +438,7 @@ impl RuntimeMetadata { SettingMeta { name: setting_name, deserialize: Box::new(|bytes| Ok(Box::new(serde_json::from_slice(bytes)?))), - serialize: Box::new(|source| { - serde_json::to_value(source.downcast::().unwrap()) - }), + serialize: Box::new(|source| Ok(*source.downcast::().unwrap())), }, ) .is_some() @@ -499,19 +498,21 @@ impl GiteratedStack { .network_get_value(object, object_type.clone(), operation, operation_state) .await; } else if message.operation == "get_setting" { + let operation: GetSetting = serde_json::from_slice(&message.payload.0).unwrap(); + info!("1"); let setting_meta = self .metadata .settings - .get(&object_type) + .get(&operation.setting_name) .ok_or_else(|| OperationError::Unhandled)?; - - let operation: GetSetting = serde_json::from_slice(&message.payload.0).unwrap(); + info!("2"); let raw_result = self .get_setting(object, object_type.clone(), operation, operation_state) .await; - + info!("3"); return match raw_result { Ok(success) => { + info!("3a"); // Success is the setting type, serialize it let serialized = (setting_meta.serialize)(success).unwrap(); @@ -519,6 +520,7 @@ impl GiteratedStack { } Err(err) => Err(match err { OperationError::Operation(failure) => { + info!("3b"); // We know how to resolve this type let failure: GetSettingError = *failure.downcast().unwrap(); @@ -663,12 +665,6 @@ impl GiteratedStack { operation.setting_name ); - let _setting_meta = self - .metadata - .settings - .get(&object_kind) - .ok_or_else(|| OperationError::Unhandled)?; - let setting_getter = self .setting_getters .get(&object_kind)