dofus_framework/ddd/application/
repository.rs

1use crate::ddd::domain::entity::{Entity, Identifiable};
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum SaveError {
6    #[error("Entity with key: {0} already exists")]
7    DuplicatedEntity(String),
8}
9
10pub trait Repository<K: Identifiable, E: Entity<K>> {
11    fn save(&mut self, entity: E);
12    fn get_by_id(&self, key: &K) -> Option<&E>;
13    fn get_all(&self) -> Vec<&E>;
14    fn delete(&mut self, key: &K) -> Option<E>;
15}