Added all new routes
This commit is contained in:
parent
6b4e47c7a8
commit
a6cfcb89d0
|
@ -2,11 +2,11 @@ use std::sync::Arc;
|
|||
|
||||
use actix_web::{
|
||||
delete, post, put,
|
||||
web::{self, Path},
|
||||
web::{self, Path}, get,
|
||||
};
|
||||
use actix_web_utils::extensions::typed_response::TypedHttpResponse;
|
||||
use jl_types::{
|
||||
domain::{agent::Agent, location::Location, project::Project, unit::Unit},
|
||||
domain::{agent::Agent, location::Location, project::Project, unit::Unit, count::Count, contact::Contact},
|
||||
dto::payloads::{
|
||||
agent::{NewAgentPayload, UpdateAgentPayload},
|
||||
location::NewLocationPayload,
|
||||
|
@ -106,3 +106,20 @@ pub async fn delete_unit(
|
|||
) -> TypedHttpResponse<()> {
|
||||
services::admin::delete_unit(&db_conn, &unit_id).await
|
||||
}
|
||||
|
||||
#[get("visits/count")]
|
||||
pub async fn get_visits_count(db_conn: web::Data<Arc<PgPool>>) -> TypedHttpResponse<Count> {
|
||||
services::admin::get_all_page_visits(&db_conn).await
|
||||
}
|
||||
|
||||
#[get("contacts/count")]
|
||||
pub async fn get_contacts_count(db_conn: web::Data<Arc<PgPool>>) -> TypedHttpResponse<Count> {
|
||||
services::admin::get_contact_count(&db_conn).await
|
||||
}
|
||||
|
||||
#[get("contacts")]
|
||||
pub async fn get_all_contacts(db_conn: web::Data<Arc<PgPool>>) -> TypedHttpResponse<Vec<Contact>> {
|
||||
services::admin::get_all_contacts(&db_conn).await
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -30,13 +30,17 @@ pub async fn start_all_routes(start_time: i64, db_conn: Arc<PgPool>) -> Result<(
|
|||
.service(super::admin::delete_agent)
|
||||
.service(super::admin::delete_location)
|
||||
.service(super::admin::delete_project)
|
||||
.service(super::admin::delete_unit))
|
||||
.service(super::admin::delete_unit)
|
||||
.service(super::admin::get_all_contacts)
|
||||
.service(super::admin::get_contacts_count)
|
||||
.service(super::admin::get_visits_count))
|
||||
.service(web::scope("/read")
|
||||
.service(super::read::get_all_agents)
|
||||
.service(super::read::get_all_locations)
|
||||
.service(super::read::get_locations_in_city)
|
||||
.service(super::read::get_projects_paged)
|
||||
.service(super::read::get_project_data))
|
||||
.service(super::read::get_project_data)
|
||||
.service(super::read::create_contact_request))
|
||||
})
|
||||
.bind((HOST_ADDR, HOST_PORT))?
|
||||
.run();
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::{collections::{HashMap, HashSet}, str::FromStr, sync::Arc};
|
|||
|
||||
use actix_web::{
|
||||
get,
|
||||
web::{self, Path}, HttpRequest,
|
||||
web::{self, Path}, HttpRequest, post,
|
||||
};
|
||||
use actix_web_utils::extensions::typed_response::TypedHttpResponse;
|
||||
use err::MessageResource;
|
||||
|
@ -11,7 +11,7 @@ use jl_types::{
|
|||
agent::Agent, project_condition::ProjectCondition,
|
||||
project_type::ProjectType,
|
||||
},
|
||||
dto::{filters::Filter, listing::Listing, project_card::ProjectCardDto},
|
||||
dto::{filters::Filter, listing::Listing, project_card::ProjectCardDto, payloads::contact::ContactPayload},
|
||||
};
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
@ -60,6 +60,10 @@ pub async fn get_project_data(
|
|||
) -> TypedHttpResponse<Listing> {
|
||||
services::read::get_project_data(&db_conn, &project_id).await
|
||||
}
|
||||
#[post("/contact")]
|
||||
pub async fn create_contact_request(db_conn: web::Data<Arc<PgPool>>, contact: web::Json<ContactPayload>) -> TypedHttpResponse<()> {
|
||||
services::read::create_contact(&db_conn, contact.0).await
|
||||
}
|
||||
|
||||
fn parse_params_into_filters(
|
||||
params: HashMap<String, String>,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use actix_web_utils::extensions::typed_response::TypedHttpResponse;
|
||||
use jl_types::{
|
||||
domain::{agent::Agent, location::Location, project::Project, unit::Unit},
|
||||
domain::{agent::Agent, location::Location, project::Project, unit::Unit, count::Count, contact::Contact},
|
||||
dto::payloads::{
|
||||
agent::{NewAgentPayload, UpdateAgentPayload},
|
||||
location::NewLocationPayload,
|
||||
|
@ -177,3 +177,18 @@ pub async fn delete_unit(conn: &PgPool, unit_id: &Uuid) -> TypedHttpResponse<()>
|
|||
handle_tx!(tx.commit());
|
||||
success!(())
|
||||
}
|
||||
|
||||
pub async fn get_all_page_visits(conn: &PgPool) -> TypedHttpResponse<Count> {
|
||||
let count = handle_db_read_op!(dao::visit::get_count(conn));
|
||||
success!(count)
|
||||
}
|
||||
|
||||
pub async fn get_all_contacts(conn: &PgPool) -> TypedHttpResponse<Vec<Contact>> {
|
||||
let contacts = handle_db_read_op!(dao::contact::get_all(conn));
|
||||
success!(contacts)
|
||||
}
|
||||
|
||||
pub async fn get_contact_count(conn: &PgPool) -> TypedHttpResponse<Count> {
|
||||
let count = handle_db_read_op!(dao::contact::get_count(conn));
|
||||
success!(count)
|
||||
}
|
|
@ -3,7 +3,7 @@ use std::collections::HashSet;
|
|||
use actix_web_utils::extensions::typed_response::TypedHttpResponse;
|
||||
use jl_types::{
|
||||
domain::{agent::Agent},
|
||||
dto::{filters::Filter, listing::Listing, project_card::ProjectCardDto},
|
||||
dto::{filters::Filter, listing::Listing, project_card::ProjectCardDto, payloads::contact::ContactPayload},
|
||||
};
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
@ -60,3 +60,8 @@ pub async fn get_project_data(conn: &PgPool, project_id: &Uuid) -> TypedHttpResp
|
|||
);
|
||||
success!(Listing::new(project, units, location, agent))
|
||||
}
|
||||
|
||||
pub async fn create_contact(conn: &PgPool, contact: ContactPayload) -> TypedHttpResponse<()> {
|
||||
let _ = handle_db_read_op!(dao::contact::insert(conn, &contact.into()));
|
||||
success!(())
|
||||
}
|
Loading…
Reference in New Issue