use std::collections::BTreeMap;
use crate::api::endpoints::PathPart;
use macros::make_path_parts;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)]
#[serde(rename_all = "camelCase")]
pub struct Bundle {
pub id: Uuid,
pub name: String,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ItemKind {
pub id: Uuid,
pub name: String,
}
#[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 {
Approved = 0,
Discuss = 1,
OnHold = 2,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Entry {
pub id: u32,
pub bundle_id: Uuid,
pub section: Option<String>,
pub item_kind_id: Option<Uuid>,
pub english: Option<String>,
pub hebrew: Option<String>,
pub status: EntryStatus,
pub zeplin_reference: Option<String>,
pub comments: Option<String>,
pub in_app: bool,
pub in_element: bool,
pub in_mock: bool,
}
make_path_parts!(CreateEntryPath => "/v1/locale/entry");
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CreateEntryRequest {
pub bundle_id: Uuid,
pub section: Option<String>,
pub item_kind_id: Option<Uuid>,
pub english: Option<String>,
pub hebrew: Option<String>,
pub status: EntryStatus,
pub zeplin_reference: Option<String>,
pub comments: Option<String>,
pub in_app: bool,
pub in_element: bool,
pub in_mock: bool,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CreateEntryResponse {
pub id: u32,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub enum ListEntryGroupBy {
None,
Bundle,
}
impl ListEntryGroupBy {
pub fn is_none(&self) -> bool {
matches!(self, Self::None)
}
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");
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct ListEntryQuery {
#[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>,
#[serde(skip_serializing_if = "ListEntryGroupBy::is_none")]
#[serde(default)]
pub group_by: ListEntryGroupBy,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub enum ListEntryResponse {
Bundles(BTreeMap<Uuid, Vec<Entry>>),
List(Vec<Entry>),
}
make_path_parts!(GetEntryPath => "/v1/locale/entry/{}" => u32);
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GetEntryResponse {
pub entry: Entry,
}
make_path_parts!(UpdateEntryPath => "/v1/locale/entry/{}" => u32);
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct UpdateEntryRequest {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub bundle_id: Option<Uuid>,
#[serde(deserialize_with = "super::deserialize_optional_field")]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub section: Option<Option<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub item_kind_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub english: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub hebrew: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub status: Option<EntryStatus>,
#[serde(deserialize_with = "super::deserialize_optional_field")]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub zeplin_reference: Option<Option<String>>,
#[serde(deserialize_with = "super::deserialize_optional_field")]
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub comments: Option<Option<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub in_app: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub in_element: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub in_mock: Option<bool>,
}
make_path_parts!(DeleteEntryPath => "/v1/locale/entry/{}" => u32);
make_path_parts!(ListBundlePath => "/v1/locale/bundle");
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ListBundleResponse {
pub bundles: Vec<Bundle>,
}
make_path_parts!(ListItemKindPath => "/v1/locale/item-kind");
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ListItemKindResponse {
pub item_kinds: Vec<ItemKind>,
}