From e54a53a4962431fd062af6e6374c61418bed1ca6 Mon Sep 17 00:00:00 2001 From: phoenix Date: Wed, 17 Jun 2026 14:23:38 -0400 Subject: [PATCH] Got it working --- src/caller/message.rs | 19 +++++++++---------- src/config/mod.rs | 12 ++++++------ src/repo/message.rs | 3 +-- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/caller/message.rs b/src/caller/message.rs index 0427aa3..05d8280 100644 --- a/src/caller/message.rs +++ b/src/caller/message.rs @@ -5,7 +5,7 @@ pub mod request { #[derive(Debug, Deserialize, Serialize, ToSchema)] pub struct AddMessageRequest { pub content: String, - pub user_id: uuid::Uuid + pub user_id: uuid::Uuid, } impl AddMessageRequest { @@ -22,7 +22,7 @@ pub mod response { #[derive(Debug, Default, Deserialize, Serialize, ToSchema)] pub struct AddMessageResponse { pub message: String, - pub data: Vec + pub data: Vec, } } @@ -59,8 +59,7 @@ pub mod endpoint { user_id: Some(payload.user_id), ..Default::default() }; - match message_repo::insert(&pool, &msg, &payload.user_id) .await - { + match message_repo::insert(&pool, &msg, &payload.user_id).await { Ok(message_id) => { msg.id = Some(message_id); response.data.push(msg); @@ -68,13 +67,13 @@ pub mod endpoint { (axum::http::StatusCode::CREATED, axum::Json(response)) } Err(err) => { - eprintln!("Error: {err:?}"); - response.message = String::from("Contact not created"); + eprintln!("Error: {err:?}"); + response.message = String::from("Contact not created"); - ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - axum::Json(response), - ) + ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ) } } } else { diff --git a/src/config/mod.rs b/src/config/mod.rs index daf5acb..f8a03e9 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -17,8 +17,8 @@ pub mod init { use crate::caller::contact as contact_caller; use crate::caller::message as message_caller; use contact_caller::endpoint as contact_endpoints; - use message_caller::endpoint as message_endpoints; use contact_caller::response as contact_responses; + use message_caller::endpoint as message_endpoints; use message_caller::response as message_responses; mod cors { @@ -76,9 +76,9 @@ pub mod init { #[derive(utoipa::OpenApi)] #[openapi( - paths(contact_endpoints::create_contact, + paths(contact_endpoints::create_contact, message_endpoints::create_message), - components(schemas(contact_responses::AddContactResponse)), + components(schemas(contact_responses::AddContactResponse, message_responses::AddMessageResponse)), tags( (name = "textsender API", description = "Web API to manage texting") ) @@ -107,9 +107,9 @@ pub mod init { ) .route( crate::caller::endpoints::ADD_MESSAGE, - patch(message_endpoints::create_message).route_layer( - axum::middleware::from_fn(crate::auth::auth::), - ), + post(message_endpoints::create_message).route_layer(axum::middleware::from_fn( + crate::auth::auth::, + )), ) .layer(cors::configure_cors().await) } diff --git a/src/repo/message.rs b/src/repo/message.rs index a5bf5ae..312e893 100644 --- a/src/repo/message.rs +++ b/src/repo/message.rs @@ -7,7 +7,7 @@ pub async fn insert( ) -> Result { match sqlx::query( r#" - INSERT INTO "contacts" (content, user_id) + INSERT INTO "messages" (content, user_id) VALUES($1, $2) RETURNING id; "#, ) @@ -23,4 +23,3 @@ pub async fn insert( Err(_) => Err(sqlx::Error::RowNotFound), } } -