Add report + moderation messaging (#567)

* Add report + moderation messaging

* Add system messages

* address review comments

* Remove ds store

* Update messaging

* run prep

---------

Co-authored-by: Geometrically <geometrically@Jais-MacBook-Pro.local>
This commit is contained in:
Geometrically
2023-04-12 17:59:43 -07:00
committed by GitHub
parent 7605df1bd9
commit 8f61e9876f
26 changed files with 2005 additions and 2180 deletions

View File

@@ -1,7 +1,3 @@
#![allow(dead_code)]
// TODO: remove attr once routes are created
use chrono::{DateTime, Utc};
use thiserror::Error;
pub mod categories;
@@ -10,6 +6,7 @@ pub mod notification_item;
pub mod project_item;
pub mod report_item;
pub mod team_item;
pub mod thread_item;
pub mod user_item;
pub mod version_item;
@@ -17,6 +14,7 @@ pub use ids::*;
pub use project_item::Project;
pub use team_item::Team;
pub use team_item::TeamMember;
pub use thread_item::{Thread, ThreadMessage};
pub use user_item::User;
pub use version_item::Version;
@@ -28,82 +26,6 @@ pub enum DatabaseError {
RandomId,
#[error("A database request failed")]
Other(String),
}
impl ids::SideTypeId {
pub async fn get_id<'a, E>(
side: &crate::models::projects::SideType,
exec: E,
) -> Result<Option<Self>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
let result = sqlx::query!(
"
SELECT id FROM side_types
WHERE name = $1
",
side.as_str()
)
.fetch_optional(exec)
.await?;
Ok(result.map(|r| ids::SideTypeId(r.id)))
}
}
impl ids::DonationPlatformId {
pub async fn get_id<'a, E>(
id: &str,
exec: E,
) -> Result<Option<Self>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
let result = sqlx::query!(
"
SELECT id FROM donation_platforms
WHERE short = $1
",
id
)
.fetch_optional(exec)
.await?;
Ok(result.map(|r| ids::DonationPlatformId(r.id)))
}
}
impl ids::ProjectTypeId {
pub async fn get_id<'a, E>(
project_type: String,
exec: E,
) -> Result<Option<Self>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
let result = sqlx::query!(
"
SELECT id FROM project_types
WHERE name = $1
",
project_type
)
.fetch_optional(exec)
.await?;
Ok(result.map(|r| ProjectTypeId(r.id)))
}
}
pub fn convert_postgres_date(input: &str) -> DateTime<Utc> {
let mut result = DateTime::parse_from_str(input, "%Y-%m-%d %T.%f%#z");
if result.is_err() {
result = DateTime::parse_from_str(input, "%Y-%m-%d %T%#z")
}
result
.map(|x| x.with_timezone(&Utc))
.unwrap_or_else(|_| Utc::now())
#[error("Error while parsing JSON: {0}")]
Json(#[from] serde_json::Error),
}