changed backedn framwork from axum to actix and also added openapi and swagger ui

This commit is contained in:
2026-02-04 22:55:19 +01:00
parent 9b093e6739
commit e135a34d4c
11 changed files with 1716 additions and 91 deletions

View File

@@ -1,17 +1,16 @@
use std::{
sync::{Arc, Mutex},
};
use std::sync::{Arc, Mutex};
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 crate::{ringer::BeepRinger, scheduler::Scheduler};
mod handler;
mod router;
mod scheduler;
mod ringer;
mod types;
mod resources;
#[derive(Clone)]
@@ -36,16 +35,30 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
app_state.scheduler.start();
start_server(app_state).await;
let _ = start_actix_server(app_state).await;
Ok(())
}
async fn start_server(app_state: AppState) {
let router = router::router(app_state);
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();
async fn start_actix_server(app_state: AppState) -> std::io::Result<()> {
let _ = HttpServer::new(move || {
let spec = Spec {
info: Info {
title: "Snooze Pal".to_string(),
version: "0.0.1".to_string(),
..Default::default()
},
..Default::default()
};
println!("Listening on http://0.0.0.0:8080");
axum::serve(listener, router).await.unwrap();
App::new()
.document(spec)
.service(resources::v1())
.app_data(web::Data::new(app_state.clone()))
.build_with("/openapi.json", BuildConfig::default().with(SwaggerUIConfig::new(&"/swagger")))
}).bind("0.0.0.0:8080")?.run().await;
Ok(())
}