use std::sync::Arc; use cache::redis::RedisCache; use db::conn::Db; use jwt::JwtState; use crate::cache::RepoCache; use crate::config::{RepoConfig, SharedRepoConfig}; use rate_limit::RateLimitProvider; #[derive(Clone)] pub struct RepoService { pub db: Db, pub kv: Arc, pub cache: RepoCache, pub config: SharedRepoConfig, pub jwt: JwtState, pub git_root: Arc, } impl RepoService { pub fn new(db: Db, kv: Arc, jwt: JwtState) -> Self { let cache = RepoCache::new(kv.clone()); Self { db, kv, cache, config: Arc::new(RepoConfig::default()), jwt, git_root: Arc::from("git::default"), } } pub fn with_config(mut self, config: SharedRepoConfig) -> Self { self.config = config; self } pub fn with_git_root(mut self, root: impl Into>) -> Self { self.git_root = root.into(); self } } impl jwt::HasJwtState for RepoService { fn jwt_state(&self) -> &JwtState { &self.jwt } } impl RateLimitProvider for RepoService { fn rate_limit_kv(&self) -> Arc { self.kv.clone() } fn rate_limit_settings(&self) -> Arc { Arc::new(rate_limit::RateLimitConfig::default()) } }