- React SPA: dashboard, data sources CRUD, widgets CRUD, layout builder, presets. TanStack Router + Query, shadcn/ui, Vite proxy to :3000 - wire media + rss adapters into polling loop, remove xtb source type - media adapter: read username/password from headers, proper subsonic auth - event handler: subscribe to LayoutChanged, push screen update to clients - fix clippy warnings across workspace (Default impls, collapsible ifs, redundant closures, is_none_or, unused imports)
65 lines
2.0 KiB
Rust
65 lines
2.0 KiB
Rust
use crate::SqliteConfigStore;
|
|
use crate::error::SqliteConfigError;
|
|
use crate::serialization::widget as ser;
|
|
use domain::{WidgetConfig, WidgetId};
|
|
|
|
impl SqliteConfigStore {
|
|
pub(crate) async fn get_widget_impl(
|
|
&self,
|
|
id: WidgetId,
|
|
) -> Result<Option<WidgetConfig>, SqliteConfigError> {
|
|
let row = sqlx::query("SELECT * FROM widgets WHERE id = ?")
|
|
.bind(id as i64)
|
|
.fetch_optional(&self.pool)
|
|
.await
|
|
.map_err(SqliteConfigError::Sql)?;
|
|
|
|
match row {
|
|
None => Ok(None),
|
|
Some(row) => Ok(Some(ser::widget_from_row(&row)?)),
|
|
}
|
|
}
|
|
|
|
pub(crate) async fn list_widgets_impl(&self) -> Result<Vec<WidgetConfig>, SqliteConfigError> {
|
|
let rows = sqlx::query("SELECT * FROM widgets")
|
|
.fetch_all(&self.pool)
|
|
.await
|
|
.map_err(SqliteConfigError::Sql)?;
|
|
|
|
rows.iter().map(ser::widget_from_row).collect()
|
|
}
|
|
|
|
pub(crate) async fn save_widget_impl(
|
|
&self,
|
|
config: &WidgetConfig,
|
|
) -> Result<(), SqliteConfigError> {
|
|
let mappings_json = ser::mappings_to_json(&config.mappings)?;
|
|
let hint_str = ser::display_hint_to_str(&config.display_hint);
|
|
|
|
sqlx::query(
|
|
"INSERT OR REPLACE INTO widgets (id, name, display_hint, data_source_id, mappings, max_data_size)
|
|
VALUES (?, ?, ?, ?, ?, ?)"
|
|
)
|
|
.bind(config.id as i64)
|
|
.bind(&config.name)
|
|
.bind(hint_str)
|
|
.bind(config.data_source_id as i64)
|
|
.bind(&mappings_json)
|
|
.bind(config.max_data_size as i64)
|
|
.execute(&self.pool)
|
|
.await
|
|
.map_err(SqliteConfigError::Sql)?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub(crate) async fn delete_widget_impl(&self, id: WidgetId) -> Result<(), SqliteConfigError> {
|
|
sqlx::query("DELETE FROM widgets WHERE id = ?")
|
|
.bind(id as i64)
|
|
.execute(&self.pool)
|
|
.await
|
|
.map_err(SqliteConfigError::Sql)?;
|
|
Ok(())
|
|
}
|
|
}
|