Added daos
This commit is contained in:
parent
2e5e47c2be
commit
dd200f0138
@ -1,6 +1,6 @@
|
|||||||
CREATE TABLE IF NOT EXISTS "property_arrangement" (
|
CREATE TABLE IF NOT EXISTS "property_arrangement" (
|
||||||
property_id UUID PRIMARY KEY,
|
property_id UUID PRIMARY KEY,
|
||||||
price_usd FLOAT8 NOT NULL,
|
price FLOAT8 NOT NULL,
|
||||||
currency VARCHAR NOT NULL,
|
currency VARCHAR NOT NULL,
|
||||||
arrangement VARCHAR NOT NULL,
|
arrangement VARCHAR NOT NULL,
|
||||||
time_created TIMESTAMPTZ NOT NULL,
|
time_created TIMESTAMPTZ NOT NULL,
|
||||||
|
@ -1,22 +1,37 @@
|
|||||||
SELECT
|
SELECT
|
||||||
id,
|
p.id,
|
||||||
project_id,
|
p.project_id,
|
||||||
realtor_id,
|
p.realtor_id,
|
||||||
media as "media: _",
|
p.media as "media: _",
|
||||||
property_type as "property_type: _",
|
p.property_type as "property_type: _",
|
||||||
property_sale_type as "property_sale_type: _",
|
p.property_sale_type as "property_sale_type: _",
|
||||||
country,
|
p.country,
|
||||||
city,
|
p.city,
|
||||||
district,
|
p.district,
|
||||||
order_index,
|
p.order_index,
|
||||||
thumbnail_format as "thumbnail_format: _",
|
p.thumbnail_format as "thumbnail_format: _",
|
||||||
rooms,
|
p.rooms,
|
||||||
bathrooms,
|
p.bathrooms,
|
||||||
area,
|
p.area,
|
||||||
parking_spots,
|
p.parking_spots,
|
||||||
admin_tag,
|
p.admin_tag,
|
||||||
time_created,
|
p.time_created,
|
||||||
last_updated
|
p.last_updated
|
||||||
FROM property WHERE realtor_id = $1
|
FROM property p, property_arrangement pa
|
||||||
ORDER BY time_created DESC
|
WHERE p.realtor_id = $1
|
||||||
|
AND pa.property_id = p.id
|
||||||
|
-- FILTERS
|
||||||
|
AND (pa.arrangement = $3 OR $3 IS null) -- Arrangement
|
||||||
|
AND (p.property_type = $4 OR $4 IS null) -- Property Type
|
||||||
|
AND (p.country = $5 OR $5 IS null) -- Country
|
||||||
|
AND (p.city = $6 OR $6 IS null) -- City
|
||||||
|
AND (p.district = $7 OR $7 IS null) -- District
|
||||||
|
AND (p.rooms = $8 OR $8 IS null) -- Room amount
|
||||||
|
AND (p.bathrooms = $9 OR $9 IS null) -- Bathroom amount
|
||||||
|
AND (p.area >= $10 OR $10 IS null) -- Area greater than
|
||||||
|
AND (p.parking_spots = $11 OR $11 IS null) -- Parking spots amount
|
||||||
|
AND (pa.price <= $12 OR $12 IS null) -- Price Less than
|
||||||
|
AND (pa.price >= $13 OR $13 IS null) -- Price Greater than
|
||||||
|
-- END OF FILTERS
|
||||||
|
ORDER BY p.time_created DESC
|
||||||
LIMIT 25 OFFSET $2;
|
LIMIT 25 OFFSET $2;
|
@ -1,6 +1,6 @@
|
|||||||
SELECT
|
SELECT
|
||||||
property_id,
|
property_id,
|
||||||
price_usd,
|
price,
|
||||||
currency,
|
currency,
|
||||||
arrangement as "arrangement: _",
|
arrangement as "arrangement: _",
|
||||||
time_created,
|
time_created,
|
9
sql/property_arrangement/fetch_with_property_ids.sql
Normal file
9
sql/property_arrangement/fetch_with_property_ids.sql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
SELECT
|
||||||
|
property_id,
|
||||||
|
price,
|
||||||
|
currency,
|
||||||
|
arrangement as "arrangement: _",
|
||||||
|
time_created,
|
||||||
|
last_updated
|
||||||
|
FROM property_arrangement
|
||||||
|
WHERE property_id = ANY($1);
|
@ -1,6 +1,6 @@
|
|||||||
INSERT INTO property_arrangement (
|
INSERT INTO property_arrangement (
|
||||||
property_id,
|
property_id,
|
||||||
price_usd,
|
price,
|
||||||
currency,
|
currency,
|
||||||
arrangement,
|
arrangement,
|
||||||
time_created,
|
time_created,
|
||||||
@ -9,7 +9,7 @@ INSERT INTO property_arrangement (
|
|||||||
$1, $2, $3, $4, $5, $5
|
$1, $2, $3, $4, $5, $5
|
||||||
) RETURNING
|
) RETURNING
|
||||||
property_id,
|
property_id,
|
||||||
price_usd,
|
price,
|
||||||
currency,
|
currency,
|
||||||
arrangement as "arrangement: _",
|
arrangement as "arrangement: _",
|
||||||
time_created,
|
time_created,
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
UPDATE property_arrangement SET
|
UPDATE property_arrangement SET
|
||||||
price_usd = $2,
|
price = $2,
|
||||||
currency = $3,
|
currency = $3,
|
||||||
arrangement = $4,
|
arrangement = $4,
|
||||||
last_updated = $5
|
last_updated = $5
|
||||||
WHERE property_id = $1
|
WHERE property_id = $1
|
||||||
RETURNING
|
RETURNING
|
||||||
property_id,
|
property_id,
|
||||||
price_usd,
|
price,
|
||||||
currency,
|
currency,
|
||||||
arrangement as "arrangement: _",
|
arrangement as "arrangement: _",
|
||||||
time_created,
|
time_created,
|
||||||
|
1000
sqlx-data.json
1000
sqlx-data.json
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,8 @@ pub mod project;
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub mod property;
|
pub mod property;
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
|
pub mod property_arrangement;
|
||||||
|
#[allow(unused)]
|
||||||
pub mod realtor;
|
pub mod realtor;
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub mod trackable;
|
pub mod trackable;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use realtor_lp_types::domain::property::Property;
|
use realtor_lp_types::{domain::property::Property, dto::filter::Filter};
|
||||||
use sqlx::{PgPool, Postgres, Transaction};
|
use sqlx::{PgPool, Postgres, Transaction};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@ -43,14 +43,55 @@ pub async fn get_property_with_id(
|
|||||||
pub async fn fetch_with_realtor_id_paged(
|
pub async fn fetch_with_realtor_id_paged(
|
||||||
conn: &PgPool,
|
conn: &PgPool,
|
||||||
realtor_id: &Uuid,
|
realtor_id: &Uuid,
|
||||||
|
filters: &Vec<Filter>,
|
||||||
page: &i64,
|
page: &i64,
|
||||||
) -> Result<Vec<Property>, sqlx::Error> {
|
) -> Result<Vec<Property>, sqlx::Error> {
|
||||||
let offset = (page - 1) * 25;
|
let offset = (page - 1) * 25;
|
||||||
|
|
||||||
|
let mut arrangement_filter = None;
|
||||||
|
let mut property_type_filter = None;
|
||||||
|
let mut country_filter = None;
|
||||||
|
let mut city_filter = None;
|
||||||
|
let mut district_filter = None;
|
||||||
|
let mut room_count_filter = None;
|
||||||
|
let mut bathroom_count_filter = None;
|
||||||
|
let mut min_area_filter = None;
|
||||||
|
let mut parking_spots_count_filter = None;
|
||||||
|
let mut min_price_filter = None;
|
||||||
|
let mut max_price_filter = None;
|
||||||
|
|
||||||
|
for filter in filters {
|
||||||
|
match filter {
|
||||||
|
Filter::Country(country) => country_filter = Some(country),
|
||||||
|
Filter::City(city) => city_filter = Some(city),
|
||||||
|
Filter::District(district) => district_filter = Some(district),
|
||||||
|
Filter::PriceGreaterThan(price_greater_than) => min_price_filter = Some(price_greater_than),
|
||||||
|
Filter::PriceLessThan(price_less_than) => max_price_filter = Some(price_less_than),
|
||||||
|
Filter::Rooms(room_count) => room_count_filter = Some(room_count),
|
||||||
|
Filter::Bathrooms(bathroom_count) => bathroom_count_filter = Some(bathroom_count),
|
||||||
|
Filter::PropertyType(property_type) => property_type_filter = Some(property_type),
|
||||||
|
Filter::MinArea(min_area) => min_area_filter = Some(min_area),
|
||||||
|
Filter::ParkingSpots(parking_spots_count) => parking_spots_count_filter = Some(parking_spots_count),
|
||||||
|
Filter::Arrangement(arrangement) => arrangement_filter = Some(arrangement),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sqlx::query_file_as!(
|
sqlx::query_file_as!(
|
||||||
Property,
|
Property,
|
||||||
"sql/property/fetch_with_realtor_id_paged.sql",
|
"sql/property/fetch_with_realtor_id_paged.sql",
|
||||||
realtor_id,
|
realtor_id,
|
||||||
offset
|
offset,
|
||||||
|
arrangement_filter as _,
|
||||||
|
property_type_filter as _,
|
||||||
|
country_filter,
|
||||||
|
city_filter,
|
||||||
|
district_filter,
|
||||||
|
room_count_filter,
|
||||||
|
bathroom_count_filter,
|
||||||
|
min_area_filter,
|
||||||
|
parking_spots_count_filter,
|
||||||
|
max_price_filter,
|
||||||
|
min_price_filter,
|
||||||
)
|
)
|
||||||
.fetch_all(conn)
|
.fetch_all(conn)
|
||||||
.await
|
.await
|
||||||
|
63
src/dao/property_arrangement.rs
Normal file
63
src/dao/property_arrangement.rs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
use realtor_lp_types::domain::price::PropertyPrice;
|
||||||
|
use sqlx::{PgPool, Postgres, Transaction};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
pub async fn insert_arrangement<'a>(
|
||||||
|
tx: &mut Transaction<'a, Postgres>,
|
||||||
|
arrangement: PropertyPrice,
|
||||||
|
) -> Result<PropertyPrice, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(
|
||||||
|
PropertyPrice,
|
||||||
|
"sql/property_arrangement/insert.sql",
|
||||||
|
arrangement.property_id,
|
||||||
|
arrangement.price,
|
||||||
|
arrangement.currency,
|
||||||
|
arrangement.arrangement as _,
|
||||||
|
arrangement.time_created,
|
||||||
|
)
|
||||||
|
.fetch_one(tx)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn fetch_arrangements_with_property_id(
|
||||||
|
conn: &PgPool,
|
||||||
|
property_id: &Uuid,
|
||||||
|
) -> Result<Vec<PropertyPrice>, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(
|
||||||
|
PropertyPrice,
|
||||||
|
"sql/property_arrangement/fetch_with_property_id.sql",
|
||||||
|
property_id
|
||||||
|
)
|
||||||
|
.fetch_all(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn fetch_arrangements_with_property_ids(
|
||||||
|
conn: &PgPool,
|
||||||
|
property_ids: &Vec<Uuid>,
|
||||||
|
) -> Result<Vec<PropertyPrice>, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(
|
||||||
|
PropertyPrice,
|
||||||
|
"sql/property_arrangement/fetch_with_property_ids.sql",
|
||||||
|
property_ids
|
||||||
|
)
|
||||||
|
.fetch_all(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_arrangement<'a>(
|
||||||
|
tx: &mut Transaction<'a, Postgres>,
|
||||||
|
arrangement: PropertyPrice,
|
||||||
|
) -> Result<PropertyPrice, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(
|
||||||
|
PropertyPrice,
|
||||||
|
"sql/property_arrangement/update.sql",
|
||||||
|
arrangement.property_id,
|
||||||
|
arrangement.price,
|
||||||
|
arrangement.currency,
|
||||||
|
arrangement.arrangement as _,
|
||||||
|
arrangement.last_updated
|
||||||
|
)
|
||||||
|
.fetch_one(tx)
|
||||||
|
.await
|
||||||
|
}
|
@ -1,7 +1,10 @@
|
|||||||
use realtor_lp_types::domain::view::View;
|
use realtor_lp_types::domain::view::View;
|
||||||
use sqlx::{PgPool, Transaction, Postgres};
|
use sqlx::{PgPool, Postgres, Transaction};
|
||||||
|
|
||||||
pub async fn insert_view<'a>(transaction: &mut Transaction<'a, Postgres>, view: View) -> Result<View, sqlx::Error> {
|
pub async fn insert_view<'a>(
|
||||||
|
transaction: &mut Transaction<'a, Postgres>,
|
||||||
|
view: View,
|
||||||
|
) -> Result<View, sqlx::Error> {
|
||||||
sqlx::query_file_as!(
|
sqlx::query_file_as!(
|
||||||
View,
|
View,
|
||||||
"sql/view/insert.sql",
|
"sql/view/insert.sql",
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use actix_web::{web::{Path, Data}, get};
|
use actix_web::{
|
||||||
|
get,
|
||||||
|
web::{Data, Path},
|
||||||
|
};
|
||||||
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::{
|
||||||
@ -93,6 +96,5 @@ pub async fn fetch_realtor_properties_paged(
|
|||||||
conn: Data<Arc<PgPool>>,
|
conn: Data<Arc<PgPool>>,
|
||||||
path_vars: Path<(Uuid, i64)>,
|
path_vars: Path<(Uuid, i64)>,
|
||||||
) -> TypedHttpResponse<Vec<Property>> {
|
) -> TypedHttpResponse<Vec<Property>> {
|
||||||
|
|
||||||
success!(Default::default())
|
success!(Default::default())
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,13 @@ use actix_web_utils::extensions::typed_response::TypedHttpResponse;
|
|||||||
use realtor_lp_types::dto::payloads::view::ViewForCreationPayload;
|
use realtor_lp_types::dto::payloads::view::ViewForCreationPayload;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
use crate::{dao, handle_tx, handle_db_write_op, success};
|
use crate::{dao, handle_db_write_op, handle_tx, success};
|
||||||
|
|
||||||
|
|
||||||
pub async fn new_view(conn: &PgPool, view: ViewForCreationPayload) -> TypedHttpResponse<()> {
|
pub async fn new_view(conn: &PgPool, view: ViewForCreationPayload) -> TypedHttpResponse<()> {
|
||||||
let mut transaction = handle_tx!(conn.begin());
|
let mut transaction = handle_tx!(conn.begin());
|
||||||
handle_db_write_op!(dao::view::insert_view(&mut transaction, view.into()), transaction);
|
handle_db_write_op!(
|
||||||
|
dao::view::insert_view(&mut transaction, view.into()),
|
||||||
|
transaction
|
||||||
|
);
|
||||||
success!(())
|
success!(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user