// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ // ┃ Copyright: (c) 2023, Mike 'PhiSyX' S. (https://github.com/PhiSyX) ┃ // ┃ SPDX-License-Identifier: MPL-2.0 ┃ // ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ // ┃ ┃ // ┃ This Source Code Form is subject to the terms of the Mozilla Public ┃ // ┃ License, v. 2.0. If a copy of the MPL was not distributed with this ┃ // ┃ file, You can obtain one at https://mozilla.org/MPL/2.0/. ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ use std::{ops, path}; use lexa_framework::ApplicationInterface; use super::{ApplicationEnv, ApplicationState}; use crate::crud_site::applications::web; // ---- // // Type // // ---- // pub type ApplicationCLI = (); // --------- // // Structure // // --------- // pub struct Application { application: lexa_framework::DefaultApplication< ApplicationEnv, ApplicationCLI, ApplicationState, >, } // ----------- // // Énumération // // ----------- // #[derive(Debug)] #[derive(thiserror::Error)] #[error( "\n\t[{}]: erreur applicative. Raison: {0}", std::any::type_name::() )] pub enum ApplicationError { LexaFramework(#[from] lexa_framework::ApplicationError), LexaFrameworkServer(#[from] lexa_framework::server::Error), } // -------------- // // Implémentation // // -------------- // impl Application { pub async fn new( application_name: impl ToString, application_version: impl ToString, application_root_dir: impl AsRef, ) -> Result { let framework_application = lexa_framework::DefaultApplication::create( application_name.to_string().leak(), application_version.to_string().leak(), application_root_dir.as_ref(), lexa_framework::ApplicationSettingsLoaderExtension::YAML, ) .await?; Ok(Self { application: framework_application, }) } pub async fn setup(mut self) -> Result { let database_url = self.env_vars().database_url.clone(); self.application.server = self .application .server .using_database_postgres_service(&database_url) .await? .make_application::(); Ok(self) } pub async fn run(self) -> Result<(), ApplicationError> { log::info!("Hello World"); Ok(self.application.run().await?) } } // -------------- // // Implémentation // -> Interface // -------------- // impl ops::Deref for Application { type Target = lexa_framework::DefaultApplication< ApplicationEnv, ApplicationCLI, ApplicationState, >; fn deref(&self) -> &Self::Target { &self.application } } impl ops::DerefMut for Application { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.application } }