From 63a9334da0514f9b3d54c3c4a95f446c118a97c7 Mon Sep 17 00:00:00 2001 From: Franklin Date: Wed, 3 May 2023 13:50:59 -0400 Subject: [PATCH] Finished realtor dao --- sql/realtor/get_with_id.sql | 1 + sql/realtor/get_with_shortcode.sql | 1 + sql/realtor/insert.sql | 5 +++++ sql/realtor/update.sql | 11 +++++++++++ src/dao/click.rs | 0 src/dao/main_dao.rs | 0 src/dao/mod.rs | 5 +++++ src/dao/project.rs | 0 src/dao/property.rs | 0 src/dao/realtor.rs | 20 ++++++++++++++++++++ src/dao/trackable.rs | 0 11 files changed, 43 insertions(+) create mode 100644 sql/realtor/get_with_id.sql create mode 100644 sql/realtor/get_with_shortcode.sql create mode 100644 sql/realtor/insert.sql create mode 100644 sql/realtor/update.sql create mode 100644 src/dao/click.rs create mode 100644 src/dao/main_dao.rs create mode 100644 src/dao/project.rs create mode 100644 src/dao/property.rs create mode 100644 src/dao/realtor.rs create mode 100644 src/dao/trackable.rs diff --git a/sql/realtor/get_with_id.sql b/sql/realtor/get_with_id.sql new file mode 100644 index 0000000..d392538 --- /dev/null +++ b/sql/realtor/get_with_id.sql @@ -0,0 +1 @@ +SELECT * FROM realtor WHERE id = $1; \ No newline at end of file diff --git a/sql/realtor/get_with_shortcode.sql b/sql/realtor/get_with_shortcode.sql new file mode 100644 index 0000000..62cb767 --- /dev/null +++ b/sql/realtor/get_with_shortcode.sql @@ -0,0 +1 @@ +SELECT * FROM realtor WHERE shortcode = $1; \ No newline at end of file diff --git a/sql/realtor/insert.sql b/sql/realtor/insert.sql new file mode 100644 index 0000000..3354524 --- /dev/null +++ b/sql/realtor/insert.sql @@ -0,0 +1,5 @@ +INSERT INTO realtor ( + id, name, bio, phone_number, email, profile_picture_url, show_projects, shortcode, remax_agent_id, time_created, last_updated +) VALUES ( + $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $10 +) RETURNING *; \ No newline at end of file diff --git a/sql/realtor/update.sql b/sql/realtor/update.sql new file mode 100644 index 0000000..8a3b0a6 --- /dev/null +++ b/sql/realtor/update.sql @@ -0,0 +1,11 @@ +UPDATE realtor SET + name = $2, + bio = $3, + phone_number = $4, + email = $5, + profile_picture_url = $6, + show_projects = $7, + remax_agent_id = $8, + last_updated = $9 +WHERE id = $1 +RETURNING *; \ No newline at end of file diff --git a/src/dao/click.rs b/src/dao/click.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/dao/main_dao.rs b/src/dao/main_dao.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/dao/mod.rs b/src/dao/mod.rs index e69de29..49daa52 100644 --- a/src/dao/mod.rs +++ b/src/dao/mod.rs @@ -0,0 +1,5 @@ +pub mod click; +pub mod project; +pub mod property; +pub mod realtor; +pub mod trackable; \ No newline at end of file diff --git a/src/dao/project.rs b/src/dao/project.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/dao/property.rs b/src/dao/property.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/dao/realtor.rs b/src/dao/realtor.rs new file mode 100644 index 0000000..0f85757 --- /dev/null +++ b/src/dao/realtor.rs @@ -0,0 +1,20 @@ +use realtor_lp_types::domain::realtor::Realtor; +use sqlx::PgPool; +use uuid::Uuid; + + +pub async fn insert_realtor(conn: &PgPool, realtor: Realtor) -> Result { + 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, 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, 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 { + 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 +} diff --git a/src/dao/trackable.rs b/src/dao/trackable.rs new file mode 100644 index 0000000..e69de29