First one #8

Merged
phoenix merged 42 commits from get_it_going into v0.2.0 2026-06-13 19:49:15 -04:00
3 changed files with 36 additions and 23 deletions
Showing only changes of commit 39697a82e1 - Show all commits
+30 -17
View File
@@ -22,23 +22,18 @@ pub mod contact {
#[derive(Debug, Deserialize, Serialize, ToSchema)]
pub struct AddContactRequest {
pub phone_number: String,
pub first_name: String,
pub last_name: String,
pub firstname: Option<String>,
pub lastname: Option<String>,
pub nickname: Option<String>,
pub user_id: uuid::Uuid,
}
impl AddContactRequest {
pub fn is_valid(&self) -> bool {
if self.phone_number.is_empty()
|| self.first_name.is_empty()
|| self.last_name.is_empty()
self.phone_number.is_empty()
|| self.firstname.is_none()
|| self.lastname.is_none()
|| self.user_id.is_nil()
{
false
} else {
true
}
}
}
}
@@ -57,10 +52,10 @@ pub mod contact {
}
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;
// use crate::repo::contact as contact_repo;
/// Endpoint to create Contact
#[utoipa::path(
@@ -87,10 +82,28 @@ pub mod contact {
let mut response = super::response::AddContactResponse::default();
if payload.is_valid() {
(
axum::http::StatusCode::NOT_IMPLEMENTED,
axum::Json(response),
)
let 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(_) => (
axum::http::StatusCode::NOT_IMPLEMENTED,
axum::Json(response),
),
Err(err) => {
eprintln!("Error: {err:?}");
response.message = String::from("Contact not created");
(
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
)
}
}
} else {
response.message = String::from("Request body is not valid");
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
+5 -5
View File
@@ -10,13 +10,13 @@ pub mod host {
pub mod init {
use std::time::Duration;
use axum::routing::{delete, get, patch, post};
use axum::routing::post;
use tower_http::timeout::TimeoutLayer;
use utoipa::OpenApi;
use crate::caller::contact as contact_caller;
use contact_caller::endpoint as contact_endpoints;
use contact_caller::response as contact_responses;
// use contact_caller::response as contact_responses;
mod cors {
pub async fn configure_cors() -> tower_http::cors::CorsLayer {
@@ -57,8 +57,8 @@ pub mod init {
_ => {
// Development (default): Allow localhost origins
cors.allow_origin(vec![
"http://localhost:8000".parse().unwrap(),
"http://127.0.0.1:8000".parse().unwrap(),
"http://localhost:9081".parse().unwrap(),
"http://127.0.0.1:9081".parse().unwrap(),
"http://localhost:4200".parse().unwrap(),
"http://127.0.0.1:4200".parse().unwrap(),
])
@@ -74,7 +74,7 @@ pub mod init {
tags(
(name = "textsender API", description = "Web API to manage texting")
)
)]
)]
struct ApiDoc;
pub async fn routes() -> axum::Router {
+1 -1
View File
@@ -13,7 +13,7 @@ pub mod contact {
.bind(&contact.lastname)
.bind(&contact.nickname)
.bind(&contact.phone_number)
.bind(&contact.user_id)
.bind(contact.user_id)
.execute(pool)
.await;