Adding code
Rust Build / Rustfmt (pull_request) Successful in 31s
Rust Build / Test Suite (pull_request) Successful in 1m10s
Rust Build / Clippy (pull_request) Successful in 1m42s
Rust Build / Check (pull_request) Successful in 2m33s
Rust Build / build (pull_request) Successful in 3m20s
Rust Build / Rustfmt (pull_request) Successful in 31s
Rust Build / Test Suite (pull_request) Successful in 1m10s
Rust Build / Clippy (pull_request) Successful in 1m42s
Rust Build / Check (pull_request) Successful in 2m33s
Rust Build / build (pull_request) Successful in 3m20s
This commit is contained in:
+30
-17
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user