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
+6 -7
View File
@@ -45,8 +45,6 @@ pub mod contact {
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
pub struct AddContactResponse {
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>,
}
}
@@ -54,8 +52,7 @@ pub mod contact {
pub mod endpoint {
// 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
#[utoipa::path(
@@ -82,16 +79,18 @@ pub mod contact {
let mut response = super::response::AddContactResponse::default();
if payload.is_valid() {
let contact = textsender_models::contact::Contact {
let mut contact = textsender_models::contact::Contact {
firstname: payload.firstname,
lastname: payload.lastname,
phone_number: payload.phone_number,
user_id: Some(payload.user_id),
..Default::default()
};
match crate::repo::contact::insert(&pool, &contact).await {
Ok(_) => {
match contact_repo::insert(&pool, &contact).await {
Ok(id) => {
contact.id = Some(id);
response.message = String::from(super::super::response::SUCCESSFUL);
response.data.push(contact);
(axum::http::StatusCode::CREATED, axum::Json(response))
}
+10 -12
View File
@@ -1,12 +1,14 @@
pub mod contact {
use sqlx::Row;
pub async fn insert(
pool: &sqlx::PgPool,
contact: &textsender_models::contact::Contact,
) -> Result<(), sqlx::Error> {
let result = sqlx::query(
) -> Result<uuid::Uuid, sqlx::Error> {
match sqlx::query(
r#"
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)
@@ -14,16 +16,12 @@ pub mod contact {
.bind(&contact.nickname)
.bind(&contact.phone_number)
.bind(contact.user_id)
.execute(pool)
.await;
match result {
.fetch_one(pool)
.await
{
Ok(row) => {
if row.rows_affected() > 0 {
Ok(())
} else {
Err(sqlx::Error::RowNotFound)
}
let id: uuid::Uuid = row.try_get("id")?;
Ok(id)
}
Err(_) => Err(sqlx::Error::RowNotFound),
}