From 6b4e47c7a85c3bf98d93e13b589102dd08f31921 Mon Sep 17 00:00:00 2001 From: Franklin Date: Fri, 14 Apr 2023 16:46:35 -0400 Subject: [PATCH] Added visit and contact --- Cargo.lock | 229 +++++++++++------- migrations/5_visit.sql | 5 + migrations/6_contact.sql | 8 + sql/agent/insert.sql | 2 +- sql/contact/get_all.sql | 1 + sql/contact/get_count.sql | 1 + sql/contact/insert.sql | 3 + sql/visit/get_count.sql | 1 + sql/visit/insert.sql | 1 + sqlx-data.json | 477 +++++++++++++++++++++++++------------- src/dao/agent.rs | 2 + src/dao/contact.rs | 23 ++ src/dao/mod.rs | 2 + src/dao/visit.rs | 16 ++ src/routes/read.rs | 6 +- src/utils/mod.rs | 1 + src/utils/visit.rs | 20 ++ 17 files changed, 546 insertions(+), 252 deletions(-) create mode 100644 migrations/5_visit.sql create mode 100644 migrations/6_contact.sql create mode 100644 sql/contact/get_all.sql create mode 100644 sql/contact/get_count.sql create mode 100644 sql/contact/insert.sql create mode 100644 sql/visit/get_count.sql create mode 100644 sql/visit/insert.sql create mode 100644 src/dao/contact.rs create mode 100644 src/dao/visit.rs create mode 100644 src/utils/visit.rs diff --git a/Cargo.lock b/Cargo.lock index 794ab45..200a54b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -404,9 +404,9 @@ dependencies = [ [[package]] name = "chrono-tz" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa48fa079165080f11d7753fd0bc175b7d391f276b965fe4b55bfad67856e463" +checksum = "cf9cc2b23599e6d7479755f3594285efb3f74a1bdca7a7374948bc831e23a552" dependencies = [ "chrono", "chrono-tz-build", @@ -453,15 +453,15 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "cpufeatures" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" dependencies = [ "libc", ] @@ -521,9 +521,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c00419335c41018365ddf7e4d5f1c12ee3659ddcf3e01974650ba1de73d038" +checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" dependencies = [ "cc", "cxxbridge-flags", @@ -533,9 +533,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb8307ad413a98fff033c8545ecf133e3257747b3bae935e7602aab8aa92d4ca" +checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" dependencies = [ "cc", "codespan-reporting", @@ -543,24 +543,24 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.8", + "syn 2.0.15", ] [[package]] name = "cxxbridge-flags" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edc52e2eb08915cb12596d29d55f0b5384f00d697a646dbd269b6ecb0fbd9d31" +checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" [[package]] name = "cxxbridge-macro" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631569015d0d8d54e6c241733f944042623ab6df7bc3be7466874b05fcdb1c5f" +checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.8", + "syn 2.0.15", ] [[package]] @@ -699,9 +699,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", "futures-sink", @@ -709,9 +709,9 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" [[package]] name = "futures-intrusive" @@ -726,27 +726,27 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" [[package]] name = "futures-sink" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" [[package]] name = "futures-task" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" [[package]] name = "futures-util" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ "futures-core", "futures-io", @@ -760,9 +760,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -770,9 +770,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" dependencies = [ "cfg-if", "libc", @@ -781,9 +781,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be7b54589b581f624f566bf5d8eb2bab1db736c51528720b6bd36b96b55924d" +checksum = "66b91535aa35fea1523ad1b86cb6b53c28e0ae566ba4a460f4457e936cad7c6f" dependencies = [ "bytes", "fnv", @@ -894,9 +894,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "hyper" -version = "0.14.25" +version = "0.14.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc5e554ff619822309ffd57d8734d77cd5ce6238bc956f037ea06c58238c9899" +checksum = "ab302d72a6f11a3b910431ff93aae7e773078c769f0a3ef15fb9ec692ed147d4" dependencies = [ "bytes", "futures-channel", @@ -931,9 +931,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.54" +version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c17cc76786e99f8d2f055c11159e7f0091c42474dcc3189fbab96072e873e6d" +checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -965,9 +965,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown", @@ -984,9 +984,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" +checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" [[package]] name = "itertools" @@ -1033,6 +1033,7 @@ dependencies = [ "chrono", "chrono-tz", "format_num", + "rand", "serde", "serde_json", "sqlx", @@ -1065,9 +1066,9 @@ checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" [[package]] name = "libc" -version = "0.2.140" +version = "0.2.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" [[package]] name = "link-cplusplus" @@ -1342,9 +1343,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.53" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ "unicode-ident", ] @@ -1410,9 +1411,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.2" +version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cce168fea28d3e05f158bda4576cf0c844d5045bc2cc3620fa0292ed5bb5814c" +checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" dependencies = [ "aho-corasick", "memchr", @@ -1427,9 +1428,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "reqwest" -version = "0.11.15" +version = "0.11.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ba30cc2c0cd02af1222ed216ba659cdb2f879dfe3181852fe7c50b1d0005949" +checksum = "27b71749df584b7f4cac2c426c127a7c785a5106cc98f7a8feb044115f0fa254" dependencies = [ "base64 0.21.0", "bytes", @@ -1545,29 +1546,29 @@ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" [[package]] name = "serde" -version = "1.0.158" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9" +checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.158" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad" +checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" dependencies = [ "proc-macro2", "quote", - "syn 2.0.8", + "syn 2.0.15", ] [[package]] name = "serde_json" -version = "1.0.94" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" dependencies = [ "itoa", "ryu", @@ -1792,9 +1793,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.8" +version = "2.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc02725fd69ab9f26eab07fad303e2497fad6fb9eba4f96c4d1687bdf704ad9" +checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" dependencies = [ "proc-macro2", "quote", @@ -1827,7 +1828,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.8", + "syn 2.0.15", ] [[package]] @@ -1885,14 +1886,13 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.26.0" +version = "1.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" +checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" dependencies = [ "autocfg", "bytes", "libc", - "memchr", "mio", "num_cpus", "parking_lot 0.12.1", @@ -1905,13 +1905,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.8.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" +checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.15", ] [[package]] @@ -2047,9 +2047,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" +checksum = "5b55a3fef2a1e3b3a00ce878640918820d3c51081576ac657d23af9fc7928fdb" dependencies = [ "getrandom", "rand", @@ -2059,13 +2059,13 @@ dependencies = [ [[package]] name = "uuid-macro-internal" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b300a878652a387d2a0de915bdae8f1a548f0c6d45e072fe2688794b656cc9" +checksum = "20e8a505384e9309dc842520c6c9348f4b141dee06aaa845522727b1b99ca235" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.15", ] [[package]] @@ -2234,11 +2234,11 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.46.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets", + "windows-targets 0.48.0", ] [[package]] @@ -2247,7 +2247,7 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", ] [[package]] @@ -2256,13 +2256,28 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -2271,42 +2286,84 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "winreg" version = "0.10.1" @@ -2327,9 +2384,9 @@ dependencies = [ [[package]] name = "zstd-safe" -version = "6.0.4+zstd.1.5.4" +version = "6.0.5+zstd.1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7afb4b54b8910cf5447638cb54bf4e8a65cbedd783af98b98c62ffe91f185543" +checksum = "d56d9e60b4b1758206c238a10165fbcae3ca37b01744e394c463463f6529d23b" dependencies = [ "libc", "zstd-sys", @@ -2337,9 +2394,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.7+zstd.1.5.4" +version = "2.0.8+zstd.1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5" +checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" dependencies = [ "cc", "libc", diff --git a/migrations/5_visit.sql b/migrations/5_visit.sql new file mode 100644 index 0000000..034fb54 --- /dev/null +++ b/migrations/5_visit.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS "visit" ( + id SERIAL PRIMARY KEY, + ip_addr VARCHAR NOT NULL, + time_created TIMESTAMPTZ NOT NULL +) \ No newline at end of file diff --git a/migrations/6_contact.sql b/migrations/6_contact.sql new file mode 100644 index 0000000..b47e285 --- /dev/null +++ b/migrations/6_contact.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS "contact" ( + id SERIAL PRIMARY KEY, + first_name VARCHAR NOT NULL, + last_name VARCHAR NOT NULL, + credential VARCHAR NOT NULL, + message VARCHAR(2048) NOT NULL, + time_created TIMESTAMPTZ NOT NULL +) \ No newline at end of file diff --git a/sql/agent/insert.sql b/sql/agent/insert.sql index d0543f5..20164e6 100644 --- a/sql/agent/insert.sql +++ b/sql/agent/insert.sql @@ -4,7 +4,7 @@ INSERT INTO agent ( $1, $2, $3, $4, $5, $6, $7, $7 ) RETURNING id, -shortcode +shortcode, full_name, credential, credential_type as "credential_type: _", diff --git a/sql/contact/get_all.sql b/sql/contact/get_all.sql new file mode 100644 index 0000000..c91ace1 --- /dev/null +++ b/sql/contact/get_all.sql @@ -0,0 +1 @@ +SELECT * FROM contact; \ No newline at end of file diff --git a/sql/contact/get_count.sql b/sql/contact/get_count.sql new file mode 100644 index 0000000..f8f20e4 --- /dev/null +++ b/sql/contact/get_count.sql @@ -0,0 +1 @@ +SELECT COUNT(*) FROM contact; \ No newline at end of file diff --git a/sql/contact/insert.sql b/sql/contact/insert.sql new file mode 100644 index 0000000..7766edd --- /dev/null +++ b/sql/contact/insert.sql @@ -0,0 +1,3 @@ +INSERT INTO contact ( + first_name, last_name, credential, message, time_created +) VALUES ($1, $2, $3, $4, $5) \ No newline at end of file diff --git a/sql/visit/get_count.sql b/sql/visit/get_count.sql new file mode 100644 index 0000000..4a19e16 --- /dev/null +++ b/sql/visit/get_count.sql @@ -0,0 +1 @@ +SELECT COUNT(*) FROM visit; \ No newline at end of file diff --git a/sql/visit/insert.sql b/sql/visit/insert.sql new file mode 100644 index 0000000..4995d38 --- /dev/null +++ b/sql/visit/insert.sql @@ -0,0 +1 @@ +INSERT INTO visit (ip_addr, time_created) VALUES ($1, $2); \ No newline at end of file diff --git a/sqlx-data.json b/sqlx-data.json index f669a82..1650d3a 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -12,6 +12,79 @@ }, "query": "DELETE FROM agent WHERE id = $1;" }, + "181ffb1869d9acb225071b9a5650510f29fca447892f698ae597d370764e35ad": { + "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": "city", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "starts_from", + "ordinal": 5, + "type_info": "Float8" + }, + { + "name": "district", + "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "finish_date", + "ordinal": 7, + "type_info": "Timestamp" + }, + { + "name": "media: _", + "ordinal": 8, + "type_info": "Text" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + null, + 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 l.city,\n (SELECT (SELECT u.price_usd FROM unit u WHERE u.project_id = p.id ORDER BY u.price_usd DESC LIMIT 1)) as starts_from,\n l.district,\n p.finish_date,\n p.media as \"media: _\"\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;" + }, "19a20556f5e3621438cd583aae4984c8cf510f359f65ec599f8a6b46d9153ec4": { "describe": { "columns": [ @@ -98,61 +171,39 @@ }, "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 WHERE id = $1;" }, - "20a9f804be4c73f4cbbeb063dbcd7e4f848c532f4d19583857a19f4fdaa65107": { + "1a0e9afaad6fea6593538fe8c4469c3d985f75ffb35f48a1f7385ecb9e3b28a9": { "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 - ], + "columns": [], + "nullable": [], "parameters": { "Left": [ - "UuidArray" + "Varchar", + "Varchar", + "Varchar", + "Varchar", + "Timestamptz" ] } }, - "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;" + "query": "INSERT INTO contact (\n first_name, last_name, credential, message, time_created\n) VALUES ($1, $2, $3, $4, $5)" + }, + "29e776da6e36e6e9c8a4e6c8df65ccce8af5e3d0e9aa9b064c11d39982f2c99d": { + "describe": { + "columns": [ + { + "name": "count", + "ordinal": 0, + "type_info": "Int8" + } + ], + "nullable": [ + null + ], + "parameters": { + "Left": [] + } + }, + "query": "SELECT COUNT(*) FROM contact;" }, "36f6cb77e7421f42604c6f248cc69d557856cfbc9598c45c31628874db8921f0": { "describe": { @@ -178,19 +229,7 @@ }, "query": "DELETE FROM project WHERE id = $1;" }, - "581359d322685ee14958a69929947ad8a0be09da9c02a214b4a3f235f2f1f5d7": { - "describe": { - "columns": [], - "nullable": [], - "parameters": { - "Left": [ - "Uuid" - ] - } - }, - "query": "DELETE FROM unit WHERE id = $1;" - }, - "7d674df64d815d97c15a4bb2b84fb4ab7f4289904d6fb8cf9537a1ec848d926c": { + "50bc13e98126bfda724eb65361386954340191d524174605e962479bf9799446": { "describe": { "columns": [ { @@ -199,39 +238,39 @@ "type_info": "Uuid" }, { - "name": "project_state: _", + "name": "shortcode", "ordinal": 1, "type_info": "Varchar" }, { - "name": "project_type: _", + "name": "full_name", "ordinal": 2, "type_info": "Varchar" }, { - "name": "project_condition: _", + "name": "credential", "ordinal": 3, "type_info": "Varchar" }, { - "name": "city", + "name": "credential_type: _", "ordinal": 4, "type_info": "Varchar" }, { - "name": "district", + "name": "profile_picture_url", "ordinal": 5, "type_info": "Varchar" }, { - "name": "finish_date", + "name": "time_created", "ordinal": 6, - "type_info": "Timestamp" + "type_info": "Timestamptz" }, { - "name": "media: _", + "name": "last_updated", "ordinal": 7, - "type_info": "Text" + "type_info": "Timestamptz" } ], "nullable": [ @@ -246,16 +285,101 @@ ], "parameters": { "Left": [ - "Text", - "Text", - "Text", - "Text", - "Text", - "Int8" + "UuidArray" ] } }, - "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 l.city,\n l.district,\n p.finish_date,\n p.media as \"media: _\"\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;" + "query": "SELECT \n id,\n shortcode,\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;" + }, + "581359d322685ee14958a69929947ad8a0be09da9c02a214b4a3f235f2f1f5d7": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Uuid" + ] + } + }, + "query": "DELETE FROM unit WHERE id = $1;" + }, + "70fa05f0ac30cba1fb2c3c356d1da567a1b3b417bdfd313f1d3b55c550e217f0": { + "describe": { + "columns": [ + { + "name": "count", + "ordinal": 0, + "type_info": "Int8" + } + ], + "nullable": [ + null + ], + "parameters": { + "Left": [] + } + }, + "query": "SELECT COUNT(*) FROM visit;" + }, + "7792ad0bec652b57156e4ac7010324a97984263434702de060ceab7cdcf691c0": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "shortcode", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "full_name", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "credential", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "credential_type: _", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "profile_picture_url", + "ordinal": 5, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 6, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 7, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false, + false, + false + ], + "parameters": { + "Left": [] + } + }, + "query": "SELECT\n id,\n shortcode,\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 full_name DESC;" }, "825e1ac484241349c54e75bb77186ce41ea98fd17cabd7308e737a6c9c5812a9": { "describe": { @@ -352,7 +476,20 @@ }, "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": { + "84c66265921772efe5e83baaa94609aa8684ca33d15d626f194f8dc9ceba025d": { + "describe": { + "columns": [], + "nullable": [], + "parameters": { + "Left": [ + "Varchar", + "Timestamptz" + ] + } + }, + "query": "INSERT INTO visit (ip_addr, time_created) VALUES ($1, $2);" + }, + "8f26059162e14cf6f2201cf89ce3782b6f0a534c9084be11a04e8b672388ab7c": { "describe": { "columns": [ { @@ -361,33 +498,38 @@ "type_info": "Uuid" }, { - "name": "full_name", + "name": "shortcode", "ordinal": 1, "type_info": "Varchar" }, { - "name": "credential", + "name": "full_name", "ordinal": 2, "type_info": "Varchar" }, { - "name": "credential_type: _", + "name": "credential", "ordinal": 3, "type_info": "Varchar" }, { - "name": "profile_picture_url", + "name": "credential_type: _", "ordinal": 4, "type_info": "Varchar" }, { - "name": "time_created", + "name": "profile_picture_url", "ordinal": 5, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 6, "type_info": "Timestamptz" }, { "name": "last_updated", - "ordinal": 6, + "ordinal": 7, "type_info": "Timestamptz" } ], @@ -398,6 +540,7 @@ false, false, false, + false, false ], "parameters": { @@ -407,13 +550,14 @@ "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;" + "query": "INSERT INTO agent (\n id, shortcode, full_name, credential, credential_type, profile_picture_url, time_created, last_updated\n) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $7\n) RETURNING\nid,\nshortcode,\nfull_name,\ncredential,\ncredential_type as \"credential_type: _\",\nprofile_picture_url,\ntime_created,\nlast_updated;" }, - "a4b4bff48a573996a661d52576b051edc19b17de90d0823b87057e361004ecf8": { + "924abcf88270de74ab6524fbd4247b2c23ab96b4569c8b81ff6b0e1d7dacada7": { "describe": { "columns": [ { @@ -422,33 +566,38 @@ "type_info": "Uuid" }, { - "name": "full_name", + "name": "shortcode", "ordinal": 1, "type_info": "Varchar" }, { - "name": "credential", + "name": "full_name", "ordinal": 2, "type_info": "Varchar" }, { - "name": "credential_type: _", + "name": "credential", "ordinal": 3, "type_info": "Varchar" }, { - "name": "profile_picture_url", + "name": "credential_type: _", "ordinal": 4, "type_info": "Varchar" }, { - "name": "time_created", + "name": "profile_picture_url", "ordinal": 5, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 6, "type_info": "Timestamptz" }, { "name": "last_updated", - "ordinal": 6, + "ordinal": 7, "type_info": "Timestamptz" } ], @@ -459,13 +608,22 @@ false, false, false, + false, false ], "parameters": { - "Left": [] + "Left": [ + "Varchar", + "Varchar", + "Varchar", + "Varchar", + "Varchar", + "Timestamptz", + "Uuid" + ] } }, - "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;" + "query": "UPDATE agent SET\n full_name = $1,\n shortcode = $2,\n credential = $3,\n credential_type = $4,\n profile_picture_url = $5,\n last_updated = $6\nWHERE id = $7\nRETURNING \n id,\n shortcode,\n full_name,\n credential,\n credential_type as \"credential_type: _\",\n profile_picture_url,\n time_created,\n last_updated;" }, "a6f20728a46711e230dd31f5489a620554cea3e4093a3a4c727f91301811ffea": { "describe": { @@ -803,6 +961,54 @@ }, "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;" }, + "ca04328cfa0709a6cfecc33714d9318c4b928ce3e7e8e076e7739b1cf8fecd9c": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Int4" + }, + { + "name": "first_name", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "last_name", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "credential", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "message", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 5, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + false + ], + "parameters": { + "Left": [] + } + }, + "query": "SELECT * FROM contact;" + }, "d0996b65d52b1e2b9e99eed338b31eb551b313ba91e44613e32aa83835d53dbc": { "describe": { "columns": [ @@ -967,7 +1173,7 @@ }, "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": { + "d65a90a10c18f22d7e9a266fa45b6ec2622b1a039cea6b9b65c48f441a3781e4": { "describe": { "columns": [ { @@ -976,98 +1182,43 @@ "type_info": "Uuid" }, { - "name": "full_name", + "name": "shortcode", "ordinal": 1, "type_info": "Varchar" }, { - "name": "credential", + "name": "full_name", "ordinal": 2, "type_info": "Varchar" }, { - "name": "credential_type: _", + "name": "credential", "ordinal": 3, "type_info": "Varchar" }, { - "name": "profile_picture_url", + "name": "credential_type: _", "ordinal": 4, "type_info": "Varchar" }, { - "name": "time_created", + "name": "profile_picture_url", "ordinal": 5, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 6, "type_info": "Timestamptz" }, { "name": "last_updated", - "ordinal": 6, + "ordinal": 7, "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, @@ -1082,7 +1233,7 @@ ] } }, - "query": "SELECT \nid,\nfull_name,\ncredential,\ncredential_type as \"credential_type: _\",\nprofile_picture_url,\ntime_created,\nlast_updated\nFROM agent WHERE id = $1" + "query": "SELECT \n id,\n shortcode,\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 = $1" }, "e15c1255cfa5d8075536949f04cb5bc5cc03336dee8cc417297ba02e7c8bff77": { "describe": { diff --git a/src/dao/agent.rs b/src/dao/agent.rs index a07ddd7..4211a09 100644 --- a/src/dao/agent.rs +++ b/src/dao/agent.rs @@ -10,6 +10,7 @@ pub async fn insert_agent( Agent, "sql/agent/insert.sql", agent.id, + agent.shortcode, agent.full_name, agent.credential, agent.credential_type as _, @@ -45,6 +46,7 @@ pub async fn update_agent( sqlx::query_file_as!( Agent, "sql/agent/update.sql", + agent.shortcode, agent.full_name, agent.credential, agent.credential_type as _, diff --git a/src/dao/contact.rs b/src/dao/contact.rs new file mode 100644 index 0000000..5cc7c12 --- /dev/null +++ b/src/dao/contact.rs @@ -0,0 +1,23 @@ +use jl_types::domain::{count::Count, contact::Contact}; +use sqlx::{postgres::PgQueryResult, PgPool}; + +pub async fn insert(db_conn: &PgPool, contact: &Contact) -> Result { + sqlx::query_file!( + "sql/contact/insert.sql", + contact.first_name, + contact.last_name, + contact.credential, + contact.message, + contact.time_created + ) + .execute(db_conn) + .await +} + +pub async fn get_all(db_conn: &PgPool) -> Result, sqlx::Error> { + sqlx::query_file_as!(Contact, "sql/contact/get_all.sql").fetch_all(db_conn).await +} + +pub async fn get_count(db_conn: &PgPool) -> Result { + sqlx::query_file_as!(Count, "sql/contact/get_count.sql").fetch_one(db_conn).await +} \ No newline at end of file diff --git a/src/dao/mod.rs b/src/dao/mod.rs index 18e5321..a9f352b 100644 --- a/src/dao/mod.rs +++ b/src/dao/mod.rs @@ -3,3 +3,5 @@ pub mod location; pub mod main_dao; pub mod project; pub mod unit; +pub mod visit; +pub mod contact; \ No newline at end of file diff --git a/src/dao/visit.rs b/src/dao/visit.rs new file mode 100644 index 0000000..0fcef42 --- /dev/null +++ b/src/dao/visit.rs @@ -0,0 +1,16 @@ +use jl_types::domain::{visit::Visit, count::Count}; +use sqlx::{postgres::PgQueryResult, PgPool}; + +pub async fn insert(db_conn: &PgPool, visit: &Visit) -> Result { + sqlx::query_file!( + "sql/visit/insert.sql", + visit.ip_addr, + visit.time_created, + ) + .execute(db_conn) + .await +} + +pub async fn get_count(db_conn: &PgPool) -> Result { + sqlx::query_file_as!(Count, "sql/visit/get_count.sql").fetch_one(db_conn).await +} \ No newline at end of file diff --git a/src/routes/read.rs b/src/routes/read.rs index 24d13fc..804e9d7 100644 --- a/src/routes/read.rs +++ b/src/routes/read.rs @@ -2,7 +2,7 @@ use std::{collections::{HashMap, HashSet}, str::FromStr, sync::Arc}; use actix_web::{ get, - web::{self, Path}, + web::{self, Path}, HttpRequest, }; use actix_web_utils::extensions::typed_response::TypedHttpResponse; use err::MessageResource; @@ -16,7 +16,7 @@ use jl_types::{ use sqlx::PgPool; use uuid::Uuid; -use crate::services; +use crate::{services, utils::visit::store_visit_concurrent}; #[get("/agent")] pub async fn get_all_agents(db_conn: web::Data>) -> TypedHttpResponse> { @@ -40,10 +40,12 @@ pub async fn get_locations_in_city( #[get("/projects/{page}")] pub async fn get_projects_paged( + request: HttpRequest, db_conn: web::Data>, page: Path, query_params: web::Query>, ) -> TypedHttpResponse> { + store_visit_concurrent(&db_conn.clone(), request); let filters = match parse_params_into_filters(query_params.0) { Ok(filters) => filters, Err(msg) => return TypedHttpResponse::return_standard_error(400, msg), diff --git a/src/utils/mod.rs b/src/utils/mod.rs index eda363d..d1af5ac 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1 +1,2 @@ pub mod macros; +pub mod visit; \ No newline at end of file diff --git a/src/utils/visit.rs b/src/utils/visit.rs new file mode 100644 index 0000000..ebe33ee --- /dev/null +++ b/src/utils/visit.rs @@ -0,0 +1,20 @@ +use std::sync::Arc; + +use actix_web::HttpRequest; +use jl_types::domain::visit::Visit; +use sqlx::PgPool; + +use crate::dao; + + +pub fn store_visit_concurrent(db_conn: &Arc, request: HttpRequest) { + let ip = request.peer_addr().unwrap(); + let db_conn = db_conn.clone(); + tokio::spawn(async move { + match dao::visit::insert(&db_conn, &Visit::new(ip.to_string())).await { + Ok(_) => {}, + Err(error) => { println!("{}", error) }, + }; + }); + +} \ No newline at end of file