add config-sqlite and http-api adapters

SQLite config store: full ConfigRepository impl with JSON serialization
for mappings, layouts, data source configs. 12 integration tests.

HTTP API: Axum REST endpoints for widgets, data sources, layout, presets.
6 integration tests using tower::oneshot.

Port traits updated to return Send futures for Axum compatibility.
This commit is contained in:
2026-06-18 22:47:38 +02:00
parent 3ee6a5d215
commit e398c240a0
16 changed files with 3284 additions and 50 deletions

View File

@@ -1,4 +1,4 @@
use std::cell::RefCell;
use std::sync::Mutex;
use std::collections::HashMap;
use domain::{
ConfigRepository, EventPublisher,
@@ -7,19 +7,19 @@ use domain::{
};
pub struct InMemoryConfigRepository {
pub widgets: RefCell<HashMap<WidgetId, WidgetConfig>>,
pub data_sources: RefCell<HashMap<DataSourceId, DataSource>>,
pub layout: RefCell<Option<Layout>>,
pub presets: RefCell<HashMap<LayoutPresetId, LayoutPreset>>,
widgets: Mutex<HashMap<WidgetId, WidgetConfig>>,
data_sources: Mutex<HashMap<DataSourceId, DataSource>>,
layout: Mutex<Option<Layout>>,
presets: Mutex<HashMap<LayoutPresetId, LayoutPreset>>,
}
impl InMemoryConfigRepository {
pub fn new() -> Self {
Self {
widgets: RefCell::new(HashMap::new()),
data_sources: RefCell::new(HashMap::new()),
layout: RefCell::new(None),
presets: RefCell::new(HashMap::new()),
widgets: Mutex::new(HashMap::new()),
data_sources: Mutex::new(HashMap::new()),
layout: Mutex::new(None),
presets: Mutex::new(HashMap::new()),
}
}
}
@@ -37,82 +37,82 @@ impl ConfigRepository for InMemoryConfigRepository {
type Error = Never;
async fn get_widget(&self, id: WidgetId) -> Result<Option<WidgetConfig>, Self::Error> {
Ok(self.widgets.borrow().get(&id).cloned())
Ok(self.widgets.lock().unwrap().get(&id).cloned())
}
async fn list_widgets(&self) -> Result<Vec<WidgetConfig>, Self::Error> {
Ok(self.widgets.borrow().values().cloned().collect())
Ok(self.widgets.lock().unwrap().values().cloned().collect())
}
async fn save_widget(&self, config: &WidgetConfig) -> Result<(), Self::Error> {
self.widgets.borrow_mut().insert(config.id, config.clone());
self.widgets.lock().unwrap().insert(config.id, config.clone());
Ok(())
}
async fn delete_widget(&self, id: WidgetId) -> Result<(), Self::Error> {
self.widgets.borrow_mut().remove(&id);
self.widgets.lock().unwrap().remove(&id);
Ok(())
}
async fn get_data_source(&self, id: DataSourceId) -> Result<Option<DataSource>, Self::Error> {
Ok(self.data_sources.borrow().get(&id).cloned())
Ok(self.data_sources.lock().unwrap().get(&id).cloned())
}
async fn list_data_sources(&self) -> Result<Vec<DataSource>, Self::Error> {
Ok(self.data_sources.borrow().values().cloned().collect())
Ok(self.data_sources.lock().unwrap().values().cloned().collect())
}
async fn save_data_source(&self, source: &DataSource) -> Result<(), Self::Error> {
self.data_sources.borrow_mut().insert(source.id, source.clone());
self.data_sources.lock().unwrap().insert(source.id, source.clone());
Ok(())
}
async fn delete_data_source(&self, id: DataSourceId) -> Result<(), Self::Error> {
self.data_sources.borrow_mut().remove(&id);
self.data_sources.lock().unwrap().remove(&id);
Ok(())
}
async fn get_layout(&self) -> Result<Option<Layout>, Self::Error> {
Ok(self.layout.borrow().clone())
Ok(self.layout.lock().unwrap().clone())
}
async fn save_layout(&self, layout: &Layout) -> Result<(), Self::Error> {
*self.layout.borrow_mut() = Some(layout.clone());
*self.layout.lock().unwrap() = Some(layout.clone());
Ok(())
}
async fn get_preset(&self, id: LayoutPresetId) -> Result<Option<LayoutPreset>, Self::Error> {
Ok(self.presets.borrow().get(&id).cloned())
Ok(self.presets.lock().unwrap().get(&id).cloned())
}
async fn list_presets(&self) -> Result<Vec<LayoutPreset>, Self::Error> {
Ok(self.presets.borrow().values().cloned().collect())
Ok(self.presets.lock().unwrap().values().cloned().collect())
}
async fn save_preset(&self, preset: &LayoutPreset) -> Result<(), Self::Error> {
self.presets.borrow_mut().insert(preset.id, preset.clone());
self.presets.lock().unwrap().insert(preset.id, preset.clone());
Ok(())
}
async fn delete_preset(&self, id: LayoutPresetId) -> Result<(), Self::Error> {
self.presets.borrow_mut().remove(&id);
self.presets.lock().unwrap().remove(&id);
Ok(())
}
}
pub struct InMemoryEventPublisher {
pub events: RefCell<Vec<DomainEvent>>,
events: Mutex<Vec<DomainEvent>>,
}
impl InMemoryEventPublisher {
pub fn new() -> Self {
Self {
events: RefCell::new(Vec::new()),
events: Mutex::new(Vec::new()),
}
}
pub fn emitted(&self) -> Vec<DomainEvent> {
self.events.borrow().clone()
self.events.lock().unwrap().clone()
}
}
@@ -120,7 +120,7 @@ impl EventPublisher for InMemoryEventPublisher {
type Error = Never;
async fn publish(&self, event: DomainEvent) -> Result<(), Self::Error> {
self.events.borrow_mut().push(event);
self.events.lock().unwrap().push(event);
Ok(())
}
}