aboutsummaryrefslogtreecommitdiff
path: root/src/routes/device.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2023-10-29 21:09:46 +0100
committerFxQnLr <[email protected]>2023-10-29 21:09:46 +0100
commitdd303dc41e4d500e48760f79351720cc2c1c9ffe (patch)
treeb730a1da1e0e58e12494bbab88076d403f4ccd97 /src/routes/device.rs
parent84c32953ae5f52be44af4b48381747f55cb04f4a (diff)
downloadwebol-dd303dc41e4d500e48760f79351720cc2c1c9ffe.tar
webol-dd303dc41e4d500e48760f79351720cc2c1c9ffe.tar.gz
webol-dd303dc41e4d500e48760f79351720cc2c1c9ffe.zip
add ip to database and use for ping, remove arc from pingmap
Diffstat (limited to 'src/routes/device.rs')
-rw-r--r--src/routes/device.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/routes/device.rs b/src/routes/device.rs
index 248d1e0..7353733 100644
--- a/src/routes/device.rs
+++ b/src/routes/device.rs
@@ -16,7 +16,7 @@ pub async fn get_device(State(state): State<Arc<crate::AppState>>, headers: Head
16 let device = sqlx::query_as!( 16 let device = sqlx::query_as!(
17 Device, 17 Device,
18 r#" 18 r#"
19 SELECT id, mac, broadcast_addr 19 SELECT id, mac, broadcast_addr, ip
20 FROM devices 20 FROM devices
21 WHERE id = $1; 21 WHERE id = $1;
22 "#, 22 "#,
@@ -40,12 +40,13 @@ pub async fn put_device(State(state): State<Arc<crate::AppState>>, headers: Head
40 if auth(secret).map_err(WebolError::Auth)? { 40 if auth(secret).map_err(WebolError::Auth)? {
41 sqlx::query!( 41 sqlx::query!(
42 r#" 42 r#"
43 INSERT INTO devices (id, mac, broadcast_addr) 43 INSERT INTO devices (id, mac, broadcast_addr, ip)
44 VALUES ($1, $2, $3); 44 VALUES ($1, $2, $3, $4);
45 "#, 45 "#,
46 payload.id, 46 payload.id,
47 payload.mac, 47 payload.mac,
48 payload.broadcast_addr 48 payload.broadcast_addr,
49 payload.ip
49 ).execute(&state.db).await.map_err(WebolError::DB)?; 50 ).execute(&state.db).await.map_err(WebolError::DB)?;
50 51
51 Ok(Json(json!(PutDeviceResponse { success: true }))) 52 Ok(Json(json!(PutDeviceResponse { success: true })))
@@ -59,6 +60,7 @@ pub struct PutDevicePayload {
59 id: String, 60 id: String,
60 mac: String, 61 mac: String,
61 broadcast_addr: String, 62 broadcast_addr: String,
63 ip: String
62} 64}
63 65
64#[derive(Serialize)] 66#[derive(Serialize)]
@@ -74,11 +76,12 @@ pub async fn post_device(State(state): State<Arc<crate::AppState>>, headers: Hea
74 Device, 76 Device,
75 r#" 77 r#"
76 UPDATE devices 78 UPDATE devices
77 SET mac = $1, broadcast_addr = $2 WHERE id = $3 79 SET mac = $1, broadcast_addr = $2, ip = $3 WHERE id = $4
78 RETURNING id, mac, broadcast_addr; 80 RETURNING id, mac, broadcast_addr, ip;
79 "#, 81 "#,
80 payload.mac, 82 payload.mac,
81 payload.broadcast_addr, 83 payload.broadcast_addr,
84 payload.ip,
82 payload.id 85 payload.id
83 ).fetch_one(&state.db).await.map_err(WebolError::DB)?; 86 ).fetch_one(&state.db).await.map_err(WebolError::DB)?;
84 87
@@ -93,4 +96,5 @@ pub struct PostDevicePayload {
93 id: String, 96 id: String,
94 mac: String, 97 mac: String,
95 broadcast_addr: String, 98 broadcast_addr: String,
99 ip: String,
96} 100}