summaryrefslogtreecommitdiff
path: root/src/domain/repositories.rs
blob: 36223738a56f571df7a301ffe8306831e54e0c3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::domain::models::*;
use anyhow::Result;

/// Domain-focused repository for OAuth clients
pub trait DomainClientRepository: Send + Sync {
    fn get_client(&self, client_id: &str) -> Result<Option<OAuthClient>>;
    fn create_client(&self, client: &OAuthClient, client_secret_hash: &str) -> Result<()>;
    fn update_client(&self, client: &OAuthClient) -> Result<()>;
    fn delete_client(&self, client_id: &str) -> Result<()>;
    fn list_clients(&self) -> Result<Vec<OAuthClient>>;
}

/// Domain-focused repository for authorization codes
pub trait DomainAuthCodeRepository: Send + Sync {
    fn create_auth_code(&self, code: &AuthorizationCode) -> Result<()>;
    fn get_auth_code(&self, code: &str) -> Result<Option<AuthorizationCode>>;
    fn mark_auth_code_used(&self, code: &str) -> Result<()>;
    fn cleanup_expired_codes(&self) -> Result<()>;
}

/// Domain-focused repository for access tokens
pub trait DomainTokenRepository: Send + Sync {
    fn create_access_token(&self, token: &AccessToken, token_hash: &str) -> Result<()>;
    fn get_access_token(&self, token_hash: &str) -> Result<Option<AccessToken>>;
    fn revoke_access_token(&self, token_hash: &str) -> Result<()>;
    fn cleanup_expired_tokens(&self) -> Result<()>;
}

/// Domain-focused repository for audit events
pub trait DomainAuditRepository: Send + Sync {
    fn create_audit_event(&self, event: &AuditEvent) -> Result<()>;
    fn get_audit_events(&self, limit: Option<u32>) -> Result<Vec<AuditEvent>>;
    fn cleanup_old_audit_events(&self, days: u32) -> Result<()>;
}

/// Domain-focused repository for rate limiting
pub trait DomainRateRepository: Send + Sync {
    fn check_rate_limit(&self, limit: &RateLimit) -> Result<u32>; // Returns current count
    fn increment_rate_limit(
        &self,
        identifier: &str,
        endpoint: &str,
        window_minutes: u32,
    ) -> Result<u32>;
    fn cleanup_old_rate_limits(&self) -> Result<()>;
}