From b43021122c4eee247d88ca036cb1f317885f2d29 Mon Sep 17 00:00:00 2001 From: Dmitry Balashov <43530070+0x009922@users.noreply.github.com> Date: Thu, 23 Nov 2023 13:33:30 +0700 Subject: [PATCH] [refactor] #4063: use DTO naming Signed-off-by: Dmitry Balashov <43530070+0x009922@users.noreply.github.com> --- cli/src/torii/routing.rs | 6 +++--- client/src/client.rs | 9 ++++----- config/src/client_api.rs | 12 ++++++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cli/src/torii/routing.rs b/cli/src/torii/routing.rs index 77f809f0f4a..e62e9f3b556 100644 --- a/cli/src/torii/routing.rs +++ b/cli/src/torii/routing.rs @@ -7,7 +7,7 @@ use eyre::{eyre, WrapErr}; use futures::TryStreamExt; -use iroha_config::{client_api::ConfigurationSubset, iroha::Configuration, torii::uri}; +use iroha_config::{client_api::ConfigurationDTO, iroha::Configuration, torii::uri}; use iroha_core::{ query::{pagination::Paginate, store::LiveQueryStoreHandle}, smartcontracts::query::ValidQueryRequest, @@ -165,14 +165,14 @@ async fn handle_pending_transactions( #[iroha_futures::telemetry_future] async fn handle_get_configuration(iroha_cfg: Configuration) -> Result { - let subset = ConfigurationSubset::from(&iroha_cfg); + let subset = ConfigurationDTO::from(&iroha_cfg); Ok(reply::json(&subset)) } #[iroha_futures::telemetry_future] async fn handle_post_configuration( iroha_cfg: Configuration, - value: ConfigurationSubset, + value: ConfigurationDTO, ) -> Result { value.update_base(&iroha_cfg)?; Ok(reply::reply()) diff --git a/client/src/client.rs b/client/src/client.rs index b3d5b23d0c3..32736bb6b3b 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -13,7 +13,7 @@ use derive_more::{DebugCustom, Display}; use eyre::{eyre, Result, WrapErr}; use futures_util::StreamExt; use http_default::{AsyncWebSocketStream, WebSocketStream}; -use iroha_config::{client::Configuration, client_api::ConfigurationSubset, torii::uri}; +use iroha_config::{client::Configuration, client_api::ConfigurationDTO, torii::uri}; use iroha_crypto::{HashOf, KeyPair}; use iroha_logger::prelude::*; use iroha_telemetry::metrics::Status; @@ -1076,7 +1076,7 @@ impl Client { /// /// # Errors /// Fails if sending request or decoding fails - pub fn get_config(&self) -> Result { + pub fn get_config(&self) -> Result { let resp = DefaultRequestBuilder::new( HttpMethod::GET, self.torii_url.join(uri::CONFIGURATION).expect("Valid URI"), @@ -1099,9 +1099,8 @@ impl Client { /// /// # Errors /// If sending request or decoding fails - pub fn set_config(&self, config: ConfigurationSubset) -> Result { - let body = - serde_json::to_vec(&config).wrap_err(format!("Failed to serialize {config:?}"))?; + pub fn set_config(&self, dto: ConfigurationDTO) -> Result { + let body = serde_json::to_vec(&dto).wrap_err(format!("Failed to serialize {dto:?}"))?; let url = self.torii_url.join(uri::CONFIGURATION).expect("Valid URI"); let resp = DefaultRequestBuilder::new(HttpMethod::POST, url) .header(http::header::CONTENT_TYPE, APPLICATION_JSON) diff --git a/config/src/client_api.rs b/config/src/client_api.rs index 884ea49153d..4d45813dcb0 100644 --- a/config/src/client_api.rs +++ b/config/src/client_api.rs @@ -2,8 +2,8 @@ //! //! Intended usage: //! -//! - Create [`Root`] from [`crate::iroha::Configuration`] and serialize it for the client -//! - Deserialize [`Root`] from the client and use [`Root::apply_update()`] to update the configuration +//! - Create [`ConfigurationDTO`] from [`crate::iroha::Configuration`] and serialize it for the client +//! - Deserialize [`ConfigurationDTO`] from the client and use [`ConfigurationDTO::apply_update()`] to update the configuration // TODO: Currently logic here is not generalised and handles only `logger.max_log_level` parameter. In future, when // other parts of configuration are refactored and there is a solid foundation e.g. as a general // configuration-related crate, this part should be re-written in a clean way. @@ -17,11 +17,11 @@ use super::{iroha::Configuration as BaseConfiguration, logger::Configuration as /// Subset of [`super::iroha`] configuration. #[derive(Debug, Serialize, Deserialize, Clone, Copy)] -pub struct ConfigurationSubset { +pub struct ConfigurationDTO { logger: Logger, } -impl From<&'_ BaseConfiguration> for ConfigurationSubset { +impl From<&'_ BaseConfiguration> for ConfigurationDTO { fn from(value: &'_ BaseConfiguration) -> Self { Self { logger: value.logger.as_ref().into(), @@ -29,7 +29,7 @@ impl From<&'_ BaseConfiguration> for ConfigurationSubset { } } -impl ConfigurationSubset { +impl ConfigurationDTO { /// Update the base configuration with the values stored in [`Self`]. pub fn update_base(&self, target: &BaseConfiguration) -> Result<(), ReloadError> { target @@ -60,7 +60,7 @@ mod test { #[test] fn snapshot_serialized_form() { - let value = ConfigurationSubset { + let value = ConfigurationDTO { logger: Logger { max_log_level: Level::TRACE, },