operator/
region_req_factory.rs

1// Copyright 2023 Greptime Team
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 api::v1::region::region_request::Body;
16use api::v1::region::{
17    DeleteRequests as RegionDeleteRequests, InsertRequests as RegionInsertRequests, RegionRequest,
18    RegionRequestHeader,
19};
20
21pub struct RegionRequestFactory {
22    header: RegionRequestHeader,
23}
24
25impl RegionRequestFactory {
26    pub fn new(header: RegionRequestHeader) -> Self {
27        Self { header }
28    }
29
30    pub fn build_insert(&self, requests: RegionInsertRequests) -> RegionRequest {
31        RegionRequest {
32            header: Some(self.header.clone()),
33            body: Some(Body::Inserts(requests)),
34        }
35    }
36
37    pub fn build_delete(&self, requests: RegionDeleteRequests) -> RegionRequest {
38        RegionRequest {
39            header: Some(self.header.clone()),
40            body: Some(Body::Deletes(requests)),
41        }
42    }
43
44    pub fn build_request(&self, body: Body) -> RegionRequest {
45        RegionRequest {
46            header: Some(self.header.clone()),
47            body: Some(body),
48        }
49    }
50}