Cargo fmt & Finished project dao

This commit is contained in:
Franklin 2023-05-03 14:29:52 -04:00
parent 8cd8d4bc90
commit fe0b804c83
4 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,19 @@
SELECT
id,
title,
description,
realtor_id,
media as "media: _",
project_condition as "project_condition: _",
project_type as "project_type: _",
project_state as "project_state: _",
country,
city,
district,
admin_tag,
floors,
finish_date,
order_index,
time_created,
last_updated
FROM project WHERE id = $1;

38
sql/project/insert.sql Normal file
View File

@ -0,0 +1,38 @@
INSERT INTO project (
id,
title,
description,
realtor_id,
media,
project_condition,
project_type,
project_state,
country,
city,
district,
admin_tag,
floors,
finish_date,
order_index,
time_created,
last_updated
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $16
) RETURNING
id,
title,
description,
realtor_id,
media as "media: _",
project_condition as "project_condition: _",
project_type as "project_type: _",
project_state as "project_state: _",
country,
city,
district,
admin_tag,
floors,
finish_date,
order_index,
time_created,
last_updated;

35
sql/project/update.sql Normal file
View File

@ -0,0 +1,35 @@
UPDATE project SET
title = $2,
description = $3,
realtor_id = $4,
media = $5,
project_condition = $6,
project_type = $7,
project_state = $8,
country = $9,
city = $10,
district = $11,
admin_tag = $12,
floors = $13,
finish_date = $14,
order_index = $15,
last_updated = $16
WHERE id = $1
RETURNING
id,
title,
description,
realtor_id,
media as "media: _",
project_condition as "project_condition: _",
project_type as "project_type: _",
project_state as "project_state: _",
country,
city,
district,
admin_tag,
floors,
finish_date,
order_index,
time_created,
last_updated;

View File

@ -1 +1,62 @@
use realtor_lp_types::domain::project::Project;
use sqlx::PgPool;
use uuid::Uuid;
pub async fn insert_project(conn: &PgPool, project: Project) -> Result<Project, sqlx::Error> {
sqlx::query_file_as!(
Project,
"sql/project/insert.sql",
project.id,
project.title,
project.description,
project.realtor_id,
project.media as _,
project.project_condition as _,
project.project_type as _,
project.project_state as _,
project.country,
project.city,
project.district,
project.admin_tag,
project.floors,
project.finish_date,
project.order_index,
project.time_created
)
.fetch_one(conn)
.await
}
pub async fn get_project_with_id(
conn: &PgPool,
project_id: &Uuid,
) -> Result<Option<Project>, sqlx::Error> {
sqlx::query_file_as!(Project, "sql/project/get_with_id.sql", project_id)
.fetch_optional(conn)
.await
}
pub async fn update_project(conn: &PgPool, project: Project) -> Result<Project, sqlx::Error> {
sqlx::query_file_as!(
Project,
"sql/project/update.sql",
project.id,
project.title,
project.description,
project.realtor_id,
project.media as _,
project.project_condition as _,
project.project_type as _,
project.project_state as _,
project.country,
project.city,
project.district,
project.admin_tag,
project.floors,
project.finish_date,
project.order_index,
project.last_updated
)
.fetch_one(conn)
.await
}