diff --git a/Cargo.lock b/Cargo.lock index 12efce8..62f6c6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,7 +44,7 @@ dependencies = [ "actix-rt", "actix-service", "actix-utils", - "ahash", + "ahash 0.7.6", "base64 0.21.0", "bitflags 1.3.2", "brotli", @@ -54,8 +54,8 @@ dependencies = [ "encoding_rs", "flate2", "futures-core", - "h2", - "http", + "h2 0.3.15", + "http 0.2.8", "httparse", "httpdate", "itoa", @@ -80,7 +80,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6" dependencies = [ "quote", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] @@ -90,7 +90,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66ff4d247d2b160861fa2866457e85706833527840e4133f8f49aa423a38799" dependencies = [ "bytestring", - "http", + "http 0.2.8", "regex", "serde", "tracing", @@ -160,7 +160,7 @@ dependencies = [ "actix-service", "actix-utils", "actix-web-codegen", - "ahash", + "ahash 0.7.6", "bytes", "bytestring", "cfg-if", @@ -169,7 +169,7 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "http", + "http 0.2.8", "itoa", "language-tags", "log", @@ -195,7 +195,7 @@ dependencies = [ "actix-router", "proc-macro2", "quote", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] @@ -224,6 +224,18 @@ dependencies = [ "version_check", ] +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "0.7.20" @@ -248,6 +260,12 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -257,6 +275,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + [[package]] name = "anyhow" version = "1.0.68" @@ -271,9 +295,9 @@ checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" [[package]] name = "async-trait" -version = "0.1.77" +version = "0.1.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" +checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" dependencies = [ "proc-macro2", "quote", @@ -322,6 +346,12 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + [[package]] name = "bitflags" version = "1.3.2" @@ -333,6 +363,9 @@ name = "bitflags" version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +dependencies = [ + "serde", +] [[package]] name = "block" @@ -361,7 +394,7 @@ dependencies = [ "dbus", "dbus-tokio", "futures", - "itertools", + "itertools 0.10.5", "log", "serde", "serde-xml-rs", @@ -435,9 +468,9 @@ checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" @@ -456,11 +489,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.79" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" dependencies = [ "jobserver", + "libc", ] [[package]] @@ -502,7 +536,7 @@ dependencies = [ "cocoa-foundation", "core-foundation", "core-graphics", - "foreign-types", + "foreign-types 0.5.0", "libc", "objc", ] @@ -583,7 +617,7 @@ dependencies = [ "bitflags 1.3.2", "core-foundation", "core-graphics-types", - "foreign-types", + "foreign-types 0.5.0", "libc", ] @@ -618,9 +652,9 @@ dependencies = [ [[package]] name = "crc-catalog" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" [[package]] name = "crc32fast" @@ -633,22 +667,18 @@ dependencies = [ [[package]] name = "crossbeam-queue" -version = "0.3.8" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.14" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crypto-common" @@ -694,7 +724,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] @@ -711,7 +741,7 @@ checksum = "81bbeb29798b407ccd82a3324ade1a7286e0d29851475990b612670f6f5124d2" dependencies = [ "proc-macro2", "quote", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] @@ -735,7 +765,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] @@ -746,7 +776,7 @@ checksum = "b36230598a2d5de7ec1c6f51f72d8a99a9208daff41de2084d06e3fd3ea56685" dependencies = [ "darling_core", "quote", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] @@ -794,7 +824,7 @@ checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2", "quote", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] @@ -807,7 +837,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] @@ -865,12 +895,40 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "event-listener" version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +[[package]] +name = "fastrand" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" + +[[package]] +name = "finl_unicode" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" + [[package]] name = "flate2" version = "1.0.25" @@ -899,7 +957,7 @@ dependencies = [ "futures-core", "futures-sink", "pin-project", - "spin 0.9.4", + "spin 0.9.8", ] [[package]] @@ -908,6 +966,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared 0.1.1", +] + [[package]] name = "foreign-types" version = "0.5.0" @@ -915,7 +982,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" dependencies = [ "foreign-types-macros", - "foreign-types-shared", + "foreign-types-shared 0.3.1", ] [[package]] @@ -929,6 +996,12 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "foreign-types-shared" version = "0.3.1" @@ -1062,9 +1135,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.8" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "a06fddc2749e0528d2813f95e050e87e52c8cbbae56223b9babf73b3e53b0cc6" dependencies = [ "cfg-if", "libc", @@ -1088,8 +1161,27 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", - "indexmap", + "http 0.2.8", + "indexmap 1.9.2", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "816ec7294445779408f36fe57bc5b7fc1cf59664059096c65f905c1c61f58069" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 1.1.0", + "indexmap 2.2.6", "slab", "tokio", "tokio-util", @@ -1101,23 +1193,24 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash", -] [[package]] name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash 0.8.11", + "allocator-api2", +] [[package]] name = "hashlink" -version = "0.8.1" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69fe1fcf8b4278d860ad0548329f892a3631fb63f82574df68275f34cdbe0ffa" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" dependencies = [ - "hashbrown 0.12.3", + "hashbrown 0.14.3", ] [[package]] @@ -1126,11 +1219,18 @@ version = "0.1.0" dependencies = [ "actix-cors", "actix-web", - "healthpi-db", + "async-trait", + "chrono", + "dotenv", "healthpi-model", + "itertools 0.10.5", "log", "log4rs", + "ron", + "rustc-hash", "serde", + "sqlx", + "tokio", ] [[package]] @@ -1141,34 +1241,21 @@ dependencies = [ "btleplug", "futures", "healthpi-model", - "mockall", + "mockall 0.11.3", "serde", "uuid", ] [[package]] -name = "healthpi-db" +name = "healthpi-client" version = "0.1.0" dependencies = [ "async-trait", - "chrono", - "dotenv", - "healthpi-bt", "healthpi-model", - "itertools", - "log", - "mockall", - "num", - "num-derive", - "num-traits", - "ron", - "rustc-hash", - "serde", - "serde_with", - "sqlx", - "strum", - "tokio", - "uuid", + "itertools 0.12.1", + "mockall 0.12.1", + "reqwest", + "thiserror", ] [[package]] @@ -1180,11 +1267,11 @@ dependencies = [ "ctrlc", "futures", "healthpi-bt", - "healthpi-db", + "healthpi-client", "healthpi-model", "log", "log4rs", - "mockall", + "mockall 0.11.3", "serde", "serde_json", "tokio", @@ -1239,6 +1326,40 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" +dependencies = [ + "bytes", + "futures-core", + "http 1.1.0", + "http-body", + "pin-project-lite", +] + [[package]] name = "httparse" version = "1.8.0" @@ -1257,6 +1378,62 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "hyper" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186548d73ac615b32a73aafe38fb4f56c0d340e110e5a200bcadbaf2e199263a" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.4", + "http 1.1.0", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body", + "hyper", + "pin-project-lite", + "socket2 0.5.5", + "tokio", + "tower", + "tower-service", + "tracing", +] + [[package]] name = "iana-time-zone" version = "0.1.53" @@ -1308,6 +1485,16 @@ dependencies = [ "serde", ] +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", +] + [[package]] name = "instant" version = "0.1.12" @@ -1317,6 +1504,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + [[package]] name = "itertools" version = "0.10.5" @@ -1326,6 +1519,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.5" @@ -1438,6 +1640,12 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + [[package]] name = "local-channel" version = "0.1.3" @@ -1574,8 +1782,23 @@ dependencies = [ "downcast", "fragile", "lazy_static", - "mockall_derive", - "predicates", + "mockall_derive 0.11.3", + "predicates 2.1.5", + "predicates-tree", +] + +[[package]] +name = "mockall" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43766c2b5203b10de348ffe19f7e54564b64f3d6018ff7648d1e2d6d3a0f0a48" +dependencies = [ + "cfg-if", + "downcast", + "fragile", + "lazy_static", + "mockall_derive 0.12.1", + "predicates 3.1.0", "predicates-tree", ] @@ -1588,7 +1811,37 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 1.0.107", + "syn 1.0.109", +] + +[[package]] +name = "mockall_derive" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af7cbce79ec385a1d4f54baa90a76401eb15d9cab93685f62e7e9f942aa00ae2" +dependencies = [ + "cfg-if", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", ] [[package]] @@ -1661,7 +1914,7 @@ checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ "proc-macro2", "quote", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] @@ -1740,6 +1993,50 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "openssl" +version = "0.10.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +dependencies = [ + "bitflags 2.4.2", + "cfg-if", + "foreign-types 0.3.2", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "ordered-float" version = "2.10.0" @@ -1826,7 +2123,7 @@ checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ "proc-macro2", "quote", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] @@ -1861,12 +2158,22 @@ checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd" dependencies = [ "difflib", "float-cmp", - "itertools", + "itertools 0.10.5", "normalize-line-endings", "predicates-core", "regex", ] +[[package]] +name = "predicates" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" +dependencies = [ + "anstyle", + "predicates-core", +] + [[package]] name = "predicates-core" version = "1.0.5" @@ -1966,6 +2273,48 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +[[package]] +name = "reqwest" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e6cc1e89e689536eb5aeede61520e874df5a4707df811cd5da4aa5fbb2aae19" +dependencies = [ + "base64 0.22.0", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2 0.4.4", + "http 1.1.0", + "http-body", + "http-body-util", + "hyper", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile 2.1.2", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "ring" version = "0.16.20" @@ -1976,20 +2325,36 @@ dependencies = [ "libc", "once_cell", "spin 0.5.2", - "untrusted", + "untrusted 0.7.1", "web-sys", "winapi", ] +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin 0.9.8", + "untrusted 0.9.0", + "windows-sys 0.52.0", +] + [[package]] name = "ron" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "300a51053b1cb55c80b7a9fde4120726ddf25ca241a1cbb926626f62fb136bff" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" dependencies = [ - "base64 0.13.1", - "bitflags 1.3.2", + "base64 0.21.0", + "bitflags 2.4.2", "serde", + "serde_derive", ] [[package]] @@ -2013,27 +2378,56 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +dependencies = [ + "bitflags 2.4.2", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "rustls" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" dependencies = [ "log", - "ring", + "ring 0.16.20", "sct", "webpki", ] [[package]] name = "rustls-pemfile" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ "base64 0.21.0", ] +[[package]] +name = "rustls-pemfile" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" +dependencies = [ + "base64 0.22.0", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247" + [[package]] name = "rustversion" version = "1.0.11" @@ -2055,6 +2449,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -2069,12 +2472,35 @@ checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" [[package]] name = "sct" -version = "0.7.0" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring 0.17.8", + "untrusted 0.9.0", +] + +[[package]] +name = "security-framework" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" dependencies = [ - "ring", - "untrusted", + "core-foundation-sys", + "libc", ] [[package]] @@ -2157,7 +2583,7 @@ dependencies = [ "base64 0.13.1", "chrono", "hex", - "indexmap", + "indexmap 1.9.2", "serde", "serde_json", "serde_with_macros", @@ -2173,7 +2599,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] @@ -2182,7 +2608,7 @@ version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b" dependencies = [ - "indexmap", + "indexmap 1.9.2", "ryu", "serde", "yaml-rust", @@ -2230,9 +2656,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" @@ -2262,29 +2688,29 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spin" -version = "0.9.4" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" dependencies = [ "lock_api", ] [[package]] name = "sqlformat" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c12bc9199d1db8234678b7051747c07f517cdcf019262d1847b94ec8b1aee3e" +checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" dependencies = [ - "itertools", + "itertools 0.12.1", "nom", "unicode_categories", ] [[package]] name = "sqlx" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9249290c05928352f71c077cc44a464d880c63f26f7534728cca008e135c0428" +checksum = "f8de3b03a925878ed54a954f621e64bf55a3c1bd29652d0d1a17830405350188" dependencies = [ "sqlx-core", "sqlx-macros", @@ -2292,11 +2718,11 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcbc16ddba161afc99e14d1713a453747a2b07fc097d2009f4c300ec99286105" +checksum = "fa8241483a83a3f33aa5fff7e7d9def398ff9990b2752b6c6112b83c6d246029" dependencies = [ - "ahash", + "ahash 0.7.6", "atoi", "bitflags 1.3.2", "byteorder", @@ -2314,7 +2740,7 @@ dependencies = [ "futures-util", "hashlink", "hex", - "indexmap", + "indexmap 1.9.2", "itoa", "libc", "libsqlite3-sys", @@ -2324,7 +2750,7 @@ dependencies = [ "paste", "percent-encoding", "rustls", - "rustls-pemfile", + "rustls-pemfile 1.0.4", "sha2", "smallvec", "sqlformat", @@ -2338,9 +2764,9 @@ dependencies = [ [[package]] name = "sqlx-macros" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b850fa514dc11f2ee85be9d055c512aa866746adfacd1cb42d867d68e6a5b0d9" +checksum = "9966e64ae989e7e575b19d7265cb79d7fc3cbbdf179835cb0d716f294c2049c9" dependencies = [ "dotenvy", "either", @@ -2351,15 +2777,15 @@ dependencies = [ "sha2", "sqlx-core", "sqlx-rt", - "syn 1.0.107", + "syn 1.0.109", "url", ] [[package]] name = "sqlx-rt" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24c5b2d25fa654cc5f841750b8e1cdedbe21189bf9a9382ee90bfa9dd3562396" +checksum = "804d3f245f894e61b1e6263c84b23ca675d96753b5abfd5cc8597d86806e8024" dependencies = [ "once_cell", "tokio", @@ -2374,10 +2800,11 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "stringprep" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" +checksum = "bb41d74e231a107a1b4ee36bd1214b11285b77768d2e3824aedafa988fd36ee6" dependencies = [ + "finl_unicode", "unicode-bidi", "unicode-normalization", ] @@ -2407,14 +2834,14 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 1.0.107", + "syn 1.0.109", ] [[package]] name = "syn" -version = "1.0.107" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", @@ -2432,6 +2859,45 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + [[package]] name = "termcolor" version = "1.2.0" @@ -2449,18 +2915,18 @@ checksum = "95059e91184749cb66be6dc994f67f182b6d897cb3df74a5bf66b5e709295fd8" [[package]] name = "thiserror" -version = "1.0.56" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.56" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", @@ -2561,6 +3027,16 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.23.4" @@ -2598,6 +3074,34 @@ dependencies = [ "tracing", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + [[package]] name = "tracing" version = "0.1.37" @@ -2619,6 +3123,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "typemap-ors" version = "1.0.0" @@ -2657,9 +3167,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.10.1" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" [[package]] name = "unicode-width" @@ -2688,6 +3198,12 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.3.1" @@ -2705,7 +3221,6 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" dependencies = [ - "getrandom", "serde", ] @@ -2731,6 +3246,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" @@ -2764,10 +3288,22 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 1.0.107", + "syn 1.0.109", "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.84" @@ -2786,7 +3322,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn 1.0.107", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2809,12 +3345,12 @@ dependencies = [ [[package]] name = "webpki" -version = "0.22.0" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" dependencies = [ - "ring", - "untrusted", + "ring 0.17.8", + "untrusted 0.9.0", ] [[package]] @@ -2900,6 +3436,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -3056,6 +3601,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +[[package]] +name = "winreg" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "xml-rs" version = "0.8.4" @@ -3071,6 +3626,26 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "zstd" version = "0.12.3+zstd.1.5.2" diff --git a/Cargo.toml b/Cargo.toml index d300484..a0d1bd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,9 @@ [workspace] -members = ["healthpi-api", "healthpi-bt", "healthpi-db", "healthpi-loader", "healthpi-model"] +members = [ + "healthpi-api", + "healthpi-bt", + "healthpi-client", + "healthpi-loader", + "healthpi-model", +] resolver = "2" diff --git a/healthpi-api/Cargo.toml b/healthpi-api/Cargo.toml index d0f2ef4..960f5b3 100644 --- a/healthpi-api/Cargo.toml +++ b/healthpi-api/Cargo.toml @@ -4,11 +4,18 @@ version = "0.1.0" edition = "2021" [dependencies] -healthpi-db = { path = "../healthpi-db" } healthpi-model = { path = "../healthpi-model" } actix-web = "4.3.0" +actix-cors = "0.6.4" +async-trait = "0.1.63" +chrono = { version = "0.4.19" } +dotenv = "0.15.0" +itertools = "0.10.5" log = "0.4.17" log4rs = "1.2.0" +ron = "0.8.0" +rustc-hash = "1.1.0" serde = { version = "1.0.152", features = ["derive"] } -actix-cors = "0.6.4" +sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "sqlite"] } +tokio = "1.24.2" diff --git a/healthpi-db/src/connection.rs b/healthpi-api/src/db/connection.rs similarity index 100% rename from healthpi-db/src/connection.rs rename to healthpi-api/src/db/connection.rs diff --git a/healthpi-db/src/measurement.rs b/healthpi-api/src/db/measurement.rs similarity index 99% rename from healthpi-db/src/measurement.rs rename to healthpi-api/src/db/measurement.rs index ea1f6e4..0fe4551 100644 --- a/healthpi-db/src/measurement.rs +++ b/healthpi-api/src/db/measurement.rs @@ -106,7 +106,6 @@ impl<'r> FromRow<'r, SqliteRow> for RecordRow { } } -#[mockall::automock] #[async_trait] pub trait MeasurementRepository: Send + Sync { async fn store_records(&self, records: Vec) -> Result<(), Box>; diff --git a/healthpi-api/src/db/mod.rs b/healthpi-api/src/db/mod.rs new file mode 100644 index 0000000..eb11e35 --- /dev/null +++ b/healthpi-api/src/db/mod.rs @@ -0,0 +1,2 @@ +pub(crate) mod connection; +pub(crate) mod measurement; diff --git a/healthpi-api/src/main.rs b/healthpi-api/src/main.rs index 0236c00..c72d045 100644 --- a/healthpi-api/src/main.rs +++ b/healthpi-api/src/main.rs @@ -1,14 +1,17 @@ +mod db; + use std::str::FromStr; use actix_cors::Cors; -use actix_web::{get, web, App, HttpServer, Responder}; -use healthpi_db::{ +use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder}; +use healthpi_model::measurement::{Record, ValueType}; +use log::info; +use serde::{de, Deserialize}; + +use crate::db::{ connection::Connection, measurement::{MeasurementRepository, MeasurementRepositoryImpl}, }; -use healthpi_model::measurement::ValueType; -use log::info; -use serde::{de, Deserialize}; fn comma_separated_value_types<'de, D>(deserializer: D) -> Result, D::Error> where @@ -22,6 +25,7 @@ where #[derive(Debug, Deserialize)] struct Query { + #[serde(default)] #[serde(deserialize_with = "comma_separated_value_types")] select: Vec, } @@ -39,6 +43,17 @@ async fn index( ) } +#[post("/")] +async fn post_measurements( + measurement_repository: web::Data, + measurements: web::Json>, +) -> impl Responder { + match measurement_repository.store_records(measurements.0).await { + Ok(_) => HttpResponse::Created().json(()), + Err(_) => HttpResponse::InternalServerError().json(()), + } +} + #[actix_web::main] async fn main() -> std::io::Result<()> { log4rs::init_file("log4rs.yml", Default::default()).unwrap(); @@ -53,6 +68,7 @@ async fn main() -> std::io::Result<()> { .wrap(cors) .app_data(web::Data::new(measurement_repository.clone())) .service(index) + .service(post_measurements) }) .bind(("127.0.0.1", 8080))? .run() diff --git a/healthpi-client/Cargo.toml b/healthpi-client/Cargo.toml new file mode 100644 index 0000000..97f3230 --- /dev/null +++ b/healthpi-client/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "healthpi-client" +version = "0.1.0" +edition = "2021" + +[dependencies] +async-trait = "0.1.79" +healthpi-model = { path = "../healthpi-model", features = ["serde"] } + +itertools = "0.12.1" +mockall = "0.12.1" +reqwest = { version = "0.12.3", features = ["json"] } +thiserror = "1.0.58" diff --git a/healthpi-client/src/client.rs b/healthpi-client/src/client.rs new file mode 100644 index 0000000..d042659 --- /dev/null +++ b/healthpi-client/src/client.rs @@ -0,0 +1,78 @@ +use async_trait::async_trait; +use healthpi_model::measurement::{Record, ValueType}; +use itertools::Itertools; + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("failed to communicate with the server")] + ServerError, +} + +type Result = std::result::Result; + +#[mockall::automock] +#[async_trait] +pub trait Client: Send + Sync { + async fn get_records(&self) -> Result>; + async fn get_records_with_value_types(&self, types: &[ValueType]) -> Result>; + async fn post_records(&self, records: &[Record]) -> Result<()>; +} + +pub struct ClientImpl { + url: String, + client: reqwest::Client, +} + +impl ClientImpl { + fn new(url: String) -> Self { + Self { + url, + client: reqwest::Client::new(), + } + } +} + +pub fn create(url: String) -> impl Client { + ClientImpl::new(url) +} + +#[async_trait] +impl Client for ClientImpl { + async fn get_records(&self) -> Result> { + self.client + .get(&self.url) + .send() + .await + .map_err(|_| Error::ServerError)? + .json() + .await + .map_err(|_| Error::ServerError) + } + + async fn get_records_with_value_types(&self, types: &[ValueType]) -> Result> { + self.client + .get(&self.url) + .query(&[ + "select", + &types.iter().map(|t| format!("{:?}", t)).join(","), + ]) + .send() + .await + .map_err(|_| Error::ServerError)? + .json() + .await + .map_err(|_| Error::ServerError) + } + + async fn post_records(&self, records: &[Record]) -> Result<()> { + self.client + .post(&self.url) + .json(&records) + .send() + .await + .map_err(|_| Error::ServerError)? + .json() + .await + .map_err(|_| Error::ServerError) + } +} diff --git a/healthpi-client/src/lib.rs b/healthpi-client/src/lib.rs new file mode 100644 index 0000000..d624770 --- /dev/null +++ b/healthpi-client/src/lib.rs @@ -0,0 +1,3 @@ +mod client; + +pub use client::{create, Client, Error, MockClient}; diff --git a/healthpi-db/Cargo.toml b/healthpi-db/Cargo.toml deleted file mode 100644 index 90f2f2d..0000000 --- a/healthpi-db/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "healthpi-db" -version = "0.1.0" -edition = "2021" - -[dependencies] -healthpi-bt = { path = "../healthpi-bt" } -healthpi-model = { path = "../healthpi-model", features = ["serde"] } - -chrono = { version = "0.4.19", features = ["serde"] } -sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "sqlite"] } -dotenv = "0.15.0" -log = "0.4.17" -num = "0.4" -num-derive = "0.3" -num-traits = "0.2" -rustc-hash = "1.1.0" -uuid = { version = "1.1.2", features = ["v4"] } -mockall = "0.11.3" -async-trait = "0.1.63" -tokio = "1.24.2" -serde = { version = "1.0.152", features = ["derive"] } -ron = "0.8.0" -itertools = "0.10.5" -strum = { version = "0.24.1", features = ["derive"] } -serde_with = "2.2.0" diff --git a/healthpi-db/src/lib.rs b/healthpi-db/src/lib.rs deleted file mode 100644 index 0594f21..0000000 --- a/healthpi-db/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod connection; -pub mod measurement; diff --git a/healthpi-loader/Cargo.toml b/healthpi-loader/Cargo.toml index 842c9e6..4f4dfea 100644 --- a/healthpi-loader/Cargo.toml +++ b/healthpi-loader/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] healthpi-bt = { path = "../healthpi-bt" } -healthpi-db = { path = "../healthpi-db" } +healthpi-client = { path = "../healthpi-client" } healthpi-model = { path = "../healthpi-model" } async-trait = "0.1.56" diff --git a/healthpi-loader/src/bin/load_json.rs b/healthpi-loader/src/bin/load_json.rs index 9993c26..df93f25 100644 --- a/healthpi-loader/src/bin/load_json.rs +++ b/healthpi-loader/src/bin/load_json.rs @@ -1,17 +1,13 @@ use std::{error::Error, fs::File, io::BufReader}; -use healthpi_db::{ - connection::Connection, - measurement::{MeasurementRepository, MeasurementRepositoryImpl}, -}; +use healthpi_client::Client; #[tokio::main] async fn main() -> Result<(), Box> { let file = File::open("data.json")?; - let values = serde_json::from_reader(BufReader::new(file))?; - let db = Connection::establish().await?; - let repository = MeasurementRepositoryImpl::new(db); - repository.store_records(values).await?; + let values: Vec<_> = serde_json::from_reader(BufReader::new(file))?; + let client = healthpi_client::create("http://localhost:8080/".to_owned()); + client.post_records(&values).await?; Ok(()) } diff --git a/healthpi-loader/src/daemon.rs b/healthpi-loader/src/daemon.rs index 75a7ce4..5088c22 100644 --- a/healthpi-loader/src/daemon.rs +++ b/healthpi-loader/src/daemon.rs @@ -4,8 +4,6 @@ use std::sync::{ Arc, }; -use healthpi_db::connection::Connection; -use healthpi_db::measurement::MeasurementRepositoryImpl; use log::info; use healthpi_loader::devices::device::FactoryImpl; @@ -15,9 +13,7 @@ use healthpi_loader::Loader; async fn main() -> Result<(), Box> { log4rs::init_file("log4rs.yml", Default::default())?; - info!("Connecting to database"); - let conn = Connection::establish().await?; - let measurement_repository = Box::new(MeasurementRepositoryImpl::new(conn.clone())); + let api_client = Box::new(healthpi_client::create("http://localhost:8080/".to_owned())); info!("Starting Bluetooth session"); let ble_session = healthpi_bt::create_session().await?; @@ -27,7 +23,7 @@ async fn main() -> Result<(), Box> { let loader = Arc::new(Loader::new( ble_session, factory, - measurement_repository, + api_client, running.clone(), )); ctrlc::set_handler(move || running.store(false, Ordering::Relaxed))?; diff --git a/healthpi-loader/src/lib.rs b/healthpi-loader/src/lib.rs index 50489d2..8ce8865 100644 --- a/healthpi-loader/src/lib.rs +++ b/healthpi-loader/src/lib.rs @@ -11,7 +11,6 @@ use std::{ use futures::lock::Mutex; use healthpi_bt::BleSession; -use healthpi_db::measurement::MeasurementRepository; use log::{debug, error, info}; use tokio::time; @@ -20,7 +19,7 @@ use crate::devices::device::Factory; pub struct Loader { ble_session: Box, factory: Arc>>, - repository: Box, + api_client: Box, running: Arc, } @@ -28,13 +27,13 @@ impl Loader { pub fn new( ble_session: Box, factory: Box, - repository: Box, + api_client: Box, running: Arc, ) -> Self { Self { ble_session, factory: Arc::new(Mutex::new(factory)), - repository, + api_client, running, } } @@ -82,7 +81,7 @@ impl Loader { device.disconnect().await?; info!("Storing records in database"); - if let Err(e) = self.repository.store_records(records).await { + if let Err(e) = self.api_client.post_records(&records).await { error!("Failed to store records in database, skipping. {}", e); continue; } diff --git a/healthpi-loader/tests/integration.rs b/healthpi-loader/tests/integration.rs index fa73546..64daf87 100644 --- a/healthpi-loader/tests/integration.rs +++ b/healthpi-loader/tests/integration.rs @@ -6,7 +6,6 @@ use std::sync::{ use chrono::Utc; use futures::stream; use healthpi_bt::{BleCharacteristicEvent, MockBleCharacteristic, MockBleDevice, MockBleSession}; -use healthpi_db::measurement::MockMeasurementRepository; use healthpi_loader::{ devices::{device::MockFactory, soehnle::Shape200}, Loader, @@ -67,9 +66,9 @@ async fn shape_200_returns_no_records() { .returning(|ble_device| Some(Box::new(Shape200::new(ble_device)))); factory.expect_mark_processed().returning(|_| Utc::now()); - let mut measurement_repository = MockMeasurementRepository::new(); + let mut measurement_repository = healthpi_client::MockClient::new(); measurement_repository - .expect_store_records() + .expect_post_records() .with(eq(vec![])) .returning(|_| Ok(())); diff --git a/log4rs.yml b/log4rs.yml index b297f59..14018b1 100644 --- a/log4rs.yml +++ b/log4rs.yml @@ -29,3 +29,7 @@ loggers: level: error btleplug: level: error + reqwest: + level: error + hyper_util: + level: error