mod data;
use crate::client::location::{Location, LocationClient};
use crate::client::reqwest::{fetch_entities_list, fetch_entity, post_batches};
use crate::client::Client;
use crate::error::ClientError;
use sawtooth_sdk::messages::batch::BatchList;
const LOCATION_ROUTE: &str = "location";
pub struct ReqwestLocationClient {
url: String,
}
impl ReqwestLocationClient {
pub fn new(url: String) -> Self {
Self { url }
}
}
impl Client for ReqwestLocationClient {
fn post_batches(
&self,
wait: u64,
batch_list: &BatchList,
service_id: Option<&str>,
) -> Result<(), ClientError> {
post_batches(&self.url, wait, batch_list, service_id)
}
}
impl LocationClient for ReqwestLocationClient {
fn get_location(&self, id: String, service_id: Option<&str>) -> Result<Location, ClientError> {
let dto = fetch_entity::<data::Location>(
&self.url,
format!("{}/{}", LOCATION_ROUTE, id),
service_id,
)?;
Ok(Location::from(&dto))
}
fn list_locations(&self, service_id: Option<&str>) -> Result<Vec<Location>, ClientError> {
let dto_vec = fetch_entities_list::<data::Location>(
&self.url,
LOCATION_ROUTE.to_string(),
service_id,
None,
)?;
Ok(dto_vec.iter().map(Location::from).collect())
}
}