Page MenuHomeDevCentral

D2094.id5288.diff
No OneTemporary

D2094.id5288.diff

diff --git a/Cargo.toml b/Cargo.toml
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "limiting-factor"
-version = "0.6.0"
+version = "0.7.0"
authors = [
"Sébastien Santoro <dereckson@espace-win.org>",
]
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:40 (21 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264773
Default Alt Text
D2094.id5288.diff (1 KB)

Event Timeline