diff options
author | FxQnLr <[email protected]> | 2023-11-02 19:44:29 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2023-11-02 19:44:29 +0100 |
commit | 5b7302cf9be4e0badd691203e160ca110613e34c (patch) | |
tree | 38c4b47ae97742560963e6b2b4cba3eb84bbaf8a /src/routes/device.rs | |
parent | f8f0565c42db7c612ac12b9a58155051e795639a (diff) | |
download | webol-5b7302cf9be4e0badd691203e160ca110613e34c.tar webol-5b7302cf9be4e0badd691203e160ca110613e34c.tar.gz webol-5b7302cf9be4e0badd691203e160ca110613e34c.zip |
ping timeout and cleanup
Diffstat (limited to 'src/routes/device.rs')
-rw-r--r-- | src/routes/device.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/routes/device.rs b/src/routes/device.rs index 7353733..1eeff0b 100644 --- a/src/routes/device.rs +++ b/src/routes/device.rs | |||
@@ -4,13 +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 tracing::{debug, info}; |
8 | use crate::auth::auth; | 8 | use crate::auth::auth; |
9 | use crate::db::Device; | 9 | use crate::db::Device; |
10 | use crate::error::WebolError; | 10 | use crate::error::WebolError; |
11 | 11 | ||
12 | 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"); | 13 | info!("add device {}", payload.id); |
14 | let secret = headers.get("authorization"); | 14 | let secret = headers.get("authorization"); |
15 | if auth(secret).map_err(WebolError::Auth)? { | 15 | if auth(secret).map_err(WebolError::Auth)? { |
16 | let device = sqlx::query_as!( | 16 | let device = sqlx::query_as!( |
@@ -23,6 +23,8 @@ pub async fn get_device(State(state): State<Arc<crate::AppState>>, headers: Head | |||
23 | payload.id | 23 | payload.id |
24 | ).fetch_one(&state.db).await.map_err(WebolError::DB)?; | 24 | ).fetch_one(&state.db).await.map_err(WebolError::DB)?; |
25 | 25 | ||
26 | debug!("got device {:?}", device); | ||
27 | |||
26 | Ok(Json(json!(device))) | 28 | Ok(Json(json!(device))) |
27 | } else { | 29 | } else { |
28 | Err(WebolError::Generic) | 30 | Err(WebolError::Generic) |
@@ -35,7 +37,7 @@ pub struct GetDevicePayload { | |||
35 | } | 37 | } |
36 | 38 | ||
37 | pub async fn put_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PutDevicePayload>) -> Result<Json<Value>, WebolError> { | 39 | 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"); | 40 | info!("add device {} ({}, {}, {})", payload.id, payload.mac, payload.broadcast_addr, payload.ip); |
39 | let secret = headers.get("authorization"); | 41 | let secret = headers.get("authorization"); |
40 | if auth(secret).map_err(WebolError::Auth)? { | 42 | if auth(secret).map_err(WebolError::Auth)? { |
41 | sqlx::query!( | 43 | sqlx::query!( |
@@ -69,7 +71,7 @@ pub struct PutDeviceResponse { | |||
69 | } | 71 | } |
70 | 72 | ||
71 | pub async fn post_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PostDevicePayload>) -> Result<Json<Value>, WebolError> { | 73 | pub async fn post_device(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<PostDevicePayload>) -> Result<Json<Value>, WebolError> { |
72 | info!("POST request"); | 74 | info!("edit device {} ({}, {}, {})", payload.id, payload.mac, payload.broadcast_addr, payload.ip); |
73 | let secret = headers.get("authorization"); | 75 | let secret = headers.get("authorization"); |
74 | if auth(secret).map_err(WebolError::Auth)? { | 76 | if auth(secret).map_err(WebolError::Auth)? { |
75 | let device = sqlx::query_as!( | 77 | let device = sqlx::query_as!( |