shared/domain/jig/
report.rs1use 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 pub struct ReportId
15}
16
17make_path_parts!(GetJigReportPath => "/v1/jig/{}/report/{}" => JigId, ReportId);
18
19#[derive(Serialize, Deserialize, Clone, Debug)]
21#[cfg_attr(feature = "backend", derive(sqlx::Type))]
22#[serde(rename_all = "camelCase")]
23pub struct JigReport {
24 pub id: ReportId,
26
27 pub jig_id: JigId,
29
30 pub report_type: JigReportType,
32
33 #[serde(skip_serializing_if = "Option::is_none")]
35 pub reporter_id: Option<Uuid>,
36
37 #[serde(skip_serializing_if = "Option::is_none")]
39 pub reporter_name: Option<String>,
40
41 #[serde(skip_serializing_if = "Option::is_none")]
43 pub reporter_email: Option<String>,
44
45 pub created_at: DateTime<Utc>,
47}
48
49make_path_parts!(CreateJigReportPath => "/v1/jig/{}/report" => JigId);
50
51#[derive(Serialize, Deserialize, Debug)]
53#[serde(rename_all = "camelCase")]
54pub struct CreateJigReport {
55 pub report_type: JigReportType,
57}
58
59#[derive(Serialize, Deserialize, Debug)]
61#[serde(rename_all = "camelCase")]
62pub struct JigReportEmail {
63 pub display_name: String,
65
66 pub report_type: JigReportType,
68
69 pub reporter_name: Option<String>,
71
72 pub reporter_email: Option<String>,
74
75 pub creator_name: String,
77}
78
79#[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}