use crate::http::http_client::HttpClient;
use crate::http::http_transport::HttpTransport;
use crate::prelude::{Identifier, IggyError};
use async_trait::async_trait;
use iggy_common::PartitionClient;
use iggy_common::create_partitions::CreatePartitions;
use iggy_common::delete_partitions::DeletePartitions;
#[async_trait]
impl PartitionClient for HttpClient {
async fn create_partitions(
&self,
stream_id: &Identifier,
topic_id: &Identifier,
partitions_count: u32,
) -> Result<(), IggyError> {
self.post(
&get_path(&stream_id.as_cow_str(), &topic_id.as_cow_str()),
&CreatePartitions {
stream_id: stream_id.clone(),
topic_id: topic_id.clone(),
partitions_count,
},
)
.await?;
Ok(())
}
async fn delete_partitions(
&self,
stream_id: &Identifier,
topic_id: &Identifier,
partitions_count: u32,
) -> Result<(), IggyError> {
self.delete_with_query(
&get_path(&stream_id.as_cow_str(), &topic_id.as_cow_str()),
&DeletePartitions {
stream_id: stream_id.clone(),
topic_id: topic_id.clone(),
partitions_count,
},
)
.await?;
Ok(())
}
}
fn get_path(stream_id: &str, topic_id: &str) -> String {
format!("streams/{stream_id}/topics/{topic_id}/partitions")
}