fe2o3_amqp_management/operations/node/
get_types.rs

1use std::borrow::Cow;
2
3use fe2o3_amqp_types::{messaging::Message, primitives::OrderedMap};
4
5use crate::{constants::GET_TYPES, error::Error, request::Request, response::Response};
6
7use super::get::GetRequest;
8
9/// A trait for handling GetTypes request on a Manageable Node.
10pub trait GetTypes {
11    /// Handles a GetTypes request.
12    fn get_types(&self, req: GetTypesRequest) -> Result<GetTypesResponse, Error>;
13}
14
15/// GET-TYPES
16///
17/// Body:
18///
19/// No information is carried in the message body therefore any message body is valid and MUST be ignored.
20#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
21pub struct GetTypesRequest<'a> {
22    inner: GetRequest<'a>,
23}
24
25impl<'a> GetTypesRequest<'a> {
26    /// Creates a new GetTypes request.
27    pub fn new(
28        entity_type: impl Into<Option<Cow<'a, str>>>,
29        r#type: impl Into<Cow<'a, str>>,
30        locales: Option<impl Into<Cow<'a, str>>>,
31    ) -> Self {
32        Self {
33            inner: GetRequest::new(entity_type, r#type, locales),
34        }
35    }
36}
37
38impl Request for GetTypesRequest<'_> {
39    const OPERATION: &'static str = GET_TYPES;
40
41    type Response = GetTypesResponse;
42
43    type Body = ();
44
45    fn manageable_entity_type(&mut self) -> Option<String> {
46        self.inner.manageable_entity_type()
47    }
48
49    fn locales(&mut self) -> Option<String> {
50        self.inner.locales()
51    }
52
53    fn encode_application_properties(
54        &mut self,
55    ) -> Option<fe2o3_amqp_types::messaging::ApplicationProperties> {
56        self.inner.encode_application_properties()
57    }
58
59    fn encode_body(self) -> Self::Body {}
60}
61
62/// The response to a GetTypes request.
63#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
64pub struct GetTypesResponse {
65    /// The types of the manageable entities.
66    pub types: OrderedMap<String, Vec<String>>,
67}
68
69impl GetTypesResponse {}
70
71impl Response for GetTypesResponse {
72    const STATUS_CODE: u16 = 200;
73
74    type Body = Option<OrderedMap<String, Vec<String>>>;
75
76    type Error = Error;
77
78    fn decode_message(message: Message<Self::Body>) -> Result<Self, Self::Error> {
79        match message.body {
80            Some(types) => Ok(Self { types }),
81            None => Ok(Self {
82                types: OrderedMap::with_capacity(0),
83            }),
84        }
85    }
86}