backend/keycloak_api/traits.rs
1//! Traits for the Keycloak API.
2
3use async_trait::async_trait;
4
5use crate::model::dto::{PageParameters, UserSearchParameters};
6
7use super::{errors::KeycloakApiError, UserDto};
8
9/// Helper type for results.
10pub type Result<T> = std::result::Result<T, KeycloakApiError>;
11
12#[async_trait]
13pub trait KeycloakApi {
14 /// Search for users by their username.
15 ///
16 /// # Errors
17 /// - If the url cannot be parsed.
18 /// - If the authorization header cannot be created.
19 /// - If the request fails or the response cannot be deserialized.
20 async fn search_users_by_username(
21 &self,
22 search_params: &UserSearchParameters,
23 pagination: &PageParameters,
24 client: &reqwest::Client,
25 ) -> Result<Vec<UserDto>>;
26
27 /// Gets all users given their ids from the Keycloak API.
28 ///
29 /// # Errors
30 /// - If the url cannot be parsed.
31 /// - If the authorization header cannot be created.
32 /// - If the request fails or the response cannot be deserialized.
33 async fn get_users_by_ids(
34 &self,
35 client: &reqwest::Client,
36 user_ids: Vec<uuid::Uuid>,
37 ) -> Result<Vec<UserDto>>;
38
39 /// Gets a user by its id from the Keycloak API.
40 ///
41 /// # Errors
42 /// - If the url cannot be parsed.
43 /// - If the authorization header cannot be created.
44 /// - If the request fails or the response cannot be deserialized.
45 async fn get_user_by_id(
46 &self,
47 client: &reqwest::Client,
48 user_id: uuid::Uuid,
49 ) -> Result<UserDto>;
50}