shared/domain/
locale.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
//! Locale types

use std::collections::BTreeMap;

use crate::api::endpoints::PathPart;
use macros::make_path_parts;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

/// A bundle of [`Entry`]s
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)]
#[serde(rename_all = "camelCase")]
pub struct Bundle {
    /// The bundle's id
    pub id: Uuid,

    /// the bundle's name
    pub name: String,
}

/// What kind of item an [`Entry`] is.
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ItemKind {
    /// The item kind's id
    pub id: Uuid,

    /// the item kind's name
    pub name: String,
}

/// The status of a given [`Entry`]
#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[repr(i16)]
pub enum EntryStatus {
    /// The entry has been approved.
    Approved = 0,

    /// The entry is in discussion.
    Discuss = 1,

    // todo: what does this even *mean*
    /// The entry is on hold.
    OnHold = 2,
}

// todo: an entry into the what?
/// An entry into the ?
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Entry {
    /// This entry's id
    pub id: u32,

    /// This entry's parent [`Bundle`]'s id
    pub bundle_id: Uuid,

    /// The section this entry belongs in
    pub section: Option<String>,

    /// This entry's [`ItemKind`]'s id.
    pub item_kind_id: Option<Uuid>,

    /// The English version of this entry.
    pub english: Option<String>,

    /// The hebrew version of this entry.
    pub hebrew: Option<String>,

    /// This entry's current status.
    pub status: EntryStatus,

    /// A reference url in zeplin
    pub zeplin_reference: Option<String>,

    /// This entry's comments
    pub comments: Option<String>,

    /// If the entry is in the app.
    pub in_app: bool,

    /// If the entry is in an element.
    pub in_element: bool,

    /// If the entry is in mock.
    pub in_mock: bool,
}

make_path_parts!(CreateEntryPath => "/v1/locale/entry");

/// Request for creating an entry.
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CreateEntryRequest {
    /// This entry's parent [`Bundle`]'s id
    pub bundle_id: Uuid,

    /// The section this entry belongs in
    pub section: Option<String>,

    /// This entry's [`ItemKind`]'s id.
    pub item_kind_id: Option<Uuid>,

    /// The English version of this entry.
    pub english: Option<String>,

    /// The hebrew version of this entry.
    pub hebrew: Option<String>,

    /// This entry's current status.
    pub status: EntryStatus,

    /// A reference url in zeplin
    pub zeplin_reference: Option<String>,

    /// This entry's comments
    pub comments: Option<String>,

    /// If the entry is in the app.
    pub in_app: bool,

    /// If the entry is in an element.
    pub in_element: bool,

    /// If the entry is in mock.
    pub in_mock: bool,
}

/// Response for successful creation of an entry.
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CreateEntryResponse {
    /// The newly created [`Entry`]'s id.
    pub id: u32,
}

/// Group by modifier for listing entries
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub enum ListEntryGroupBy {
    /// No grouping, just return a plain list
    None,

    /// Group by parent bundle
    Bundle,
}

impl ListEntryGroupBy {
    /// Returns `true` if `self` is [`None`](Self::None).
    pub fn is_none(&self) -> bool {
        matches!(self, Self::None)
    }

    /// Returns `true` if `self` is [`Bundle`](Self::Bundle).
    pub fn is_bundle(&self) -> bool {
        matches!(self, Self::Bundle)
    }
}

impl Default for ListEntryGroupBy {
    fn default() -> Self {
        Self::None
    }
}

make_path_parts!(ListEntryPath => "/v1/locale/entry");

/// Query for listing [`entries`](Entry)
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct ListEntryQuery {
    /// The [`Bundle`]s to filter to (empty means "all")
    #[serde(skip_serializing_if = "Vec::is_empty")]
    #[serde(default)]
    #[serde(
        serialize_with = "crate::domain::csv_encode_uuids",
        deserialize_with = "crate::domain::from_csv"
    )]
    pub bundles: Vec<Uuid>,

    /// Whether the response should be returned as
    /// [`Bundles`](ListEntryResponse::Bundles) or [`List`](ListEntryResponse::List)
    #[serde(skip_serializing_if = "ListEntryGroupBy::is_none")]
    #[serde(default)]
    pub group_by: ListEntryGroupBy,
}

/// Response for listing entries
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub enum ListEntryResponse {
    /// Entries grouped by [`Bundle`]
    Bundles(BTreeMap<Uuid, Vec<Entry>>),

    /// Ungrouped entries
    List(Vec<Entry>),
}

// u32 is local id
make_path_parts!(GetEntryPath => "/v1/locale/entry/{}" => u32);

/// Response for getting a individual entry.
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GetEntryResponse {
    /// The requested entry.
    pub entry: Entry,
}

// u32 is local id
make_path_parts!(UpdateEntryPath => "/v1/locale/entry/{}" => u32);

/// Request for updating an [`Entry`]
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct UpdateEntryRequest {
    /// This entry's parent [`Bundle`]'s id
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub bundle_id: Option<Uuid>,

    /// The section this entry belongs in
    #[serde(deserialize_with = "super::deserialize_optional_field")]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub section: Option<Option<String>>,

    /// This entry's [`ItemKind`]'s id.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub item_kind_id: Option<Uuid>,

    /// The English version of this entry.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub english: Option<String>,

    /// The hebrew version of this entry.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub hebrew: Option<String>,

    /// This entry's current status.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub status: Option<EntryStatus>,

    /// A reference url in zeplin
    #[serde(deserialize_with = "super::deserialize_optional_field")]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub zeplin_reference: Option<Option<String>>,

    /// This entry's comments
    #[serde(deserialize_with = "super::deserialize_optional_field")]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub comments: Option<Option<String>>,

    /// If the entry is in the app.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub in_app: Option<bool>,

    /// If the entry is in an element.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub in_element: Option<bool>,

    /// If the entry is in mock.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default)]
    pub in_mock: Option<bool>,
}

// u32 is local id
make_path_parts!(DeleteEntryPath => "/v1/locale/entry/{}" => u32);

make_path_parts!(ListBundlePath => "/v1/locale/bundle");

/// Response for listing bundles
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ListBundleResponse {
    /// A list of bundles
    pub bundles: Vec<Bundle>,
}

make_path_parts!(ListItemKindPath => "/v1/locale/item-kind");

/// Response for listing item kinds
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ListItemKindResponse {
    /// A list of item kinds
    pub item_kinds: Vec<ItemKind>,
}