blob: 3fd9daed630258190b6dc6c9fb00f8f29b2e48c8 [file] [log] [blame]
use crate::client::PartitionClient;
use crate::error::IggyError;
use crate::http::client::HttpClient;
use crate::http::HttpTransport;
use crate::identifier::Identifier;
use crate::partitions::create_partitions::CreatePartitions;
use crate::partitions::delete_partitions::DeletePartitions;
use async_trait::async_trait;
#[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")
}