Skip to content
Clone

feat(project): add project service entrypoint

zhenyi committed
parent 11ce3f2 commit 4390904 Browse files

1 file changed

+55 −0

Added lib/project/service.rs View lib/project/service.rs
@@ -0,0 +1,55 @@
1use std::sync::Arc;
2
3use cache::redis::RedisCache;
4use db::conn::Db;
5use jwt::JwtState;
6
7use crate::cache::ProjectCache;
8use crate::config::{ProjectConfig, SharedProjectConfig};
9
10#[derive(Clone)]
11pub struct ProjectService {
12 pub db: Db,
13 pub kv: Arc<RedisCache>,
14 pub cache: ProjectCache,
15 pub config: SharedProjectConfig,
16 pub jwt: JwtState,
17}
18
19impl ProjectService {
20 pub fn new(db: Db, kv: Arc<RedisCache>, jwt: JwtState) -> Self {
21 let cache = ProjectCache::new(kv.clone());
22 Self {
23 db,
24 kv,
25 cache,
26 config: Arc::new(ProjectConfig::default()),
27 jwt,
28 }
29 }
30
31 pub fn with_config(mut self, config: SharedProjectConfig) -> Self {
32 self.config = config;
33 self
34 }
35}
36
37impl jwt::HasJwtState for ProjectService {
38 fn jwt_state(&self) -> &JwtState {
39 &self.jwt
40 }
41
42 fn access_blacklist(&self) -> Option<Arc<rate_limit::AccessTokenBlacklist>> {
43 Some(Arc::new(rate_limit::AccessTokenBlacklist::new(self.kv.clone())))
44 }
45}
46
47impl rate_limit::RateLimitProvider for ProjectService {
48 fn rate_limit_kv(&self) -> Arc<RedisCache> {
49 self.kv.clone()
50 }
51
52 fn rate_limit_settings(&self) -> Arc<rate_limit::RateLimitConfig> {
53 Arc::new(rate_limit::RateLimitConfig::default())
54 }
55}