Code cleanup
Rust Build / Rustfmt (pull_request) Successful in 34s
Rust Build / Test Suite (pull_request) Successful in 58s

This commit is contained in:
2026-06-17 17:08:21 -04:00
parent 20bd0f9e4d
commit a78078bddd
3 changed files with 19 additions and 14 deletions
+15 -9
View File
@@ -24,7 +24,7 @@ pub mod response {
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
pub struct ScheduleMessageResponse {
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))
} else {
if can_schedule(&payload.scheduled) {
let mut scheduled_message = textsender_models::message::scheduling::ScheduledMessage {
scheduled: payload.scheduled,
status: payload.status,
..Default::default()
};
match scheduling_repo::insert(&pool, &scheduled_message, &payload.user_id).await {
let mut scheduled_message =
textsender_models::message::scheduling::ScheduledMessage {
scheduled: payload.scheduled,
status: payload.status,
..Default::default()
};
match scheduling_repo::insert(&pool, &scheduled_message, &payload.user_id).await
{
Ok((id, created)) => {
scheduled_message.id = id;
scheduled_message.created = Some(created);
@@ -78,7 +80,10 @@ pub mod endpoint {
Err(err) => {
eprintln!("Error: {err:?}");
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 {
@@ -93,6 +98,7 @@ pub mod endpoint {
}
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
View File
@@ -22,8 +22,8 @@ pub mod init {
use contact_caller::response as contact_responses;
use message_caller::endpoint as message_endpoints;
use message_caller::response as message_responses;
use scheduling_caller::response as scheduling_responses;
use scheduling_caller::endpoint as scheduling_endpoints;
use scheduling_caller::response as scheduling_responses;
mod cors {
pub async fn configure_cors() -> tower_http::cors::CorsLayer {
@@ -126,9 +126,9 @@ pub mod init {
)
.route(
crate::caller::endpoints::SCHEDULE_MESSAGE,
post(scheduling_endpoints::schedule_message).route_layer(axum::middleware::from_fn(
crate::auth::auth::<axum::body::Body>,
)),
post(scheduling_endpoints::schedule_message).route_layer(
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
),
)
.layer(cors::configure_cors().await)
}
-1
View File
@@ -25,4 +25,3 @@ pub async fn insert(
Err(_) => Err(sqlx::Error::RowNotFound),
}
}