a06673b
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<RedisCache>,
pub cache: RepoCache,
pub config: SharedRepoConfig,
pub jwt: JwtState,
pub git_root: Arc<str>,
}
impl RepoService {
pub fn new(db: Db, kv: Arc<RedisCache>, 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<Arc<str>>) -> 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<RedisCache> {
self.kv.clone()
}
fn rate_limit_settings(&self) -> Arc<rate_limit::RateLimitConfig> {
Arc::new(rate_limit::RateLimitConfig::default())
}
}