koprogo_api/application/ports/
local_exchange_repository.rs1use crate::domain::entities::LocalExchange;
2use async_trait::async_trait;
3use uuid::Uuid;
4
5#[async_trait]
7pub trait LocalExchangeRepository: Send + Sync {
8 async fn create(&self, exchange: &LocalExchange) -> Result<LocalExchange, String>;
10
11 async fn find_by_id(&self, id: Uuid) -> Result<Option<LocalExchange>, String>;
13
14 async fn find_by_building(&self, building_id: Uuid) -> Result<Vec<LocalExchange>, String>;
16
17 async fn find_by_building_and_status(
19 &self,
20 building_id: Uuid,
21 status: &str,
22 ) -> Result<Vec<LocalExchange>, String>;
23
24 async fn find_by_provider(&self, provider_id: Uuid) -> Result<Vec<LocalExchange>, String>;
26
27 async fn find_by_requester(&self, requester_id: Uuid) -> Result<Vec<LocalExchange>, String>;
29
30 async fn find_by_owner(&self, owner_id: Uuid) -> Result<Vec<LocalExchange>, String>;
32
33 async fn find_active_by_building(
35 &self,
36 building_id: Uuid,
37 ) -> Result<Vec<LocalExchange>, String>;
38
39 async fn find_available_by_building(
41 &self,
42 building_id: Uuid,
43 ) -> Result<Vec<LocalExchange>, String>;
44
45 async fn find_by_type(
47 &self,
48 building_id: Uuid,
49 exchange_type: &str,
50 ) -> Result<Vec<LocalExchange>, String>;
51
52 async fn update(&self, exchange: &LocalExchange) -> Result<LocalExchange, String>;
54
55 async fn delete(&self, id: Uuid) -> Result<bool, String>;
57
58 async fn count_by_building(&self, building_id: Uuid) -> Result<i64, String>;
60
61 async fn count_by_building_and_status(
63 &self,
64 building_id: Uuid,
65 status: &str,
66 ) -> Result<i64, String>;
67
68 async fn get_total_credits_exchanged(&self, building_id: Uuid) -> Result<i32, String>;
70
71 async fn get_average_exchange_rating(&self, building_id: Uuid) -> Result<Option<f32>, String>;
73}