koprogo_api/application/ports/
notice_repository.rs

1use crate::domain::entities::{Notice, NoticeCategory, NoticeStatus, NoticeType};
2use async_trait::async_trait;
3use uuid::Uuid;
4
5/// Repository port for Notice aggregate
6#[async_trait]
7pub trait NoticeRepository: Send + Sync {
8    /// Create a new notice
9    async fn create(&self, notice: &Notice) -> Result<Notice, String>;
10
11    /// Find notice by ID
12    async fn find_by_id(&self, id: Uuid) -> Result<Option<Notice>, String>;
13
14    /// Find all notices for a building
15    async fn find_by_building(&self, building_id: Uuid) -> Result<Vec<Notice>, String>;
16
17    /// Find all published notices for a building (visible to members)
18    async fn find_published_by_building(&self, building_id: Uuid) -> Result<Vec<Notice>, String>;
19
20    /// Find all pinned notices for a building (important announcements)
21    async fn find_pinned_by_building(&self, building_id: Uuid) -> Result<Vec<Notice>, String>;
22
23    /// Find notices by type (Announcement, Event, LostAndFound, ClassifiedAd)
24    async fn find_by_type(
25        &self,
26        building_id: Uuid,
27        notice_type: NoticeType,
28    ) -> Result<Vec<Notice>, String>;
29
30    /// Find notices by category (General, Maintenance, Social, Security, etc.)
31    async fn find_by_category(
32        &self,
33        building_id: Uuid,
34        category: NoticeCategory,
35    ) -> Result<Vec<Notice>, String>;
36
37    /// Find notices by status (Draft, Published, Archived, Expired)
38    async fn find_by_status(
39        &self,
40        building_id: Uuid,
41        status: NoticeStatus,
42    ) -> Result<Vec<Notice>, String>;
43
44    /// Find all notices created by an author (Owner)
45    async fn find_by_author(&self, author_id: Uuid) -> Result<Vec<Notice>, String>;
46
47    /// Find all expired notices for a building (for auto-archiving)
48    async fn find_expired(&self, building_id: Uuid) -> Result<Vec<Notice>, String>;
49
50    /// Update an existing notice
51    async fn update(&self, notice: &Notice) -> Result<Notice, String>;
52
53    /// Delete a notice
54    async fn delete(&self, id: Uuid) -> Result<(), String>;
55
56    /// Count total notices for a building
57    async fn count_by_building(&self, building_id: Uuid) -> Result<i64, String>;
58
59    /// Count published notices for a building
60    async fn count_published_by_building(&self, building_id: Uuid) -> Result<i64, String>;
61
62    /// Count pinned notices for a building
63    async fn count_pinned_by_building(&self, building_id: Uuid) -> Result<i64, String>;
64}