Adding code
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
pub mod request {
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, ToSchema)]
|
||||
pub struct RecordMessageEventRequest {
|
||||
pub scheduled_message_event_id: uuid::Uuid,
|
||||
pub response: String,
|
||||
pub user_id: uuid::Uuid,
|
||||
pub sent: time::OffsetDateTime,
|
||||
pub status: String,
|
||||
pub contact_id: uuid::Uuid,
|
||||
pub message_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
impl RecordMessageEventRequest {
|
||||
pub fn is_valid(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* {
|
||||
"scheduled_message_event_id": "{{scheduled_message_event_id}}",
|
||||
"response": {{text_response_raw}},
|
||||
"user_id": "{{user_id}}",
|
||||
"sent": "2026-06-20T17:10:00Z",
|
||||
"status": "{{mer_status_scheduled}}",
|
||||
"contact_id": {{contact_id}},
|
||||
"message_id": {{message_id}}
|
||||
}
|
||||
*
|
||||
*/
|
||||
|
||||
pub mod response {
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
|
||||
pub struct RecordMessageEventResponse {
|
||||
pub message: String,
|
||||
pub data: Vec<textsender_models::message::event::MessageEventResponse>
|
||||
}
|
||||
}
|
||||
|
||||
pub mod endpoint {
|
||||
use crate::repo::message::event as event_repo;
|
||||
|
||||
/// Endpoint to create a Message Event Response
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = crate::caller::endpoints::RECORD_MESSAGE_EVENT_RESPONSE,
|
||||
request_body(
|
||||
content = super::request::RecordMessageEventRequest,
|
||||
description = "Data needed to create a Message Event Response",
|
||||
content_type = "application/json"
|
||||
),
|
||||
responses(
|
||||
(status = 201, description = "Message Event Response created", body = super::response::RecordMessageEventResponse),
|
||||
(status = 400, description = "Error", body = super::response::RecordMessageEventResponse),
|
||||
(status = 500, description = "Error creating Message Event Response", body = super::response::RecordMessageEventResponse)
|
||||
)
|
||||
)]
|
||||
pub async fn record_message_event_response(
|
||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||
axum::Json(payload): axum::Json<super::request::RecordMessageEventRequest>,
|
||||
) -> (
|
||||
axum::http::StatusCode,
|
||||
axum::Json<super::response::RecordMessageEventResponse>,
|
||||
) {
|
||||
let mut response = super::response::RecordMessageEventResponse::default();
|
||||
|
||||
if payload.is_valid() {
|
||||
let mut mer = textsender_models::message::event::MessageEventResponse {
|
||||
scheduled_message_event_id: payload.scheduled_message_event_id,
|
||||
user_id: payload.user_id,
|
||||
sent: Some(payload.sent),
|
||||
status: payload.status,
|
||||
contact_id: payload.contact_id,
|
||||
message_id: payload.message_id,
|
||||
response: payload.response,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
println!("MER: {mer:?}");
|
||||
|
||||
match event_repo::insert(&pool, &mer).await {
|
||||
Ok(id) => {
|
||||
mer.id = id;
|
||||
response.message = String::from(super::super::super::response::SUCCESSFUL);
|
||||
response.data.push(mer);
|
||||
(axum::http::StatusCode::CREATED, axum::Json(response))
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
response.message = String::from("Request body is not valid");
|
||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
response.message = String::from("Request body is not valid");
|
||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod event;
|
||||
pub mod scheduling;
|
||||
|
||||
pub mod request {
|
||||
|
||||
Reference in New Issue
Block a user