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();