Ran cargo fmt & added trackable dao's

This commit is contained in:
Franklin 2023-05-03 14:00:02 -04:00
parent 63a9334da0
commit 375a224d11
14 changed files with 99 additions and 11 deletions

View File

@ -0,0 +1 @@
SELECT * FROM trackable WHERE ip_address = $1;

View File

@ -0,0 +1 @@
SELECT * FROM trackable WHERE id = $1;

5
sql/trackable/insert.sql Normal file
View File

@ -0,0 +1,5 @@
INSERT INTO trackable (
id, who_was, ip_address, browser_width, browser_height, user_agent, time_created
) VALUES(
$1, $2, $3, $4, $5, $6, $7
) RETURNING *;

View File

@ -0,0 +1 @@

View File

@ -1,5 +1,9 @@
pub mod click;
#[allow(unused)]
pub mod project;
#[allow(unused)]
pub mod property;
#[allow(unused)]
pub mod realtor;
#[allow(unused)]
pub mod trackable;

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -2,19 +2,61 @@ use realtor_lp_types::domain::realtor::Realtor;
use sqlx::PgPool;
use uuid::Uuid;
pub async fn insert_realtor(conn: &PgPool, realtor: Realtor) -> Result<Realtor, sqlx::Error> {
sqlx::query_file_as!(Realtor, "sql/realtor/insert.sql", realtor.id, realtor.name, realtor.bio, realtor.phone_number, realtor.email, realtor.profile_picture_url, realtor.show_projects, realtor.shortcode, realtor.remax_agent_id, realtor.time_created).fetch_one(conn).await
sqlx::query_file_as!(
Realtor,
"sql/realtor/insert.sql",
realtor.id,
realtor.name,
realtor.bio,
realtor.phone_number,
realtor.email,
realtor.profile_picture_url,
realtor.show_projects,
realtor.shortcode,
realtor.remax_agent_id,
realtor.time_created
)
.fetch_one(conn)
.await
}
pub async fn get_realtor_with_id(conn: &PgPool, realtor_id: &Uuid) -> Result<Option<Realtor>, sqlx::Error> {
sqlx::query_file_as!(Realtor, "sql/realtor/get_with_id.sql", realtor_id).fetch_optional(conn).await
pub async fn get_realtor_with_id(
conn: &PgPool,
realtor_id: &Uuid,
) -> Result<Option<Realtor>, sqlx::Error> {
sqlx::query_file_as!(Realtor, "sql/realtor/get_with_id.sql", realtor_id)
.fetch_optional(conn)
.await
}
pub async fn get_realtor_with_shortcode(conn: &PgPool, realtor_shortcode: &String) -> Result<Option<Realtor>, sqlx::Error> {
sqlx::query_file_as!(Realtor, "sql/realtor/get_with_shortcode.sql", realtor_shortcode).fetch_optional(conn).await
pub async fn get_realtor_with_shortcode(
conn: &PgPool,
realtor_shortcode: &String,
) -> Result<Option<Realtor>, sqlx::Error> {
sqlx::query_file_as!(
Realtor,
"sql/realtor/get_with_shortcode.sql",
realtor_shortcode
)
.fetch_optional(conn)
.await
}
pub async fn update_realtor(conn: &PgPool, realtor: Realtor) -> Result<Realtor, sqlx::Error> {
sqlx::query_file_as!(Realtor, "sql/realtor/update.sql", realtor.id, realtor.name, realtor.bio, realtor.phone_number, realtor.email, realtor.profile_picture_url, realtor.show_projects, realtor.remax_agent_id, realtor.last_updated).fetch_one(conn).await
sqlx::query_file_as!(
Realtor,
"sql/realtor/update.sql",
realtor.id,
realtor.name,
realtor.bio,
realtor.phone_number,
realtor.email,
realtor.profile_picture_url,
realtor.show_projects,
realtor.remax_agent_id,
realtor.last_updated
)
.fetch_one(conn)
.await
}

View File

@ -0,0 +1,30 @@
use realtor_lp_types::domain::trackable::Trackable;
use sqlx::PgPool;
use uuid::Uuid;
pub async fn insert_trackable(
conn: &PgPool,
trackable: Trackable,
) -> Result<Trackable, sqlx::Error> {
sqlx::query_file_as!(
Trackable,
"sql/trackable/insert.sql",
trackable.id,
trackable.who_was,
trackable.ip_address,
trackable.browser_width,
trackable.browser_height,
trackable.user_agent,
trackable.time_created
)
.fetch_one(conn)
.await
}
pub async fn get_trackable_with_id(conn: &PgPool, trackable_id: &Uuid) -> Result<Option<Trackable>, sqlx::Error> {
sqlx::query_file_as!(Trackable, "sql/trackable/get_with_id.sql", trackable_id).fetch_optional(conn).await
}
pub async fn fetch_trackables_with_ip_address(conn: &PgPool, ip_addr: String) -> Result<Vec<Trackable>, sqlx::Error> {
sqlx::query_file_as!(Trackable, "sql/trackable/fetch_all_with_ip.sql", ip_addr).fetch_all(conn).await
}

View File

@ -4,5 +4,4 @@ mod services;
mod utils;
#[tokio::main]
async fn main() {
}
async fn main() {}

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@