Add fmt options and move handlers

This commit is contained in:
Tobias Reisinger 2023-11-29 14:27:46 +01:00
parent 50bcac2a1b
commit fdca5b7277
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
28 changed files with 85 additions and 70 deletions
emgauwa-core/src/handlers/v1

View file

@ -0,0 +1,17 @@
use actix_web::{get, web, HttpResponse};
use emgauwa_lib::db::DbController;
use emgauwa_lib::models::{convert_db_list, Controller};
use sqlx::{Pool, Sqlite};
use crate::handlers::errors::ApiError;
#[get("/api/v1/controllers")]
pub async fn index(pool: web::Data<Pool<Sqlite>>) -> Result<HttpResponse, ApiError> {
let mut pool_conn = pool.acquire().await?;
let db_controllers = DbController::get_all(&mut pool_conn).await?;
let controllers: Vec<Controller> = convert_db_list(&mut pool_conn, db_controllers)?;
Ok(HttpResponse::Ok().json(controllers))
}