diff options
author | FxQnLr <[email protected]> | 2023-10-15 17:51:08 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2023-10-15 17:51:08 +0200 |
commit | e0be33fc23d210dbd630a1bed2fe0ecb2ea6ce0b (patch) | |
tree | 4d7a2e553c0ea67f7aa3c63d788d76d714479fd1 /src/routes | |
parent | b0e8aabfb9ea0f4c40a2aa330dd59f07b6c91216 (diff) | |
parent | abd4fbbf0ebd0385f68507eb20f9385db1b96793 (diff) | |
download | webol-e0be33fc23d210dbd630a1bed2fe0ecb2ea6ce0b.tar webol-e0be33fc23d210dbd630a1bed2fe0ecb2ea6ce0b.tar.gz webol-e0be33fc23d210dbd630a1bed2fe0ecb2ea6ce0b.zip |
Merge pull request #2 from FxQnLr/test
Get working actions and build into main
Diffstat (limited to 'src/routes')
-rw-r--r-- | src/routes/device.rs | 4 | ||||
-rw-r--r-- | src/routes/start.rs | 3 |
2 files changed, 6 insertions, 1 deletions
diff --git a/src/routes/device.rs b/src/routes/device.rs index d5d7144..025c7d0 100644 --- a/src/routes/device.rs +++ b/src/routes/device.rs | |||
@@ -4,11 +4,13 @@ use axum::headers::HeaderMap; | |||
4 | use axum::Json; | 4 | use axum::Json; |
5 | use serde::{Deserialize, Serialize}; | 5 | use serde::{Deserialize, Serialize}; |
6 | use serde_json::{json, Value}; | 6 | use serde_json::{json, Value}; |
7 | use tracing::info; | ||
7 | use crate::auth::auth; | 8 | use crate::auth::auth; |
8 | use crate::db::Device; | 9 | use crate::db::Device; |
9 | use crate::error::WebolError; | 10 | use crate::error::WebolError; |
10 | 11 | ||
11 | pub async fn get_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<GetDevicePayload>) -> Result<Json<Value>, WebolError> { | 12 | pub async fn get_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<GetDevicePayload>) -> Result<Json<Value>, WebolError> { |
13 | info!("GET request"); | ||
12 | let secret = headers.get("authorization"); | 14 | let secret = headers.get("authorization"); |
13 | if auth(secret).map_err(WebolError::Auth)? { | 15 | if auth(secret).map_err(WebolError::Auth)? { |
14 | let device = sqlx::query_as!( | 16 | let device = sqlx::query_as!( |
@@ -33,6 +35,7 @@ pub struct GetDevicePayload { | |||
33 | } | 35 | } |
34 | 36 | ||
35 | pub async fn put_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PutDevicePayload>) -> Result<Json<Value>, WebolError> { | 37 | pub async fn put_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PutDevicePayload>) -> Result<Json<Value>, WebolError> { |
38 | info!("PUT request"); | ||
36 | let secret = headers.get("authorization"); | 39 | let secret = headers.get("authorization"); |
37 | if auth(secret).map_err(WebolError::Auth)? { | 40 | if auth(secret).map_err(WebolError::Auth)? { |
38 | sqlx::query!( | 41 | sqlx::query!( |
@@ -64,6 +67,7 @@ pub struct PutDeviceResponse { | |||
64 | } | 67 | } |
65 | 68 | ||
66 | pub async fn post_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PostDevicePayload>) -> Result<Json<Value>, WebolError> { | 69 | pub async fn post_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PostDevicePayload>) -> Result<Json<Value>, WebolError> { |
70 | info!("POST request"); | ||
67 | let secret = headers.get("authorization"); | 71 | let secret = headers.get("authorization"); |
68 | if auth(secret).map_err(WebolError::Auth)? { | 72 | if auth(secret).map_err(WebolError::Auth)? { |
69 | let device = sqlx::query_as!( | 73 | let device = sqlx::query_as!( |
diff --git a/src/routes/start.rs b/src/routes/start.rs index d16ea4e..163d58c 100644 --- a/src/routes/start.rs +++ b/src/routes/start.rs | |||
@@ -12,6 +12,7 @@ use crate::db::Device; | |||
12 | use crate::error::WebolError; | 12 | use crate::error::WebolError; |
13 | 13 | ||
14 | pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<StartPayload>) -> Result<Json<Value>, WebolError> { | 14 | pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<StartPayload>) -> Result<Json<Value>, WebolError> { |
15 | info!("POST request"); | ||
15 | let secret = headers.get("authorization"); | 16 | let secret = headers.get("authorization"); |
16 | if auth(secret).map_err(WebolError::Auth)? { | 17 | if auth(secret).map_err(WebolError::Auth)? { |
17 | let device = sqlx::query_as!( | 18 | let device = sqlx::query_as!( |
@@ -28,7 +29,7 @@ pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap | |||
28 | 29 | ||
29 | let bind_addr = SETTINGS | 30 | let bind_addr = SETTINGS |
30 | .get_string("bindaddr") | 31 | .get_string("bindaddr") |
31 | .map_err(|err| WebolError::Server(Box::new(err)))?; | 32 | .unwrap_or("0.0.0.0:1111".to_string()); |
32 | 33 | ||
33 | let _ = send_packet( | 34 | let _ = send_packet( |
34 | &bind_addr.parse().map_err(|err| WebolError::Server(Box::new(err)))?, | 35 | &bind_addr.parse().map_err(|err| WebolError::Server(Box::new(err)))?, |