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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use derive_builder::Builder;
use http::Method;
use std::borrow::Cow;
use crate::api::custom_fields::CustomFieldEssentialsWithValue;
use crate::api::{Endpoint, ReturnsJsonResponse};
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct MyAccount {
pub id: u64,
pub login: String,
pub admin: bool,
pub firstname: String,
pub lastname: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub mail: Option<String>,
#[serde(
serialize_with = "crate::api::serialize_rfc3339",
deserialize_with = "crate::api::deserialize_rfc3339"
)]
pub created_on: time::OffsetDateTime,
#[serde(
serialize_with = "crate::api::serialize_optional_rfc3339",
deserialize_with = "crate::api::deserialize_optional_rfc3339"
)]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_login_on: Option<time::OffsetDateTime>,
pub api_key: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub custom_fields: Option<Vec<CustomFieldEssentialsWithValue>>,
}
#[derive(Debug, Builder)]
#[builder(setter(strip_option))]
pub struct GetMyAccount {}
impl ReturnsJsonResponse for GetMyAccount {}
impl GetMyAccount {
#[must_use]
pub fn builder() -> GetMyAccountBuilder {
GetMyAccountBuilder::default()
}
}
impl<'a> Endpoint for GetMyAccount {
fn method(&self) -> Method {
Method::GET
}
fn endpoint(&self) -> Cow<'static, str> {
"my/account.json".into()
}
}
#[cfg(test)]
mod test {
use super::*;
use crate::api::users::UserWrapper;
use pretty_assertions::assert_eq;
use std::error::Error;
use tracing_test::traced_test;
#[traced_test]
#[test]
fn test_get_my_account() -> Result<(), Box<dyn Error>> {
dotenv::dotenv()?;
let redmine = crate::api::Redmine::from_env()?;
let endpoint = GetMyAccount::builder().build()?;
redmine.json_response_body::<_, UserWrapper<MyAccount>>(&endpoint)?;
Ok(())
}
#[traced_test]
#[test]
fn test_completeness_my_account_type() -> Result<(), Box<dyn Error>> {
dotenv::dotenv()?;
let redmine = crate::api::Redmine::from_env()?;
let endpoint = GetMyAccount::builder().build()?;
let UserWrapper { user: value } =
redmine.json_response_body::<_, UserWrapper<serde_json::Value>>(&endpoint)?;
let o: MyAccount = serde_json::from_value(value.clone())?;
let reserialized = serde_json::to_value(o)?;
assert_eq!(value, reserialized);
Ok(())
}
}