feat: init
This commit is contained in:
+121
@@ -0,0 +1,121 @@
|
||||
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 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<ServiceContext>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct UserService {
|
||||
pub ctx: Arc<ServiceContext>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct WorkspaceService {
|
||||
pub ctx: Arc<ServiceContext>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RepoService {
|
||||
pub ctx: Arc<ServiceContext>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct IssueService {
|
||||
pub ctx: Arc<ServiceContext>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PrService {
|
||||
pub ctx: Arc<ServiceContext>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct NotificationService {
|
||||
pub ctx: Arc<ServiceContext>,
|
||||
}
|
||||
|
||||
pub use im::ImService;
|
||||
|
||||
#[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 ctx: Arc<ServiceContext>,
|
||||
}
|
||||
|
||||
impl AppService {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
version: String,
|
||||
db: AppDatabase,
|
||||
redis: AppRedis,
|
||||
cache: Arc<AppCache>,
|
||||
config: AppConfig,
|
||||
storage: AppS3Storage,
|
||||
registry: Arc<EtcdRegistry>,
|
||||
nats: Arc<NatsQueue>,
|
||||
) -> Self {
|
||||
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() },
|
||||
ctx,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug, utoipa::ToSchema)]
|
||||
pub struct Pager {
|
||||
pub page: i64,
|
||||
pub per_page: i64,
|
||||
}
|
||||
Reference in New Issue
Block a user