Changed property queries, dao, and added proeprty_arrangemenet table

This commit is contained in:
Franklin 2023-05-08 13:22:36 -04:00
parent c168bca044
commit 2e5e47c2be
20 changed files with 105 additions and 36 deletions

View File

@ -5,13 +5,16 @@ CREATE TABLE IF NOT EXISTS "property" (
media TEXT NOT NULL, media TEXT NOT NULL,
property_type VARCHAR NOT NULL, property_type VARCHAR NOT NULL,
property_sale_type VARCHAR NOT NULL, property_sale_type VARCHAR NOT NULL,
country VARCHAR, country VARCHAR NOT NULL,
city VARCHAR, city VARCHAR NOT NULL,
district VARCHAR, district VARCHAR NOT NULL,
order_index INT NOT NULL,
thumbnail_format VARCHAR NOT NULL,
price_usd FLOAT8 NOT NULL, price_usd FLOAT8 NOT NULL,
rooms SMALLINT NOT NULL, rooms SMALLINT NOT NULL,
bathrooms FLOAT4 NOT NULL, bathrooms FLOAT4 NOT NULL,
area FLOAT4 NOT NULL, area FLOAT4 NOT NULL,
parking_spots SMALLINT NOT NULL,
admin_tag VARCHAR, admin_tag VARCHAR,
time_created TIMESTAMPTZ NOT NULL, time_created TIMESTAMPTZ NOT NULL,
last_updated TIMESTAMPTZ NOT NULL last_updated TIMESTAMPTZ NOT NULL

View File

@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS "property_arrangement" (
property_id UUID PRIMARY KEY,
price_usd FLOAT8 NOT NULL,
currency VARCHAR NOT NULL,
arrangement VARCHAR NOT NULL,
time_created TIMESTAMPTZ NOT NULL,
last_updated TIMESTAMPTZ NOT NULL
);

View File

@ -8,11 +8,15 @@ SELECT
country, country,
city, city,
district, district,
price_usd, order_index,
thumbnail_format as "thumbnail_format: _",
rooms, rooms,
bathrooms, bathrooms,
area, area,
parking_spots,
admin_tag, admin_tag,
time_created, time_created,
last_updated last_updated
FROM property WHERE realtor_id = $1; FROM property WHERE realtor_id = $1
ORDER BY time_created DESC
LIMIT 25 OFFSET $2;

View File

@ -8,10 +8,12 @@ SELECT
country, country,
city, city,
district, district,
price_usd, order_index,
thumbnail_format as "thumbnail_format: _",
rooms, rooms,
bathrooms, bathrooms,
area, area,
parking_spots,
admin_tag, admin_tag,
time_created, time_created,
last_updated last_updated

View File

@ -8,15 +8,17 @@ INSERT INTO property (
country, country,
city, city,
district, district,
price_usd, order_index,
thumbnail_format,
rooms, rooms,
bathrooms, bathrooms,
area, area,
parking_spots,
admin_tag, admin_tag,
time_created, time_created,
last_updated last_updated
) VALUES ( ) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $15 $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $17
) RETURNING ) RETURNING
id, id,
project_id, project_id,
@ -27,10 +29,12 @@ INSERT INTO property (
country, country,
city, city,
district, district,
price_usd, order_index,
thumbnail_format as "thumbnail_format: _",
rooms, rooms,
bathrooms, bathrooms,
area, area,
parking_spots,
admin_tag, admin_tag,
time_created, time_created,
last_updated; last_updated;

View File

@ -7,12 +7,14 @@ UPDATE property SET
country = $7, country = $7,
city = $8, city = $8,
district = $9, district = $9,
price_usd = $10, order_index = $10,
rooms = $11, thumbnail_format = $11,
bathrooms = $12, rooms = $12,
area = $13, bathrooms = $13,
admin_tag = $14, area = $14,
last_updated = $15 parking_spots = $15,
admin_tag = $16,
last_updated = $17
WHERE id = $1 WHERE id = $1
RETURNING RETURNING
id, id,
@ -24,10 +26,12 @@ RETURNING
country, country,
city, city,
district, district,
price_usd, order_index,
thumbnail_format as "thumbnail_format: _",
rooms, rooms,
bathrooms, bathrooms,
area, area,
parking_spots,
admin_tag, admin_tag,
time_created, time_created,
last_updated; last_updated;

View File

@ -0,0 +1,9 @@
SELECT
property_id,
price_usd,
currency,
arrangement as "arrangement: _",
time_created,
last_updated
FROM property_arrangement
WHERE property_id = $1;

View File

@ -0,0 +1,16 @@
INSERT INTO property_arrangement (
property_id,
price_usd,
currency,
arrangement,
time_created,
last_updated
) VALUES (
$1, $2, $3, $4, $5, $5
) RETURNING
property_id,
price_usd,
currency,
arrangement as "arrangement: _",
time_created,
last_updated;

View File

@ -0,0 +1,13 @@
UPDATE property_arrangement SET
price_usd = $2,
currency = $3,
arrangement = $4,
last_updated = $5
WHERE property_id = $1
RETURNING
property_id,
price_usd,
currency,
arrangement as "arrangement: _",
time_created,
last_updated;

View File

@ -18,10 +18,12 @@ pub async fn insert_property<'a>(
property.country, property.country,
property.city, property.city,
property.district, property.district,
property.price_usd, property.order_index,
property.thumbnail_format as _,
property.rooms, property.rooms,
property.bathrooms, property.bathrooms,
property.area, property.area,
property.parking_spots,
property.admin_tag, property.admin_tag,
property.time_created property.time_created
) )
@ -38,14 +40,17 @@ pub async fn get_property_with_id(
.await .await
} }
pub async fn fetch_with_realtor_id( pub async fn fetch_with_realtor_id_paged(
conn: &PgPool, conn: &PgPool,
realtor_id: &Uuid, realtor_id: &Uuid,
page: &i64,
) -> Result<Vec<Property>, sqlx::Error> { ) -> Result<Vec<Property>, sqlx::Error> {
let offset = (page - 1) * 25;
sqlx::query_file_as!( sqlx::query_file_as!(
Property, Property,
"sql/property/fetch_with_realtor_id.sql", "sql/property/fetch_with_realtor_id_paged.sql",
realtor_id realtor_id,
offset
) )
.fetch_all(conn) .fetch_all(conn)
.await .await
@ -67,10 +72,12 @@ pub async fn update_property<'a>(
property.country, property.country,
property.city, property.city,
property.district, property.district,
property.price_usd, property.order_index,
property.thumbnail_format as _,
property.rooms, property.rooms,
property.bathrooms, property.bathrooms,
property.area, property.area,
property.parking_spots,
property.admin_tag, property.admin_tag,
property.last_updated property.last_updated
) )

View File

@ -5,7 +5,6 @@ use dao::main_dao;
mod dao; mod dao;
mod routes; mod routes;
mod services;
mod utils; mod utils;
#[tokio::main] #[tokio::main]

View File

@ -1,3 +1,6 @@
use std::sync::Arc;
use actix_web::{web::{Path, Data}, get};
use actix_web_utils::extensions::typed_response::TypedHttpResponse; use actix_web_utils::extensions::typed_response::TypedHttpResponse;
use err::MessageResource; use err::MessageResource;
use realtor_lp_types::{ use realtor_lp_types::{
@ -84,3 +87,12 @@ pub async fn udpate_property(
transaction transaction
)) ))
} }
#[get("/properties/{realtor_id}/{page}")]
pub async fn fetch_realtor_properties_paged(
conn: Data<Arc<PgPool>>,
path_vars: Path<(Uuid, i64)>,
) -> TypedHttpResponse<Vec<Property>> {
success!(Default::default())
}

View File

@ -1 +0,0 @@

View File

@ -1,6 +0,0 @@
pub mod click;
pub mod project;
pub mod property;
pub mod realtor;
pub mod trackable;
pub mod view;

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@