Update scheduled message status endpoint #20
@@ -46,7 +46,7 @@ pub mod request {
|
||||
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
|
||||
pub struct UpdateScheduledMessageStatusRequest {
|
||||
pub status: String,
|
||||
pub scheduled_message_id: uuid::Uuid
|
||||
pub scheduled_message_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
impl UpdateScheduledMessageStatusRequest {
|
||||
@@ -259,18 +259,26 @@ pub mod endpoint {
|
||||
match scheduling_repo::get(&pool, &payload.scheduled_message_id).await {
|
||||
Ok(scheduled_message) => {
|
||||
let old_status = scheduled_message.status;
|
||||
match scheduling_repo::update_status(&pool, &scheduled_message.id, &payload.status).await {
|
||||
match scheduling_repo::update_status(
|
||||
&pool,
|
||||
&scheduled_message.id,
|
||||
&payload.status,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
response.message = String::from(super::super::super::response::SUCCESSFUL);
|
||||
response.data = vec![super::response::ChangedStatus {
|
||||
old_status,
|
||||
}];
|
||||
response.message =
|
||||
String::from(super::super::super::response::SUCCESSFUL);
|
||||
response.data = vec![super::response::ChangedStatus { old_status }];
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
response.message = String::from("Invalid");
|
||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response))
|
||||
(
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,21 +88,20 @@ pub async fn update_status(
|
||||
pool: &sqlx::PgPool,
|
||||
id: &uuid::Uuid,
|
||||
status: &str,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
) -> Result<(), sqlx::Error> {
|
||||
match sqlx::query(
|
||||
r#"
|
||||
UPDATE "scheduled_message" SET status = $1 WHERE id = $2;
|
||||
"#,
|
||||
)
|
||||
.bind(status)
|
||||
.bind(id)
|
||||
.execute(pool)
|
||||
.await {
|
||||
Ok(_row) => {
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => Err(err)
|
||||
}
|
||||
)
|
||||
.bind(status)
|
||||
.bind(id)
|
||||
.execute(pool)
|
||||
.await
|
||||
{
|
||||
Ok(_row) => Ok(()),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
async fn parse_row(
|
||||
|
||||
Reference in New Issue
Block a user