tansu_storage/service/delete_records.rs
1// Copyright ⓒ 2024-2025 Peter Morgan <peter.james.morgan@gmail.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use rama::{Context, Service};
16use tansu_sans_io::{ApiKey, DeleteRecordsRequest, DeleteRecordsResponse};
17use tracing::instrument;
18
19use crate::{Error, Result, Storage};
20
21/// A [`Service`] using [`Storage`] as [`Context`] taking [`DeleteRecordsRequest`] returning [`DeleteRecordsResponse`].
22#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
23pub struct DeleteRecordsService;
24
25impl ApiKey for DeleteRecordsService {
26 const KEY: i16 = DeleteRecordsRequest::KEY;
27}
28
29impl<G> Service<G, DeleteRecordsRequest> for DeleteRecordsService
30where
31 G: Storage,
32{
33 type Response = DeleteRecordsResponse;
34 type Error = Error;
35
36 #[instrument(skip(ctx, req))]
37 async fn serve(
38 &self,
39 ctx: Context<G>,
40 req: DeleteRecordsRequest,
41 ) -> Result<Self::Response, Self::Error> {
42 ctx.state()
43 .delete_records(req.topics.as_deref().unwrap_or_default())
44 .await
45 .map(Some)
46 .map(|topics| {
47 DeleteRecordsResponse::default()
48 .throttle_time_ms(0)
49 .topics(topics)
50 })
51 }
52}