Added endpoint
This commit is contained in:
@@ -25,6 +25,12 @@ pub mod request {
|
|||||||
|| !self.message_id.is_nil()
|
|| !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 {
|
pub mod response {
|
||||||
@@ -36,6 +42,8 @@ pub mod response {
|
|||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<textsender_models::message::event::MessageEventResponse>,
|
pub data: Vec<textsender_models::message::event::MessageEventResponse>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub use RecordMessageEventResponse as GetMERResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod endpoint {
|
pub mod endpoint {
|
||||||
@@ -95,4 +103,63 @@ pub mod endpoint {
|
|||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user