51 lines
1018 B
Rust
51 lines
1018 B
Rust
mod ingredient;
|
|
mod recipe;
|
|
|
|
pub use ingredient::IngredientRepoPort;
|
|
pub use recipe::RecipeRepoPort;
|
|
|
|
use crate::app_core::shared::lib::{Entity, EntityId};
|
|
|
|
use shaku::Interface;
|
|
|
|
#[derive(Debug)]
|
|
pub enum GetDbConnectionError {
|
|
TimedOut,
|
|
Unknown,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum FindOneError {
|
|
Unknown,
|
|
NotFound,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum FindOneOptError {
|
|
Unknown,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum InsertError {
|
|
Unknown,
|
|
Conflict,
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait RepositoryPort: Interface {
|
|
type Entity: Entity;
|
|
|
|
async fn insert(&self, entity: Self::Entity) -> Result<(), InsertError>;
|
|
|
|
async fn find_one(&self, id: &EntityId) -> Result<Self::Entity, FindOneError> {
|
|
self.find_one_opt(id)
|
|
.await
|
|
.map_err(|e| match e {
|
|
FindOneOptError::Unknown => FindOneError::Unknown,
|
|
})?
|
|
.ok_or(FindOneError::NotFound)
|
|
}
|
|
|
|
async fn find_one_opt(&self, id: &EntityId) -> Result<Option<Self::Entity>, FindOneOptError>;
|
|
}
|