shared/domain/resource/
report.rsuse 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::ResourceId;
wrap_uuid! {
pub struct ReportId
}
make_path_parts!(GetResourceReportPath => "/v1/resource/{}/report/{}" => ResourceId, ReportId);
#[derive(Serialize, Deserialize, Clone, Debug)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[serde(rename_all = "camelCase")]
pub struct ResourceReport {
pub id: ReportId,
pub resource_id: ResourceId,
pub report_type: ResourceReportType,
#[serde(skip_serializing_if = "Option::is_none")]
pub reporter_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reporter_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reporter_email: Option<String>,
pub created_at: DateTime<Utc>,
}
make_path_parts!(CreateResourceReportPath => "/v1/resource/{}/report" => ResourceId);
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CreateResourceReport {
pub report_type: ResourceReportType,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ResourceReportEmail {
pub display_name: String,
pub report_type: ResourceReportType,
pub reporter_name: Option<String>,
pub reporter_email: Option<String>,
pub creator_name: String,
}
#[derive(Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Debug, EnumIter)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[serde(rename_all = "camelCase")]
#[repr(i16)]
pub enum ResourceReportType {
#[allow(missing_docs)]
Offensive = 0,
#[allow(missing_docs)]
CopyrightInfringement = 1,
#[allow(missing_docs)]
Spam = 2,
#[allow(missing_docs)]
Privacy = 3,
#[allow(missing_docs)]
ResourceNotPlaying = 4,
#[allow(missing_docs)]
Other = 5,
}
impl ResourceReportType {
#[allow(missing_docs)]
pub fn as_str(&self) -> &'static str {
match self {
ResourceReportType::Offensive => "Offensive",
ResourceReportType::CopyrightInfringement => "Copyright Infringement",
ResourceReportType::Spam => "Spam",
ResourceReportType::Privacy => "Privacy",
ResourceReportType::ResourceNotPlaying => "Resource Can't Be Viewed",
ResourceReportType::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()
}
}