Cleanup
This commit is contained in:
+15
-10
@@ -1,6 +1,7 @@
|
|||||||
pub mod endpoints {
|
pub mod endpoints {
|
||||||
pub const ROOT: &str = "/";
|
pub const ROOT: &str = "/";
|
||||||
|
|
||||||
|
/// Constant for adding Contact endpoint
|
||||||
pub const ADD_CONTACT: &str = "/api/v1/contact/new";
|
pub const ADD_CONTACT: &str = "/api/v1/contact/new";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +30,15 @@ pub mod contact {
|
|||||||
|
|
||||||
impl AddContactRequest {
|
impl AddContactRequest {
|
||||||
pub fn is_valid(&self) -> bool {
|
pub fn is_valid(&self) -> bool {
|
||||||
|
if self.phone_number.is_empty()
|
||||||
|
|| self.first_name.is_empty()
|
||||||
|
|| self.last_name.is_empty()
|
||||||
|
|| self.user_id.is_nil()
|
||||||
|
{
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,7 +77,7 @@ pub mod contact {
|
|||||||
(status = 500, description = "Error creating Contact", body = super::response::AddContactResponse)
|
(status = 500, description = "Error creating Contact", body = super::response::AddContactResponse)
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
pub async fn create_metadata(
|
pub async fn create_contact(
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
axum::Json(payload): axum::Json<super::request::AddContactRequest>,
|
axum::Json(payload): axum::Json<super::request::AddContactRequest>,
|
||||||
) -> (
|
) -> (
|
||||||
@@ -77,7 +87,10 @@ pub mod contact {
|
|||||||
let mut response = super::response::AddContactResponse::default();
|
let mut response = super::response::AddContactResponse::default();
|
||||||
|
|
||||||
if payload.is_valid() {
|
if payload.is_valid() {
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(
|
||||||
|
axum::http::StatusCode::NOT_IMPLEMENTED,
|
||||||
|
axum::Json(response),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
response.message = String::from("Request body is not valid");
|
response.message = String::from("Request body is not valid");
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
@@ -85,11 +98,3 @@ pub mod contact {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
"phone_number": "+16303831708",
|
|
||||||
"first_name": "Bob",
|
|
||||||
"last_name": "De-buildor",
|
|
||||||
"nickname": "Bob",
|
|
||||||
"user_id": "{{user_id}}"
|
|
||||||
*/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user