Move app state

This commit is contained in:
Andras Schmelczer 2025-01-04 16:14:54 +00:00
parent cd7fe5fe39
commit 0943681702
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
7 changed files with 15 additions and 20 deletions

View file

@ -0,0 +1,20 @@
use anyhow::Result;
use crate::{config::Config, consts::CONFIG_PATH, database::Database};
#[derive(Clone, Debug)]
pub struct AppState {
pub config: Config,
pub database: Database,
}
impl AppState {
pub async fn try_new() -> Result<Self> {
let path = std::path::Path::new(CONFIG_PATH);
let config = Config::read_or_create(path).await?;
let database = Database::try_new(&config.database).await?;
Ok(Self { config, database })
}
}

View file

@ -1,5 +1,5 @@
use super::app_state::AppState;
use crate::{
app_state::AppState,
config::user_config::User,
errors::{unauthorized_error, SyncServerError},
};

View file

@ -10,9 +10,8 @@ use axum_extra::{
use schemars::JsonSchema;
use serde::Deserialize;
use super::auth::auth;
use super::{app_state::AppState, auth::auth};
use crate::{
app_state::AppState,
database::models::{DocumentId, DocumentVersion, VaultId},
errors::{not_found_error, server_error, SyncServerError},
};

View file

@ -9,9 +9,8 @@ use axum_extra::{
use schemars::JsonSchema;
use serde::Deserialize;
use super::{auth::auth, responses::FetchLatestDocumentsResponse};
use super::{app_state::AppState, auth::auth, responses::FetchLatestDocumentsResponse};
use crate::{
app_state::AppState,
database::models::{VaultId, VaultUpdateId},
errors::{server_error, SyncServerError},
};

View file

@ -4,8 +4,8 @@ use axum_extra::{
TypedHeader,
};
use super::{auth::auth, responses::PingResponse};
use crate::{app_state::AppState, errors::SyncServerError};
use super::{app_state::AppState, auth::auth, responses::PingResponse};
use crate::errors::SyncServerError;
#[axum::debug_handler]
pub async fn ping(