redmine_api/api/
enumerations.rs

1//! Enumerations Rest API Endpoint definitions
2//!
3//! [Redmine Documentation](https://www.redmine.org/projects/redmine/wiki/Rest_Enumerations)
4//!
5//! - [x] all issue priorities endpoint
6//! - [x] all time entry activities endpoint
7//! - [x] all document categories endpoint
8
9use derive_builder::Builder;
10use reqwest::Method;
11use std::borrow::Cow;
12
13use crate::api::{Endpoint, ReturnsJsonResponse};
14
15/// a minimal type for Redmine issue priorities included in
16/// other Redmine objects
17#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
18pub struct IssuePriorityEssentials {
19    /// numeric id
20    pub id: u64,
21    /// display name
22    pub name: String,
23}
24
25impl From<IssuePriority> for IssuePriorityEssentials {
26    fn from(v: IssuePriority) -> Self {
27        IssuePriorityEssentials {
28            id: v.id,
29            name: v.name,
30        }
31    }
32}
33
34impl From<&IssuePriority> for IssuePriorityEssentials {
35    fn from(v: &IssuePriority) -> Self {
36        IssuePriorityEssentials {
37            id: v.id,
38            name: v.name.to_owned(),
39        }
40    }
41}
42
43/// a type for issue priority to use as an API return type
44///
45/// alternatively you can use your own type limited to the fields you need
46#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
47pub struct IssuePriority {
48    /// numeric id
49    pub id: u64,
50    /// display name
51    pub name: String,
52    /// whether this value is the default value
53    pub is_default: bool,
54}
55
56/// The endpoint for all issue priorities
57#[derive(Debug, Clone, Builder)]
58#[builder(setter(strip_option))]
59pub struct ListIssuePriorities {}
60
61impl ReturnsJsonResponse for ListIssuePriorities {}
62
63impl ListIssuePriorities {
64    /// Create a builder for the endpoint.
65    #[must_use]
66    pub fn builder() -> ListIssuePrioritiesBuilder {
67        ListIssuePrioritiesBuilder::default()
68    }
69}
70
71impl Endpoint for ListIssuePriorities {
72    fn method(&self) -> Method {
73        Method::GET
74    }
75
76    fn endpoint(&self) -> Cow<'static, str> {
77        "enumerations/issue_priorities.json".into()
78    }
79}
80
81/// helper struct for outer layers with a issue_priorities field holding the inner data
82#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
83pub struct IssuePrioritiesWrapper<T> {
84    /// to parse JSON with issue_priorities key
85    pub issue_priorities: Vec<T>,
86}
87
88/// a minimal type for Redmine time entry activities included in
89/// other Redmine objects
90#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
91pub struct TimeEntryActivityEssentials {
92    /// numeric id
93    pub id: u64,
94    /// display name
95    pub name: String,
96}
97
98impl From<TimeEntryActivity> for TimeEntryActivityEssentials {
99    fn from(v: TimeEntryActivity) -> Self {
100        TimeEntryActivityEssentials {
101            id: v.id,
102            name: v.name,
103        }
104    }
105}
106
107impl From<&TimeEntryActivity> for TimeEntryActivityEssentials {
108    fn from(v: &TimeEntryActivity) -> Self {
109        TimeEntryActivityEssentials {
110            id: v.id,
111            name: v.name.to_owned(),
112        }
113    }
114}
115
116/// a type for time entry activity to use as an API return type
117///
118/// alternatively you can use your own type limited to the fields you need
119#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
120pub struct TimeEntryActivity {
121    /// numeric id
122    pub id: u64,
123    /// display name
124    pub name: String,
125    /// whether this value is the default value
126    pub is_default: bool,
127}
128
129/// The endpoint for all time entry activities
130#[derive(Debug, Clone, Builder)]
131#[builder(setter(strip_option))]
132pub struct ListTimeEntryActivities {}
133
134impl ReturnsJsonResponse for ListTimeEntryActivities {}
135
136impl ListTimeEntryActivities {
137    /// Create a builder for the endpoint.
138    #[must_use]
139    pub fn builder() -> ListTimeEntryActivitiesBuilder {
140        ListTimeEntryActivitiesBuilder::default()
141    }
142}
143
144impl Endpoint for ListTimeEntryActivities {
145    fn method(&self) -> Method {
146        Method::GET
147    }
148
149    fn endpoint(&self) -> Cow<'static, str> {
150        "enumerations/time_entry_activities.json".into()
151    }
152}
153
154/// helper struct for outer layers with a time_entry_activities field holding the inner data
155#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
156pub struct TimeEntryActivitiesWrapper<T> {
157    /// to parse JSON with time_entry_activities key
158    pub time_entry_activities: Vec<T>,
159}
160
161/// a minimal type for Redmine document categories included in
162/// other Redmine objects
163#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
164pub struct DocumentCategoryEssentials {
165    /// numeric id
166    pub id: u64,
167    /// display name
168    pub name: String,
169}
170
171impl From<DocumentCategory> for DocumentCategoryEssentials {
172    fn from(v: DocumentCategory) -> Self {
173        DocumentCategoryEssentials {
174            id: v.id,
175            name: v.name,
176        }
177    }
178}
179
180impl From<&DocumentCategory> for DocumentCategoryEssentials {
181    fn from(v: &DocumentCategory) -> Self {
182        DocumentCategoryEssentials {
183            id: v.id,
184            name: v.name.to_owned(),
185        }
186    }
187}
188
189/// a type for document category to use as an API return type
190///
191/// alternatively you can use your own type limited to the fields you need
192#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
193pub struct DocumentCategory {
194    /// numeric id
195    pub id: u64,
196    /// display name
197    pub name: String,
198    /// whether this value is the default value
199    pub is_default: bool,
200}
201
202/// The endpoint for all document categories
203#[derive(Debug, Clone, Builder)]
204#[builder(setter(strip_option))]
205pub struct ListDocumentCategories {}
206
207impl ReturnsJsonResponse for ListDocumentCategories {}
208
209impl ListDocumentCategories {
210    /// Create a builder for the endpoint.
211    #[must_use]
212    pub fn builder() -> ListDocumentCategoriesBuilder {
213        ListDocumentCategoriesBuilder::default()
214    }
215}
216
217impl Endpoint for ListDocumentCategories {
218    fn method(&self) -> Method {
219        Method::GET
220    }
221
222    fn endpoint(&self) -> Cow<'static, str> {
223        "enumerations/document_categories.json".into()
224    }
225}
226
227/// helper struct for outer layers with a document_categories field holding the inner data
228#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
229pub struct DocumentCategoriesWrapper<T> {
230    /// to parse JSON with document_categories key
231    pub document_categories: Vec<T>,
232}
233
234#[cfg(test)]
235mod test {
236    use super::*;
237    use std::error::Error;
238    use tracing_test::traced_test;
239
240    #[traced_test]
241    #[test]
242    fn test_list_issue_priorities_no_pagination() -> Result<(), Box<dyn Error>> {
243        dotenvy::dotenv()?;
244        let redmine = crate::api::Redmine::from_env()?;
245        let endpoint = ListIssuePriorities::builder().build()?;
246        redmine.json_response_body::<_, IssuePrioritiesWrapper<IssuePriority>>(&endpoint)?;
247        Ok(())
248    }
249
250    #[traced_test]
251    #[test]
252    fn test_list_time_entry_activities_no_pagination() -> Result<(), Box<dyn Error>> {
253        dotenvy::dotenv()?;
254        let redmine = crate::api::Redmine::from_env()?;
255        let endpoint = ListTimeEntryActivities::builder().build()?;
256        redmine
257            .json_response_body::<_, TimeEntryActivitiesWrapper<TimeEntryActivity>>(&endpoint)?;
258        Ok(())
259    }
260
261    #[traced_test]
262    #[test]
263    fn test_list_document_categories_no_pagination() -> Result<(), Box<dyn Error>> {
264        dotenvy::dotenv()?;
265        let redmine = crate::api::Redmine::from_env()?;
266        let endpoint = ListDocumentCategories::builder().build()?;
267        redmine.json_response_body::<_, DocumentCategoriesWrapper<DocumentCategory>>(&endpoint)?;
268        Ok(())
269    }
270}