some_auth/repository/
mod.rs

1#[cfg(feature = "pg-repository")]
2pub mod pg_repository;
3
4use std::fmt;
5
6use async_trait::async_trait;
7use chrono::{DateTime, Utc};
8use mockall::automock;
9
10use crate::user_service::{AuthUser, Role};
11
12/// Auth repository which is used in [`UserService`]
13#[automock]
14#[async_trait]
15pub trait AuthRepository<TAuthUser: AuthUser + fmt::Debug + Send + Sync> {
16    /// returns created id
17    async fn add_user(&self, user: &TAuthUser) -> Result<i32, String>;
18    async fn update_user(&self, user: &TAuthUser) -> Result<(), String>;
19    async fn get_users(&self) -> Result<Vec<TAuthUser>, String>;
20    async fn get_user(&self, id: i32) -> Result<Option<TAuthUser>, String>;
21    async fn get_user_by_username(&self, username: &str) -> Result<Option<TAuthUser>, String>;
22    async fn update_user_refresh_token(&self, user_id: i32, token_hash: &str, time_updated: DateTime<Utc>) -> Result<(), String>;
23    /// returns token's hash
24    async fn get_user_refresh_token(&self, user_id: i32) -> Result<Option<String>, String>;
25    /// returns created id
26    async fn add_role(&self, role: &Role) -> Result<i32, String>;
27    async fn update_role(&self, role: &Role) -> Result<(), String>;
28    /// Updates user's roles with new set of roles and clears all existing user's roles if they are not present in `roles` param.
29    async fn update_user_roles(&self, user_id: i32, roles: &Vec<i32>) -> Result<(), String>;
30    async fn get_roles(&self) -> Result<Vec<Role>, String>;
31    async fn get_role(&self, role_id: i32) -> Result<Option<Role>, String>;
32    async fn get_role_by_name(&self, role_name: &str) -> Result<Option<Role>, String>;
33    async fn get_user_roles(&self, user_id: i32) -> Result<Vec<Role>, String>;
34}