First one #8
Generated
+2
-2
@@ -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
@@ -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
@@ -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
@@ -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),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user