Yes
Rust Build / Test Suite (pull_request) Successful in 59s
Rust Build / Rustfmt (pull_request) Successful in 57s
Rust Build / Check (pull_request) Successful in 2m53s
Rust Build / build (pull_request) Successful in 2m6s
Rust Build / Clippy (pull_request) Successful in 2m28s

This commit is contained in:
2026-06-13 18:50:58 -04:00
parent 0b542b3f26
commit 306511074a
4 changed files with 19 additions and 22 deletions
Generated
+2 -2
View File
@@ -2325,8 +2325,8 @@ dependencies = [
[[package]] [[package]]
name = "textsender_models" name = "textsender_models"
version = "0.3.1" version = "0.3.3"
source = "git+ssh://git@git.kundeng.us/phoenix/textsender_models.git?tag=v0.3.1-25-ca3b0c92d4-111#ca3b0c92d401ff8ee9b06b1506af042f622667da" source = "git+ssh://git@git.kundeng.us/phoenix/textsender_models.git?tag=v0.3.3-27-ec46697714-111#ec466977146cdfca34b4fa50d82d63025a9aa82a"
dependencies = [ dependencies = [
"const_format", "const_format",
"dotenvy", "dotenvy",
+1 -1
View File
@@ -25,7 +25,7 @@ jsonwebtoken = { version = "10.3.0", features = ["rust_crypto"] }
josekit = { version = "0.10.3" } josekit = { version = "0.10.3" }
utoipa = { version = "5.5.0", features = ["axum_extras"] } utoipa = { version = "5.5.0", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.3.2" } textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.3.3-27-ec46697714-111" }
[dev-dependencies] [dev-dependencies]
common-multipart-rfc7578 = { version = "0.7.0" } common-multipart-rfc7578 = { version = "0.7.0" }
+6 -7
View File
@@ -45,8 +45,6 @@ pub mod contact {
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)] #[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
pub struct AddContactResponse { pub struct AddContactResponse {
pub message: String, pub message: String,
// TODO: Should be this. Update code in textsender_models
// pub data: Vec<textsender_models::contact::Contact>,
pub data: Vec<textsender_models::contact::Contact>, pub data: Vec<textsender_models::contact::Contact>,
} }
} }
@@ -54,8 +52,7 @@ pub mod contact {
pub mod endpoint { pub mod endpoint {
// use axum::{Json, response::IntoResponse}; // use axum::{Json, response::IntoResponse};
// use crate::repo; use crate::repo::contact as contact_repo;
// use crate::repo::contact as contact_repo;
/// Endpoint to create Contact /// Endpoint to create Contact
#[utoipa::path( #[utoipa::path(
@@ -82,16 +79,18 @@ pub mod contact {
let mut response = super::response::AddContactResponse::default(); let mut response = super::response::AddContactResponse::default();
if payload.is_valid() { if payload.is_valid() {
let contact = textsender_models::contact::Contact { let mut contact = textsender_models::contact::Contact {
firstname: payload.firstname, firstname: payload.firstname,
lastname: payload.lastname, lastname: payload.lastname,
phone_number: payload.phone_number, phone_number: payload.phone_number,
user_id: Some(payload.user_id), user_id: Some(payload.user_id),
..Default::default() ..Default::default()
}; };
match crate::repo::contact::insert(&pool, &contact).await { match contact_repo::insert(&pool, &contact).await {
Ok(_) => { Ok(id) => {
contact.id = Some(id);
response.message = String::from(super::super::response::SUCCESSFUL); response.message = String::from(super::super::response::SUCCESSFUL);
response.data.push(contact);
(axum::http::StatusCode::CREATED, axum::Json(response)) (axum::http::StatusCode::CREATED, axum::Json(response))
} }
+10 -12
View File
@@ -1,12 +1,14 @@
pub mod contact { pub mod contact {
use sqlx::Row;
pub async fn insert( pub async fn insert(
pool: &sqlx::PgPool, pool: &sqlx::PgPool,
contact: &textsender_models::contact::Contact, contact: &textsender_models::contact::Contact,
) -> Result<(), sqlx::Error> { ) -> Result<uuid::Uuid, sqlx::Error> {
let result = sqlx::query( match sqlx::query(
r#" r#"
INSERT INTO "contacts" (firstname, lastname, nickname, phone_number, user_id) INSERT INTO "contacts" (firstname, lastname, nickname, phone_number, user_id)
VALUES($1, $2, $3, $4, $5); VALUES($1, $2, $3, $4, $5) RETURNING id;
"#, "#,
) )
.bind(&contact.firstname) .bind(&contact.firstname)
@@ -14,16 +16,12 @@ pub mod contact {
.bind(&contact.nickname) .bind(&contact.nickname)
.bind(&contact.phone_number) .bind(&contact.phone_number)
.bind(contact.user_id) .bind(contact.user_id)
.execute(pool) .fetch_one(pool)
.await; .await
{
match result {
Ok(row) => { Ok(row) => {
if row.rows_affected() > 0 { let id: uuid::Uuid = row.try_get("id")?;
Ok(()) Ok(id)
} else {
Err(sqlx::Error::RowNotFound)
}
} }
Err(_) => Err(sqlx::Error::RowNotFound), Err(_) => Err(sqlx::Error::RowNotFound),
} }