trivial enhancements to state management solution
This commit is contained in:
@@ -83,32 +83,44 @@ impl DollsRemote {
|
||||
|
||||
pub async fn get_dolls(&self) -> Result<Vec<DollDto>, RemoteError> {
|
||||
let url = format!("{}/dolls/me", self.base_url);
|
||||
tracing::info!("DollsRemote::get_dolls - Sending GET request to URL: {}", url);
|
||||
tracing::info!(
|
||||
"DollsRemote::get_dolls - Sending GET request to URL: {}",
|
||||
url
|
||||
);
|
||||
let resp = with_auth(self.client.get(url)).await.send().await?;
|
||||
|
||||
|
||||
let resp = resp.error_for_status().map_err(|e| {
|
||||
tracing::error!("DollsRemote::get_dolls - HTTP error: {}", e);
|
||||
e
|
||||
})?;
|
||||
|
||||
let text = resp.text().await.map_err(|e| {
|
||||
tracing::error!("DollsRemote::get_dolls - Failed to read response text: {}", e);
|
||||
tracing::error!(
|
||||
"DollsRemote::get_dolls - Failed to read response text: {}",
|
||||
e
|
||||
);
|
||||
e
|
||||
})?;
|
||||
|
||||
|
||||
let dolls: Vec<DollDto> = serde_json::from_str(&text).map_err(|e| {
|
||||
tracing::error!("DollsRemote::get_dolls - Failed to parse JSON: {}", e);
|
||||
e
|
||||
})?;
|
||||
|
||||
tracing::info!("DollsRemote::get_dolls - Successfully parsed {} dolls", dolls.len());
|
||||
|
||||
tracing::info!(
|
||||
"DollsRemote::get_dolls - Successfully parsed {} dolls",
|
||||
dolls.len()
|
||||
);
|
||||
Ok(dolls)
|
||||
}
|
||||
|
||||
pub async fn get_doll(&self, id: &str) -> Result<DollDto, RemoteError> {
|
||||
let url = format!("{}/dolls/{}", self.base_url, id);
|
||||
tracing::info!("DollsRemote::get_doll - Sending GET request to URL: {}", url);
|
||||
|
||||
tracing::info!(
|
||||
"DollsRemote::get_doll - Sending GET request to URL: {}",
|
||||
url
|
||||
);
|
||||
|
||||
let resp = with_auth(self.client.get(url)).await.send().await?;
|
||||
|
||||
let resp = resp.error_for_status().map_err(|e| {
|
||||
@@ -117,7 +129,10 @@ impl DollsRemote {
|
||||
})?;
|
||||
|
||||
let text = resp.text().await.map_err(|e| {
|
||||
tracing::error!("DollsRemote::get_doll - Failed to read response text: {}", e);
|
||||
tracing::error!(
|
||||
"DollsRemote::get_doll - Failed to read response text: {}",
|
||||
e
|
||||
);
|
||||
e
|
||||
})?;
|
||||
|
||||
@@ -125,14 +140,17 @@ impl DollsRemote {
|
||||
tracing::error!("DollsRemote::get_doll - Failed to parse JSON: {}", e);
|
||||
e
|
||||
})?;
|
||||
|
||||
|
||||
Ok(doll)
|
||||
}
|
||||
|
||||
pub async fn create_doll(&self, dto: CreateDollDto) -> Result<DollDto, RemoteError> {
|
||||
let url = format!("{}/dolls", self.base_url);
|
||||
tracing::info!("DollsRemote::create_doll - Sending POST request to URL: {}", url);
|
||||
|
||||
tracing::info!(
|
||||
"DollsRemote::create_doll - Sending POST request to URL: {}",
|
||||
url
|
||||
);
|
||||
|
||||
let resp = with_auth(self.client.post(url))
|
||||
.await
|
||||
.json(&dto)
|
||||
@@ -145,7 +163,10 @@ impl DollsRemote {
|
||||
})?;
|
||||
|
||||
let text = resp.text().await.map_err(|e| {
|
||||
tracing::error!("DollsRemote::create_doll - Failed to read response text: {}", e);
|
||||
tracing::error!(
|
||||
"DollsRemote::create_doll - Failed to read response text: {}",
|
||||
e
|
||||
);
|
||||
e
|
||||
})?;
|
||||
|
||||
@@ -153,14 +174,17 @@ impl DollsRemote {
|
||||
tracing::error!("DollsRemote::create_doll - Failed to parse JSON: {}", e);
|
||||
e
|
||||
})?;
|
||||
|
||||
|
||||
Ok(doll)
|
||||
}
|
||||
|
||||
pub async fn update_doll(&self, id: &str, dto: UpdateDollDto) -> Result<DollDto, RemoteError> {
|
||||
let url = format!("{}/dolls/{}", self.base_url, id);
|
||||
tracing::info!("DollsRemote::update_doll - Sending PATCH request to URL: {}", url);
|
||||
|
||||
tracing::info!(
|
||||
"DollsRemote::update_doll - Sending PATCH request to URL: {}",
|
||||
url
|
||||
);
|
||||
|
||||
let resp = with_auth(self.client.patch(url))
|
||||
.await
|
||||
.json(&dto)
|
||||
@@ -173,7 +197,10 @@ impl DollsRemote {
|
||||
})?;
|
||||
|
||||
let text = resp.text().await.map_err(|e| {
|
||||
tracing::error!("DollsRemote::update_doll - Failed to read response text: {}", e);
|
||||
tracing::error!(
|
||||
"DollsRemote::update_doll - Failed to read response text: {}",
|
||||
e
|
||||
);
|
||||
e
|
||||
})?;
|
||||
|
||||
@@ -181,16 +208,19 @@ impl DollsRemote {
|
||||
tracing::error!("DollsRemote::update_doll - Failed to parse JSON: {}", e);
|
||||
e
|
||||
})?;
|
||||
|
||||
|
||||
Ok(doll)
|
||||
}
|
||||
|
||||
pub async fn delete_doll(&self, id: &str) -> Result<(), RemoteError> {
|
||||
let url = format!("{}/dolls/{}", self.base_url, id);
|
||||
tracing::info!("DollsRemote::delete_doll - Sending DELETE request to URL: {}", url);
|
||||
|
||||
tracing::info!(
|
||||
"DollsRemote::delete_doll - Sending DELETE request to URL: {}",
|
||||
url
|
||||
);
|
||||
|
||||
let resp = with_auth(self.client.delete(url)).await.send().await?;
|
||||
|
||||
|
||||
resp.error_for_status().map_err(|e| {
|
||||
tracing::error!("DollsRemote::delete_doll - HTTP error: {}", e);
|
||||
e
|
||||
|
||||
Reference in New Issue
Block a user