From 39510e0a9db7bd7c9aeeb846172f6b2ba1e68dbc Mon Sep 17 00:00:00 2001 From: Franklin Date: Tue, 25 Apr 2023 08:53:29 -0400 Subject: [PATCH] Added get unit with id --- src/routes/main_router.rs | 3 ++- src/routes/read.rs | 10 +++++++++- src/services/read.rs | 9 ++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/routes/main_router.rs b/src/routes/main_router.rs index 8a749a2..f18a4d4 100644 --- a/src/routes/main_router.rs +++ b/src/routes/main_router.rs @@ -53,7 +53,8 @@ pub async fn start_all_routes(start_time: i64, db_conn: Arc) -> Result<( .service(super::read::create_contact_request) .service(super::read::get_agent_with_shortcode) .service(super::read::get_location_with_city_and_district) - .service(super::read::get_agent_with_id), + .service(super::read::get_agent_with_id) + .service(super::read::get_unit_with_id), ) }) .bind((HOST_ADDR, HOST_PORT))? diff --git a/src/routes/read.rs b/src/routes/read.rs index a8bdd44..d8d9ad2 100644 --- a/src/routes/read.rs +++ b/src/routes/read.rs @@ -14,7 +14,7 @@ use err::MessageResource; use jl_types::{ domain::{ agent::Agent, location::Location, project_condition::ProjectCondition, - project_type::ProjectType, + project_type::ProjectType, unit::Unit, }, dto::{ filters::Filter, listing::Listing, payloads::contact::ContactPayload, @@ -44,6 +44,14 @@ pub async fn get_agent_with_shortcode( services::read::get_agent_with_shortcode(&db_conn, &shortcode).await } +#[get("/unit/{id}")] +pub async fn get_unit_with_id( + db_conn: web::Data>, + id: web::Path, +) -> TypedHttpResponse { + services::read::get_unit_with_id(&db_conn, &id).await +} + #[get("/locations")] pub async fn get_all_locations( db_conn: web::Data>, diff --git a/src/services/read.rs b/src/services/read.rs index 8a1f91f..28438bb 100644 --- a/src/services/read.rs +++ b/src/services/read.rs @@ -2,7 +2,7 @@ use std::collections::HashSet; use actix_web_utils::extensions::typed_response::TypedHttpResponse; use jl_types::{ - domain::{agent::Agent, location::Location}, + domain::{agent::Agent, location::Location, unit::Unit}, dto::{ filters::Filter, listing::Listing, payloads::contact::ContactPayload, project_card::ProjectCardDto, @@ -37,6 +37,13 @@ pub async fn get_agent_with_id( )) } +pub async fn get_unit_with_id(conn: &PgPool, id: &Uuid) -> TypedHttpResponse { + success!(unwrap_or_not_found!( + handle_db_read_op!(dao::unit::get_with_id(conn, id)), + "units" + )) +} + pub async fn get_all_locations(conn: &PgPool) -> TypedHttpResponse> { let locations: HashSet = handle_db_read_op!(dao::location::fetch_all_locations(conn)) .into_iter()