shared/domain/jig/
report.rs

1//! Types for Jig short codes for sharing
2use chrono::{DateTime, Utc};
3use macros::make_path_parts;
4use serde::{Deserialize, Serialize};
5use strum_macros::EnumIter;
6use uuid::Uuid;
7
8use crate::api::endpoints::PathPart;
9
10use super::JigId;
11
12wrap_uuid! {
13    /// Wrapper type around [`Uuid`](Uuid), represents the ID of a curation comment.
14    pub struct ReportId
15}
16
17make_path_parts!(GetJigReportPath => "/v1/jig/{}/report/{}" => JigId, ReportId);
18
19/// Jig report details
20#[derive(Serialize, Deserialize, Clone, Debug)]
21#[cfg_attr(feature = "backend", derive(sqlx::Type))]
22#[serde(rename_all = "camelCase")]
23pub struct JigReport {
24    /// Id of report
25    pub id: ReportId,
26
27    /// Id of reported jig
28    pub jig_id: JigId,
29
30    /// Type of     report
31    pub report_type: JigReportType,
32
33    /// Optional id of reporter
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub reporter_id: Option<Uuid>,
36
37    /// Optional name for reporter
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub reporter_name: Option<String>,
40
41    /// Optional email of reporter
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub reporter_email: Option<String>,
44
45    /// When report was submitted
46    pub created_at: DateTime<Utc>,
47}
48
49make_path_parts!(CreateJigReportPath => "/v1/jig/{}/report" => JigId);
50
51/// Request for reporting a jig
52#[derive(Serialize, Deserialize, Debug)]
53#[serde(rename_all = "camelCase")]
54pub struct CreateJigReport {
55    /// Description of the jig.
56    pub report_type: JigReportType,
57}
58
59/// Request for reporting a jig
60#[derive(Serialize, Deserialize, Debug)]
61#[serde(rename_all = "camelCase")]
62pub struct JigReportEmail {
63    /// Display name of the jig.
64    pub display_name: String,
65
66    /// Report type of the report.
67    pub report_type: JigReportType,
68
69    /// Optional name for reporter
70    pub reporter_name: Option<String>,
71
72    /// Optional email of reporter
73    pub reporter_email: Option<String>,
74
75    /// Creator name of jig
76    pub creator_name: String,
77}
78
79/// Type of report
80#[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Debug, EnumIter)]
81#[cfg_attr(feature = "backend", derive(sqlx::Type))]
82#[serde(rename_all = "camelCase")]
83#[repr(i16)]
84pub enum JigReportType {
85    #[allow(missing_docs)]
86    Offensive = 0,
87    #[allow(missing_docs)]
88    CopyrightInfringement = 1,
89    #[allow(missing_docs)]
90    Spam = 2,
91    #[allow(missing_docs)]
92    Privacy = 3,
93    #[allow(missing_docs)]
94    JiTapGameNotPlaying = 4,
95    #[allow(missing_docs)]
96    Other = 5,
97}
98
99impl JigReportType {
100    #[allow(missing_docs)]
101    pub fn as_str(&self) -> &'static str {
102        match self {
103            JigReportType::Offensive => "Offensive",
104            JigReportType::CopyrightInfringement => "Copyright Infringement",
105            JigReportType::Spam => "Spam",
106            JigReportType::Privacy => "Privacy",
107            JigReportType::JiTapGameNotPlaying => "Ji Tap Game Not Playing",
108            JigReportType::Other => "Other",
109        }
110    }
111
112    #[allow(missing_docs)]
113    pub fn to_value_str(&self) -> String {
114        serde_json::to_string(&self).unwrap()
115    }
116
117    #[allow(missing_docs)]
118    pub fn from_value_str(s: &str) -> Self {
119        serde_json::from_str(s).unwrap()
120    }
121}