// // Copyright 2021, Jesús Pérez Lorenzo // use std::collections::HashMap; use serde::Deserialize; use crate::{ config::Config, module::Module, appinfo::AppInfo, }; #[derive(Clone, Debug, Default, Deserialize)] pub struct DataCollUsers { pub fields: String, } #[derive(Clone, Debug)] pub struct AppEnv { pub info: AppInfo, pub config: Config, pub debug_level: String, pub appkey: String, pub checked: bool, pub collections: HashMap, pub modules: HashMap, // pub modules: HashMap, } impl Default for AppEnv { fn default() -> Self { Self { info: AppInfo::default(), config: Config::default(), debug_level: String::from(""), appkey: String::from(""), checked: true, collections: HashMap::new(), modules: HashMap::new(), } } } impl AppEnv { #[allow(clippy::too_many_arguments)] pub async fn new( config: Config, debug_level: &str, info: AppInfo, appkey: &str, checked: bool, collections: HashMap, modules: HashMap, // jwt_sign: Option, ) -> Self { let akey = appkey.to_string(); Self { info, config, debug_level: debug_level.to_string(), appkey: akey, checked, collections, modules, // jwt_sign, } } pub async fn set_appkey(&mut self, app_key: &str, key: &str) { if key.is_empty() { self.appkey = app_key.to_string(); } } #[must_use] pub fn has_appkey(&self) -> bool { self.appkey.as_str() == "" } pub fn get_module(&self, key_module: &str) -> Module { if let Some(module) = self.modules.get(key_module) { module.to_owned() } else { Module::default() } } }