Code cleanup
This commit is contained in:
@@ -24,7 +24,7 @@ pub mod response {
|
|||||||
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
|
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
|
||||||
pub struct ScheduleMessageResponse {
|
pub struct ScheduleMessageResponse {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<textsender_models::message::scheduling::ScheduledMessage>
|
pub data: Vec<textsender_models::message::scheduling::ScheduledMessage>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,12 +61,14 @@ pub mod endpoint {
|
|||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
} else {
|
} else {
|
||||||
if can_schedule(&payload.scheduled) {
|
if can_schedule(&payload.scheduled) {
|
||||||
let mut scheduled_message = textsender_models::message::scheduling::ScheduledMessage {
|
let mut scheduled_message =
|
||||||
scheduled: payload.scheduled,
|
textsender_models::message::scheduling::ScheduledMessage {
|
||||||
status: payload.status,
|
scheduled: payload.scheduled,
|
||||||
..Default::default()
|
status: payload.status,
|
||||||
};
|
..Default::default()
|
||||||
match scheduling_repo::insert(&pool, &scheduled_message, &payload.user_id).await {
|
};
|
||||||
|
match scheduling_repo::insert(&pool, &scheduled_message, &payload.user_id).await
|
||||||
|
{
|
||||||
Ok((id, created)) => {
|
Ok((id, created)) => {
|
||||||
scheduled_message.id = id;
|
scheduled_message.id = id;
|
||||||
scheduled_message.created = Some(created);
|
scheduled_message.created = Some(created);
|
||||||
@@ -78,7 +80,10 @@ pub mod endpoint {
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
response.message = String::from("Error inserting");
|
response.message = String::from("Error inserting");
|
||||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response))
|
(
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -93,6 +98,7 @@ pub mod endpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn can_schedule(scheduled_time: &Option<time::OffsetDateTime>) -> bool {
|
fn can_schedule(scheduled_time: &Option<time::OffsetDateTime>) -> bool {
|
||||||
scheduled_time.is_some_and(|t| t - time::OffsetDateTime::now_utc() >= time::Duration::minutes(10))
|
scheduled_time
|
||||||
|
.is_some_and(|t| t - time::OffsetDateTime::now_utc() >= time::Duration::minutes(10))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -22,8 +22,8 @@ pub mod init {
|
|||||||
use contact_caller::response as contact_responses;
|
use contact_caller::response as contact_responses;
|
||||||
use message_caller::endpoint as message_endpoints;
|
use message_caller::endpoint as message_endpoints;
|
||||||
use message_caller::response as message_responses;
|
use message_caller::response as message_responses;
|
||||||
use scheduling_caller::response as scheduling_responses;
|
|
||||||
use scheduling_caller::endpoint as scheduling_endpoints;
|
use scheduling_caller::endpoint as scheduling_endpoints;
|
||||||
|
use scheduling_caller::response as scheduling_responses;
|
||||||
|
|
||||||
mod cors {
|
mod cors {
|
||||||
pub async fn configure_cors() -> tower_http::cors::CorsLayer {
|
pub async fn configure_cors() -> tower_http::cors::CorsLayer {
|
||||||
@@ -126,9 +126,9 @@ pub mod init {
|
|||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
crate::caller::endpoints::SCHEDULE_MESSAGE,
|
crate::caller::endpoints::SCHEDULE_MESSAGE,
|
||||||
post(scheduling_endpoints::schedule_message).route_layer(axum::middleware::from_fn(
|
post(scheduling_endpoints::schedule_message).route_layer(
|
||||||
crate::auth::auth::<axum::body::Body>,
|
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
|
||||||
)),
|
),
|
||||||
)
|
)
|
||||||
.layer(cors::configure_cors().await)
|
.layer(cors::configure_cors().await)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,3 @@ pub async fn insert(
|
|||||||
Err(_) => Err(sqlx::Error::RowNotFound),
|
Err(_) => Err(sqlx::Error::RowNotFound),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user