Get scheduled message event (#18)
textsender_api PR / Check (pull_request) Successful in 1m25s
textsender_api PR / Rustfmt (pull_request) Successful in 1m34s
textsender_api PR / Clippy (pull_request) Successful in 2m0s

Reviewed-on: phoenix/textsender_api#18
This commit was merged in pull request #18.
This commit is contained in:
2026-06-18 19:59:22 -04:00
parent 7873e8ed00
commit c1557d09f6
4 changed files with 194 additions and 0 deletions
+77
View File
@@ -36,6 +36,12 @@ pub mod request {
|| !self.scheduled_message_id.is_nil()
}
}
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct GetScheduledMessageEventParams {
pub id: Option<uuid::Uuid>,
pub scheduled_message_id: Option<uuid::Uuid>,
}
}
pub mod response {
@@ -59,6 +65,8 @@ pub mod response {
pub message: String,
pub data: Vec<textsender_models::message::scheduling::ScheduledMessageEvent>,
}
pub use CreateScheduleMessageEventResponse as GetScheduledMessageEventResponse;
}
pub mod endpoint {
@@ -278,4 +286,73 @@ pub mod endpoint {
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
}
/// Endpoint to get Scheduled Message Event
#[utoipa::path(
get,
path = crate::caller::endpoints::GET_SCHEDULED_MESSAGE_EVENT,
params(
("id" = uuid::Uuid, Path, description = "Id of Scheduled Message Event"),
("scheduled_message_id" = uuid::Uuid, Path, description = "Scheduled Message Id associated with the Scheduled Message Event")
),
responses(
(status = 200, description = "Scheduled Message Event found", body = super::response::GetScheduledMessageEventResponse),
(status = 400, description = "Invalid request", body = super::response::GetScheduledMessageEventResponse),
(status = 500, description = "Error getting Scheduled Message Event", body = super::response::GetScheduledMessageEventResponse)
)
)]
pub async fn get_scheduled_message_events(
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::extract::Query(params): axum::extract::Query<
super::request::GetScheduledMessageEventParams,
>,
) -> (
axum::http::StatusCode,
axum::Json<super::response::GetScheduledMessageEventResponse>,
) {
let mut response = super::response::GetScheduledMessageEventResponse::default();
let scheduled_message_events = match params.id {
Some(id) => match scheduling_repo::sched_msg_event::get(&pool, &id).await {
Ok(scheduled_message) => {
vec![scheduled_message]
}
Err(err) => {
eprintln!("Error: {err:?}");
return (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
);
}
},
None => match params.scheduled_message_id {
Some(scheduled_message_id) => {
match scheduling_repo::sched_msg_event::get_with_scheduled_message_id(
&pool,
&scheduled_message_id,
)
.await
{
Ok(scheduled_messages) => scheduled_messages,
Err(err) => {
eprintln!("Error: {err:?}");
return (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
);
}
}
}
None => {
response.message = String::from("Invalid parameter");
return (axum::http::StatusCode::BAD_REQUEST, axum::Json(response));
}
},
};
response.data = scheduled_message_events;
response.message = String::from(super::super::super::response::SUCCESSFUL);
(axum::http::StatusCode::OK, axum::Json(response))
}
}