|
| 1 | +use chrono::{self, NaiveDate, NaiveDateTime}; |
| 2 | +use uuid::{self, Uuid}; |
| 3 | + |
| 4 | +#[cfg(feature = "facet")] |
| 5 | +use facet::Facet; |
| 6 | +#[cfg(feature = "serde")] |
| 7 | +use serde::{Deserialize, Serialize}; |
| 8 | + |
| 9 | +/// The root struct representing the inventory of everything. |
| 10 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 11 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 12 | +#[derive(Clone, Debug)] |
| 13 | +pub struct Inventory { |
| 14 | + pub id: Uuid, |
| 15 | + pub companies: Vec<Company>, |
| 16 | + pub created_at: NaiveDateTime, |
| 17 | + pub metadata: InventoryMetadata, |
| 18 | +} |
| 19 | + |
| 20 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 21 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 22 | +#[derive(Clone, Debug)] |
| 23 | +pub struct InventoryMetadata { |
| 24 | + pub version: String, |
| 25 | + pub region: String, |
| 26 | +} |
| 27 | + |
| 28 | +/// A company represented in the inventory. |
| 29 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 30 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 31 | +#[derive(Clone, Debug)] |
| 32 | +pub struct Company { |
| 33 | + pub id: Uuid, |
| 34 | + pub name: String, |
| 35 | + pub address: Location, |
| 36 | + pub proprietor: CompanyProprietor, |
| 37 | + pub members: Vec<CompanyMember>, |
| 38 | + pub offices: Vec<Office>, |
| 39 | + pub goods: Vec<Item>, |
| 40 | + pub created_at: NaiveDateTime, |
| 41 | +} |
| 42 | + |
| 43 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 44 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 45 | +#[derive(Clone, Debug)] |
| 46 | +pub struct CompanyProprietor { |
| 47 | + pub person: Person, |
| 48 | + pub ownership_percent: f32, |
| 49 | +} |
| 50 | + |
| 51 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 52 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 53 | +#[derive(Clone, Debug)] |
| 54 | +pub struct Office { |
| 55 | + pub id: Uuid, |
| 56 | + pub name: String, |
| 57 | + pub address: Location, |
| 58 | + pub staff: Vec<CompanyMember>, |
| 59 | + pub stock: Vec<OfficeStock>, |
| 60 | + pub open: bool, |
| 61 | +} |
| 62 | + |
| 63 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 64 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 65 | +#[derive(Clone, Debug)] |
| 66 | +pub struct OfficeStock { |
| 67 | + pub item: Item, |
| 68 | + pub quantity: u32, |
| 69 | + pub location_code: Option<String>, |
| 70 | +} |
| 71 | + |
| 72 | +/// A member of the company |
| 73 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 74 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 75 | +#[derive(Clone, Debug)] |
| 76 | +pub struct CompanyMember { |
| 77 | + pub person: Person, |
| 78 | + pub roles: Vec<Position>, |
| 79 | + pub is_active: bool, |
| 80 | + pub created_at: NaiveDateTime, |
| 81 | +} |
| 82 | + |
| 83 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 84 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 85 | +#[derive(Clone, Debug)] |
| 86 | +pub struct Person { |
| 87 | + pub id: Uuid, |
| 88 | + pub username: String, |
| 89 | + pub email: String, |
| 90 | + pub created_at: NaiveDateTime, |
| 91 | + pub updated_at: NaiveDateTime, |
| 92 | + pub profile: PersonProfile, |
| 93 | + pub preferences: Preferences, |
| 94 | +} |
| 95 | + |
| 96 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 97 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 98 | +#[derive(Clone, Debug)] |
| 99 | +pub struct PersonProfile { |
| 100 | + pub first_name: String, |
| 101 | + pub last_name: String, |
| 102 | + pub date_of_birth: NaiveDate, |
| 103 | + pub gender: Sex, |
| 104 | + pub bio: Option<String>, |
| 105 | + pub avatar_url: Option<String>, |
| 106 | + pub home_address: Location, |
| 107 | +} |
| 108 | + |
| 109 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 110 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 111 | +#[derive(Clone, Debug)] |
| 112 | +pub struct Location { |
| 113 | + pub street: String, |
| 114 | + pub city: String, |
| 115 | + pub state: String, |
| 116 | + pub postal_code: String, |
| 117 | + pub country: String, |
| 118 | + pub geo: Option<Coordinates>, |
| 119 | +} |
| 120 | + |
| 121 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 122 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 123 | +#[derive(Clone, Debug)] |
| 124 | +pub struct Coordinates { |
| 125 | + pub latitude: f64, |
| 126 | + pub longitude: f64, |
| 127 | +} |
| 128 | + |
| 129 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 130 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 131 | +#[derive(Clone, Debug)] |
| 132 | +#[repr(u8)] |
| 133 | +pub enum Sex { |
| 134 | + Male, |
| 135 | + Female, |
| 136 | + Other, |
| 137 | + PreferNotToSay, |
| 138 | +} |
| 139 | + |
| 140 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 141 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 142 | +#[derive(Clone, Debug)] |
| 143 | +pub struct Item { |
| 144 | + pub id: Uuid, |
| 145 | + pub name: String, |
| 146 | + pub description: Option<String>, |
| 147 | + pub price_cents: u64, |
| 148 | + pub currency: String, |
| 149 | + pub available: bool, |
| 150 | + pub metadata: Option<ItemMetadata>, |
| 151 | + pub reviews: Vec<ItemReview>, |
| 152 | + pub categories: Vec<Group>, |
| 153 | +} |
| 154 | + |
| 155 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 156 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 157 | +#[derive(Clone, Debug)] |
| 158 | +pub struct ItemMetadata { |
| 159 | + pub sku: Option<String>, |
| 160 | + pub categories: Vec<String>, |
| 161 | + pub weight_grams: Option<u32>, |
| 162 | + pub dimensions: Option<ItemDimensions>, |
| 163 | +} |
| 164 | + |
| 165 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 166 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 167 | +#[derive(Clone, Debug)] |
| 168 | +pub struct ItemDimensions { |
| 169 | + pub length_mm: Option<f32>, |
| 170 | + pub width_mm: Option<f32>, |
| 171 | + pub height_mm: Option<f32>, |
| 172 | +} |
| 173 | + |
| 174 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 175 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 176 | +#[derive(Clone, Debug)] |
| 177 | +pub struct ItemReview { |
| 178 | + pub id: Uuid, |
| 179 | + pub reviewer: PersonSummary, |
| 180 | + pub rating: u8, |
| 181 | + pub text: Option<String>, |
| 182 | + pub created_at: NaiveDateTime, |
| 183 | +} |
| 184 | + |
| 185 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 186 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 187 | +#[derive(Clone, Debug)] |
| 188 | +pub struct Group { |
| 189 | + pub id: Uuid, |
| 190 | + pub name: String, |
| 191 | + pub description: Option<String>, |
| 192 | + pub parent: Option<Box<Group>>, |
| 193 | +} |
| 194 | + |
| 195 | +/// Brief person reference (for lists) |
| 196 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 197 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 198 | +#[derive(Clone, Debug)] |
| 199 | +pub struct PersonSummary { |
| 200 | + pub id: Uuid, |
| 201 | + pub username: String, |
| 202 | + pub avatar_url: Option<String>, |
| 203 | +} |
| 204 | + |
| 205 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 206 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 207 | +#[derive(Clone, Debug)] |
| 208 | +pub struct Position { |
| 209 | + pub id: Uuid, |
| 210 | + pub name: String, |
| 211 | + pub description: Option<String>, |
| 212 | + pub permissions: Vec<Right>, |
| 213 | +} |
| 214 | + |
| 215 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 216 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 217 | +#[derive(Clone, Debug)] |
| 218 | +pub struct Right { |
| 219 | + pub id: Uuid, |
| 220 | + pub name: String, |
| 221 | + pub description: Option<String>, |
| 222 | +} |
| 223 | + |
| 224 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 225 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 226 | +#[derive(Clone, Debug)] |
| 227 | +pub struct Preferences { |
| 228 | + pub person_id: Uuid, |
| 229 | + pub email_notifications: bool, |
| 230 | + pub push_notifications: bool, |
| 231 | + pub theme: Style, |
| 232 | + pub language: String, |
| 233 | +} |
| 234 | + |
| 235 | +#[cfg_attr(feature = "facet", derive(Facet))] |
| 236 | +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
| 237 | +#[derive(Clone, Debug)] |
| 238 | +#[repr(u8)] |
| 239 | +pub enum Style { |
| 240 | + Light, |
| 241 | + Dark, |
| 242 | + System, |
| 243 | +} |
0 commit comments