ResourceHub API. Not for production. Code slitted into fucntional Modules
This commit is contained in:
31
ResourceHub/.idea/betterCommentsSettings.xml
generated
Normal file
31
ResourceHub/.idea/betterCommentsSettings.xml
generated
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="BetterCommentsSettings">
|
||||||
|
<option name="initialized" value="true" />
|
||||||
|
<option name="tags">
|
||||||
|
<list>
|
||||||
|
<CustomTag>
|
||||||
|
<option name="color" value="#FF2D00" />
|
||||||
|
<option name="type" value="!" />
|
||||||
|
</CustomTag>
|
||||||
|
<CustomTag>
|
||||||
|
<option name="color" value="#3498DB" />
|
||||||
|
<option name="type" value="?" />
|
||||||
|
</CustomTag>
|
||||||
|
<CustomTag>
|
||||||
|
<option name="color" value="#474747" />
|
||||||
|
<option name="hasStrikethrough" value="true" />
|
||||||
|
<option name="type" value="//" />
|
||||||
|
</CustomTag>
|
||||||
|
<CustomTag>
|
||||||
|
<option name="color" value="#FF8C00" />
|
||||||
|
<option name="type" value="todo" />
|
||||||
|
</CustomTag>
|
||||||
|
<CustomTag>
|
||||||
|
<option name="color" value="#98C379" />
|
||||||
|
<option name="type" value="*" />
|
||||||
|
</CustomTag>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
1
ResourceHub/.idea/vcs.xml
generated
1
ResourceHub/.idea/vcs.xml
generated
@@ -2,5 +2,6 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="" vcs="Git" />
|
<mapping directory="" vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
120
ResourceHub/Cargo.lock
generated
120
ResourceHub/Cargo.lock
generated
@@ -373,9 +373,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.4.1"
|
version = "0.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "139ef39800118c7683f2fd3c98c1b23c09ae076556b435f8e9064ae108aaeeec"
|
checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -661,9 +661,9 @@ checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.182"
|
version = "0.2.183"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
|
checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linux-raw-sys"
|
name = "linux-raw-sys"
|
||||||
@@ -933,18 +933,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.44"
|
version = "1.0.45"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
|
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "r-efi"
|
name = "r-efi"
|
||||||
version = "5.3.0"
|
version = "6.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "rand"
|
||||||
@@ -978,9 +978,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redis"
|
name = "redis"
|
||||||
version = "1.0.4"
|
version = "1.0.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dbe7f6e08ce1c6a9b21684e643926f6fc3b683bc006cb89afd72a5e0eb16e3a2"
|
checksum = "b36964393906eb775b89b25b05b7b95685b8dd14062f1663a31ff93e75c452e5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arcstr",
|
"arcstr",
|
||||||
"bytes",
|
"bytes",
|
||||||
@@ -993,7 +993,7 @@ dependencies = [
|
|||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"ryu",
|
"ryu",
|
||||||
"sha1_smol",
|
"sha1_smol",
|
||||||
"socket2 0.6.2",
|
"socket2 0.6.3",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"url",
|
"url",
|
||||||
@@ -1278,12 +1278,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "socket2"
|
name = "socket2"
|
||||||
version = "0.6.2"
|
version = "0.6.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0"
|
checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.60.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1345,7 +1345,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0"
|
checksum = "82a72c767771b47409d2345987fda8628641887d5466101319899796367354a0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fastrand",
|
"fastrand",
|
||||||
"getrandom 0.4.1",
|
"getrandom 0.4.2",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustix",
|
"rustix",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
@@ -1409,9 +1409,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.49.0"
|
version = "1.50.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86"
|
checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -1419,16 +1419,16 @@ dependencies = [
|
|||||||
"parking_lot",
|
"parking_lot",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"signal-hook-registry",
|
"signal-hook-registry",
|
||||||
"socket2 0.6.2",
|
"socket2 0.6.3",
|
||||||
"tokio-macros",
|
"tokio-macros",
|
||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-macros"
|
name = "tokio-macros"
|
||||||
version = "2.6.0"
|
version = "2.6.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5"
|
checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -1725,15 +1725,6 @@ dependencies = [
|
|||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-sys"
|
|
||||||
version = "0.60.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
|
|
||||||
dependencies = [
|
|
||||||
"windows-targets 0.53.5",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.61.2"
|
version = "0.61.2"
|
||||||
@@ -1767,30 +1758,13 @@ dependencies = [
|
|||||||
"windows_aarch64_gnullvm 0.52.6",
|
"windows_aarch64_gnullvm 0.52.6",
|
||||||
"windows_aarch64_msvc 0.52.6",
|
"windows_aarch64_msvc 0.52.6",
|
||||||
"windows_i686_gnu 0.52.6",
|
"windows_i686_gnu 0.52.6",
|
||||||
"windows_i686_gnullvm 0.52.6",
|
"windows_i686_gnullvm",
|
||||||
"windows_i686_msvc 0.52.6",
|
"windows_i686_msvc 0.52.6",
|
||||||
"windows_x86_64_gnu 0.52.6",
|
"windows_x86_64_gnu 0.52.6",
|
||||||
"windows_x86_64_gnullvm 0.52.6",
|
"windows_x86_64_gnullvm 0.52.6",
|
||||||
"windows_x86_64_msvc 0.52.6",
|
"windows_x86_64_msvc 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-targets"
|
|
||||||
version = "0.53.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
|
|
||||||
dependencies = [
|
|
||||||
"windows-link",
|
|
||||||
"windows_aarch64_gnullvm 0.53.1",
|
|
||||||
"windows_aarch64_msvc 0.53.1",
|
|
||||||
"windows_i686_gnu 0.53.1",
|
|
||||||
"windows_i686_gnullvm 0.53.1",
|
|
||||||
"windows_i686_msvc 0.53.1",
|
|
||||||
"windows_x86_64_gnu 0.53.1",
|
|
||||||
"windows_x86_64_gnullvm 0.53.1",
|
|
||||||
"windows_x86_64_msvc 0.53.1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_gnullvm"
|
name = "windows_aarch64_gnullvm"
|
||||||
version = "0.48.5"
|
version = "0.48.5"
|
||||||
@@ -1803,12 +1777,6 @@ version = "0.52.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_aarch64_gnullvm"
|
|
||||||
version = "0.53.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_msvc"
|
name = "windows_aarch64_msvc"
|
||||||
version = "0.48.5"
|
version = "0.48.5"
|
||||||
@@ -1821,12 +1789,6 @@ version = "0.52.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_aarch64_msvc"
|
|
||||||
version = "0.53.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_gnu"
|
name = "windows_i686_gnu"
|
||||||
version = "0.48.5"
|
version = "0.48.5"
|
||||||
@@ -1839,24 +1801,12 @@ version = "0.52.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_i686_gnu"
|
|
||||||
version = "0.53.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_gnullvm"
|
name = "windows_i686_gnullvm"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_i686_gnullvm"
|
|
||||||
version = "0.53.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_msvc"
|
name = "windows_i686_msvc"
|
||||||
version = "0.48.5"
|
version = "0.48.5"
|
||||||
@@ -1869,12 +1819,6 @@ version = "0.52.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_i686_msvc"
|
|
||||||
version = "0.53.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnu"
|
name = "windows_x86_64_gnu"
|
||||||
version = "0.48.5"
|
version = "0.48.5"
|
||||||
@@ -1887,12 +1831,6 @@ version = "0.52.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_gnu"
|
|
||||||
version = "0.53.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnullvm"
|
name = "windows_x86_64_gnullvm"
|
||||||
version = "0.48.5"
|
version = "0.48.5"
|
||||||
@@ -1905,12 +1843,6 @@ version = "0.52.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_gnullvm"
|
|
||||||
version = "0.53.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_msvc"
|
name = "windows_x86_64_msvc"
|
||||||
version = "0.48.5"
|
version = "0.48.5"
|
||||||
@@ -1923,17 +1855,11 @@ version = "0.52.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_msvc"
|
|
||||||
version = "0.53.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winnow"
|
name = "winnow"
|
||||||
version = "0.7.14"
|
version = "0.7.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
|
checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
cache:
|
cache:
|
||||||
image: redis:7.4-alpine
|
image: redis:8.4.2-alpine
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "${REDIS_PORT}:6379" # port_on_public:port_in_docker_container
|
- "${REDIS_PORT}:6379" # port_on_public:port_in_docker_container
|
||||||
|
|||||||
1
ResourceHub/src/endpoints/mod.rs
Normal file
1
ResourceHub/src/endpoints/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod sensors;
|
||||||
@@ -1,18 +1,12 @@
|
|||||||
// use database
|
use rocket::serde::{json::Json};
|
||||||
use rocket::serde::{Deserialize, Serialize, json::Json};
|
|
||||||
use rocket::response::status;
|
use rocket::response::status;
|
||||||
|
|
||||||
|
|
||||||
use rocket::{get, post};
|
use rocket::{get, post};
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
use crate::models::sensors::SensorData;
|
||||||
#[serde(crate = "rocket::serde")]
|
use crate::models::sensors::get_sensor_data;
|
||||||
pub struct SensorData {
|
|
||||||
id: Option<u32>,
|
// use repository::Redis::
|
||||||
name: String,
|
|
||||||
value: f32,
|
|
||||||
unit: String,
|
|
||||||
}
|
|
||||||
// get data json obj
|
// get data json obj
|
||||||
// database.getSensorData()
|
// database.getSensorData()
|
||||||
// send 200 http response with json obj
|
// send 200 http response with json obj
|
||||||
@@ -26,16 +20,10 @@ pub struct SensorData {
|
|||||||
pub async fn create(json: Json<SensorData>) -> status::Accepted<Json<SensorData>> {
|
pub async fn create(json: Json<SensorData>) -> status::Accepted<Json<SensorData>> {
|
||||||
let received_data = json.into_inner();
|
let received_data = json.into_inner();
|
||||||
|
|
||||||
let data = SensorData {
|
let data = get_sensor_data();
|
||||||
id: None,
|
|
||||||
name: String::from(received_data.name),
|
|
||||||
value: received_data.value,
|
|
||||||
unit: received_data.unit
|
|
||||||
};
|
|
||||||
status::Accepted(Json(data))
|
status::Accepted(Json(data))
|
||||||
|
|
||||||
// saved_data = database.create(data);
|
// saved_data = database.create(data);
|
||||||
|
|
||||||
// status::Accepted(Json(saved_data))
|
// status::Accepted(Json(saved_data))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
1
ResourceHub/src/endpoints/sensors/mod.rs
Normal file
1
ResourceHub/src/endpoints/sensors/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod data;
|
||||||
@@ -1,21 +1,30 @@
|
|||||||
|
mod util;
|
||||||
|
mod endpoints;
|
||||||
|
mod models;
|
||||||
|
|
||||||
use rocket::{routes};
|
use rocket::{routes};
|
||||||
use crate::util::constants;
|
use util::constants;
|
||||||
|
use util::debug;
|
||||||
|
|
||||||
|
|
||||||
mod util {
|
pub fn connect() -> redis::RedisResult<()> {
|
||||||
pub mod constants;
|
let client = redis::Client::open("redis://127.0.0.1:7878/")?;
|
||||||
pub mod colored_text;
|
let mut connector = client.get_connection()?;
|
||||||
}
|
// let mut connector = client.get_connection();
|
||||||
|
// connector.set("Name", "Redis");
|
||||||
|
// println!("DB name:: {}", connector.get("Name"));
|
||||||
|
|
||||||
mod endpoints {
|
match client.get_connection() {
|
||||||
pub mod sensors {
|
Ok(mut connector) => {
|
||||||
pub mod data;
|
util::colored_text::print_colored_text_info("[DB] Connected ");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
util::colored_text::print_colored_text_err("[DB] Error, check redis database is running? (./Database/run.sh) Fix REDIS_PORT if not correctly setted;\n[Wiki] Instructions: https://git.sociocyber.site:5000/SocioCybereeng/Hydroponic_systems/src/branch/master/ResourceHub/Readme.md ", e.to_string());
|
||||||
|
Err(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn print_debug_info() {
|
|
||||||
util::colored_text::print_colored_text_info(&format!("- SERVER INFO:"));
|
|
||||||
util::colored_text::print_colored_text_info(&format!(" - API VERSION: {} ", constants::API_VERSION));
|
|
||||||
util::colored_text::print_colored_text_info(&format!(" - DB NAME: {} ", constants::DB_NAME));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::main]
|
||||||
@@ -25,28 +34,21 @@ fn print_debug_info() {
|
|||||||
util::colored_text::print_colored_text_info("- [Welcome to ResourceHUB API] ");
|
util::colored_text::print_colored_text_info("- [Welcome to ResourceHUB API] ");
|
||||||
|
|
||||||
if util::constants::IS_DEBUG == true {
|
if util::constants::IS_DEBUG == true {
|
||||||
print_debug_info();
|
debug::print_debug_info();
|
||||||
}
|
}
|
||||||
|
|
||||||
// let mut status = ServerStatus::Online;
|
|
||||||
|
|
||||||
// // Use the colored printing function based on the server status
|
// let DBconnector = ;
|
||||||
// match status {
|
|
||||||
// ServerStatus::Online => {
|
// Attempt to connect to DB and check the result
|
||||||
// }
|
let conection = connect();
|
||||||
// ServerStatus::Offline => {
|
match conection {
|
||||||
// util::colored_text::print_colored_text_notify("[SERVER_STATUS] The server is stopped.");
|
// match DBconnector::connect() {
|
||||||
// }
|
|
||||||
// ServerStatus::Starting => {
|
Ok(conection) => {
|
||||||
// util::colored_text::print_colored_text_notify("[SERVER_STATUS] The server is starting.");
|
// If the connection is successful, store it or use it as needed
|
||||||
// }
|
let mut _db = conection;
|
||||||
// ServerStatus::Stopping => {
|
|
||||||
// util::colored_text::print_colored_text_notify("[SERVER_STATUS] The server is stopping.");
|
|
||||||
// }
|
|
||||||
// ServerStatus::Error(ref err) => {
|
|
||||||
// util::colored_text::print_colored_text_err(&format!("[SERVER_STATUS] An error occurred: {}", err));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
let _rocket = rocket::build()
|
let _rocket = rocket::build()
|
||||||
@@ -57,16 +59,13 @@ fn print_debug_info() {
|
|||||||
])
|
])
|
||||||
.launch()
|
.launch()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
// Handle connection error and stop execution
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
// #[macro_use] extern crate rocket;
|
|
||||||
// #[launch]
|
|
||||||
// fn rocket() -> _ {
|
|
||||||
|
|
||||||
// Create an instance of ServerStatus
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
6
ResourceHub/src/models/mod.rs
Normal file
6
ResourceHub/src/models/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
pub mod sensors;
|
||||||
|
// pub mod something_data;
|
||||||
|
// pub mod something_data;
|
||||||
|
// pub mod something_data;
|
||||||
|
// pub mod something_data;
|
||||||
|
// pub mod something_data;
|
||||||
22
ResourceHub/src/models/sensors.rs
Normal file
22
ResourceHub/src/models/sensors.rs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
use rocket::serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
#[serde(crate = "rocket::serde")]
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SensorData {
|
||||||
|
pub id: Option<u32>,
|
||||||
|
pub name: String,
|
||||||
|
pub value: f32,
|
||||||
|
pub unit: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
// #[derive(Debug)]
|
||||||
|
pub fn get_sensor_data() -> SensorData {
|
||||||
|
SensorData {
|
||||||
|
id: Some(1),
|
||||||
|
name: String::from("Sensor name"),
|
||||||
|
value: 4.5,
|
||||||
|
unit: String::from("C")
|
||||||
|
}
|
||||||
|
}
|
||||||
6
ResourceHub/src/repository/DBConnector.rs
Normal file
6
ResourceHub/src/repository/DBConnector.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// use redis::AsyncCommands;
|
||||||
|
// ! Load REDIS_PORT from env
|
||||||
|
|
||||||
|
// pub mod DBConnector {
|
||||||
|
|
||||||
|
// }
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
// DBconnector
|
|
||||||
mod DBconnector {
|
|
||||||
use redis::AsyncCommands;
|
|
||||||
|
|
||||||
async fn run() {
|
|
||||||
let mut r = match redis::Client::open("redis://127.0.0.1:7878") {
|
|
||||||
Ok(client) => {
|
|
||||||
match client.get_multiplexed_async_connection().await {
|
|
||||||
Ok(conn) => conn,
|
|
||||||
Err(e) => {
|
|
||||||
println!("Failed to connect to Redis: {e}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
println!("Failed to create Redis client: {e}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Ok(res) = r.set("foo", "bar").await {
|
|
||||||
let res: String = res;
|
|
||||||
println!("{res}"); // >>> OK
|
|
||||||
} else {
|
|
||||||
println!("Error setting foo");
|
|
||||||
}
|
|
||||||
|
|
||||||
match r.get("foo").await {
|
|
||||||
Ok(res) => {
|
|
||||||
let res: String = res;
|
|
||||||
println!("{res}"); // >>> bar
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
println!("Error getting foo: {e}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let hash_fields = [
|
|
||||||
("model", "Deimos"),
|
|
||||||
("brand", "Ergonom"),
|
|
||||||
("type", "Enduro bikes"),
|
|
||||||
("price", "4972"),
|
|
||||||
];
|
|
||||||
|
|
||||||
if let Ok(res) = r.hset_multiple("bike:1", &hash_fields).await {
|
|
||||||
let res: String = res;
|
|
||||||
println!("{res}"); // >>> OK
|
|
||||||
} else {
|
|
||||||
println!("Error setting bike:1");
|
|
||||||
}
|
|
||||||
|
|
||||||
match r.hget("bike:1", "model").await {
|
|
||||||
Ok(res) => {
|
|
||||||
let res: String = res;
|
|
||||||
println!("{res}"); // >>> Deimos
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
println!("Error getting bike:1 model: {e}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match r.hget("bike:1", "price").await {
|
|
||||||
Ok(res) => {
|
|
||||||
let res: String = res;
|
|
||||||
println!("{res}"); // >>> 4972
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
println!("Error getting bike:1 price: {e}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match r.hgetall("bike:1").await {
|
|
||||||
Ok(res) => {
|
|
||||||
let res: Vec<(String, String)> = res;
|
|
||||||
|
|
||||||
for (key, value) in res {
|
|
||||||
println!("{key}: {value}");
|
|
||||||
}
|
|
||||||
// >>> model: Deimos
|
|
||||||
// >>> brand: Ergonom
|
|
||||||
// >>> type: Enduro bikes
|
|
||||||
// >>> price: 4972
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
println!("Error getting bike:1: {e}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1
ResourceHub/src/repository/local/sqlite.rs
Normal file
1
ResourceHub/src/repository/local/sqlite.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
sqlite
|
||||||
2
ResourceHub/src/repository/remote/redis.rs
Normal file
2
ResourceHub/src/repository/remote/redis.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
redis
|
||||||
|
postgresql
|
||||||
@@ -13,12 +13,16 @@ pub fn print_colored_text_info(string: &str) {
|
|||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// pub fn print_colored_text_err(string: &str) {
|
pub fn print_colored_text_err(string: &str, error_message: String) {
|
||||||
// println!("{}", string
|
println!("{}", string
|
||||||
// .color(Color::RED)
|
.color(Color::RED)
|
||||||
// .bg(Color::BLACK)
|
.bg(Color::BLACK)
|
||||||
// );
|
);
|
||||||
// }
|
println!("{}", error_message
|
||||||
|
.color(Color::RED)
|
||||||
|
.bg(Color::BLACK)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn print_colored_text_brand(string: &str) {
|
pub fn print_colored_text_brand(string: &str) {
|
||||||
println!("{}", string
|
println!("{}", string
|
||||||
|
|||||||
8
ResourceHub/src/util/debug.rs
Normal file
8
ResourceHub/src/util/debug.rs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
use crate::constants;
|
||||||
|
use crate::util::colored_text::*;
|
||||||
|
|
||||||
|
pub fn print_debug_info() {
|
||||||
|
print_colored_text_info(&format!("- SERVER INFO:"));
|
||||||
|
print_colored_text_info(&format!(" - API VERSION: {} ", constants::API_VERSION));
|
||||||
|
print_colored_text_info(&format!(" - DB NAME: {} ", constants::DB_NAME));
|
||||||
|
}
|
||||||
3
ResourceHub/src/util/mod.rs
Normal file
3
ResourceHub/src/util/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub mod constants;
|
||||||
|
pub mod colored_text;
|
||||||
|
pub mod debug;
|
||||||
Reference in New Issue
Block a user