aboutsummaryrefslogtreecommitdiff
path: root/src/domain/repository.rs
blob: 00b397487a867edba4710d765604c6caa6043b1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use async_trait::async_trait;
use super::{
    calendar::Calendar,
    event::Event,
    recurrence::RecurringEvent,
    value_objects::{CalendarId, EventId, TimeRange},
};

pub type Result<T> = std::result::Result<T, RepositoryError>;

#[derive(Debug, thiserror::Error)]
pub enum RepositoryError {
    #[error("Entity not found")]
    NotFound,
    
    #[error("Database error: {0}")]
    DatabaseError(String),
    
    #[error("Constraint violation: {0}")]
    ConstraintViolation(String),
}

#[async_trait]
pub trait CalendarRepository: Send + Sync {
    async fn save(&self, calendar: &Calendar) -> Result<()>;
    async fn find_by_id(&self, id: &CalendarId) -> Result<Option<Calendar>>;
    async fn find_all_active(&self) -> Result<Vec<Calendar>>;
    async fn delete(&self, id: &CalendarId) -> Result<()>;
}

#[async_trait]
pub trait EventRepository: Send + Sync {
    async fn save(&self, event: &Event) -> Result<()>;
    async fn find_by_id(&self, id: &EventId) -> Result<Option<Event>>;
    async fn find_by_calendar(&self, calendar_id: &CalendarId) -> Result<Vec<Event>>;
    async fn find_in_range(&self, calendar_id: &CalendarId, range: &TimeRange) -> Result<Vec<Event>>;
    async fn delete(&self, id: &EventId) -> Result<()>;
}

#[async_trait]
pub trait RecurringEventRepository: Send + Sync {
    async fn save(&self, event: &RecurringEvent) -> Result<()>;
    async fn find_by_calendar(&self, calendar_id: &CalendarId) -> Result<Vec<RecurringEvent>>;
    async fn delete(&self, id: &str) -> Result<()>;
}