summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-25 01:19:49 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-25 01:23:22 -0400
commit3a2f37e41681c2b233728c3cbddaea3f9fc74c08 (patch)
tree9034ab3a2fd014dcf1f9806c2215eec0947ddcc3 /src
parent5423ec3937a4e28f3958a71b3db7498a4c427dc1 (diff)
To make it easier to correlate deletes to the event stream, have deletes return the ID of the affected entity.
Diffstat (limited to 'src')
-rw-r--r--src/channel/routes/channel/delete.rs23
-rw-r--r--src/channel/routes/channel/test/delete.rs7
-rw-r--r--src/message/routes/message/mod.rs21
-rw-r--r--src/message/routes/message/test.rs7
4 files changed, 37 insertions, 21 deletions
diff --git a/src/channel/routes/channel/delete.rs b/src/channel/routes/channel/delete.rs
index 91eb506..2d2b5f1 100644
--- a/src/channel/routes/channel/delete.rs
+++ b/src/channel/routes/channel/delete.rs
@@ -1,12 +1,12 @@
use axum::{
- extract::{Path, State},
+ extract::{Json, Path, State},
http::StatusCode,
- response::{IntoResponse, Response},
+ response::{self, IntoResponse},
};
use crate::{
app::App,
- channel::app,
+ channel::{self, app},
clock::RequestedAt,
error::{Internal, NotFound},
token::extract::Identity,
@@ -17,10 +17,21 @@ pub async fn handler(
Path(channel): Path<super::PathInfo>,
RequestedAt(deleted_at): RequestedAt,
_: Identity,
-) -> Result<StatusCode, Error> {
+) -> Result<Response, Error> {
app.channels().delete(&channel, &deleted_at).await?;
- Ok(StatusCode::ACCEPTED)
+ Ok(Response { id: channel })
+}
+
+#[derive(Debug, serde::Serialize)]
+pub struct Response {
+ pub id: channel::Id,
+}
+
+impl IntoResponse for Response {
+ fn into_response(self) -> response::Response {
+ (StatusCode::ACCEPTED, Json(self)).into_response()
+ }
}
#[derive(Debug, thiserror::Error)]
@@ -28,7 +39,7 @@ pub async fn handler(
pub struct Error(#[from] pub app::Error);
impl IntoResponse for Error {
- fn into_response(self) -> Response {
+ fn into_response(self) -> response::Response {
let Self(error) = self;
#[allow(clippy::match_wildcard_for_single_variants)]
match error {
diff --git a/src/channel/routes/channel/test/delete.rs b/src/channel/routes/channel/test/delete.rs
index e1210fd..0371b0a 100644
--- a/src/channel/routes/channel/test/delete.rs
+++ b/src/channel/routes/channel/test/delete.rs
@@ -1,7 +1,4 @@
-use axum::{
- extract::{Path, State},
- http::StatusCode,
-};
+use axum::extract::{Path, State};
use crate::{
channel::{app, routes::channel::delete},
@@ -29,7 +26,7 @@ pub async fn valid_channel() {
// Verify the response
- assert_eq!(response, StatusCode::ACCEPTED);
+ assert_eq!(channel.id, response.id);
// Verify the semantics
diff --git a/src/message/routes/message/mod.rs b/src/message/routes/message/mod.rs
index 545ad26..45a7e9d 100644
--- a/src/message/routes/message/mod.rs
+++ b/src/message/routes/message/mod.rs
@@ -3,9 +3,9 @@ mod test;
pub mod delete {
use axum::{
- extract::{Path, State},
+ extract::{Json, Path, State},
http::StatusCode,
- response::{IntoResponse, Response},
+ response::{self, IntoResponse},
};
use crate::{
@@ -21,10 +21,21 @@ pub mod delete {
Path(message): Path<message::Id>,
RequestedAt(deleted_at): RequestedAt,
_: Identity,
- ) -> Result<StatusCode, Error> {
+ ) -> Result<Response, Error> {
app.messages().delete(&message, &deleted_at).await?;
- Ok(StatusCode::ACCEPTED)
+ Ok(Response { id: message })
+ }
+
+ #[derive(Debug, serde::Serialize)]
+ pub struct Response {
+ pub id: message::Id,
+ }
+
+ impl IntoResponse for Response {
+ fn into_response(self) -> response::Response {
+ (StatusCode::ACCEPTED, Json(self)).into_response()
+ }
}
#[derive(Debug, thiserror::Error)]
@@ -32,7 +43,7 @@ pub mod delete {
pub struct Error(#[from] pub DeleteError);
impl IntoResponse for Error {
- fn into_response(self) -> Response {
+ fn into_response(self) -> response::Response {
let Self(error) = self;
#[allow(clippy::match_wildcard_for_single_variants)]
match error {
diff --git a/src/message/routes/message/test.rs b/src/message/routes/message/test.rs
index 2016fb8..ae89506 100644
--- a/src/message/routes/message/test.rs
+++ b/src/message/routes/message/test.rs
@@ -1,7 +1,4 @@
-use axum::{
- extract::{Path, State},
- http::StatusCode,
-};
+use axum::extract::{Path, State};
use super::delete;
use crate::{message::app, test::fixtures};
@@ -29,7 +26,7 @@ pub async fn delete_message() {
// Verify the response
- assert_eq!(response, StatusCode::ACCEPTED);
+ assert_eq!(message.id, response.id);
// Verify the semantics