feat: define types aliases for GenerateRandomStringInterface

This commit is contained in:
Aravinth Manivannan 2024-05-17 23:27:44 +05:30
parent eba678b6de
commit b83112d359
Signed by: realaravinth
GPG key ID: F8F50389936984FF
2 changed files with 15 additions and 8 deletions

View file

@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use std::env;
use actix_identity::IdentityMiddleware;
@ -11,14 +10,15 @@ use actix_web::{cookie::Key, middleware, App, HttpServer};
use db::migrate::RunMigrations;
mod billing;
mod db;
mod identity;
mod inventory;
mod ordering;
mod settings;
mod db;
#[cfg(test)]
mod tests;
mod utils;
#[actix_web::main]
async fn main() {
let settings = settings::Settings::new().unwrap();
@ -39,7 +39,11 @@ async fn main() {
let secret_key = Key::from(settings.server.cookie_secret.as_bytes());
let socket_addr = settings.server.get_ip();
log::info!("Starting server at: {} {}", socket_addr, settings.server.domain);
log::info!(
"Starting server at: {} {}",
socket_addr,
settings.server.domain
);
HttpServer::new(move || {
App::new()
.wrap(IdentityMiddleware::default())
@ -53,7 +57,7 @@ async fn main() {
.wrap(
middleware::DefaultHeaders::new().add(("Permissions-Policy", "interest-cohort=()")),
)
// .configure(auth::adapter::load_adapters(db.pool.clone(), &settings))
// .configure(auth::adapter::load_adapters(db.pool.clone(), &settings))
.configure(utils::random_string::GenerateRandomString::inject())
})
.bind(&socket_addr)
@ -62,4 +66,3 @@ async fn main() {
.await
.unwrap();
}

View file

@ -7,8 +7,12 @@ use std::sync::Arc;
use actix_web::web;
use mockall::predicate::*;
use mockall::*;
#[cfg(test)]
#[allow(unused_imports)]
use tests::*;
pub type WebGenerateRandomStringInterface = web::Data<Arc<dyn GenerateRandomStringInterface>>;
pub type GenerateRandomStringInterfaceObj = Arc<dyn GenerateRandomStringInterface>;
pub type WebGenerateRandomStringInterfaceObj = web::Data<GenerateRandomStringInterfaceObj>;
#[automock]
pub trait GenerateRandomStringInterface: Send + Sync {
@ -34,7 +38,7 @@ impl GenerateRandomStringInterface for GenerateRandomString {
impl GenerateRandomString {
pub fn inject() -> impl FnOnce(&mut web::ServiceConfig) {
let g = WebGenerateRandomStringInterface::new(Arc::new(GenerateRandomString));
let g = WebGenerateRandomStringInterfaceObj::new(Arc::new(GenerateRandomString));
let f = move |cfg: &mut web::ServiceConfig| {
cfg.app_data(g);
};