Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3780606
D2094.id5287.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D2094.id5287.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D2094: Allow to craft a JSON response for DELETE SQL queries
Attached
Detach File
Event Timeline
Log In to Comment