samling/
entities.rs

1use bytes::Bytes;
2use reqwest::Url;
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::{signing::Claims, Id, Organization, User};
7
8#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, strum::EnumString, strum::Display)]
9#[serde(rename_all = "snake_case")]
10#[strum(serialize_all = "snake_case")]
11pub enum Environment {
12    Production,
13    Staging,
14    Development,
15}
16
17#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]
18#[serde(rename_all = "snake_case")]
19pub enum ImageSource {
20    Url(Url),
21    Bytes(Bytes),
22    Base64(String),
23}
24
25impl From<Url> for ImageSource {
26    fn from(url: Url) -> Self {
27        ImageSource::Url(url)
28    }
29}
30
31impl From<Bytes> for ImageSource {
32    fn from(data: Bytes) -> Self {
33        ImageSource::Bytes(data)
34    }
35}
36
37/// Information about which organization data is requested for, and by whom
38#[derive(Debug, Clone, Copy)]
39pub struct RequestMetaData {
40    user_id: Id<User>,
41    organization_id: Id<Organization>,
42}
43
44impl RequestMetaData {
45    pub fn new(claims: &Claims, organization_id: Id<Organization>) -> Self {
46        Self {
47            user_id: claims.user_id(),
48            organization_id,
49        }
50    }
51
52    pub fn user_id(&self) -> Id<User> {
53        self.user_id
54    }
55
56    pub fn organization_id(&self) -> Id<Organization> {
57        self.organization_id
58    }
59}