Add wrapper around repository backend error

This commit is contained in:
2025-01-29 20:24:41 +00:00
parent d2de03fde1
commit fc07051558
8 changed files with 58 additions and 35 deletions

View File

@@ -10,7 +10,7 @@ pub trait RepositoryProvider {
where
Self: 'a;
async fn get(&self) -> Result<Self::Repository<'_>, Self::BackendError>;
async fn get(&self) -> Result<Self::Repository<'_>, RepositoryError<Self::BackendError>>;
}
pub trait Repository
@@ -19,3 +19,6 @@ where
{
type BackendError: std::error::Error;
}
#[derive(Debug)]
pub struct RepositoryError<E>(pub E);

View File

@@ -1,14 +1,16 @@
use super::RepositoryError;
#[async_trait::async_trait]
pub trait UserRepository {
type BackendError: std::error::Error;
async fn user(&mut self, id: i32) -> Result<Option<User>, Self::BackendError>;
async fn user(&mut self, id: i32) -> Result<Option<User>, RepositoryError<Self::BackendError>>;
async fn insert_user(&mut self, new_user: NewUser) -> Result<User, Self::BackendError>;
async fn insert_user(&mut self, new_user: NewUser) -> Result<User, RepositoryError<Self::BackendError>>;
async fn update_user(&mut self, user: User) -> Result<Option<User>, Self::BackendError>;
async fn update_user(&mut self, user: User) -> Result<Option<User>, RepositoryError<Self::BackendError>>;
async fn remove_user(&mut self, id: i32) -> Result<Option<User>, Self::BackendError>;
async fn remove_user(&mut self, id: i32) -> Result<Option<User>, RepositoryError<Self::BackendError>>;
}
pub struct User {