summaryrefslogtreecommitdiff
path: root/src/routes
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/device.rs4
-rw-r--r--src/routes/start.rs9
2 files changed, 7 insertions, 6 deletions
diff --git a/src/routes/device.rs b/src/routes/device.rs
index 1eeff0b..678d117 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, ip 19 SELECT id, mac, broadcast_addr, ip, times
20 FROM devices 20 FROM devices
21 WHERE id = $1; 21 WHERE id = $1;
22 "#, 22 "#,
@@ -79,7 +79,7 @@ pub async fn post_device(State(state): State<Arc<crate::AppState>>, headers: Hea
79 r#" 79 r#"
80 UPDATE devices 80 UPDATE devices
81 SET mac = $1, broadcast_addr = $2, ip = $3 WHERE id = $4 81 SET mac = $1, broadcast_addr = $2, ip = $3 WHERE id = $4
82 RETURNING id, mac, broadcast_addr, ip; 82 RETURNING id, mac, broadcast_addr, ip, times;
83 "#, 83 "#,
84 payload.mac, 84 payload.mac,
85 payload.broadcast_addr, 85 payload.broadcast_addr,
diff --git a/src/routes/start.rs b/src/routes/start.rs
index 271f924..401ae97 100644
--- a/src/routes/start.rs
+++ b/src/routes/start.rs
@@ -22,7 +22,7 @@ pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap
22 let device = sqlx::query_as!( 22 let device = sqlx::query_as!(
23 Device, 23 Device,
24 r#" 24 r#"
25 SELECT id, mac, broadcast_addr, ip 25 SELECT id, mac, broadcast_addr, ip, times
26 FROM devices 26 FROM devices
27 WHERE id = $1; 27 WHERE id = $1;
28 "#, 28 "#,
@@ -40,19 +40,20 @@ pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap
40 &device.broadcast_addr.parse().map_err(WebolError::IpParse)?, 40 &device.broadcast_addr.parse().map_err(WebolError::IpParse)?,
41 create_buffer(&device.mac)? 41 create_buffer(&device.mac)?
42 )?; 42 )?;
43 43 let dev_id = device.id.clone();
44 let uuid = if payload.ping.is_some_and(|ping| ping) { 44 let uuid = if payload.ping.is_some_and(|ping| ping) {
45 let uuid_gen = Uuid::new_v4().to_string(); 45 let uuid_gen = Uuid::new_v4().to_string();
46 let uuid_genc = uuid_gen.clone(); 46 let uuid_genc = uuid_gen.clone();
47 // TODO: Check if service already runs
47 tokio::spawn(async move { 48 tokio::spawn(async move {
48 debug!("init ping service"); 49 debug!("init ping service");
49 state.ping_map.insert(uuid_gen.clone(), PingValue { ip: device.ip.clone(), online: false }); 50 state.ping_map.insert(uuid_gen.clone(), PingValue { ip: device.ip.clone(), online: false });
50 51
51 crate::services::ping::spawn(state.ping_send.clone(), device.ip, uuid_gen.clone(), &state.ping_map).await 52 crate::services::ping::spawn(state.ping_send.clone(), device, uuid_gen.clone(), &state.ping_map, &state.db).await
52 }); 53 });
53 Some(uuid_genc) 54 Some(uuid_genc)
54 } else { None }; 55 } else { None };
55 Ok(Json(json!(StartResponse { id: device.id, boot: true, uuid }))) 56 Ok(Json(json!(StartResponse { id: dev_id, boot: true, uuid })))
56 } else { 57 } else {
57 Err(WebolError::Generic) 58 Err(WebolError::Generic)
58 } 59 }