apisix_admin_client/models/
consumer_group_requests.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use serde::{Deserialize, Serialize};
use crate::models::generate_identifier;
use crate::plugins::Plugins;
use crate::{Result};

#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ConsumerGroupBuilder {
    pub plugins: Plugins,
    pub id: Option<String>,
    pub desc: Option<String>,
}

impl ConsumerGroupBuilder {
    pub fn new() -> Self {
        ConsumerGroupRequest::default().into()
    }

    pub fn with_id(mut self, id: String) -> Self {
        self.id = Some(id);
        self
    }

    /// Description of usage scenarios
    pub fn with_desc(mut self, desc: String) -> Self {
        self.desc = Some(desc);
        self
    }

    /// Plugins that are executed during the request/response cycle. See [@Plugins] for more
    pub fn with_plugins(mut self, plugins: Plugins) -> Self {
        self.plugins = plugins;
        self
    }

    pub fn build(&self) -> Result<ConsumerGroupRequest> {
        Ok(ConsumerGroupRequest {
            plugins: self.plugins.clone(),
            id: self.id.clone(),
            desc: self.desc.clone(),
        })
    }
}

#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ConsumerGroupRequest {
    pub plugins: Plugins,
    pub id: Option<String>,
    pub desc: Option<String>,
}

impl Default for ConsumerGroupRequest {
    fn default() -> Self {
        ConsumerGroupRequest {
            plugins: Plugins::default(),
            id: Some(generate_identifier()),
            desc: None,
        }
    }
}

impl From<ConsumerGroupRequest> for ConsumerGroupBuilder {
    fn from(consumer_group: ConsumerGroupRequest) -> Self {
        ConsumerGroupBuilder {
            plugins: consumer_group.plugins,
            id: consumer_group.id,
            desc: consumer_group.desc,
        }
    }
}