All base daos done.
This commit is contained in:
parent
b8d62012b2
commit
1e3c395f92
@ -3,8 +3,8 @@ by Franklin Blanco
|
||||
|
||||
### Todo's
|
||||
|
||||
- [ ] Add properties
|
||||
- [ ] Add agents
|
||||
- [x] Add properties
|
||||
- [x] Add agents
|
||||
- [ ] Fetch them both
|
||||
- [ ] Delete, update
|
||||
- [ ] Admin panel functions
|
||||
|
@ -3,7 +3,7 @@ INSERT INTO property_details (
|
||||
meters,
|
||||
listing_type,
|
||||
photo_urls,
|
||||
location_id,
|
||||
location_id
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
@ -15,4 +15,4 @@ property_id,
|
||||
meters,
|
||||
listing_type as "listing_type: _",
|
||||
photo_urls as "photo_urls: _",
|
||||
location_id
|
||||
location_id;
|
@ -1 +1,40 @@
|
||||
use remax_types::domain::agent::Agent;
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn insert_agent(
|
||||
conn: &PgPool,
|
||||
agent: &Agent,
|
||||
) -> Result<Agent, sqlx::error::Error> {
|
||||
sqlx::query_file_as!(
|
||||
Agent,
|
||||
"sql/agent/insert.sql",
|
||||
agent.id,
|
||||
agent.full_name,
|
||||
agent.time_created
|
||||
)
|
||||
.fetch_one(conn)
|
||||
.await
|
||||
}
|
||||
pub async fn get_properties_with_ids(
|
||||
conn: &PgPool,
|
||||
ids: &Vec<Uuid>,
|
||||
) -> Result<Vec<Agent>, sqlx::error::Error> {
|
||||
sqlx::query_file_as!(Agent, "sql/agent/fetch_with_ids.sql", ids)
|
||||
.fetch_all(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn update_agent(
|
||||
conn: &PgPool,
|
||||
agent: &Agent,
|
||||
) -> Result<Agent, sqlx::error::Error> {
|
||||
sqlx::query_file_as!(
|
||||
Agent,
|
||||
"sql/agent/update.sql",
|
||||
agent.full_name,
|
||||
agent.last_updated
|
||||
)
|
||||
.fetch_one(conn)
|
||||
.await
|
||||
}
|
||||
|
44
src/dao/contact_info.rs
Normal file
44
src/dao/contact_info.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use remax_types::domain::contact_info::ContactInformation;
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn insert_contact_info(
|
||||
conn: &PgPool,
|
||||
contact_info: &ContactInformation,
|
||||
) -> Result<ContactInformation, sqlx::error::Error> {
|
||||
sqlx::query_file_as!(
|
||||
ContactInformation,
|
||||
"sql/contact_info/insert.sql",
|
||||
contact_info.agent_id,
|
||||
contact_info.phone_number,
|
||||
contact_info.email,
|
||||
contact_info.profile_picture_url,
|
||||
contact_info.default_message
|
||||
)
|
||||
.fetch_one(conn)
|
||||
.await
|
||||
}
|
||||
pub async fn get_properties_with_ids(
|
||||
conn: &PgPool,
|
||||
ids: &Vec<Uuid>,
|
||||
) -> Result<Vec<ContactInformation>, sqlx::error::Error> {
|
||||
sqlx::query_file_as!(ContactInformation, "sql/contact_info/fetch_with_ids.sql", ids)
|
||||
.fetch_all(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn update_contact_info(
|
||||
conn: &PgPool,
|
||||
contact_info: &ContactInformation,
|
||||
) -> Result<ContactInformation, sqlx::error::Error> {
|
||||
sqlx::query_file_as!(
|
||||
ContactInformation,
|
||||
"sql/contact_info/update.sql",
|
||||
contact_info.phone_number,
|
||||
contact_info.email,
|
||||
contact_info.profile_picture_url,
|
||||
contact_info.default_message
|
||||
)
|
||||
.fetch_one(conn)
|
||||
.await
|
||||
}
|
29
src/dao/location.rs
Normal file
29
src/dao/location.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use remax_types::domain::location::Location;
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn insert_location(
|
||||
conn: &PgPool,
|
||||
location: &Location,
|
||||
) -> Result<Location, sqlx::error::Error> {
|
||||
sqlx::query_file_as!(
|
||||
Location,
|
||||
"sql/location/insert.sql",
|
||||
location.id,
|
||||
location.country,
|
||||
location.province,
|
||||
location.city,
|
||||
location.district,
|
||||
location.google_maps_url
|
||||
)
|
||||
.fetch_one(conn)
|
||||
.await
|
||||
}
|
||||
pub async fn get_location_with_id(
|
||||
conn: &PgPool,
|
||||
id: &Uuid,
|
||||
) -> Result<Vec<Location>, sqlx::error::Error> {
|
||||
sqlx::query_file_as!(Location, "sql/location/get.sql", id)
|
||||
.fetch_all(conn)
|
||||
.await
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
pub mod agent;
|
||||
pub mod main_dao;
|
||||
pub mod property;
|
||||
pub mod location;
|
||||
pub mod contact_info;
|
||||
pub mod property_details;
|
44
src/dao/property_details.rs
Normal file
44
src/dao/property_details.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use remax_types::domain::property_details::PropertyDetails;
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn insert_property_details(
|
||||
conn: &PgPool,
|
||||
property_details: &PropertyDetails,
|
||||
) -> Result<PropertyDetails, sqlx::error::Error> {
|
||||
sqlx::query_file_as!(
|
||||
PropertyDetails,
|
||||
"sql/property_details/insert.sql",
|
||||
property_details.property_id,
|
||||
property_details.meters,
|
||||
property_details.listing_type as _,
|
||||
property_details.photo_urls as _,
|
||||
property_details.location_id
|
||||
)
|
||||
.fetch_one(conn)
|
||||
.await
|
||||
}
|
||||
pub async fn get_properties_with_ids(
|
||||
conn: &PgPool,
|
||||
ids: &Vec<Uuid>,
|
||||
) -> Result<Vec<PropertyDetails>, sqlx::error::Error> {
|
||||
sqlx::query_file_as!(PropertyDetails, "sql/property_details/fetch_with_ids.sql", ids)
|
||||
.fetch_all(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn update_property_details(
|
||||
conn: &PgPool,
|
||||
property_details: &PropertyDetails,
|
||||
) -> Result<PropertyDetails, sqlx::error::Error> {
|
||||
sqlx::query_file_as!(
|
||||
PropertyDetails,
|
||||
"sql/property_details/update.sql",
|
||||
property_details.meters,
|
||||
property_details.listing_type as _,
|
||||
property_details.photo_urls as _,
|
||||
property_details.location_id
|
||||
)
|
||||
.fetch_one(conn)
|
||||
.await
|
||||
}
|
Loading…
Reference in New Issue
Block a user