(refactor) AppState to state mod
This commit is contained in:
parent
8a03bdee96
commit
5b3c2d4ec7
6 changed files with 92 additions and 14 deletions
32
src/state.rs
Normal file
32
src/state.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// src/state.rs
|
||||
// Ответственность: создание и управление общим состоянием приложения (AppState)
|
||||
|
||||
use crate::db;
|
||||
use crate::api::banking::BankingClients;
|
||||
use sqlx::PgPool;
|
||||
|
||||
/// Общее состояние приложения, доступное во всех handlers
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub db_pool: PgPool,
|
||||
pub banking_clients: BankingClients,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
/// Асинхронный конструктор для AppState
|
||||
///
|
||||
/// Инициализирует все необходимые ресурсы (пул БД, HTTP клиенты)
|
||||
/// и собирает их в единый стейт.
|
||||
pub async fn new() -> Self {
|
||||
let db_pool = db::init_pool().await;
|
||||
println!("✅ Database connection pool created successfully.");
|
||||
|
||||
let banking_clients = BankingClients::new().await;
|
||||
println!("✅ Banking API clients initialized.");
|
||||
|
||||
Self {
|
||||
db_pool,
|
||||
banking_clients,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue