Skip to content

Commit

Permalink
rename to FindById
Browse files Browse the repository at this point in the history
  • Loading branch information
wilyle committed Oct 31, 2023
1 parent 33d731f commit 9adb5bd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
8 changes: 4 additions & 4 deletions contracts/src/digital_twin_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ pub trait DigitalTwinAdapter {
/// - `request`: the request for finding an entity's access information
async fn find_by_id(
&self,
request: GetDigitalTwinProviderRequest,
) -> Result<GetDigitalTwinProviderResponse, DigitalTwinAdapterError>;
request: FindByIdRequest,
) -> Result<FindByIdResponse, DigitalTwinAdapterError>;
}

/// A request for digital twin providers
#[derive(Debug, Serialize, Deserialize)]
pub struct GetDigitalTwinProviderRequest {
pub struct FindByIdRequest {
/// The entity's id to inquire about
pub entity_id: String,
}

/// The response for digital twin providers
#[derive(Debug, Serialize, Deserialize)]
pub struct GetDigitalTwinProviderResponse {
pub struct FindByIdResponse {
/// Entity information
pub entity: Entity,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use async_trait::async_trait;
use crate::config::Config;
use freyja_common::{config_utils, out_dir};
use freyja_contracts::digital_twin_adapter::{
DigitalTwinAdapter, DigitalTwinAdapterError, DigitalTwinAdapterErrorKind,
GetDigitalTwinProviderRequest, GetDigitalTwinProviderResponse,
DigitalTwinAdapter, DigitalTwinAdapterError, DigitalTwinAdapterErrorKind, FindByIdRequest,
FindByIdResponse,
};

const CONFIG_FILE_STEM: &str = "in_memory_digital_twin_config";
Expand Down Expand Up @@ -51,13 +51,13 @@ impl DigitalTwinAdapter for InMemoryMockDigitalTwinAdapter {
/// - `request`: the request to send
async fn find_by_id(
&self,
request: GetDigitalTwinProviderRequest,
) -> Result<GetDigitalTwinProviderResponse, DigitalTwinAdapterError> {
request: FindByIdRequest,
) -> Result<FindByIdResponse, DigitalTwinAdapterError> {
self.config
.values
.iter()
.find(|entity_config| entity_config.entity.id == request.entity_id)
.map(|entity_config| GetDigitalTwinProviderResponse {
.map(|entity_config| FindByIdResponse {
entity: entity_config.entity.clone(),
})
.ok_or(DigitalTwinAdapterErrorKind::EntityNotFound.into())
Expand Down Expand Up @@ -97,7 +97,7 @@ mod in_memory_mock_digital_twin_adapter_tests {
};

let in_memory_digital_twin_adapter = InMemoryMockDigitalTwinAdapter { config };
let request = GetDigitalTwinProviderRequest {
let request = FindByIdRequest {
entity_id: String::from(ENTITY_ID),
};
let response = in_memory_digital_twin_adapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use reqwest::Client;

use crate::config::Config;
use freyja_contracts::digital_twin_adapter::{
DigitalTwinAdapter, DigitalTwinAdapterError, GetDigitalTwinProviderRequest,
GetDigitalTwinProviderResponse,
DigitalTwinAdapter, DigitalTwinAdapterError, FindByIdRequest, FindByIdResponse,
};
use mock_digital_twin::ENTITY_QUERY_PATH;

Expand Down Expand Up @@ -72,8 +71,8 @@ impl DigitalTwinAdapter for MockDigitalTwinAdapter {
/// - `request`: the request to send to the mock digital twin server
async fn find_by_id(
&self,
request: GetDigitalTwinProviderRequest,
) -> Result<GetDigitalTwinProviderResponse, DigitalTwinAdapterError> {
request: FindByIdRequest,
) -> Result<FindByIdResponse, DigitalTwinAdapterError> {
let target = format!(
"{}{ENTITY_QUERY_PATH}{}",
self.config.digital_twin_service_uri, request.entity_id
Expand All @@ -86,7 +85,7 @@ impl DigitalTwinAdapter for MockDigitalTwinAdapter {
.map_err(DigitalTwinAdapterError::communication)?
.error_for_status()
.map_err(Self::map_status_err)?
.json::<GetDigitalTwinProviderResponse>()
.json::<FindByIdResponse>()
.await
.map_err(DigitalTwinAdapterError::deserialize)
}
Expand Down
13 changes: 6 additions & 7 deletions freyja/src/cartographer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use log::{info, warn};
use freyja_contracts::{
conversion::Conversion,
digital_twin_adapter::{
DigitalTwinAdapter, DigitalTwinAdapterError, DigitalTwinAdapterErrorKind,
GetDigitalTwinProviderRequest,
DigitalTwinAdapter, DigitalTwinAdapterError, DigitalTwinAdapterErrorKind, FindByIdRequest,
},
mapping_client::{CheckForWorkRequest, GetMappingRequest, MappingClient},
provider_proxy_selector::ProviderProxySelector,
Expand Down Expand Up @@ -180,7 +179,7 @@ impl<
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
signal.source = self
.digital_twin_client
.find_by_id(GetDigitalTwinProviderRequest {
.find_by_id(FindByIdRequest {
entity_id: signal.id.clone(),
})
.await?
Expand Down Expand Up @@ -208,7 +207,7 @@ mod cartographer_tests {
use mockall::{predicate::eq, *};

use freyja_contracts::{
digital_twin_adapter::{DigitalTwinAdapterError, GetDigitalTwinProviderResponse},
digital_twin_adapter::{DigitalTwinAdapterError, FindByIdResponse},
digital_twin_map_entry::DigitalTwinMapEntry,
entity::Entity,
mapping_client::{
Expand All @@ -229,8 +228,8 @@ mod cartographer_tests {

async fn find_by_id(
&self,
request: GetDigitalTwinProviderRequest,
) -> Result<GetDigitalTwinProviderResponse, DigitalTwinAdapterError>;
request: FindByIdRequest,
) -> Result<FindByIdResponse, DigitalTwinAdapterError>;
}
}

Expand Down Expand Up @@ -350,7 +349,7 @@ mod cartographer_tests {

let mut mock_dt_adapter = MockDigitalTwinAdapterImpl::new();
mock_dt_adapter.expect_find_by_id().returning(move |_| {
Ok(GetDigitalTwinProviderResponse {
Ok(FindByIdResponse {
entity: test_entity_clone.clone(),
})
});
Expand Down
4 changes: 2 additions & 2 deletions mocks/mock_digital_twin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use tokio::sync::{mpsc, mpsc::UnboundedSender};

use crate::config::{Config, EntityConfig};
use freyja_common::{config_utils, out_dir};
use freyja_contracts::digital_twin_adapter::GetDigitalTwinProviderResponse;
use freyja_contracts::digital_twin_adapter::FindByIdResponse;
use http_mock_provider_proxy::http_mock_provider_proxy::{EntityValueRequest, EntityValueResponse};
use mock_digital_twin::{ENTITY_GET_VALUE_PATH, ENTITY_PATH, ENTITY_SUBSCRIBE_PATH};

Expand Down Expand Up @@ -265,7 +265,7 @@ async fn get_entity(
let mut entity = config_item.entity.clone();
entity.uri = format!("{}{operation_path}", config_item.entity.uri);

ok!(GetDigitalTwinProviderResponse { entity })
ok!(FindByIdResponse { entity })
})
.unwrap_or(not_found!())
}
Expand Down

0 comments on commit 9adb5bd

Please sign in to comment.