koprogo_api/application/ports/
shared_object_repository.rs

1use crate::domain::entities::{SharedObject, SharedObjectCategory};
2use async_trait::async_trait;
3use uuid::Uuid;
4
5/// Repository port for SharedObject aggregate
6#[async_trait]
7pub trait SharedObjectRepository: Send + Sync {
8    /// Create a new shared object
9    async fn create(&self, object: &SharedObject) -> Result<SharedObject, String>;
10
11    /// Find shared object by ID
12    async fn find_by_id(&self, id: Uuid) -> Result<Option<SharedObject>, String>;
13
14    /// Find all shared objects for a building
15    async fn find_by_building(&self, building_id: Uuid) -> Result<Vec<SharedObject>, String>;
16
17    /// Find all available shared objects for a building (not currently borrowed)
18    async fn find_available_by_building(
19        &self,
20        building_id: Uuid,
21    ) -> Result<Vec<SharedObject>, String>;
22
23    /// Find all borrowed shared objects for a building
24    async fn find_borrowed_by_building(
25        &self,
26        building_id: Uuid,
27    ) -> Result<Vec<SharedObject>, String>;
28
29    /// Find all overdue shared objects for a building
30    async fn find_overdue_by_building(
31        &self,
32        building_id: Uuid,
33    ) -> Result<Vec<SharedObject>, String>;
34
35    /// Find all shared objects by owner
36    async fn find_by_owner(&self, owner_id: Uuid) -> Result<Vec<SharedObject>, String>;
37
38    /// Find all shared objects borrowed by a specific user
39    async fn find_borrowed_by_user(&self, borrower_id: Uuid) -> Result<Vec<SharedObject>, String>;
40
41    /// Find shared objects by category (Tools, Books, Electronics, etc.)
42    async fn find_by_category(
43        &self,
44        building_id: Uuid,
45        category: SharedObjectCategory,
46    ) -> Result<Vec<SharedObject>, String>;
47
48    /// Find free/volunteer shared objects for a building (rental_credits_per_day IS NULL OR = 0)
49    async fn find_free_by_building(&self, building_id: Uuid) -> Result<Vec<SharedObject>, String>;
50
51    /// Update an existing shared object
52    async fn update(&self, object: &SharedObject) -> Result<SharedObject, String>;
53
54    /// Delete a shared object
55    async fn delete(&self, id: Uuid) -> Result<(), String>;
56
57    /// Count total shared objects for a building
58    async fn count_by_building(&self, building_id: Uuid) -> Result<i64, String>;
59
60    /// Count available shared objects for a building
61    async fn count_available_by_building(&self, building_id: Uuid) -> Result<i64, String>;
62
63    /// Count borrowed shared objects for a building
64    async fn count_borrowed_by_building(&self, building_id: Uuid) -> Result<i64, String>;
65
66    /// Count overdue shared objects for a building
67    async fn count_overdue_by_building(&self, building_id: Uuid) -> Result<i64, String>;
68
69    /// Count shared objects by category (for statistics)
70    async fn count_by_category(
71        &self,
72        building_id: Uuid,
73        category: SharedObjectCategory,
74    ) -> Result<i64, String>;
75}