Delete scheduled message event endpoint (#19)
textsender_api PR / Rustfmt (pull_request) Successful in 56s
textsender_api PR / Check (pull_request) Successful in 1m32s
textsender_api PR / Clippy (pull_request) Successful in 1m37s

Reviewed-on: phoenix/textsender_api#19
This commit was merged in pull request #19.
This commit is contained in:
2026-06-19 16:02:53 -04:00
parent c1557d09f6
commit 3a387813d7
7 changed files with 206 additions and 5 deletions
+49
View File
@@ -67,6 +67,8 @@ pub mod response {
}
pub use CreateScheduleMessageEventResponse as GetScheduledMessageEventResponse;
pub use CreateScheduleMessageEventResponse as DeleteScheduledMessageEventResponse;
}
pub mod endpoint {
@@ -355,4 +357,51 @@ pub mod endpoint {
(axum::http::StatusCode::OK, axum::Json(response))
}
/// Endpoint to delete the Scheduled Message Event
#[utoipa::path(
delete,
path = crate::caller::endpoints::DELETE_SCHEDULED_MESSAGE_EVENT,
params(("id" = uuid::Uuid, Path, description = "Scheduled Message Event Id")),
responses(
(status = 200, description = "Deleted", body = super::response::DeleteScheduledMessageEventResponse),
(status = 400, description = "Bad request", body = super::response::DeleteScheduledMessageEventResponse),
(status = 500, description = "Error deleting", body = super::response::DeleteScheduledMessageEventResponse)
)
)]
pub async fn delete_scheduled_message_event(
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
) -> (
axum::http::StatusCode,
axum::Json<super::response::DeleteScheduledMessageEventResponse>,
) {
let mut response = super::response::DeleteScheduledMessageEventResponse::default();
match scheduling_repo::sched_msg_event::get(&pool, &id).await {
Ok(scheduled_message_event) => {
match scheduling_repo::sched_msg_event::delete(&pool, &scheduled_message_event)
.await
{
Ok(_) => {
response.message = String::from(super::super::super::response::SUCCESSFUL);
response.data.push(scheduled_message_event);
(axum::http::StatusCode::OK, axum::Json(response))
}
Err(err) => {
eprintln!("Error: {err:?}");
response.message = String::from("Error deleting");
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
}
}
}
Err(err) => {
eprintln!("Error: {err:?}");
response.message = String::from("Bad request");
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
}
}
}
+2
View File
@@ -22,6 +22,8 @@ pub mod endpoints {
pub const CREATE_SCHEDULED_MESSAGE_EVENT: &str = "/api/v1/schedule/message/event";
/// Constant for getting Scheduled Message Event endpoint
pub const GET_SCHEDULED_MESSAGE_EVENT: &str = "/api/v1/schedule/message/event";
/// Constant for deleting Scheduled Message Event endpoint
pub const DELETE_SCHEDULED_MESSAGE_EVENT: &str = "/api/v1/schedule/message/event/{id}";
}
pub mod response {
+7 -1
View File
@@ -10,7 +10,7 @@ pub mod host {
pub mod init {
use std::time::Duration;
use axum::routing::{get, patch, post};
use axum::routing::{delete, get, patch, post};
use tower_http::timeout::TimeoutLayer;
use utoipa::OpenApi;
@@ -148,6 +148,12 @@ pub mod init {
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
),
)
.route(
crate::caller::endpoints::DELETE_SCHEDULED_MESSAGE_EVENT,
delete(scheduling_endpoints::delete_scheduled_message_event).route_layer(
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
),
)
.layer(cors::configure_cors().await)
}
+19
View File
@@ -189,6 +189,25 @@ pub mod sched_msg_event {
}
}
pub async fn delete(
pool: &sqlx::PgPool,
scheduled_message_event: &textsender_models::message::scheduling::ScheduledMessageEvent,
) -> Result<(), sqlx::Error> {
match sqlx::query(
r#"
DELETE FROM "scheduled_message_events"
WHERE id = $1
"#,
)
.bind(scheduled_message_event.id)
.execute(pool)
.await
{
Ok(_) => Ok(()),
Err(err) => Err(err),
}
}
async fn parse_row(
row: &sqlx::postgres::PgRow,
) -> Result<textsender_models::message::scheduling::ScheduledMessageEvent, sqlx::Error> {