43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
use std::sync::Arc;
|
|
use sea_orm::DatabaseConnection;
|
|
use crate::event_bus::EventBus;
|
|
use crate::repositories::category::CategoryRepository;
|
|
use crate::repositories::channel::ChannelRepository;
|
|
use crate::repositories::message::MessageRepository;
|
|
use crate::repositories::server::ServerRepository;
|
|
use crate::repositories::user::UserRepository;
|
|
|
|
mod server;
|
|
mod category;
|
|
mod channel;
|
|
mod message;
|
|
mod user;
|
|
|
|
#[derive(Clone)]
|
|
pub struct RepositoryContext {
|
|
db: DatabaseConnection,
|
|
events: EventBus, // si tu veux publier des events “post-save” plus tard
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct Repositories {
|
|
pub server: ServerRepository,
|
|
pub category: CategoryRepository,
|
|
pub channel: ChannelRepository,
|
|
pub message: MessageRepository,
|
|
pub user: UserRepository,
|
|
}
|
|
|
|
impl Repositories {
|
|
pub fn new(db: &DatabaseConnection, events: EventBus) -> Self {
|
|
let context = Arc::new(RepositoryContext { db: db.clone(), events });
|
|
|
|
Self {
|
|
server: ServerRepository {context: context.clone()},
|
|
category: CategoryRepository {context: context.clone()},
|
|
channel: ChannelRepository {context: context.clone()},
|
|
message: MessageRepository {context: context.clone()},
|
|
user: UserRepository {context: context.clone()},
|
|
}
|
|
}
|
|
} |