Get Message Event Response endpoint (#23)
textsender_api PR / Rustfmt (pull_request) Successful in 50s
textsender_api PR / Clippy (pull_request) Successful in 1m22s
textsender_api PR / Check (pull_request) Successful in 2m11s
Rust Build / Rustfmt (pull_request) Successful in 37s
Rust Build / Test Suite (pull_request) Successful in 40s

Reviewed-on: phoenix/textsender_api#23
This commit was merged in pull request #23.
This commit is contained in:
2026-06-20 15:05:20 -04:00
parent a9d7429d75
commit 295140a216
7 changed files with 250 additions and 4 deletions
+69
View File
@@ -25,6 +25,12 @@ pub mod request {
|| !self.message_id.is_nil()
}
}
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct GetMessageEventResponseParams {
pub id: Option<uuid::Uuid>,
pub user_id: Option<uuid::Uuid>,
}
}
pub mod response {
@@ -36,6 +42,8 @@ pub mod response {
pub message: String,
pub data: Vec<textsender_models::message::event::MessageEventResponse>,
}
pub use RecordMessageEventResponse as GetMERResponse;
}
pub mod endpoint {
@@ -95,4 +103,65 @@ pub mod endpoint {
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
}
/// Endpoint to get Messages
#[utoipa::path(
get,
path = crate::caller::endpoints::GET_MESSAGE_EVENT_RESPONSE,
params(
("id" = uuid::Uuid, Path, description = "Id of Message Event Response"),
("user_id" = uuid::Uuid, Path, description = "User Id associated with the Message Event Response")
),
responses(
(status = 200, description = "Message Event Response found", body = super::response::GetMERResponse),
(status = 400, description = "Error getting Message Event Response", body = super::response::GetMERResponse)
)
)]
pub async fn get_record_message_event_response(
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::extract::Query(params): axum::extract::Query<
super::request::GetMessageEventResponseParams,
>,
) -> (
axum::http::StatusCode,
axum::Json<super::response::GetMERResponse>,
) {
let mut response = super::response::GetMERResponse::default();
let messages = match params.id {
Some(id) => match event_repo::get(&pool, &id).await {
Ok(message) => {
vec![message]
}
Err(err) => {
eprintln!("Error: {err:?}");
return (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
);
}
},
None => match params.user_id {
Some(user_id) => match event_repo::get_with_user_id(&pool, &user_id).await {
Ok(messages) => messages,
Err(err) => {
eprintln!("Error: {err:?}");
return (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
);
}
},
None => {
response.message = String::from("Invalid parameter");
return (axum::http::StatusCode::BAD_REQUEST, axum::Json(response));
}
},
};
response.data = messages;
response.message = String::from(super::super::super::response::SUCCESSFUL);
(axum::http::StatusCode::OK, axum::Json(response))
}
}
+2
View File
@@ -31,6 +31,8 @@ pub mod endpoints {
/// Constant for recording Message Event Response endpoint
pub const RECORD_MESSAGE_EVENT_RESPONSE: &str =
"/api/v1/schedule/message/event/response/record";
/// Constant for getting Message Event Response endpoint
pub const GET_MESSAGE_EVENT_RESPONSE: &str = "/api/v1/schedule/message/event/response";
}
pub mod response {
+6
View File
@@ -177,6 +177,12 @@ pub mod init {
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
),
)
.route(
crate::caller::endpoints::GET_MESSAGE_EVENT_RESPONSE,
get(event_endpoints::get_record_message_event_response).route_layer(
axum::middleware::from_fn(crate::auth::auth::<axum::body::Body>),
),
)
.layer(cors::configure_cors().await)
}
+2 -2
View File
@@ -96,7 +96,7 @@ async fn parse_row(
let contact_id: uuid::Uuid = row.try_get("contact_id")?;
let message_id: uuid::Uuid = row.try_get("message_id")?;
let sent: time::OffsetDateTime = row.try_get("sent")?;
let scheduled_message_id: uuid::Uuid = row.try_get("scheduled_message_id")?;
let scheduled_message_event_id: uuid::Uuid = row.try_get("scheduled_message_event_id")?;
let user_id: uuid::Uuid = row.try_get("user_id")?;
Ok(textsender_models::message::event::MessageEventResponse {
@@ -106,7 +106,7 @@ async fn parse_row(
message_id,
status,
sent: Some(sent),
scheduled_message_event_id: scheduled_message_id,
scheduled_message_event_id,
user_id,
})
}