use std::sync::Arc; use serde::{Deserialize, Serialize}; use crate::cache::AppCache; use crate::cache::redis::AppRedis; use crate::config::AppConfig; use crate::etcd::EtcdRegistry; use crate::models::db::AppDatabase; use crate::queue::NatsQueue; use crate::service::im::events::ImEventBus; use crate::storage::s3::AppS3Storage; pub mod context; pub mod util; pub mod auth; pub mod im; pub mod internal_auth; pub mod issues; pub mod notify; pub mod pr; pub mod repo; pub mod user; pub mod wiki; pub mod workspace; pub use context::ServiceContext; #[derive(Clone)] pub struct AuthService { pub ctx: Arc, } #[derive(Clone)] pub struct UserService { pub ctx: Arc, } #[derive(Clone)] pub struct WorkspaceService { pub ctx: Arc, } #[derive(Clone)] pub struct RepoService { pub ctx: Arc, } #[derive(Clone)] pub struct IssueService { pub ctx: Arc, } #[derive(Clone)] pub struct PrService { pub ctx: Arc, } #[derive(Clone)] pub struct NotificationService { pub ctx: Arc, } pub use im::ImService; pub use internal_auth::TokenService; #[derive(Clone)] pub struct AppService { pub auth: AuthService, pub user: UserService, pub workspace: WorkspaceService, pub repo: RepoService, pub issue: IssueService, pub pr: PrService, pub notify: NotificationService, pub im: ImService, pub internal_auth: TokenService, pub ctx: Arc, } impl AppService { #[allow(clippy::too_many_arguments)] pub async fn new( version: String, db: AppDatabase, redis: AppRedis, cache: Arc, config: AppConfig, storage: AppS3Storage, registry: Arc, nats: Arc, ) -> Self { let token_service = TokenService::new(redis.clone()) .await .expect("failed to initialize TokenService"); let ctx = Arc::new(ServiceContext { version, db, redis, cache, config, storage, registry, nats, im_events: Arc::new(ImEventBus::default()), }); Self { auth: AuthService { ctx: ctx.clone() }, user: UserService { ctx: ctx.clone() }, workspace: WorkspaceService { ctx: ctx.clone() }, repo: RepoService { ctx: ctx.clone() }, issue: IssueService { ctx: ctx.clone() }, pr: PrService { ctx: ctx.clone() }, notify: NotificationService { ctx: ctx.clone() }, im: ImService { ctx: ctx.clone() }, internal_auth: token_service, ctx, } } } #[derive(Deserialize, Serialize, Clone, Debug, utoipa::ToSchema)] pub struct Pager { pub page: i64, pub per_page: i64, }