shared/domain/jig/
report.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! Types for Jig short codes for sharing
use chrono::{DateTime, Utc};
use macros::make_path_parts;
use serde::{Deserialize, Serialize};
use strum_macros::EnumIter;
use uuid::Uuid;

use crate::api::endpoints::PathPart;

use super::JigId;

wrap_uuid! {
    /// Wrapper type around [`Uuid`](Uuid), represents the ID of a curation comment.
    pub struct ReportId
}

make_path_parts!(GetJigReportPath => "/v1/jig/{}/report/{}" => JigId, ReportId);

/// Jig report details
#[derive(Serialize, Deserialize, Clone, Debug)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[serde(rename_all = "camelCase")]
pub struct JigReport {
    /// Id of report
    pub id: ReportId,

    /// Id of reported jig
    pub jig_id: JigId,

    /// Type of     report
    pub report_type: JigReportType,

    /// Optional id of reporter
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reporter_id: Option<Uuid>,

    /// Optional name for reporter
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reporter_name: Option<String>,

    /// Optional email of reporter
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reporter_email: Option<String>,

    /// When report was submitted
    pub created_at: DateTime<Utc>,
}

make_path_parts!(CreateJigReportPath => "/v1/jig/{}/report" => JigId);

/// Request for reporting a jig
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CreateJigReport {
    /// Description of the jig.
    pub report_type: JigReportType,
}

/// Request for reporting a jig
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct JigReportEmail {
    /// Display name of the jig.
    pub display_name: String,

    /// Report type of the report.
    pub report_type: JigReportType,

    /// Optional name for reporter
    pub reporter_name: Option<String>,

    /// Optional email of reporter
    pub reporter_email: Option<String>,

    /// Creator name of jig
    pub creator_name: String,
}

/// Type of report
#[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Debug, EnumIter)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[serde(rename_all = "camelCase")]
#[repr(i16)]
pub enum JigReportType {
    #[allow(missing_docs)]
    Offensive = 0,
    #[allow(missing_docs)]
    CopyrightInfringement = 1,
    #[allow(missing_docs)]
    Spam = 2,
    #[allow(missing_docs)]
    Privacy = 3,
    #[allow(missing_docs)]
    JiTapGameNotPlaying = 4,
    #[allow(missing_docs)]
    Other = 5,
}

impl JigReportType {
    #[allow(missing_docs)]
    pub fn as_str(&self) -> &'static str {
        match self {
            JigReportType::Offensive => "Offensive",
            JigReportType::CopyrightInfringement => "Copyright Infringement",
            JigReportType::Spam => "Spam",
            JigReportType::Privacy => "Privacy",
            JigReportType::JiTapGameNotPlaying => "Ji Tap Game Not Playing",
            JigReportType::Other => "Other",
        }
    }

    #[allow(missing_docs)]
    pub fn to_value_str(&self) -> String {
        serde_json::to_string(&self).unwrap()
    }

    #[allow(missing_docs)]
    pub fn from_value_str(s: &str) -> Self {
        serde_json::from_str(s).unwrap()
    }
}