Fetch schedule message endpoint (#21)
textsender_api PR / Rustfmt (pull_request) Successful in 49s
textsender_api PR / Check (pull_request) Successful in 1m22s
textsender_api PR / Clippy (pull_request) Successful in 2m5s
Rust Build / Test Suite (pull_request) Successful in 35s
Rust Build / Rustfmt (pull_request) Successful in 41s
textsender_api PR / Rustfmt (pull_request) Successful in 49s
textsender_api PR / Check (pull_request) Successful in 1m22s
textsender_api PR / Clippy (pull_request) Successful in 2m5s
Rust Build / Test Suite (pull_request) Successful in 35s
Rust Build / Rustfmt (pull_request) Successful in 41s
Reviewed-on: phoenix/textsender_api#21
This commit was merged in pull request #21.
This commit is contained in:
@@ -52,15 +52,10 @@ pub mod request {
|
||||
impl UpdateScheduledMessageStatusRequest {
|
||||
pub fn is_valid(&self) -> bool {
|
||||
if !self.status.is_empty() || !self.scheduled_message_id.is_nil() {
|
||||
if self.status == textsender_models::message::scheduling::PENDING
|
||||
self.status == textsender_models::message::scheduling::PENDING
|
||||
|| self.status == textsender_models::message::scheduling::READY
|
||||
|| self.status == textsender_models::message::scheduling::PROCESSING
|
||||
|| self.status == textsender_models::message::scheduling::DONE
|
||||
{
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@@ -104,6 +99,8 @@ pub mod response {
|
||||
pub struct ChangedStatus {
|
||||
pub old_status: String,
|
||||
}
|
||||
|
||||
pub use ScheduleMessageResponse as FetchScheduledMessageResponse;
|
||||
}
|
||||
|
||||
pub mod endpoint {
|
||||
@@ -243,6 +240,48 @@ pub mod endpoint {
|
||||
.is_some_and(|t| t - time::OffsetDateTime::now_utc() >= time::Duration::minutes(10))
|
||||
}
|
||||
|
||||
/// Endpoint to fetch Scheduled Message that is ready
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = crate::caller::endpoints::FETCH_SCHEDULED_MESSAGE,
|
||||
responses(
|
||||
(status = 200, description = "Scheduled Message found", body = super::response::FetchScheduledMessageResponse),
|
||||
(status = 400, description = "Error getting Scheduled Message", body = super::response::FetchScheduledMessageResponse)
|
||||
)
|
||||
)]
|
||||
pub async fn fetch_scheduled_message(
|
||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||
) -> (
|
||||
axum::http::StatusCode,
|
||||
axum::Json<super::response::FetchScheduledMessageResponse>,
|
||||
) {
|
||||
let mut response = super::response::FetchScheduledMessageResponse::default();
|
||||
|
||||
match scheduling_repo::fetch(&pool).await {
|
||||
Ok(scheduled_message) => {
|
||||
response.data.push(scheduled_message);
|
||||
response.message = String::from(super::super::super::response::SUCCESSFUL);
|
||||
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
Err(err) => match err {
|
||||
sqlx::Error::RowNotFound => {
|
||||
response.message = String::from("Nothing to fetch");
|
||||
|
||||
(axum::http::StatusCode::NO_CONTENT, axum::Json(response))
|
||||
}
|
||||
_ => {
|
||||
eprintln!("Error: {err:?}");
|
||||
response.message = String::from("Error");
|
||||
(
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Endpoint to update status of Scheduled Message
|
||||
#[utoipa::path(
|
||||
patch,
|
||||
|
||||
@@ -26,6 +26,8 @@ pub mod endpoints {
|
||||
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}";
|
||||
/// Constant for fetching Scheduled Message endpoint
|
||||
pub const FETCH_SCHEDULED_MESSAGE: &str = "/api/v1/schedule/message/fetch";
|
||||
}
|
||||
|
||||
pub mod response {
|
||||
|
||||
Reference in New Issue
Block a user