Delete scheduled message event endpoint (#19)
Reviewed-on: phoenix/textsender_api#19
This commit was merged in pull request #19.
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user