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,
property_type VARCHAR NOT NULL,
property_sale_type VARCHAR NOT NULL,
country VARCHAR,
city VARCHAR,
district VARCHAR,
country VARCHAR NOT NULL,
city VARCHAR NOT NULL,
district VARCHAR NOT NULL,
order_index INT NOT NULL,
thumbnail_format VARCHAR NOT NULL,
price_usd FLOAT8 NOT NULL,
rooms SMALLINT NOT NULL,
bathrooms FLOAT4 NOT NULL,
area FLOAT4 NOT NULL,
parking_spots SMALLINT NOT NULL,
admin_tag VARCHAR,
time_created 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,7 +8,7 @@ SELECT
project_type as "project_type: _",
project_state as "project_state: _",
country,
city,
city,
district,
admin_tag,
floors,
@ -16,4 +16,4 @@ SELECT
order_index,
time_created,
last_updated
FROM project WHERE realtor_id = $1;
FROM project WHERE realtor_id = $1;

View File

@ -8,11 +8,15 @@ SELECT
country,
city,
district,
price_usd,
order_index,
thumbnail_format as "thumbnail_format: _",
rooms,
bathrooms,
area,
parking_spots,
admin_tag,
time_created,
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,
city,
district,
price_usd,
order_index,
thumbnail_format as "thumbnail_format: _",
rooms,
bathrooms,
area,
parking_spots,
admin_tag,
time_created,
last_updated

View File

@ -8,15 +8,17 @@ INSERT INTO property (
country,
city,
district,
price_usd,
order_index,
thumbnail_format,
rooms,
bathrooms,
area,
parking_spots,
admin_tag,
time_created,
last_updated
) 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
id,
project_id,
@ -27,10 +29,12 @@ INSERT INTO property (
country,
city,
district,
price_usd,
order_index,
thumbnail_format as "thumbnail_format: _",
rooms,
bathrooms,
area,
parking_spots,
admin_tag,
time_created,
last_updated;

View File

@ -7,12 +7,14 @@ UPDATE property SET
country = $7,
city = $8,
district = $9,
price_usd = $10,
rooms = $11,
bathrooms = $12,
area = $13,
admin_tag = $14,
last_updated = $15
order_index = $10,
thumbnail_format = $11,
rooms = $12,
bathrooms = $13,
area = $14,
parking_spots = $15,
admin_tag = $16,
last_updated = $17
WHERE id = $1
RETURNING
id,
@ -24,10 +26,12 @@ RETURNING
country,
city,
district,
price_usd,
order_index,
thumbnail_format as "thumbnail_format: _",
rooms,
bathrooms,
area,
parking_spots,
admin_tag,
time_created,
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.city,
property.district,
property.price_usd,
property.order_index,
property.thumbnail_format as _,
property.rooms,
property.bathrooms,
property.area,
property.parking_spots,
property.admin_tag,
property.time_created
)
@ -38,14 +40,17 @@ pub async fn get_property_with_id(
.await
}
pub async fn fetch_with_realtor_id(
pub async fn fetch_with_realtor_id_paged(
conn: &PgPool,
realtor_id: &Uuid,
page: &i64,
) -> Result<Vec<Property>, sqlx::Error> {
let offset = (page - 1) * 25;
sqlx::query_file_as!(
Property,
"sql/property/fetch_with_realtor_id.sql",
realtor_id
"sql/property/fetch_with_realtor_id_paged.sql",
realtor_id,
offset
)
.fetch_all(conn)
.await
@ -67,10 +72,12 @@ pub async fn update_property<'a>(
property.country,
property.city,
property.district,
property.price_usd,
property.order_index,
property.thumbnail_format as _,
property.rooms,
property.bathrooms,
property.area,
property.parking_spots,
property.admin_tag,
property.last_updated
)

View File

@ -5,7 +5,6 @@ use dao::main_dao;
mod dao;
mod routes;
mod services;
mod utils;
#[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 err::MessageResource;
use realtor_lp_types::{
@ -84,3 +87,12 @@ pub async fn udpate_property(
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 @@