Page MenuHomeDevCentral

D2094.diff
No OneTemporary

D2094.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
@@ -135,6 +135,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
:: Implementation for diesel::result::Error

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 13:38 (22 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264667
Default Alt Text
D2094.diff (1 KB)

Event Timeline