Browse Source

get active with config

active-analytic-unit-#66
Alexey Velikiy 2 years ago
parent
commit
86a1f7e3a6
  1. 28
      server/src/services/analytic_unit_service.rs

28
server/src/services/analytic_unit_service.rs

@ -55,8 +55,6 @@ impl AnalyticUnitService {
let res = stmt.exists(params![id])?;
if res == false {
// TODO: save default
// TODO: save serialised config
let cfg_json = serde_json::to_string(&cfg)?;
conn.execute(
"INSERT INTO analytic_unit (id, type, config) VALUES (?1, ?1, ?2)",
@ -64,6 +62,15 @@ impl AnalyticUnitService {
)?;
}
conn.execute(
"UPDATE analytic_unit set active = FALSE where active = TRUE",
params![]
)?;
conn.execute(
"UPDATE analytic_unit set active = TRUE where id = ?1",
params![id]
)?;
return Ok(au);
}
@ -79,20 +86,17 @@ impl AnalyticUnitService {
pub fn get_active(&self) -> anyhow::Result<Box<dyn types::AnalyticUnit + Send + Sync>> {
let conn = self.connection.lock().unwrap();
let stmt = conn.prepare(
let mut stmt = conn.prepare(
"SELECT id, type, config from analytic_unit WHERE active = TRUE"
)?;
// stmt.query_row([], |row| {
let au = stmt.query_row([], |row| {
let c: String = row.get(2)?;
let cfg = serde_json::from_str(&c).unwrap();
Ok(self.resolve(cfg))
})?;
// // resolve_au()
// });
// TODO: use serde to deserialise config
return Ok(au);
return Err(anyhow::format_err!("bot implemented"));
// TODO: query by id
// TODO: deserialisation of analytic_unit by config and it's type
}
}
Loading…
Cancel
Save