-impl<'a, 'b: 'a> PrivateMessageReportQuery<'a, 'b> {
- pub async fn list(self) -> Result<Vec<PrivateMessageReportView>, Error> {
- let conn = &mut get_conn(self.pool).await?;
- let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
-
- let mut query = private_message_report::table
- .inner_join(private_message::table)
- .inner_join(person::table.on(private_message::creator_id.eq(person::id)))
- .inner_join(
- person_alias_1.on(private_message_report::creator_id.eq(person_alias_1.field(person::id))),
- )
- .left_join(
- person_alias_2
- .on(private_message_report::resolver_id.eq(person_alias_2.field(person::id).nullable())),
- )
- .select((
- private_message_report::all_columns,
- private_message::all_columns,
- person::all_columns,
- person_alias_1.fields(person::all_columns),
- person_alias_2.fields(person::all_columns).nullable(),
- ))
- .into_boxed();
-
- if self.unresolved_only.unwrap_or(false) {
- query = query.filter(private_message_report::resolved.eq(false));
- }
-
- let (limit, offset) = limit_and_offset(self.page, self.limit)?;
-
- query = query
- .order_by(private_message::published.desc())
- .limit(limit)
- .offset(offset);
-
- let res = query.load::<PrivateMessageReportViewTuple>(conn).await?;
-
- Ok(
- res
- .into_iter()
- .map(PrivateMessageReportView::from_tuple)
- .collect(),
- )
+impl PrivateMessageReportQuery {
+ pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<PrivateMessageReportView>, Error> {
+ queries().list(pool, self).await