From 30c9f86edb71ede60d214dc3d41774c2d17dbe47 Mon Sep 17 00:00:00 2001 From: Franklin Date: Sun, 19 Mar 2023 12:22:33 -0400 Subject: [PATCH] Added service methods to project, location, agent --- Cargo.lock | 12 +- sql/location/fetch_all.sql | 1 + sqlx-data.json | 1263 ++++++++++++++++++++++++++++++++++++ src/dao/agent.rs | 2 +- src/dao/location.rs | 10 +- src/services/admin.rs | 81 +++ src/services/mod.rs | 2 +- src/services/read.rs | 1 + src/utils/mod.rs | 2 +- 9 files changed, 1364 insertions(+), 10 deletions(-) create mode 100644 sql/location/fetch_all.sql create mode 100644 sqlx-data.json diff --git a/Cargo.lock b/Cargo.lock index 58fe456..32b8b3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -543,7 +543,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.0", + "syn 2.0.2", ] [[package]] @@ -560,7 +560,7 @@ checksum = "631569015d0d8d54e6c241733f944042623ab6df7bc3be7466874b05fcdb1c5f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.0", + "syn 2.0.2", ] [[package]] @@ -1577,7 +1577,7 @@ checksum = "78997f4555c22a7971214540c4a661291970619afd56de19f77e0de86296e1e5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.0", + "syn 2.0.2", ] [[package]] @@ -1809,9 +1809,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cff13bb1732bccfe3b246f3fdb09edfd51c01d6f5299b7ccd9457c2e4e37774" +checksum = "59d3276aee1fa0c33612917969b5172b5be2db051232a6e4826f1a1a9191b045" dependencies = [ "proc-macro2", "quote", @@ -1844,7 +1844,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.0", + "syn 2.0.2", ] [[package]] diff --git a/sql/location/fetch_all.sql b/sql/location/fetch_all.sql new file mode 100644 index 0000000..0e3060c --- /dev/null +++ b/sql/location/fetch_all.sql @@ -0,0 +1 @@ +SELECT * FROM location; \ No newline at end of file diff --git a/sqlx-data.json b/sqlx-data.json new file mode 100644 index 0000000..bc35a62 --- /dev/null +++ b/sqlx-data.json @@ -0,0 +1,1263 @@ +{ + "db": "PostgreSQL", + "0c4873abb3c8b85936d39d304a1246e7ea1ed205ddac4082c1d6565eb40ba05a": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Uuid" + ] + } + }, + "query": "DELETE FROM agent WHERE id = $1;" + }, + "20a9f804be4c73f4cbbeb063dbcd7e4f848c532f4d19583857a19f4fdaa65107": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "full_name", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "credential", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "credential_type: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "profile_picture_url", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 5, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 6, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + false + ], + "parameters": { + "Left": [ + "UuidArray" + ] + } + }, + "query": "SELECT \n id,\n full_name,\n credential,\n credential_type as \"credential_type: _\",\n profile_picture_url,\n time_created,\n last_updated\nFROM agent where id = ANY($1)\nORDER BY time_created DESC;" + }, + "36f6cb77e7421f42604c6f248cc69d557856cfbc9598c45c31628874db8921f0": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Uuid" + ] + } + }, + "query": "DELETE FROM location where id = $1;" + }, + "444248a6ee54ce3f8345077330be191e04cc9bdf31feba0e661efab1acf21716": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "project_state: _", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "project_type: _", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "project_condition: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "agent_id", + "ordinal": 4, + "type_info": "Uuid" + }, + { + "name": "location_id", + "ordinal": 5, + "type_info": "Uuid" + }, + { + "name": "title", + "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "description", + "ordinal": 7, + "type_info": "Text" + }, + { + "name": "admin_tag", + "ordinal": 8, + "type_info": "Varchar" + }, + { + "name": "finish_date", + "ordinal": 9, + "type_info": "Timestamp" + }, + { + "name": "floors", + "ordinal": 10, + "type_info": "Int2" + }, + { + "name": "media: _", + "ordinal": 11, + "type_info": "Text" + }, + { + "name": "time_created", + "ordinal": 12, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 13, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + true, + false, + true, + false, + false, + false, + false, + false + ], + "parameters": { + "Left": [ + "Text", + "Text", + "Text", + "Text", + "Text", + "Int8" + ] + } + }, + "query": "SELECT \n p.id,\n p.project_state as \"project_state: _\",\n p.project_type as \"project_type: _\",\n p.project_condition as \"project_condition: _\",\n p.agent_id,\n p.location_id,\n p.title,\n p.description,\n p.admin_tag,\n p.finish_date,\n p.floors,\n p.media as \"media: _\",\n p.time_created,\n p.last_updated\nFROM project p, location l\nWHERE p.location_id = l.id\n-- Filters here:\nAND (LOWER(l.city) LIKE '%' || LOWER($1) || '%' OR $1 IS null) -- City Filter\nAND (LOWER(l.district) LIKE '%' || LOWER($2) || '%' OR $2 IS null) -- District Filter\nAND (p.project_type = $3 OR $3 IS null) -- ProjectType\nAND (p.project_condition = $4 OR $4 IS null) -- ProjectCondition\nAND (p.project_state = $5 OR $5 IS null) -- ProjectState\n-- End of filters\nORDER BY p.time_created DESC\nLIMIT 50 OFFSET $6;" + }, + "4ef2f2177dd00503913e281cf97bd922bcdc4b30ed834505eb8ea9a396f73331": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Uuid" + ] + } + }, + "query": "DELETE FROM project WHERE id = $1;" + }, + "581359d322685ee14958a69929947ad8a0be09da9c02a214b4a3f235f2f1f5d7": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Uuid" + ] + } + }, + "query": "DELETE FROM unit WHERE id = $1;" + }, + "825e1ac484241349c54e75bb77186ce41ea98fd17cabd7308e737a6c9c5812a9": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "project_id", + "ordinal": 1, + "type_info": "Uuid" + }, + { + "name": "price_usd", + "ordinal": 2, + "type_info": "Float8" + }, + { + "name": "unit_type: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "rooms", + "ordinal": 4, + "type_info": "Int2" + }, + { + "name": "bathrooms", + "ordinal": 5, + "type_info": "Int2" + }, + { + "name": "area", + "ordinal": 6, + "type_info": "Float4" + }, + { + "name": "description", + "ordinal": 7, + "type_info": "Text" + }, + { + "name": "media: _", + "ordinal": 8, + "type_info": "Text" + }, + { + "name": "admin_tag", + "ordinal": 9, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 10, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 11, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + false, + false, + false, + true, + false, + false + ], + "parameters": { + "Left": [ + "Float8", + "Varchar", + "Int2", + "Int2", + "Float4", + "Text", + "Text", + "Varchar", + "Timestamptz", + "Uuid" + ] + } + }, + "query": "UPDATE unit SET \n price_usd = $1,\n unit_type = $2,\n rooms = $3,\n bathrooms = $4,\n area = $5,\n description = $6,\n media = $7,\n admin_tag = $8,\n last_updated = $9\nWHERE id = $10\nRETURNING \n id,\n project_id,\n price_usd,\n unit_type as \"unit_type: _\",\n rooms,\n bathrooms,\n area,\n description,\n media as \"media: _\",\n admin_tag,\n time_created,\n last_updated;" + }, + "83b50a1a380e102deb741b6dd135b833fb66daefb8ec51bbff9ccca9cfd3b21b": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "full_name", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "credential", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "credential_type: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "profile_picture_url", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 5, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 6, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + false + ], + "parameters": { + "Left": [ + "Uuid", + "Varchar", + "Varchar", + "Varchar", + "Varchar", + "Timestamptz" + ] + } + }, + "query": "INSERT INTO agent (\n id, full_name, credential, credential_type, profile_picture_url, time_created, last_updated\n) VALUES (\n $1, $2, $3, $4, $5, $6, $6\n) RETURNING\nid,\nfull_name,\ncredential,\ncredential_type as \"credential_type: _\",\nprofile_picture_url,\ntime_created,\nlast_updated;" + }, + "992569b87c0b84f2d99c58a3991d794274a543ea4cb43270f6f93a80a93458b8": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "project_id", + "ordinal": 1, + "type_info": "Uuid" + }, + { + "name": "price_usd", + "ordinal": 2, + "type_info": "Float8" + }, + { + "name": "unit_type: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "rooms", + "ordinal": 4, + "type_info": "Int2" + }, + { + "name": "bathrooms", + "ordinal": 5, + "type_info": "Int2" + }, + { + "name": "area", + "ordinal": 6, + "type_info": "Float4" + }, + { + "name": "description", + "ordinal": 7, + "type_info": "Text" + }, + { + "name": "media: _", + "ordinal": 8, + "type_info": "Text" + }, + { + "name": "admin_tag", + "ordinal": 9, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 10, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 11, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + false, + false, + false, + true, + false, + false + ], + "parameters": { + "Left": [ + "Uuid", + "Uuid", + "Float8", + "Varchar", + "Int2", + "Int2", + "Float4", + "Text", + "Text", + "Varchar", + "Timestamptz" + ] + } + }, + "query": "INSERT INTO unit (\n id,\n project_id,\n price_usd,\n unit_type,\n rooms,\n bathrooms,\n area,\n description,\n media,\n admin_tag,\n time_created,\n last_updated\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10,\n $11,\n $11\n)\nRETURNING \nid,\nproject_id,\nprice_usd,\nunit_type as \"unit_type: _\",\nrooms,\nbathrooms,\narea,\ndescription,\nmedia as \"media: _\",\nadmin_tag,\ntime_created,\nlast_updated;" + }, + "a4b4bff48a573996a661d52576b051edc19b17de90d0823b87057e361004ecf8": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "full_name", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "credential", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "credential_type: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "profile_picture_url", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 5, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 6, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + false + ], + "parameters": { + "Left": [] + } + }, + "query": "SELECT\n id,\n full_name,\n credential,\n credential_type as \"credential_type: _\",\n profile_picture_url,\n time_created,\n last_updated\nFROM agent\nORDER BY time_created DESC;" + }, + "a6f20728a46711e230dd31f5489a620554cea3e4093a3a4c727f91301811ffea": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "project_id", + "ordinal": 1, + "type_info": "Uuid" + }, + { + "name": "price_usd", + "ordinal": 2, + "type_info": "Float8" + }, + { + "name": "unit_type: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "rooms", + "ordinal": 4, + "type_info": "Int2" + }, + { + "name": "bathrooms", + "ordinal": 5, + "type_info": "Int2" + }, + { + "name": "area", + "ordinal": 6, + "type_info": "Float4" + }, + { + "name": "description", + "ordinal": 7, + "type_info": "Text" + }, + { + "name": "media: _", + "ordinal": 8, + "type_info": "Text" + }, + { + "name": "admin_tag", + "ordinal": 9, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 10, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 11, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + false, + false, + false, + true, + false, + false + ], + "parameters": { + "Left": [ + "Uuid" + ] + } + }, + "query": "SELECT \nid,\nproject_id,\nprice_usd,\nunit_type as \"unit_type: _\",\nrooms,\nbathrooms,\narea,\ndescription,\nmedia as \"media: _\",\nadmin_tag,\ntime_created,\nlast_updated\nFROM unit\nWHERE project_id = $1;" + }, + "a7e2e579020a4f8fed4c15c78f7800b14cc503afb4d26f77b5d8e0fef116ca06": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "project_state: _", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "project_type: _", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "project_condition: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "agent_id", + "ordinal": 4, + "type_info": "Uuid" + }, + { + "name": "location_id", + "ordinal": 5, + "type_info": "Uuid" + }, + { + "name": "title", + "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "description", + "ordinal": 7, + "type_info": "Text" + }, + { + "name": "admin_tag", + "ordinal": 8, + "type_info": "Varchar" + }, + { + "name": "finish_date", + "ordinal": 9, + "type_info": "Timestamp" + }, + { + "name": "floors", + "ordinal": 10, + "type_info": "Int2" + }, + { + "name": "media: _", + "ordinal": 11, + "type_info": "Text" + }, + { + "name": "time_created", + "ordinal": 12, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 13, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + true, + false, + true, + false, + false, + false, + false, + false + ], + "parameters": { + "Left": [ + "Varchar", + "Varchar", + "Varchar", + "Uuid", + "Uuid", + "Varchar", + "Text", + "Varchar", + "Timestamp", + "Int2", + "Text", + "Timestamptz", + "Uuid" + ] + } + }, + "query": "UPDATE project SET \n project_state = $1,\n project_type = $2,\n project_condition = $3,\n agent_id = $4,\n location_id = $5,\n title = $6,\n description = $7,\n admin_tag = $8,\n finish_date = $9,\n floors = $10,\n media = $11,\n last_updated = $12\nWHERE id = $13\nRETURNING\n id,\n project_state as \"project_state: _\",\n project_type as \"project_type: _\",\n project_condition as \"project_condition: _\",\n agent_id,\n location_id,\n title,\n description,\n admin_tag,\n finish_date,\n floors,\n media as \"media: _\",\n time_created,\n last_updated;\n" + }, + "bfe82090be44c2d527aa8da51c47307eb3c88c2e3e3e6154c24f8a8456e161dd": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "city", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "district", + "ordinal": 2, + "type_info": "Varchar" + } + ], + "nullable": [ + false, + false, + false + ], + "parameters": { + "Left": [] + } + }, + "query": "SELECT * FROM location;" + }, + "c05de1af555fa15d0ad1f5323b8c9ba392ab6618a41b0f5bb7914c10855d68a6": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "project_state: _", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "project_type: _", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "project_condition: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "agent_id", + "ordinal": 4, + "type_info": "Uuid" + }, + { + "name": "location_id", + "ordinal": 5, + "type_info": "Uuid" + }, + { + "name": "title", + "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "description", + "ordinal": 7, + "type_info": "Text" + }, + { + "name": "admin_tag", + "ordinal": 8, + "type_info": "Varchar" + }, + { + "name": "finish_date", + "ordinal": 9, + "type_info": "Timestamp" + }, + { + "name": "floors", + "ordinal": 10, + "type_info": "Int2" + }, + { + "name": "media: _", + "ordinal": 11, + "type_info": "Text" + }, + { + "name": "time_created", + "ordinal": 12, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 13, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + true, + false, + true, + false, + false, + false, + false, + false + ], + "parameters": { + "Left": [ + "Uuid", + "Varchar", + "Varchar", + "Varchar", + "Uuid", + "Uuid", + "Varchar", + "Text", + "Varchar", + "Timestamp", + "Int2", + "Text", + "Timestamptz" + ] + } + }, + "query": "INSERT INTO project (\n id,\n project_state,\n project_type,\n project_condition,\n agent_id,\n location_id,\n title,\n description,\n admin_tag,\n finish_date,\n floors,\n media,\n time_created,\n last_updated\n) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $13\n) RETURNING\nid,\nproject_state as \"project_state: _\",\nproject_type as \"project_type: _\",\nproject_condition as \"project_condition: _\",\nagent_id,\nlocation_id,\ntitle,\ndescription,\nadmin_tag,\nfinish_date,\nfloors,\nmedia as \"media: _\",\ntime_created,\nlast_updated;" + }, + "d0996b65d52b1e2b9e99eed338b31eb551b313ba91e44613e32aa83835d53dbc": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "city", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "district", + "ordinal": 2, + "type_info": "Varchar" + } + ], + "nullable": [ + false, + false, + false + ], + "parameters": { + "Left": [ + "Uuid", + "Varchar", + "Varchar" + ] + } + }, + "query": "INSERT INTO location (\n id, city, district\n) VALUES (\n $1, $2, $3\n) RETURNING *;" + }, + "d556cb1971f386a7997c2e3dbce191cde2d488c55c05edbfe3746208a782d5f6": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "city", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "district", + "ordinal": 2, + "type_info": "Varchar" + } + ], + "nullable": [ + false, + false, + false + ], + "parameters": { + "Left": [ + "Uuid" + ] + } + }, + "query": "SELECT * FROM location WHERE id = $1;" + }, + "d590e9f4fed693df4e873e226c6c278b9f608290e7c31fd3145a0223b2e7b221": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "project_state: _", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "project_type: _", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "project_condition: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "agent_id", + "ordinal": 4, + "type_info": "Uuid" + }, + { + "name": "location_id", + "ordinal": 5, + "type_info": "Uuid" + }, + { + "name": "title", + "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "description", + "ordinal": 7, + "type_info": "Text" + }, + { + "name": "admin_tag", + "ordinal": 8, + "type_info": "Varchar" + }, + { + "name": "finish_date", + "ordinal": 9, + "type_info": "Timestamp" + }, + { + "name": "floors", + "ordinal": 10, + "type_info": "Int2" + }, + { + "name": "media: _", + "ordinal": 11, + "type_info": "Text" + }, + { + "name": "time_created", + "ordinal": 12, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 13, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + true, + false, + true, + false, + false, + false, + false, + false + ], + "parameters": { + "Left": [ + "UuidArray" + ] + } + }, + "query": "SELECT \nid,\nproject_state as \"project_state: _\",\nproject_type as \"project_type: _\",\nproject_condition as \"project_condition: _\",\nagent_id,\nlocation_id,\ntitle,\ndescription,\nadmin_tag,\nfinish_date,\nfloors,\nmedia as \"media: _\",\ntime_created,\nlast_updated\nFROM project WHERE id = ANY($1);" + }, + "d6c3fb73ef53898660351142f921b36efdd683c0a4798423f73198760299a418": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "full_name", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "credential", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "credential_type: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "profile_picture_url", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 5, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 6, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + false + ], + "parameters": { + "Left": [ + "Varchar", + "Varchar", + "Varchar", + "Varchar", + "Timestamptz", + "Uuid" + ] + } + }, + "query": "UPDATE agent SET\n full_name = $1,\n credential = $2,\n credential_type = $3,\n profile_picture_url = $4,\n last_updated = $5\nWHERE id = $6\nRETURNING \n id,\n full_name,\n credential,\n credential_type as \"credential_type: _\",\n profile_picture_url,\n time_created,\n last_updated;" + }, + "d816f83fcb8b77a4ae08b46918c039fa5616946943419e5135f3ffd79337e244": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "full_name", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "credential", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "credential_type: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "profile_picture_url", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 5, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 6, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + false + ], + "parameters": { + "Left": [ + "Uuid" + ] + } + }, + "query": "SELECT \nid,\nfull_name,\ncredential,\ncredential_type as \"credential_type: _\",\nprofile_picture_url,\ntime_created,\nlast_updated\nFROM agent WHERE id = $1" + }, + "e249fa71f1bfd550a78b5838b9f393bd0d1d062291c8ea0fdcec61388a8712b8": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "project_state: _", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "project_type: _", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "project_condition: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "agent_id", + "ordinal": 4, + "type_info": "Uuid" + }, + { + "name": "location_id", + "ordinal": 5, + "type_info": "Uuid" + }, + { + "name": "title", + "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "description", + "ordinal": 7, + "type_info": "Text" + }, + { + "name": "admin_tag", + "ordinal": 8, + "type_info": "Varchar" + }, + { + "name": "finish_date", + "ordinal": 9, + "type_info": "Timestamp" + }, + { + "name": "floors", + "ordinal": 10, + "type_info": "Int2" + }, + { + "name": "media: _", + "ordinal": 11, + "type_info": "Text" + }, + { + "name": "time_created", + "ordinal": 12, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 13, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + true, + false, + true, + false, + false, + false, + false, + false + ], + "parameters": { + "Left": [ + "Uuid" + ] + } + }, + "query": " SELECT \n id,\n project_state as \"project_state: _\",\n project_type as \"project_type: _\",\n project_condition as \"project_condition: _\",\n agent_id,\n location_id,\n title,\n description,\n admin_tag,\n finish_date,\n floors,\n media as \"media: _\",\n time_created,\n last_updated\nFROM project WHERE id = $1;" + }, + "e8875f08303c3e36ff2e83aec5185ae2f5ddc04da80ba9947ecf509693c11673": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "city", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "district", + "ordinal": 2, + "type_info": "Varchar" + } + ], + "nullable": [ + false, + false, + false + ], + "parameters": { + "Left": [ + "Text" + ] + } + }, + "query": "SELECT * FROM location WHERE city = $1 ORDER BY district DESC;" + } +} \ No newline at end of file diff --git a/src/dao/agent.rs b/src/dao/agent.rs index f0040aa..a07ddd7 100644 --- a/src/dao/agent.rs +++ b/src/dao/agent.rs @@ -40,7 +40,7 @@ pub async fn get_agents_with_ids( pub async fn update_agent( tx: &mut Transaction<'_, Postgres>, - agent: Agent, + agent: &Agent, ) -> Result { sqlx::query_file_as!( Agent, diff --git a/src/dao/location.rs b/src/dao/location.rs index b5563ba..8a0400c 100644 --- a/src/dao/location.rs +++ b/src/dao/location.rs @@ -4,7 +4,7 @@ use uuid::Uuid; pub async fn insert_location( tx: &mut Transaction<'_, Postgres>, - location: Location, + location: &Location, ) -> Result { sqlx::query_file_as!( Location, @@ -35,6 +35,14 @@ pub async fn get_locations_in_city( .await } +pub async fn fetch_all_locations( + conn: &PgPool, +) -> Result, sqlx::Error> { + sqlx::query_file_as!(Location, "sql/location/fetch_all.sql") + .fetch_all(conn) + .await +} + pub async fn delete_location( tx: &mut Transaction<'_, Postgres>, location_id: Uuid, diff --git a/src/services/admin.rs b/src/services/admin.rs index e69de29..717ca54 100644 --- a/src/services/admin.rs +++ b/src/services/admin.rs @@ -0,0 +1,81 @@ +use actix_web_utils::extensions::typed_response::TypedHttpResponse; +use jl_types::{ + domain::{agent::Agent, project::Project, location::Location}, + dto::payloads::{agent::{NewAgentPayload, UpdateAgentPayload}, project::{NewProjectPayload, UpdateProjectPayload}, location::NewLocationPayload}, +}; + +use sqlx::PgPool; + +use crate::{dao, handle_db_read_op, handle_db_write_op, handle_tx, success, unwrap_or_not_found}; + +// +// Insert Methods +// + +pub async fn create_new_agent_profile( + conn: &PgPool, + new_agent: NewAgentPayload, +) -> TypedHttpResponse { + let mut tx = handle_tx!(conn.begin()); + let persisted_agent = + handle_db_write_op!(dao::agent::insert_agent(&mut tx, &new_agent.into()), tx); + handle_tx!(tx.commit()); + + success!(persisted_agent) +} + +pub async fn create_new_location( + conn: &PgPool, + new_location: NewLocationPayload, +) -> TypedHttpResponse { + let mut tx = handle_tx!(conn.begin()); + let persisted_location = handle_db_write_op!(dao::location::insert_location(&mut tx, &new_location.into()), tx); + handle_tx!(tx.commit()); + success!(persisted_location) +} + +pub async fn create_new_project( + conn: &PgPool, + new_project: NewProjectPayload, +) -> TypedHttpResponse { + let mut tx = handle_tx!(conn.begin()); + unwrap_or_not_found!(handle_db_read_op!(dao::agent::get_agent_with_id(conn, &new_project.agent_id)), "agents"); + unwrap_or_not_found!(handle_db_read_op!(dao::location::get_location_with_id(conn, &new_project.location_id)), "locations"); + let persisted_project = handle_db_write_op!(dao::project::insert(&mut tx, &new_project.into()), tx); + handle_tx!(tx.commit()); + success!(persisted_project) +} + +// +// Update Methods +// + +pub async fn update_agent( + conn: &PgPool, + update_agent_payload: UpdateAgentPayload, +) -> TypedHttpResponse { + let mut tx = handle_tx!(conn.begin()); + let mut persisted_agent = unwrap_or_not_found!( + handle_db_read_op!(dao::agent::get_agent_with_id( + conn, + &update_agent_payload.id + )), + "agents" + ); + update_agent_payload.update_agent(&mut persisted_agent); + + let updated_agent = + handle_db_write_op!(dao::agent::update_agent(&mut tx, &persisted_agent), tx); + handle_tx!(tx.commit()); + + success!(updated_agent) +} + +pub async fn update_project(conn: &PgPool, update_project_payload: UpdateProjectPayload) -> TypedHttpResponse { + let mut tx = handle_tx!(conn.begin()); + let mut persisted_project = unwrap_or_not_found!(handle_db_read_op!(dao::project::get_with_id(conn, &update_project_payload.id)), "projects"); + update_project_payload.update_project(&mut persisted_project); + let updated_project = handle_db_write_op!(dao::project::update(&mut tx, &persisted_project), tx); + handle_tx!(tx.commit()); + success!(updated_project) +} diff --git a/src/services/mod.rs b/src/services/mod.rs index 26a8412..6e88d31 100644 --- a/src/services/mod.rs +++ b/src/services/mod.rs @@ -1,2 +1,2 @@ pub mod admin; -pub mod read; \ No newline at end of file +pub mod read; diff --git a/src/services/read.rs b/src/services/read.rs index e69de29..8b13789 100644 --- a/src/services/read.rs +++ b/src/services/read.rs @@ -0,0 +1 @@ + diff --git a/src/utils/mod.rs b/src/utils/mod.rs index d28af63..eda363d 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1 +1 @@ -pub mod macros; \ No newline at end of file +pub mod macros;