database persistence in progress

This commit is contained in:
2026-02-05 23:22:00 +01:00
parent a398911527
commit f7e55536ab
17 changed files with 3600 additions and 22 deletions

View File

@@ -4,6 +4,7 @@ use actix_web::{App, HttpServer, web};
use apistos::{SwaggerUIConfig, app::{BuildConfig, OpenApiWrapper}, info::Info, spec::Spec};
use cron_tab::Cron;
use gpio_cdev::Chip;
use sea_orm::Database;
use crate::{ringer::BeepRinger, scheduler::Scheduler};
@@ -11,6 +12,8 @@ mod scheduler;
mod ringer;
mod types;
mod resources;
mod dao;
mod model;
#[derive(Clone)]
@@ -18,20 +21,22 @@ struct AppState {
scheduler: Arc<Scheduler<BeepRinger>>
}
fn app_state() -> AppState {
async fn app_state() -> AppState {
let chip: Arc<Mutex<Chip>> = Arc::new(Mutex::new(Chip::new("/dev/gpiochip0").unwrap()));
let cron = Arc::new(Mutex::new(Cron::new(chrono::Local)));
let db = Database::connect("sqlite://snooze-pal.db").await.unwrap();
AppState {
scheduler: Arc::new(Scheduler::new(
Arc::new(Mutex::new(BeepRinger::new(chip.clone()))),
cron.clone()
cron.clone(),
Arc::new(db)
))
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app_state = app_state();
let app_state = app_state().await;
app_state.scheduler.start();