style: apply cargo fmt to entire codebase

Standardize code formatting across all 173 Rust source files
using rustfmt. No functional changes - purely cosmetic.

This establishes a consistent code style baseline for the
project going forward.
This commit is contained in:
Dionisio
2026-02-14 01:29:34 +01:00
parent 67137a3ef2
commit 4c98c5a657
173 changed files with 23368 additions and 17590 deletions
@@ -1,6 +1,6 @@
use async_trait::async_trait;
use uuid::Uuid;
use std::result::Result;
use uuid::Uuid;
use crate::common::errors::DomainError;
use crate::domain::entities::contact::AddressBook;
@@ -9,14 +9,41 @@ pub type AddressBookRepositoryResult<T> = Result<T, DomainError>;
#[async_trait]
pub trait AddressBookRepository: Send + Sync + 'static {
async fn create_address_book(&self, address_book: AddressBook) -> AddressBookRepositoryResult<AddressBook>;
async fn update_address_book(&self, address_book: AddressBook) -> AddressBookRepositoryResult<AddressBook>;
async fn create_address_book(
&self,
address_book: AddressBook,
) -> AddressBookRepositoryResult<AddressBook>;
async fn update_address_book(
&self,
address_book: AddressBook,
) -> AddressBookRepositoryResult<AddressBook>;
async fn delete_address_book(&self, id: &Uuid) -> AddressBookRepositoryResult<()>;
async fn get_address_book_by_id(&self, id: &Uuid) -> AddressBookRepositoryResult<Option<AddressBook>>;
async fn get_address_books_by_owner(&self, owner_id: &str) -> AddressBookRepositoryResult<Vec<AddressBook>>;
async fn get_shared_address_books(&self, user_id: &str) -> AddressBookRepositoryResult<Vec<AddressBook>>;
async fn get_address_book_by_id(
&self,
id: &Uuid,
) -> AddressBookRepositoryResult<Option<AddressBook>>;
async fn get_address_books_by_owner(
&self,
owner_id: &str,
) -> AddressBookRepositoryResult<Vec<AddressBook>>;
async fn get_shared_address_books(
&self,
user_id: &str,
) -> AddressBookRepositoryResult<Vec<AddressBook>>;
async fn get_public_address_books(&self) -> AddressBookRepositoryResult<Vec<AddressBook>>;
async fn share_address_book(&self, address_book_id: &Uuid, user_id: &str, can_write: bool) -> AddressBookRepositoryResult<()>;
async fn unshare_address_book(&self, address_book_id: &Uuid, user_id: &str) -> AddressBookRepositoryResult<()>;
async fn get_address_book_shares(&self, address_book_id: &Uuid) -> AddressBookRepositoryResult<Vec<(String, bool)>>;
}
async fn share_address_book(
&self,
address_book_id: &Uuid,
user_id: &str,
can_write: bool,
) -> AddressBookRepositoryResult<()>;
async fn unshare_address_book(
&self,
address_book_id: &Uuid,
user_id: &str,
) -> AddressBookRepositoryResult<()>;
async fn get_address_book_shares(
&self,
address_book_id: &Uuid,
) -> AddressBookRepositoryResult<Vec<(String, bool)>>;
}
@@ -1,8 +1,8 @@
use async_trait::async_trait;
use uuid::Uuid;
use chrono::{DateTime, Utc};
use crate::common::errors::DomainError;
use crate::domain::entities::calendar_event::CalendarEvent;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use uuid::Uuid;
pub type CalendarEventRepositoryResult<T> = Result<T, DomainError>;
@@ -10,53 +10,76 @@ pub type CalendarEventRepositoryResult<T> = Result<T, DomainError>;
#[async_trait]
pub trait CalendarEventRepository: Send + Sync + 'static {
/// Creates a new calendar event
async fn create_event(&self, event: CalendarEvent) -> CalendarEventRepositoryResult<CalendarEvent>;
async fn create_event(
&self,
event: CalendarEvent,
) -> CalendarEventRepositoryResult<CalendarEvent>;
/// Updates an existing calendar event
async fn update_event(&self, event: CalendarEvent) -> CalendarEventRepositoryResult<CalendarEvent>;
async fn update_event(
&self,
event: CalendarEvent,
) -> CalendarEventRepositoryResult<CalendarEvent>;
/// Deletes a calendar event by ID
async fn delete_event(&self, id: &Uuid) -> CalendarEventRepositoryResult<()>;
/// Finds a calendar event by its ID
async fn find_event_by_id(&self, id: &Uuid) -> CalendarEventRepositoryResult<CalendarEvent>;
/// Lists all events in a specific calendar
async fn list_events_by_calendar(&self, calendar_id: &Uuid) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
async fn list_events_by_calendar(
&self,
calendar_id: &Uuid,
) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
/// Finds events in a calendar by their summary/title (partial match)
async fn find_events_by_summary(&self, calendar_id: &Uuid, summary: &str) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
async fn find_events_by_summary(
&self,
calendar_id: &Uuid,
summary: &str,
) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
/// Gets events in a specific time range for a calendar
async fn get_events_in_time_range(
&self,
calendar_id: &Uuid,
start: &DateTime<Utc>,
end: &DateTime<Utc>
&self,
calendar_id: &Uuid,
start: &DateTime<Utc>,
end: &DateTime<Utc>,
) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
/// Finds an event by its iCalendar UID in a specific calendar
async fn find_event_by_ical_uid(&self, calendar_id: &Uuid, ical_uid: &str) -> CalendarEventRepositoryResult<Option<CalendarEvent>>;
async fn find_event_by_ical_uid(
&self,
calendar_id: &Uuid,
ical_uid: &str,
) -> CalendarEventRepositoryResult<Option<CalendarEvent>>;
/// Counts events in a calendar
async fn count_events_in_calendar(&self, calendar_id: &Uuid) -> CalendarEventRepositoryResult<i64>;
async fn count_events_in_calendar(
&self,
calendar_id: &Uuid,
) -> CalendarEventRepositoryResult<i64>;
/// Deletes all events in a calendar
async fn delete_all_events_in_calendar(&self, calendar_id: &Uuid) -> CalendarEventRepositoryResult<i64>;
async fn delete_all_events_in_calendar(
&self,
calendar_id: &Uuid,
) -> CalendarEventRepositoryResult<i64>;
/// Lists events by calendar with pagination
async fn list_events_by_calendar_paginated(
&self,
&self,
calendar_id: &Uuid,
limit: i64,
offset: i64
offset: i64,
) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
/// Finds events with recurrence rules that might occur in a time range
async fn find_recurring_events_in_range(
&self,
calendar_id: &Uuid,
start: &DateTime<Utc>,
end: &DateTime<Utc>
end: &DateTime<Utc>,
) -> CalendarEventRepositoryResult<Vec<CalendarEvent>>;
}
}
+76 -30
View File
@@ -1,7 +1,7 @@
use async_trait::async_trait;
use uuid::Uuid;
use crate::common::errors::DomainError;
use crate::domain::entities::calendar::Calendar;
use async_trait::async_trait;
use uuid::Uuid;
pub type CalendarRepositoryResult<T> = Result<T, DomainError>;
@@ -10,49 +10,95 @@ pub type CalendarRepositoryResult<T> = Result<T, DomainError>;
pub trait CalendarRepository: Send + Sync + 'static {
/// Creates a new calendar
async fn create_calendar(&self, calendar: Calendar) -> CalendarRepositoryResult<Calendar>;
/// Updates an existing calendar
async fn update_calendar(&self, calendar: Calendar) -> CalendarRepositoryResult<Calendar>;
/// Deletes a calendar by ID
async fn delete_calendar(&self, id: &Uuid) -> CalendarRepositoryResult<()>;
/// Finds a calendar by its ID
async fn find_calendar_by_id(&self, id: &Uuid) -> CalendarRepositoryResult<Calendar>;
/// Lists all calendars for a specific user
async fn list_calendars_by_owner(&self, owner_id: &str) -> CalendarRepositoryResult<Vec<Calendar>>;
async fn list_calendars_by_owner(
&self,
owner_id: &str,
) -> CalendarRepositoryResult<Vec<Calendar>>;
/// Finds a calendar by name and owner
async fn find_calendar_by_name_and_owner(&self, name: &str, owner_id: &str) -> CalendarRepositoryResult<Calendar>;
async fn find_calendar_by_name_and_owner(
&self,
name: &str,
owner_id: &str,
) -> CalendarRepositoryResult<Calendar>;
/// Lists calendars shared with a specific user
async fn list_calendars_shared_with_user(&self, user_id: &str) -> CalendarRepositoryResult<Vec<Calendar>>;
async fn list_calendars_shared_with_user(
&self,
user_id: &str,
) -> CalendarRepositoryResult<Vec<Calendar>>;
/// List public calendars
async fn list_public_calendars(&self, limit: i64, offset: i64) -> CalendarRepositoryResult<Vec<Calendar>>;
async fn list_public_calendars(
&self,
limit: i64,
offset: i64,
) -> CalendarRepositoryResult<Vec<Calendar>>;
/// Checks if a user has access to a calendar
async fn user_has_calendar_access(&self, calendar_id: &Uuid, user_id: &str) -> CalendarRepositoryResult<bool>;
async fn user_has_calendar_access(
&self,
calendar_id: &Uuid,
user_id: &str,
) -> CalendarRepositoryResult<bool>;
/// Gets a custom property for a calendar
async fn get_calendar_property(&self, calendar_id: &Uuid, property_name: &str) -> CalendarRepositoryResult<Option<String>>;
async fn get_calendar_property(
&self,
calendar_id: &Uuid,
property_name: &str,
) -> CalendarRepositoryResult<Option<String>>;
/// Sets a custom property for a calendar
async fn set_calendar_property(&self, calendar_id: &Uuid, property_name: &str, property_value: &str) -> CalendarRepositoryResult<()>;
async fn set_calendar_property(
&self,
calendar_id: &Uuid,
property_name: &str,
property_value: &str,
) -> CalendarRepositoryResult<()>;
/// Removes a custom property from a calendar
async fn remove_calendar_property(&self, calendar_id: &Uuid, property_name: &str) -> CalendarRepositoryResult<()>;
async fn remove_calendar_property(
&self,
calendar_id: &Uuid,
property_name: &str,
) -> CalendarRepositoryResult<()>;
/// Gets all custom properties for a calendar
async fn get_calendar_properties(&self, calendar_id: &Uuid) -> CalendarRepositoryResult<std::collections::HashMap<String, String>>;
async fn get_calendar_properties(
&self,
calendar_id: &Uuid,
) -> CalendarRepositoryResult<std::collections::HashMap<String, String>>;
/// Share calendar with another user
async fn share_calendar(&self, calendar_id: &Uuid, user_id: &str, access_level: &str) -> CalendarRepositoryResult<()>;
async fn share_calendar(
&self,
calendar_id: &Uuid,
user_id: &str,
access_level: &str,
) -> CalendarRepositoryResult<()>;
/// Remove calendar sharing for a user
async fn remove_calendar_sharing(&self, calendar_id: &Uuid, user_id: &str) -> CalendarRepositoryResult<()>;
async fn remove_calendar_sharing(
&self,
calendar_id: &Uuid,
user_id: &str,
) -> CalendarRepositoryResult<()>;
/// Get calendar sharing information (who has access to this calendar)
async fn get_calendar_shares(&self, calendar_id: &Uuid) -> CalendarRepositoryResult<Vec<(String, String)>>;
}
async fn get_calendar_shares(
&self,
calendar_id: &Uuid,
) -> CalendarRepositoryResult<Vec<(String, String)>>;
}
+38 -11
View File
@@ -1,6 +1,6 @@
use async_trait::async_trait;
use uuid::Uuid;
use std::result::Result;
use uuid::Uuid;
use crate::common::errors::DomainError;
use crate::domain::entities::contact::{Contact, ContactGroup};
@@ -13,11 +13,23 @@ pub trait ContactRepository: Send + Sync + 'static {
async fn update_contact(&self, contact: Contact) -> ContactRepositoryResult<Contact>;
async fn delete_contact(&self, id: &Uuid) -> ContactRepositoryResult<()>;
async fn get_contact_by_id(&self, id: &Uuid) -> ContactRepositoryResult<Option<Contact>>;
async fn get_contact_by_uid(&self, address_book_id: &Uuid, uid: &str) -> ContactRepositoryResult<Option<Contact>>;
async fn get_contacts_by_address_book(&self, address_book_id: &Uuid) -> ContactRepositoryResult<Vec<Contact>>;
async fn get_contact_by_uid(
&self,
address_book_id: &Uuid,
uid: &str,
) -> ContactRepositoryResult<Option<Contact>>;
async fn get_contacts_by_address_book(
&self,
address_book_id: &Uuid,
) -> ContactRepositoryResult<Vec<Contact>>;
async fn get_contacts_by_email(&self, email: &str) -> ContactRepositoryResult<Vec<Contact>>;
async fn get_contacts_by_group(&self, group_id: &Uuid) -> ContactRepositoryResult<Vec<Contact>>;
async fn search_contacts(&self, address_book_id: &Uuid, query: &str) -> ContactRepositoryResult<Vec<Contact>>;
async fn get_contacts_by_group(&self, group_id: &Uuid)
-> ContactRepositoryResult<Vec<Contact>>;
async fn search_contacts(
&self,
address_book_id: &Uuid,
query: &str,
) -> ContactRepositoryResult<Vec<Contact>>;
}
#[async_trait]
@@ -26,9 +38,24 @@ pub trait ContactGroupRepository: Send + Sync + 'static {
async fn update_group(&self, group: ContactGroup) -> ContactRepositoryResult<ContactGroup>;
async fn delete_group(&self, id: &Uuid) -> ContactRepositoryResult<()>;
async fn get_group_by_id(&self, id: &Uuid) -> ContactRepositoryResult<Option<ContactGroup>>;
async fn get_groups_by_address_book(&self, address_book_id: &Uuid) -> ContactRepositoryResult<Vec<ContactGroup>>;
async fn add_contact_to_group(&self, group_id: &Uuid, contact_id: &Uuid) -> ContactRepositoryResult<()>;
async fn remove_contact_from_group(&self, group_id: &Uuid, contact_id: &Uuid) -> ContactRepositoryResult<()>;
async fn get_contacts_in_group(&self, group_id: &Uuid) -> ContactRepositoryResult<Vec<Contact>>;
async fn get_groups_for_contact(&self, contact_id: &Uuid) -> ContactRepositoryResult<Vec<ContactGroup>>;
}
async fn get_groups_by_address_book(
&self,
address_book_id: &Uuid,
) -> ContactRepositoryResult<Vec<ContactGroup>>;
async fn add_contact_to_group(
&self,
group_id: &Uuid,
contact_id: &Uuid,
) -> ContactRepositoryResult<()>;
async fn remove_contact_from_group(
&self,
group_id: &Uuid,
contact_id: &Uuid,
) -> ContactRepositoryResult<()>;
async fn get_contacts_in_group(&self, group_id: &Uuid)
-> ContactRepositoryResult<Vec<Contact>>;
async fn get_groups_for_contact(
&self,
contact_id: &Uuid,
) -> ContactRepositoryResult<Vec<ContactGroup>>;
}
+9 -8
View File
@@ -15,9 +15,9 @@ use async_trait::async_trait;
use bytes::Bytes;
use futures::Stream;
use crate::common::errors::DomainError;
use crate::domain::entities::file::File;
use crate::domain::services::path_service::StoragePath;
use crate::common::errors::DomainError;
// ─────────────────────────────────────────────────────
// FileReadRepository — read/query operations
@@ -98,17 +98,14 @@ pub trait FileWriteRepository: Send + Sync + 'static {
) -> Result<File, DomainError>;
/// Renames a file (same folder, different name).
async fn rename_file(
&self,
file_id: &str,
new_name: &str,
) -> Result<File, DomainError>;
async fn rename_file(&self, file_id: &str, new_name: &str) -> Result<File, DomainError>;
/// Deletes a file.
async fn delete_file(&self, id: &str) -> Result<(), DomainError>;
/// Updates the content of an existing file.
async fn update_file_content(&self, file_id: &str, content: Vec<u8>) -> Result<(), DomainError>;
async fn update_file_content(&self, file_id: &str, content: Vec<u8>)
-> Result<(), DomainError>;
/// Registers file metadata WITHOUT writing content to disk (write-behind).
///
@@ -128,7 +125,11 @@ pub trait FileWriteRepository: Send + Sync + 'static {
async fn move_to_trash(&self, file_id: &str) -> Result<(), DomainError>;
/// Restores a file from the trash to its original location
async fn restore_from_trash(&self, file_id: &str, original_path: &str) -> Result<(), DomainError>;
async fn restore_from_trash(
&self,
file_id: &str,
original_path: &str,
) -> Result<(), DomainError>;
/// Permanently deletes a file (used by the trash)
async fn delete_file_permanently(&self, file_id: &str) -> Result<(), DomainError>;
+27 -15
View File
@@ -10,9 +10,9 @@
use async_trait::async_trait;
use crate::common::errors::DomainError;
use crate::domain::entities::folder::Folder;
use crate::domain::services::path_service::StoragePath;
use crate::common::errors::DomainError;
/// Domain port for folder persistence.
///
@@ -21,38 +21,46 @@ use crate::common::errors::DomainError;
#[async_trait]
pub trait FolderRepository: Send + Sync + 'static {
/// Creates a new folder
async fn create_folder(&self, name: String, parent_id: Option<String>) -> Result<Folder, DomainError>;
async fn create_folder(
&self,
name: String,
parent_id: Option<String>,
) -> Result<Folder, DomainError>;
/// Gets a folder by its ID
async fn get_folder(&self, id: &str) -> Result<Folder, DomainError>;
/// Gets a folder by its storage path
async fn get_folder_by_path(&self, storage_path: &StoragePath) -> Result<Folder, DomainError>;
/// Lists folders within a parent folder
async fn list_folders(&self, parent_id: Option<&str>) -> Result<Vec<Folder>, DomainError>;
/// Lists folders with pagination
async fn list_folders_paginated(
&self,
&self,
parent_id: Option<&str>,
offset: usize,
limit: usize,
include_total: bool
include_total: bool,
) -> Result<(Vec<Folder>, Option<usize>), DomainError>;
/// Renames a folder
async fn rename_folder(&self, id: &str, new_name: String) -> Result<Folder, DomainError>;
/// Moves a folder to another parent
async fn move_folder(&self, id: &str, new_parent_id: Option<&str>) -> Result<Folder, DomainError>;
async fn move_folder(
&self,
id: &str,
new_parent_id: Option<&str>,
) -> Result<Folder, DomainError>;
/// Deletes a folder
async fn delete_folder(&self, id: &str) -> Result<(), DomainError>;
/// Checks if a folder exists at the given path
async fn folder_exists(&self, storage_path: &StoragePath) -> Result<bool, DomainError>;
/// Gets the path of a folder
async fn get_folder_path(&self, id: &str) -> Result<StoragePath, DomainError>;
@@ -62,7 +70,11 @@ pub trait FolderRepository: Send + Sync + 'static {
async fn move_to_trash(&self, folder_id: &str) -> Result<(), DomainError>;
/// Restores a folder from the trash to its original location
async fn restore_from_trash(&self, folder_id: &str, original_path: &str) -> Result<(), DomainError>;
async fn restore_from_trash(
&self,
folder_id: &str,
original_path: &str,
) -> Result<(), DomainError>;
/// Permanently deletes a folder (used by the trash)
async fn delete_folder_permanently(&self, folder_id: &str) -> Result<(), DomainError>;
+3 -3
View File
@@ -1,11 +1,11 @@
pub mod address_book_repository;
pub mod calendar_repository;
pub mod calendar_event_repository;
pub mod calendar_repository;
pub mod contact_repository;
pub mod file_repository;
pub mod folder_repository;
pub mod session_repository;
pub mod settings_repository;
pub mod share_repository;
pub mod trash_repository;
pub mod settings_repository;
pub mod user_repository;
pub mod user_repository;
+20 -20
View File
@@ -1,15 +1,15 @@
use async_trait::async_trait;
use crate::domain::entities::session::Session;
use crate::common::errors::DomainError;
use crate::domain::entities::session::Session;
use async_trait::async_trait;
#[derive(Debug, thiserror::Error)]
pub enum SessionRepositoryError {
#[error("Session not found: {0}")]
NotFound(String),
#[error("Database error: {0}")]
DatabaseError(String),
#[error("Timeout error: {0}")]
Timeout(String),
}
@@ -20,15 +20,11 @@ pub type SessionRepositoryResult<T> = Result<T, SessionRepositoryError>;
impl From<SessionRepositoryError> for DomainError {
fn from(err: SessionRepositoryError) -> Self {
match err {
SessionRepositoryError::NotFound(msg) => {
DomainError::not_found("Session", msg)
},
SessionRepositoryError::NotFound(msg) => DomainError::not_found("Session", msg),
SessionRepositoryError::DatabaseError(msg) => {
DomainError::internal_error("Database", msg)
},
SessionRepositoryError::Timeout(msg) => {
DomainError::timeout("Database", msg)
},
}
SessionRepositoryError::Timeout(msg) => DomainError::timeout("Database", msg),
}
}
}
@@ -37,22 +33,26 @@ impl From<SessionRepositoryError> for DomainError {
pub trait SessionRepository: Send + Sync + 'static {
/// Creates a new session
async fn create_session(&self, session: Session) -> SessionRepositoryResult<Session>;
/// Gets a session by ID
async fn get_session_by_id(&self, id: &str) -> SessionRepositoryResult<Session>;
/// Gets a session by refresh token
async fn get_session_by_refresh_token(&self, refresh_token: &str) -> SessionRepositoryResult<Session>;
async fn get_session_by_refresh_token(
&self,
refresh_token: &str,
) -> SessionRepositoryResult<Session>;
/// Gets all sessions for a user
async fn get_sessions_by_user_id(&self, user_id: &str) -> SessionRepositoryResult<Vec<Session>>;
async fn get_sessions_by_user_id(&self, user_id: &str)
-> SessionRepositoryResult<Vec<Session>>;
/// Revokes a specific session
async fn revoke_session(&self, session_id: &str) -> SessionRepositoryResult<()>;
/// Revokes all sessions for a user
async fn revoke_all_user_sessions(&self, user_id: &str) -> SessionRepositoryResult<u64>;
/// Deletes expired sessions
async fn delete_expired_sessions(&self) -> SessionRepositoryResult<u64>;
}
}
+28 -27
View File
@@ -1,27 +1,28 @@
use std::collections::HashMap;
use async_trait::async_trait;
use crate::common::errors::DomainError;
/// Repository for platform settings stored in the database.
/// Settings are key-value pairs organized by category (e.g., "oidc", "general").
#[async_trait]
pub trait SettingsRepository: Send + Sync + 'static {
/// Get a single setting value by key
async fn get(&self, key: &str) -> Result<Option<String>, DomainError>;
/// Get all settings for a given category
async fn get_by_category(&self, category: &str) -> Result<HashMap<String, String>, DomainError>;
/// Set a setting value (upsert)
async fn set(
&self,
key: &str,
value: &str,
category: &str,
is_secret: bool,
updated_by: Option<&str>,
) -> Result<(), DomainError>;
/// Delete a setting by key
async fn delete(&self, key: &str) -> Result<(), DomainError>;
}
use crate::common::errors::DomainError;
use async_trait::async_trait;
use std::collections::HashMap;
/// Repository for platform settings stored in the database.
/// Settings are key-value pairs organized by category (e.g., "oidc", "general").
#[async_trait]
pub trait SettingsRepository: Send + Sync + 'static {
/// Get a single setting value by key
async fn get(&self, key: &str) -> Result<Option<String>, DomainError>;
/// Get all settings for a given category
async fn get_by_category(&self, category: &str)
-> Result<HashMap<String, String>, DomainError>;
/// Set a setting value (upsert)
async fn set(
&self,
key: &str,
value: &str,
category: &str,
is_secret: bool,
updated_by: Option<&str>,
) -> Result<(), DomainError>;
/// Delete a setting by key
async fn delete(&self, key: &str) -> Result<(), DomainError>;
}
+11 -8
View File
@@ -1,4 +1,3 @@
use async_trait::async_trait;
use thiserror::Error;
@@ -25,22 +24,26 @@ pub enum ShareRepositoryError {
pub trait ShareRepository: Send + Sync + 'static {
/// Save a new share or update an existing one
async fn save(&self, share: &Share) -> Result<Share, ShareRepositoryError>;
/// Find a share by its ID
async fn find_by_id(&self, id: &str) -> Result<Share, ShareRepositoryError>;
/// Find a share by its token
async fn find_by_token(&self, token: &str) -> Result<Share, ShareRepositoryError>;
/// Find all shares for a specific item
async fn find_by_item(&self, item_id: &str, item_type: &ShareItemType) -> Result<Vec<Share>, ShareRepositoryError>;
async fn find_by_item(
&self,
item_id: &str,
item_type: &ShareItemType,
) -> Result<Vec<Share>, ShareRepositoryError>;
/// Delete a share by its ID
async fn delete(&self, id: &str) -> Result<(), ShareRepositoryError>;
/// Find all shares created by a specific user
async fn find_by_user(&self, user_id: &str) -> Result<Vec<Share>, ShareRepositoryError>;
/// Find all shares (admin operation)
async fn find_all(&self) -> Result<Vec<Share>, ShareRepositoryError>;
}
+2 -2
View File
@@ -1,8 +1,8 @@
use async_trait::async_trait;
use uuid::Uuid;
use crate::domain::entities::trashed_item::TrashedItem;
use crate::common::errors::Result;
use crate::domain::entities::trashed_item::TrashedItem;
#[async_trait]
pub trait TrashRepository: Send + Sync {
@@ -13,4 +13,4 @@ pub trait TrashRepository: Send + Sync {
async fn delete_permanently(&self, id: &Uuid, user_id: &Uuid) -> Result<()>;
async fn clear_trash(&self, user_id: &Uuid) -> Result<()>;
async fn get_expired_items(&self) -> Result<Vec<TrashedItem>>;
}
}
+45 -41
View File
@@ -1,24 +1,24 @@
use async_trait::async_trait;
use crate::domain::entities::user::{User, UserRole};
use crate::common::errors::DomainError;
use crate::domain::entities::user::{User, UserRole};
use async_trait::async_trait;
#[derive(Debug, thiserror::Error)]
pub enum UserRepositoryError {
#[error("User not found: {0}")]
NotFound(String),
#[error("User already exists: {0}")]
AlreadyExists(String),
#[error("Database error: {0}")]
DatabaseError(String),
#[error("Validation error: {0}")]
ValidationError(String),
#[error("Timeout error: {0}")]
Timeout(String),
#[error("Operation not allowed: {0}")]
OperationNotAllowed(String),
}
@@ -29,24 +29,14 @@ pub type UserRepositoryResult<T> = Result<T, UserRepositoryError>;
impl From<UserRepositoryError> for DomainError {
fn from(err: UserRepositoryError) -> Self {
match err {
UserRepositoryError::NotFound(msg) => {
DomainError::not_found("User", msg)
},
UserRepositoryError::AlreadyExists(msg) => {
DomainError::already_exists("User", msg)
},
UserRepositoryError::DatabaseError(msg) => {
DomainError::internal_error("Database", msg)
},
UserRepositoryError::ValidationError(msg) => {
DomainError::validation_error(msg)
},
UserRepositoryError::Timeout(msg) => {
DomainError::timeout("Database", msg)
},
UserRepositoryError::NotFound(msg) => DomainError::not_found("User", msg),
UserRepositoryError::AlreadyExists(msg) => DomainError::already_exists("User", msg),
UserRepositoryError::DatabaseError(msg) => DomainError::internal_error("Database", msg),
UserRepositoryError::ValidationError(msg) => DomainError::validation_error(msg),
UserRepositoryError::Timeout(msg) => DomainError::timeout("Database", msg),
UserRepositoryError::OperationNotAllowed(msg) => {
DomainError::access_denied("User", msg)
},
}
}
}
}
@@ -55,48 +45,62 @@ impl From<UserRepositoryError> for DomainError {
pub trait UserRepository: Send + Sync + 'static {
/// Creates a new user
async fn create_user(&self, user: User) -> UserRepositoryResult<User>;
/// Gets a user by ID
async fn get_user_by_id(&self, id: &str) -> UserRepositoryResult<User>;
/// Gets a user by username
async fn get_user_by_username(&self, username: &str) -> UserRepositoryResult<User>;
/// Gets a user by email
async fn get_user_by_email(&self, email: &str) -> UserRepositoryResult<User>;
/// Updates an existing user
async fn update_user(&self, user: User) -> UserRepositoryResult<User>;
/// Updates only a user's storage usage
async fn update_storage_usage(&self, user_id: &str, usage_bytes: i64) -> UserRepositoryResult<()>;
async fn update_storage_usage(
&self,
user_id: &str,
usage_bytes: i64,
) -> UserRepositoryResult<()>;
/// Updates the last login date
async fn update_last_login(&self, user_id: &str) -> UserRepositoryResult<()>;
/// Lists users with pagination
async fn list_users(&self, limit: i64, offset: i64) -> UserRepositoryResult<Vec<User>>;
/// Activates or deactivates a user
async fn set_user_active_status(&self, user_id: &str, active: bool) -> UserRepositoryResult<()>;
async fn set_user_active_status(&self, user_id: &str, active: bool)
-> UserRepositoryResult<()>;
/// Changes a user's password
async fn change_password(&self, user_id: &str, password_hash: &str) -> UserRepositoryResult<()>;
async fn change_password(&self, user_id: &str, password_hash: &str)
-> UserRepositoryResult<()>;
/// Changes a user's role
async fn change_role(&self, user_id: &str, role: UserRole) -> UserRepositoryResult<()>;
/// Lists users by role (admin or user)
async fn list_users_by_role(&self, role: &str) -> UserRepositoryResult<Vec<User>>;
/// Deletes a user
async fn delete_user(&self, user_id: &str) -> UserRepositoryResult<()>;
/// Finds a user by OIDC provider + subject pair
async fn get_user_by_oidc_subject(&self, provider: &str, subject: &str) -> UserRepositoryResult<User>;
async fn get_user_by_oidc_subject(
&self,
provider: &str,
subject: &str,
) -> UserRepositoryResult<User>;
/// Updates a user's storage quota
async fn update_storage_quota(&self, user_id: &str, quota_bytes: i64) -> UserRepositoryResult<()>;
async fn update_storage_quota(
&self,
user_id: &str,
quota_bytes: i64,
) -> UserRepositoryResult<()>;
/// Counts the total number of users
async fn count_users(&self) -> UserRepositoryResult<i64>;
@@ -114,4 +118,4 @@ pub struct StorageStats {
pub total_used_bytes: i64,
pub users_over_80_percent: i64,
pub users_over_quota: i64,
}
}