feat: filter reports on fetch
This commit is contained in:
@@ -1,9 +1,30 @@
|
||||
use crate::{models::report::PartialReport, models::Report, Database, Result};
|
||||
use iso8601_timestamp::Timestamp;
|
||||
|
||||
use crate::{
|
||||
models::report::PartialReport,
|
||||
models::{report::ReportStatus, Report},
|
||||
Database, Result,
|
||||
};
|
||||
|
||||
impl Report {
|
||||
/// Update report data
|
||||
pub async fn update(&mut self, db: &Database, partial: PartialReport) -> Result<()> {
|
||||
self.apply_options(partial.clone());
|
||||
|
||||
match &mut self.status {
|
||||
ReportStatus::Created {} => {}
|
||||
ReportStatus::Rejected { closed_at, .. } => {
|
||||
if closed_at.is_none() {
|
||||
closed_at.replace(Timestamp::now_utc());
|
||||
}
|
||||
}
|
||||
ReportStatus::Resolved { closed_at } => {
|
||||
if closed_at.is_none() {
|
||||
closed_at.replace(Timestamp::now_utc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.update_report(&self.id, &partial).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use iso8601_timestamp::Timestamp;
|
||||
use rocket::FromFormField;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Reason for reporting content (message or server)
|
||||
@@ -119,6 +120,19 @@ pub enum ReportStatus {
|
||||
Resolved { closed_at: Option<Timestamp> },
|
||||
}
|
||||
|
||||
/// Just the status of the report
|
||||
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, FromFormField)]
|
||||
pub enum ReportStatusString {
|
||||
/// Report is waiting for triage / action
|
||||
Created,
|
||||
|
||||
/// Report was rejected
|
||||
Rejected,
|
||||
|
||||
/// Report was actioned and resolved
|
||||
Resolved,
|
||||
}
|
||||
|
||||
/// User-generated platform moderation report.
|
||||
#[derive(Serialize, Deserialize, JsonSchema, Debug, OptionalStruct, Clone)]
|
||||
#[optional_derive(Serialize, Deserialize, JsonSchema, Debug, Default, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user