koprogo_api/application/ports/
resource_booking_repository.rs1use crate::application::dto::BookingStatisticsDto;
2use crate::domain::entities::{BookingStatus, ResourceBooking, ResourceType};
3use async_trait::async_trait;
4use chrono::{DateTime, Utc};
5use uuid::Uuid;
6
7#[async_trait]
12pub trait ResourceBookingRepository: Send + Sync {
13 async fn create(&self, booking: &ResourceBooking) -> Result<ResourceBooking, String>;
15
16 async fn find_by_id(&self, id: Uuid) -> Result<Option<ResourceBooking>, String>;
18
19 async fn find_by_building(&self, building_id: Uuid) -> Result<Vec<ResourceBooking>, String>;
21
22 async fn find_by_building_and_resource_type(
24 &self,
25 building_id: Uuid,
26 resource_type: ResourceType,
27 ) -> Result<Vec<ResourceBooking>, String>;
28
29 async fn find_by_resource(
31 &self,
32 building_id: Uuid,
33 resource_type: ResourceType,
34 resource_name: &str,
35 ) -> Result<Vec<ResourceBooking>, String>;
36
37 async fn find_by_user(&self, user_id: Uuid) -> Result<Vec<ResourceBooking>, String>;
39
40 async fn find_by_user_and_status(
42 &self,
43 user_id: Uuid,
44 status: BookingStatus,
45 ) -> Result<Vec<ResourceBooking>, String>;
46
47 async fn find_by_building_and_status(
49 &self,
50 building_id: Uuid,
51 status: BookingStatus,
52 ) -> Result<Vec<ResourceBooking>, String>;
53
54 async fn find_upcoming(
56 &self,
57 building_id: Uuid,
58 limit: Option<i64>,
59 ) -> Result<Vec<ResourceBooking>, String>;
60
61 async fn find_active(&self, building_id: Uuid) -> Result<Vec<ResourceBooking>, String>;
63
64 async fn find_past(
66 &self,
67 building_id: Uuid,
68 limit: Option<i64>,
69 ) -> Result<Vec<ResourceBooking>, String>;
70
71 async fn find_conflicts(
79 &self,
80 building_id: Uuid,
81 resource_type: ResourceType,
82 resource_name: &str,
83 start_time: DateTime<Utc>,
84 end_time: DateTime<Utc>,
85 exclude_booking_id: Option<Uuid>,
86 ) -> Result<Vec<ResourceBooking>, String>;
87
88 async fn update(&self, booking: &ResourceBooking) -> Result<ResourceBooking, String>;
90
91 async fn delete(&self, id: Uuid) -> Result<(), String>;
93
94 async fn count_by_building(&self, building_id: Uuid) -> Result<i64, String>;
96
97 async fn count_by_building_and_status(
99 &self,
100 building_id: Uuid,
101 status: BookingStatus,
102 ) -> Result<i64, String>;
103
104 async fn count_by_resource(
106 &self,
107 building_id: Uuid,
108 resource_type: ResourceType,
109 resource_name: &str,
110 ) -> Result<i64, String>;
111
112 async fn get_statistics(&self, building_id: Uuid) -> Result<BookingStatisticsDto, String>;
114}