1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::api::_generic::handle_response;
use crate::errors::RabbitMqClientError;
use crate::RabbitMqClient;
use async_trait::async_trait;
use serde::Deserialize;

#[async_trait]
pub trait ConnectionApi {
    async fn list_connections(
        &self,
        vhost: Option<String>,
    ) -> Result<Vec<RabbitMqConnection>, RabbitMqClientError>;
}

#[async_trait]
impl ConnectionApi for RabbitMqClient {
    async fn list_connections(
        &self,
        vhost: Option<String>,
    ) -> Result<Vec<RabbitMqConnection>, RabbitMqClientError> {
        let endpoint = match vhost {
            None => format!("{}/api/connections", self.api_url),
            Some(vhost) => format!("{}/api/vhosts/{}/connections", self.api_url, vhost),
        };

        let response = self
            .client
            .request(reqwest::Method::GET, &endpoint)
            .send()
            .await?;

        handle_response(response).await
    }
}

#[derive(Debug, Deserialize)]
pub struct RabbitMqConnection {}