First one #8

Merged
phoenix merged 42 commits from get_it_going into v0.2.0 2026-06-13 19:49:15 -04:00
4 changed files with 19 additions and 22 deletions
Showing only changes of commit 306511074a - Show all commits
Generated
+2 -2
View File
@@ -2325,8 +2325,8 @@ dependencies = [
[[package]]
name = "textsender_models"
version = "0.3.1"
source = "git+ssh://git@git.kundeng.us/phoenix/textsender_models.git?tag=v0.3.1-25-ca3b0c92d4-111#ca3b0c92d401ff8ee9b06b1506af042f622667da"
version = "0.3.3"
source = "git+ssh://git@git.kundeng.us/phoenix/textsender_models.git?tag=v0.3.3-27-ec46697714-111#ec466977146cdfca34b4fa50d82d63025a9aa82a"
dependencies = [
"const_format",
"dotenvy",
+1 -1
View File
@@ -25,7 +25,7 @@ jsonwebtoken = { version = "10.3.0", features = ["rust_crypto"] }
josekit = { version = "0.10.3" }
utoipa = { version = "5.5.0", features = ["axum_extras"] }
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]
common-multipart-rfc7578 = { version = "0.7.0" }
+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),
}