Code cleanup
This commit is contained in:
@@ -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
@@ -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)
|
||||
}
|
||||
|
||||
@@ -25,4 +25,3 @@ pub async fn insert(
|
||||
Err(_) => Err(sqlx::Error::RowNotFound),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user