Finished admin routes

This commit is contained in:
Franklin 2023-03-10 19:42:25 -04:00
parent 227b0b5372
commit a672434ad4
2 changed files with 56 additions and 1 deletions

View File

@ -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<Arc<PgPool>>,
new_agent_payload: web::Json<NewAgentPayload>,
) -> TypedHttpResponse<AgentContainer> {
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<Arc<PgPool>>,
new_location_payload: web::Json<NewLocationPayload>,
) -> TypedHttpResponse<Location> {
service::admin::create_new_location(&db_conn, new_location_payload.0).await
}
#[post("/property")]
pub async fn create_new_property(
db_conn: web::Data<Arc<PgPool>>,
new_property_payload: web::Json<NewPropertyPayload>,
) -> TypedHttpResponse<PropertyContainer> {
service::admin::create_new_property(&db_conn, new_property_payload.0).await
}
#[put("/agent")]
pub async fn update_agent_info(
db_conn: web::Data<Arc<PgPool>>,
update_agent_payload: web::Json<UpdateAgentPayload>,
) -> TypedHttpResponse<ContactInformation> {
service::admin::update_agent_info(&db_conn, update_agent_payload.0).await
}
#[put("/property")]
pub async fn update_listing(
db_conn: web::Data<Arc<PgPool>>,
update_property_payload: web::Json<UpdateListingPayload>,
) -> TypedHttpResponse<PropertyWithDetails> {
service::admin::update_listing(&db_conn, update_property_payload.0).await
}

View File

@ -18,7 +18,16 @@ pub async fn start_all_routes(start_time: i64, db_conn: Arc<PgPool>) -> 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();