From a672434ad4630f2ee5b2d2d03edc802d697506b9 Mon Sep 17 00:00:00 2001 From: Franklin Date: Fri, 10 Mar 2023 19:42:25 -0400 Subject: [PATCH] Finished admin routes --- src/routes/admin.rs | 46 +++++++++++++++++++++++++++++++++++++++ src/routes/main_router.rs | 11 +++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/routes/admin.rs b/src/routes/admin.rs index 139597f..3a8a484 100644 --- a/src/routes/admin.rs +++ b/src/routes/admin.rs @@ -1,2 +1,48 @@ +use std::sync::Arc; +use actix_web::{web, post, put}; +use actix_web_utils::extensions::typed_response::TypedHttpResponse; +use remax_types::{dto::{agent::AgentContainer, payload::{agent::{NewAgentPayload, UpdateAgentPayload}, property::{NewPropertyPayload, UpdateListingPayload, PropertyWithDetails}, location::NewLocationPayload}, property::PropertyContainer}, domain::{location::Location, contact_info::ContactInformation}}; +use sqlx::PgPool; +use crate::service; + +#[post("/agent")] +pub async fn create_new_agent_profile( + db_conn: web::Data>, + new_agent_payload: web::Json, +) -> TypedHttpResponse { + service::admin::create_new_agent_profile(&db_conn, new_agent_payload.0).await +} + +#[post("/location")] +pub async fn create_new_location( + db_conn: web::Data>, + new_location_payload: web::Json, +) -> TypedHttpResponse { + service::admin::create_new_location(&db_conn, new_location_payload.0).await +} + +#[post("/property")] +pub async fn create_new_property( + db_conn: web::Data>, + new_property_payload: web::Json, +) -> TypedHttpResponse { + service::admin::create_new_property(&db_conn, new_property_payload.0).await +} + +#[put("/agent")] +pub async fn update_agent_info( + db_conn: web::Data>, + update_agent_payload: web::Json, +) -> TypedHttpResponse { + service::admin::update_agent_info(&db_conn, update_agent_payload.0).await +} + +#[put("/property")] +pub async fn update_listing( + db_conn: web::Data>, + update_property_payload: web::Json, +) -> TypedHttpResponse { + service::admin::update_listing(&db_conn, update_property_payload.0).await +} diff --git a/src/routes/main_router.rs b/src/routes/main_router.rs index 13180c8..5fc7308 100644 --- a/src/routes/main_router.rs +++ b/src/routes/main_router.rs @@ -18,7 +18,16 @@ pub async fn start_all_routes(start_time: i64, db_conn: Arc) -> Result<( .wrap(cors_policy) .app_data(client_state.clone()) .app_data(db_conn.clone()) - //.service(web::scope("/league").service(SERVICE_HERE)) + .service(web::scope("/admin") + .service(super::admin::create_new_agent_profile) + .service(super::admin::create_new_location) + .service(super::admin::create_new_property) + .service(super::admin::update_agent_info) + .service(super::admin::update_listing)) + .service(web::scope("/read") + + ) + }) .bind((HOST_ADDR, HOST_PORT))? .run();