feat: fixup "setup seaorm and a first "debug" entity as example"

This commit is contained in:
2024-09-24 14:20:55 +02:00
parent fcba21ef68
commit 777b7f2425
8 changed files with 38 additions and 14 deletions

View File

@ -2,10 +2,13 @@ use anyhow::Error as AnyError;
use axum::http::{StatusCode, Uri};
use axum::response::{IntoResponse, Response};
use axum::{routing::get, Router};
use sea_orm::{DatabaseConnection, DbErr};
use thiserror::Error;
use ::utils::config::{load_config, ConfigError};
mod db;
#[derive(Error, Debug)]
pub enum InitError {
#[error(transparent)]
@ -17,10 +20,17 @@ pub fn init() -> Result<(), InitError> {
Ok(())
}
pub fn get_router() -> Router {
Router::new()
#[derive(Clone)]
pub struct AppState {
db_connection: DatabaseConnection,
}
pub async fn get_router() -> Result<Router, DbErr> {
let db_connection = db::get_connection().await?;
Ok(Router::new()
.route("/", get(|| async { "Hello, world!" }))
.fallback(fallback)
.fallback(fallback))
}
async fn fallback(uri: Uri) -> (StatusCode, String) {