Added arrangement route

This commit is contained in:
Franklin 2023-05-11 11:44:46 -04:00
parent 5f878f04a9
commit bfb246ca7a
7 changed files with 96 additions and 57 deletions

View File

@ -3,7 +3,7 @@ UPDATE property_arrangement SET
currency = $3,
arrangement = $4,
last_updated = $5
WHERE property_id = $1
WHERE property_id = $1 AND arrangement = $4
RETURNING
property_id,
price,

View File

@ -297,60 +297,6 @@
},
"query": "SELECT * FROM realtor WHERE shortcode = $1;"
},
"22aa2761cf17dba99859d46e40c8b5e04a112f2fdae12494f4aabc384cde4727": {
"describe": {
"columns": [
{
"name": "property_id",
"ordinal": 0,
"type_info": "Uuid"
},
{
"name": "price",
"ordinal": 1,
"type_info": "Float8"
},
{
"name": "currency",
"ordinal": 2,
"type_info": "Varchar"
},
{
"name": "arrangement: _",
"ordinal": 3,
"type_info": "Varchar"
},
{
"name": "time_created",
"ordinal": 4,
"type_info": "Timestamptz"
},
{
"name": "last_updated",
"ordinal": 5,
"type_info": "Timestamptz"
}
],
"nullable": [
false,
false,
false,
false,
false,
false
],
"parameters": {
"Left": [
"Uuid",
"Float8",
"Varchar",
"Varchar",
"Timestamptz"
]
}
},
"query": "UPDATE property_arrangement SET \n price = $2,\n currency = $3,\n arrangement = $4,\n last_updated = $5\nWHERE property_id = $1\nRETURNING \n property_id,\n price,\n currency,\n arrangement as \"arrangement: _\",\n time_created,\n last_updated;"
},
"3acc0efdfdf6fd4e86b0f197cd27b7378507b82915127b76a6cf76a8f7cb5618": {
"describe": {
"columns": [
@ -953,6 +899,60 @@
},
"query": "INSERT INTO property (\n id,\n project_id,\n realtor_id,\n media,\n property_type,\n property_sale_type,\n country,\n city,\n district,\n order_index,\n thumbnail_format,\n rooms,\n bathrooms,\n area,\n parking_spots,\n admin_tag,\n time_created,\n last_updated\n) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $17\n) RETURNING \n id,\n project_id,\n realtor_id,\n media as \"media: _\",\n property_type as \"property_type: _\",\n property_sale_type as \"property_sale_type: _\",\n country,\n city,\n district,\n order_index,\n thumbnail_format as \"thumbnail_format: _\",\n rooms,\n bathrooms,\n area,\n parking_spots,\n admin_tag,\n time_created,\n last_updated;"
},
"6b566fd0b806219fa856991fc4bc93157c989d418562dc89268c9fb9363424bd": {
"describe": {
"columns": [
{
"name": "property_id",
"ordinal": 0,
"type_info": "Uuid"
},
{
"name": "price",
"ordinal": 1,
"type_info": "Float8"
},
{
"name": "currency",
"ordinal": 2,
"type_info": "Varchar"
},
{
"name": "arrangement: _",
"ordinal": 3,
"type_info": "Varchar"
},
{
"name": "time_created",
"ordinal": 4,
"type_info": "Timestamptz"
},
{
"name": "last_updated",
"ordinal": 5,
"type_info": "Timestamptz"
}
],
"nullable": [
false,
false,
false,
false,
false,
false
],
"parameters": {
"Left": [
"Uuid",
"Float8",
"Varchar",
"Text",
"Timestamptz"
]
}
},
"query": "UPDATE property_arrangement SET \n price = $2,\n currency = $3,\n arrangement = $4,\n last_updated = $5\nWHERE property_id = $1 AND arrangement = $4\nRETURNING \n property_id,\n price,\n currency,\n arrangement as \"arrangement: _\",\n time_created,\n last_updated;"
},
"7464713d873ea4ad81fdbaef816eb57ce3bdcdf3aa669036e05158e230abd82c": {
"describe": {
"columns": [

18
src/routes/arrangement.rs Normal file
View File

@ -0,0 +1,18 @@
use std::sync::Arc;
use actix_web::{
post,
web::{self, Json},
};
use actix_web_utils::extensions::typed_response::TypedHttpResponse;
use realtor_lp_types::{
domain::{price::PropertyPrice}, dto::payloads::{arrangement::PropertyPriceForCreationPayload},
};
use sqlx::PgPool;
use crate::services;
#[post("/arrangement")]
pub async fn add_property_arrangement(db_conn: web::Data<Arc<PgPool>>, arrangement: Json<PropertyPriceForCreationPayload>) -> TypedHttpResponse<PropertyPrice> {
services::arrangement::add_arrangement_to_property(&db_conn, arrangement.0).await
}

View File

@ -13,7 +13,7 @@ use sqlx::PgPool;
use crate::utils::s3;
use super::{click, property, realtor, trackable, view};
use super::{click, property, realtor, trackable, view, arrangement};
pub const HOST_ADDR: &str = "0.0.0.0";
pub const HOST_PORT: u16 = 8080;
@ -37,7 +37,8 @@ pub async fn start_all_routes(start_time: i64, db_conn: Arc<PgPool>) -> Result<(
.service(property::new_property)
.service(property::update_property)
.service(realtor::new_realtor_profile)
.service(realtor::update_realtor_profile),
.service(realtor::update_realtor_profile)
.service(arrangement::add_property_arrangement),
)
.service(
web::scope("/public")

View File

@ -12,3 +12,4 @@ pub mod realtor;
pub mod trackable;
#[allow(unused)]
pub mod view;
pub mod arrangement;

View File

@ -0,0 +1,18 @@
use actix_web_utils::extensions::typed_response::TypedHttpResponse;
use realtor_lp_types::{domain::price::PropertyPrice, dto::payloads::arrangement::PropertyPriceForCreationPayload};
use sqlx::PgPool;
use crate::{success, handle_tx, handle_db_write_op, dao, handle_db_read_op};
pub async fn add_arrangement_to_property(conn: &PgPool, arrangement: PropertyPriceForCreationPayload) -> TypedHttpResponse<PropertyPrice> {
let mut tx = handle_tx!(conn.begin());
let existing_arrangement = handle_db_read_op!(dao::property_arrangement::fetch_arrangements_with_property_id(conn, &arrangement.property_id));
if existing_arrangement.iter().any(|persisted_arrangement| persisted_arrangement.arrangement == arrangement.arrangement) {
let persisted_arrangement = handle_db_write_op!(dao::property_arrangement::update_arrangement(&mut tx, arrangement.into()), tx);
success!(persisted_arrangement)
} else {
let persisted_arrangement = handle_db_write_op!(dao::property_arrangement::insert_arrangement(&mut tx, arrangement.into()), tx);
success!(persisted_arrangement)
}
}

View File

@ -10,3 +10,4 @@ pub mod realtor;
pub mod trackable;
#[allow(unused)]
pub mod view;
pub mod arrangement;