From 3d2f6e53db472ec327f09ebbc48faf50d48f3613 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 6 Mar 2024 19:20:48 +0100 Subject: [PATCH] feat: [#448] new authorization service --- src/services/authorization.rs | 51 +++++++++++++++++++++++++++++++++++ src/services/mod.rs | 1 + 2 files changed, 52 insertions(+) create mode 100644 src/services/authorization.rs diff --git a/src/services/authorization.rs b/src/services/authorization.rs new file mode 100644 index 00000000..7d8e9265 --- /dev/null +++ b/src/services/authorization.rs @@ -0,0 +1,51 @@ +/* + + + let user_compact = self.user_repository.get_compact(&user_profile.user_id).await?; + + +*/ +use std::sync::Arc; + +use crate::databases::database::{Database, Error}; +use crate::models::user::{UserAuthorization, UserId}; +use crate::services::user::DbUserRepository; +pub struct Service { + user_repository: Arc, +} + +impl Service { + pub fn new(user_repository: Arc) -> Self { + Self { user_repository } + } + + // Check user exists in database + /* pub async fn user_exists_in_database(&self, user_id: &UserId) -> { + let user_authorization = self. + } */ + + // Check if the user has a role with enough privilages + + //Delete token from localStorage if user does not exist - FRONTEND +} + +pub struct DbUserAuthorizationRepository { + database: Arc>, +} + +impl DbUserAuthorizationRepository { + #[must_use] + pub fn new(database: Arc>) -> Self { + Self { database } + } + + /// Get user authorization data from user id. + /// + /// # Errors + /// + /// This function will return an error if unable to get the user + /// authorization data from the database. + pub async fn get_user_authorization_from_id(&self, user_id: &UserId) -> Result { + self.database.get_user_authorization_from_id(*user_id).await + } +} diff --git a/src/services/mod.rs b/src/services/mod.rs index b2431aec..567c35a9 100644 --- a/src/services/mod.rs +++ b/src/services/mod.rs @@ -1,6 +1,7 @@ //! App services. pub mod about; pub mod authentication; +pub mod authorization; pub mod category; pub mod hasher; pub mod proxy;