Delete scheduled message event endpoint #19
@@ -365,9 +365,9 @@ pub mod endpoint {
|
||||
path = crate::caller::endpoints::DELETE_SCHEDULED_MESSAGE_EVENT,
|
||||
params(("id" = uuid::Uuid, Path, description = "Scheduled Message Event Id")),
|
||||
responses(
|
||||
(status = 200, description = "Song deleted", body = super::response::DeleteScheduledMessageEventResponse),
|
||||
(status = 404, description = "Song not found", body = super::response::DeleteScheduledMessageEventResponse),
|
||||
(status = 500, description = "Error deleting song", body = super::response::DeleteScheduledMessageEventResponse)
|
||||
(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(
|
||||
@@ -377,8 +377,27 @@ pub mod endpoint {
|
||||
axum::http::StatusCode,
|
||||
axum::Json<super::response::DeleteScheduledMessageEventResponse>,
|
||||
) {
|
||||
let response = super::response::DeleteScheduledMessageEventResponse::default();
|
||||
todo!("Has not been implemented");
|
||||
(axum::http::StatusCode::NOT_IMPLEMENTED, axum::Json(response))
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,6 +189,28 @@ 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> {
|
||||
|
||||
Reference in New Issue
Block a user