use rama::{Context, Service};
use tansu_sans_io::{ApiKey, DeleteRecordsRequest, DeleteRecordsResponse};
use tracing::instrument;
use crate::{Error, Result, Storage};
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct DeleteRecordsService;
impl ApiKey for DeleteRecordsService {
const KEY: i16 = DeleteRecordsRequest::KEY;
}
impl<G> Service<G, DeleteRecordsRequest> for DeleteRecordsService
where
G: Storage,
{
type Response = DeleteRecordsResponse;
type Error = Error;
#[instrument(skip(ctx, req))]
async fn serve(
&self,
ctx: Context<G>,
req: DeleteRecordsRequest,
) -> Result<Self::Response, Self::Error> {
ctx.state()
.delete_records(req.topics.as_deref().unwrap_or_default())
.await
.map(Some)
.map(|topics| {
DeleteRecordsResponse::default()
.throttle_time_ms(0)
.topics(topics)
})
}
}