Page MenuHomeDevCentral

D2094.id5287.diff
No OneTemporary

D2094.id5287.diff

diff --git a/src/api/replies.rs b/src/api/replies.rs
--- a/src/api/replies.rs
+++ b/src/api/replies.rs
@@ -134,6 +134,33 @@
}
}
+/* -------------------------------------------------------------
+ API Delete Response
+
+ :: Implementation for QueryResult (Diesel ORM)
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+
+#[cfg(feature = "pgsql")]
+/// This trait allows to consume an object into an HTTP response.
+///
+/// This response is a odd case for DELETE queries, which return
+/// a scalar with the rows deleted count value, or an error.
+pub trait ApiDeleteResponse<T> {
+ /// Consumes the value and creates a JSON or a Status result response.
+ fn into_delete_json_response(self) -> ApiJsonResponse<()>;
+}
+
+#[cfg(feature = "pgsql")]
+impl ApiDeleteResponse<usize> for QueryResult<usize> {
+ fn into_delete_json_response(self) -> ApiJsonResponse<()> {
+ match self {
+ Ok(0) => Err(Status::NotFound),
+ Ok(1) => Ok(Json(())),
+ _ => Err(Status::BadRequest),
+ }
+ }
+}
+
/* -------------------------------------------------------------
Failure response

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 15:44 (22 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264777
Default Alt Text
D2094.id5287.diff (1 KB)

Event Timeline