2 use diesel::{dsl::*, result::Error, *};
3 use lemmy_db_schema::{naive_now, source::post_report::*};
5 impl Reportable<PostReportForm> for PostReport {
6 /// creates a post report and returns it
8 /// * `conn` - the postgres connection
9 /// * `post_report_form` - the filled CommentReportForm to insert
10 fn report(conn: &PgConnection, post_report_form: &PostReportForm) -> Result<Self, Error> {
11 use lemmy_db_schema::schema::post_report::dsl::*;
12 insert_into(post_report)
13 .values(post_report_form)
14 .get_result::<Self>(conn)
17 /// resolve a post report
19 /// * `conn` - the postgres connection
20 /// * `report_id` - the id of the report to resolve
21 /// * `by_resolver_id` - the id of the user resolving the report
22 fn resolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
23 use lemmy_db_schema::schema::post_report::dsl::*;
24 update(post_report.find(report_id))
27 resolver_id.eq(by_resolver_id),
28 updated.eq(naive_now()),
33 /// resolve a post report
35 /// * `conn` - the postgres connection
36 /// * `report_id` - the id of the report to unresolve
37 /// * `by_resolver_id` - the id of the user unresolving the report
38 fn unresolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
39 use lemmy_db_schema::schema::post_report::dsl::*;
40 update(post_report.find(report_id))
43 resolver_id.eq(by_resolver_id),
44 updated.eq(naive_now()),