Return etag in create & update responses

This commit is contained in:
2020-11-05 18:09:43 -05:00
parent 8cb76d6ff4
commit 0980d01640
5 changed files with 20 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
use anyhow::Result;
use http::StatusCode;
use uuid::Uuid;
use warp::reply::{json, with_header, with_status};
use warp::reply::{with_header, with_status};
use warp::{Rejection, Reply};
use crate::models::{InteriorRefList, ListParams};
@@ -77,7 +77,7 @@ pub async fn create(
let url = saved_interior_ref_list
.url(&env.api_url)
.map_err(reject_anyhow)?;
let reply = json(&saved_interior_ref_list);
let reply = JsonWithETag::from_serializable(&saved_interior_ref_list).map_err(reject_anyhow)?;
let reply = with_header(reply, "Location", url.as_str());
let reply = with_status(reply, StatusCode::CREATED);
env.caches.list_interior_ref_lists.clear().await;
@@ -114,7 +114,8 @@ pub async fn update(
let url = updated_interior_ref_list
.url(&env.api_url)
.map_err(reject_anyhow)?;
let reply = json(&updated_interior_ref_list);
let reply =
JsonWithETag::from_serializable(&updated_interior_ref_list).map_err(reject_anyhow)?;
let reply = with_header(reply, "Location", url.as_str());
let reply = with_status(reply, StatusCode::CREATED);
env.caches.interior_ref_list.delete_response(id).await;
@@ -144,7 +145,8 @@ pub async fn update_by_shop_id(
let url = updated_interior_ref_list
.url(&env.api_url)
.map_err(reject_anyhow)?;
let reply = json(&updated_interior_ref_list);
let reply =
JsonWithETag::from_serializable(&updated_interior_ref_list).map_err(reject_anyhow)?;
let reply = with_header(reply, "Location", url.as_str());
let reply = with_status(reply, StatusCode::CREATED);
env.caches