feat: filter reports on fetch

This commit is contained in:
Paul Makles
2023-05-31 17:04:33 +01:00
parent 2a6d532852
commit bca17b11a7
3 changed files with 83 additions and 4 deletions

View File

@@ -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
}
}

View File

@@ -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)]