Added all dao & sql methods for unit and agent
This commit is contained in:
parent
cfa25d2bf7
commit
719281492b
@ -4,13 +4,11 @@ CREATE TABLE IF NOT EXISTS "unit" (
|
|||||||
price_usd FLOAT8 NOT NULL,
|
price_usd FLOAT8 NOT NULL,
|
||||||
unit_type VARCHAR NOT NULL,
|
unit_type VARCHAR NOT NULL,
|
||||||
rooms SMALLINT NOT NULL,
|
rooms SMALLINT NOT NULL,
|
||||||
|
|
||||||
bathrooms SMALLINT NOT NULL,
|
bathrooms SMALLINT NOT NULL,
|
||||||
area FLOAT4 NOT NULL,
|
area FLOAT4 NOT NULL,
|
||||||
description TEXT NOT NULL,
|
description TEXT NOT NULL,
|
||||||
media TEXT NOT NULL,
|
media TEXT NOT NULL,
|
||||||
admin_tag VARCHAR,
|
admin_tag VARCHAR,
|
||||||
|
|
||||||
time_created TIMESTAMPTZ NOT NULL,
|
time_created TIMESTAMPTZ NOT NULL,
|
||||||
last_updated TIMESTAMPTZ NOT NULL
|
last_updated TIMESTAMPTZ NOT NULL
|
||||||
);
|
);
|
||||||
|
@ -3,6 +3,7 @@ full_name = $1,
|
|||||||
credential = $2,
|
credential = $2,
|
||||||
credential_type = $3,
|
credential_type = $3,
|
||||||
last_updated = $4
|
last_updated = $4
|
||||||
|
WHERE id = $5
|
||||||
RETURNING
|
RETURNING
|
||||||
id,
|
id,
|
||||||
full_name,
|
full_name,
|
||||||
|
1
sql/project/delete.sql
Normal file
1
sql/project/delete.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
DELETE FROM project WHERE id = $1;
|
14
sql/project/fetch_by_ids.sql
Normal file
14
sql/project/fetch_by_ids.sql
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
project_type as "project_type: _",
|
||||||
|
project_condition as "project_condition: _",
|
||||||
|
agent_id,
|
||||||
|
location_id,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
admin_tag,
|
||||||
|
floors,
|
||||||
|
media as "media: _",
|
||||||
|
time_created,
|
||||||
|
last_updated
|
||||||
|
FROM project WHERE id = ANY($1);
|
0
sql/project/fetch_with_filters_paged.sql
Normal file
0
sql/project/fetch_with_filters_paged.sql
Normal file
14
sql/project/get_with_id.sql
Normal file
14
sql/project/get_with_id.sql
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
project_type as "project_type: _",
|
||||||
|
project_condition as "project_condition: _",
|
||||||
|
agent_id,
|
||||||
|
location_id,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
admin_tag,
|
||||||
|
floors,
|
||||||
|
media as "media: _",
|
||||||
|
time_created,
|
||||||
|
last_updated
|
||||||
|
FROM project WHERE id = $1;
|
@ -0,0 +1,28 @@
|
|||||||
|
INSERT INTO project (
|
||||||
|
id,
|
||||||
|
project_type,
|
||||||
|
project_condition,
|
||||||
|
agent_id,
|
||||||
|
location_id,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
admin_tag,
|
||||||
|
floors,
|
||||||
|
media,
|
||||||
|
time_created,
|
||||||
|
last_updated
|
||||||
|
) VALUES (
|
||||||
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $11
|
||||||
|
) RETURNING
|
||||||
|
id,
|
||||||
|
project_type as "project_type: _",
|
||||||
|
project_condition as "project_condition: _",
|
||||||
|
agent_id,
|
||||||
|
location_id,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
admin_tag,
|
||||||
|
floors,
|
||||||
|
media as "media: _",
|
||||||
|
time_created,
|
||||||
|
last_updated;
|
11
sql/project/update.sql
Normal file
11
sql/project/update.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
UPDATE project SET
|
||||||
|
project_type = $1,
|
||||||
|
project_condition = $2,
|
||||||
|
agent_id = $3,
|
||||||
|
location_id = $4,
|
||||||
|
title = $5,
|
||||||
|
description = $6,
|
||||||
|
admin_tag = $7,
|
||||||
|
floors = $8,
|
||||||
|
media = $9,
|
||||||
|
last_updated = $10,
|
1
sql/unit/delete.sql
Normal file
1
sql/unit/delete.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
DELETE FROM unit WHERE id = $1;
|
15
sql/unit/fetch_with_project_id.sql
Normal file
15
sql/unit/fetch_with_project_id.sql
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
project_id,
|
||||||
|
price_usd,
|
||||||
|
unit_type as "unit_type: _",
|
||||||
|
rooms,
|
||||||
|
bathrooms,
|
||||||
|
area,
|
||||||
|
description,
|
||||||
|
media as "media: _",
|
||||||
|
admin_tag,
|
||||||
|
time_created,
|
||||||
|
last_updated
|
||||||
|
FROM unit
|
||||||
|
WHERE project_id = $1;
|
@ -0,0 +1,40 @@
|
|||||||
|
INSERT INTO unit (
|
||||||
|
id,
|
||||||
|
project_id,
|
||||||
|
price_usd,
|
||||||
|
unit_type,
|
||||||
|
rooms,
|
||||||
|
bathrooms,
|
||||||
|
area,
|
||||||
|
description,
|
||||||
|
media,
|
||||||
|
admin_tag,
|
||||||
|
time_created,
|
||||||
|
last_updated
|
||||||
|
) VALUES (
|
||||||
|
$1,
|
||||||
|
$2,
|
||||||
|
$3,
|
||||||
|
$4,
|
||||||
|
$5,
|
||||||
|
$6,
|
||||||
|
$7,
|
||||||
|
$8,
|
||||||
|
$9,
|
||||||
|
$10,
|
||||||
|
$11,
|
||||||
|
$11
|
||||||
|
)
|
||||||
|
RETURNING
|
||||||
|
id,
|
||||||
|
project_id,
|
||||||
|
price_usd,
|
||||||
|
unit_type as "unit_type: _",
|
||||||
|
rooms,
|
||||||
|
bathrooms,
|
||||||
|
area,
|
||||||
|
description,
|
||||||
|
media as "media: _",
|
||||||
|
admin_tag,
|
||||||
|
time_created,
|
||||||
|
last_updated;
|
24
sql/unit/update.sql
Normal file
24
sql/unit/update.sql
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
UPDATE unit SET
|
||||||
|
price_usd = $1,
|
||||||
|
unit_type = $2,
|
||||||
|
rooms = $3,
|
||||||
|
bathrooms = $4,
|
||||||
|
area = $5,
|
||||||
|
description = $6,
|
||||||
|
media = $7,
|
||||||
|
admin_tag = $8,
|
||||||
|
last_updated = $9
|
||||||
|
WHERE id = $10
|
||||||
|
RETURNING
|
||||||
|
id,
|
||||||
|
project_id,
|
||||||
|
price_usd,
|
||||||
|
unit_type as "unit_type: _",
|
||||||
|
rooms,
|
||||||
|
bathrooms,
|
||||||
|
area,
|
||||||
|
description,
|
||||||
|
media as "media: _",
|
||||||
|
admin_tag,
|
||||||
|
time_created,
|
||||||
|
last_updated;
|
@ -16,7 +16,7 @@ pub async fn get_agents_with_ids(conn: &PgPool, agent_ids: &Vec<Uuid>) -> Result
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_agent(tx: &mut Transaction<'_, Postgres>, agent: Agent) -> Result<Agent, sqlx::Error> {
|
pub async fn update_agent(tx: &mut Transaction<'_, Postgres>, agent: Agent) -> Result<Agent, sqlx::Error> {
|
||||||
sqlx::query_file_as!(Agent, "sql/agent/update.sql", agent.full_name, agent.credential, agent.credential_type as _, agent.last_updated).fetch_one(tx).await
|
sqlx::query_file_as!(Agent, "sql/agent/update.sql", agent.full_name, agent.credential, agent.credential_type as _, agent.last_updated, agent.id).fetch_one(tx).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_agent(tx: &mut Transaction<'_, Postgres>, agent_id: &Uuid) -> Result<PgQueryResult, sqlx::Error> {
|
pub async fn delete_agent(tx: &mut Transaction<'_, Postgres>, agent_id: &Uuid) -> Result<PgQueryResult, sqlx::Error> {
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
use jl_types::domain::project::Project;
|
||||||
|
use sqlx::postgres::PgQueryResult;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pub async fn insert() -> Result<Project, sqlx::Error> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete() -> Result<PgQueryResult, sqlx::Error> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update() -> Result<Project, sqlx::Error> {
|
||||||
|
todo!()
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
use jl_types::domain::unit::Unit;
|
||||||
|
use sqlx::{PgPool, Transaction, Postgres, postgres::PgQueryResult};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
|
||||||
|
pub async fn fetch_with_project_id(conn: &PgPool, project_id: &Uuid) -> Result<Vec<Unit>, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(Unit, "sql/unit/fetch_with_project_id.sql", project_id).fetch_all(conn).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete(tx: &mut Transaction<'_, Postgres>, unit_id: &Uuid) -> Result<PgQueryResult, sqlx::Error> {
|
||||||
|
sqlx::query_file!("sql/unit/delete.sql", unit_id).execute(tx).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn insert(tx: &mut Transaction<'_, Postgres>, unit: &Unit) -> Result<Unit, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(Unit, "sql/unit/insert.sql", unit.id, unit.project_id, unit.price_usd, unit.unit_type as _, unit.rooms, unit.bathrooms, unit.area, unit.description, unit.media as _, unit.admin_tag, unit.time_created).fetch_one(tx).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update(conn: &PgPool, unit: &Unit) -> Result<Unit, sqlx::Error> {
|
||||||
|
sqlx::query_file_as!(Unit, "sql/unit/update.sql", unit.price_usd, unit.unit_type as _, unit.rooms, unit.bathrooms, unit.area, unit.description, unit.media as _, unit.admin_tag, unit.last_updated, unit.id).fetch_one(conn).await
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user