]> Untitled Git - lemmy.git/commitdiff
Adding moderator views.
authorDessalines <tyhou13@gmx.com>
Wed, 16 Dec 2020 21:28:18 +0000 (16:28 -0500)
committerDessalines <tyhou13@gmx.com>
Wed, 16 Dec 2020 21:28:18 +0000 (16:28 -0500)
35 files changed:
lemmy_api/src/community.rs
lemmy_api/src/lib.rs
lemmy_api/src/post.rs
lemmy_api/src/site.rs
lemmy_api/src/user.rs
lemmy_apub/src/activities/receive/community.rs
lemmy_apub/src/activities/send/community.rs
lemmy_apub/src/fetcher.rs
lemmy_apub/src/http/community.rs
lemmy_apub/src/inbox/community_inbox.rs
lemmy_apub/src/objects/community.rs
lemmy_db/src/lib.rs
lemmy_db/src/moderator_views.rs [deleted file]
lemmy_db/src/source/community.rs
lemmy_db/src/source/moderator.rs
lemmy_db/src/views/community/community_follower_view.rs [moved from lemmy_db/src/views/community_follower_view.rs with 100% similarity]
lemmy_db/src/views/community/community_moderator_view.rs [moved from lemmy_db/src/views/community_moderator_view.rs with 100% similarity]
lemmy_db/src/views/community/community_user_ban_view.rs [moved from lemmy_db/src/views/community_user_ban_view.rs with 100% similarity]
lemmy_db/src/views/community/community_view.rs [moved from lemmy_db/src/views/community_view.rs with 100% similarity]
lemmy_db/src/views/community/mod.rs [new file with mode: 0644]
lemmy_db/src/views/mod.rs
lemmy_db/src/views/moderator/mod.rs [new file with mode: 0644]
lemmy_db/src/views/moderator/mod_add_community_view.rs [new file with mode: 0644]
lemmy_db/src/views/moderator/mod_add_view.rs [new file with mode: 0644]
lemmy_db/src/views/moderator/mod_ban_from_community_view.rs [new file with mode: 0644]
lemmy_db/src/views/moderator/mod_ban_view.rs [new file with mode: 0644]
lemmy_db/src/views/moderator/mod_lock_post_view.rs [new file with mode: 0644]
lemmy_db/src/views/moderator/mod_remove_comment_view.rs [new file with mode: 0644]
lemmy_db/src/views/moderator/mod_remove_community_view.rs [new file with mode: 0644]
lemmy_db/src/views/moderator/mod_remove_post_view.rs [new file with mode: 0644]
lemmy_db/src/views/moderator/mod_sticky_post_view.rs [new file with mode: 0644]
lemmy_structs/src/community.rs
lemmy_structs/src/post.rs
lemmy_structs/src/site.rs
lemmy_structs/src/user.rs

index 04059a7c5b04ed9cbd5876f74ae6edce13bcdfe0..6e20a30ba3ef8bda2092119b3e42f1e7b6196cf6 100644 (file)
@@ -15,9 +15,11 @@ use lemmy_db::{
   source::{comment::Comment, community::*, moderator::*, post::Post, site::*},
   views::{
     comment_view::CommentQueryBuilder,
-    community_follower_view::CommunityFollowerView,
-    community_moderator_view::CommunityModeratorView,
-    community_view::{CommunityQueryBuilder, CommunityView},
+    community::{
+      community_follower_view::CommunityFollowerView,
+      community_moderator_view::CommunityModeratorView,
+      community_view::{CommunityQueryBuilder, CommunityView},
+    },
     user_view::UserViewSafe,
   },
   ApubObject,
index 92287f8d3139916ab173d9ac0ef2819d9647f125..ad7355e1cb59326ecbcdd59c0529a68137cedbcc 100644 (file)
@@ -6,7 +6,7 @@ use lemmy_db::{
     post::Post,
     user::User_,
   },
-  views::community_user_ban_view::CommunityUserBanView,
+  views::community::community_user_ban_view::CommunityUserBanView,
   Crud,
   DbPool,
 };
index d998e7d977dc2b53d41a374d66bcb83bd71e722b..02da229fd912b884ab0c30db0b54fe57587cc506 100644 (file)
@@ -15,8 +15,7 @@ use lemmy_db::{
   source::{moderator::*, post::*},
   views::{
     comment_view::CommentQueryBuilder,
-    community_moderator_view::CommunityModeratorView,
-    community_view::CommunityView,
+    community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
     post_view::{PostQueryBuilder, PostView},
     site_view::SiteView,
   },
index e8dfaca3221466cf2cee812fcfb99a303d5300b6..138cc8751edaa4bbcc14d0f9e435c67504d1cdb3 100644 (file)
@@ -12,12 +12,22 @@ use lemmy_apub::fetcher::search_by_apub_id;
 use lemmy_db::{
   aggregates::site_aggregates::SiteAggregates,
   diesel_option_overwrite,
-  moderator_views::*,
   naive_now,
   source::{category::*, moderator::*, site::*},
   views::{
     comment_view::CommentQueryBuilder,
-    community_view::CommunityQueryBuilder,
+    community::community_view::CommunityQueryBuilder,
+    moderator::{
+      mod_add_community_view::ModAddCommunityView,
+      mod_add_view::ModAddView,
+      mod_ban_from_community_view::ModBanFromCommunityView,
+      mod_ban_view::ModBanView,
+      mod_lock_post_view::ModLockPostView,
+      mod_remove_comment_view::ModRemoveCommentView,
+      mod_remove_community_view::ModRemoveCommunityView,
+      mod_remove_post_view::ModRemovePostView,
+      mod_sticky_post_view::ModStickyPostView,
+    },
     post_view::PostQueryBuilder,
     site_view::SiteView,
     user_view::{UserQueryBuilder, UserViewSafe},
index 17e3fac655756865d488f9f1b195b2cda55b5410..c47a5e1ce6b3ff15b6c865abde6ddf6f6dfaae09 100644 (file)
@@ -33,8 +33,10 @@ use lemmy_db::{
   },
   views::{
     comment_view::CommentQueryBuilder,
-    community_follower_view::CommunityFollowerView,
-    community_moderator_view::CommunityModeratorView,
+    community::{
+      community_follower_view::CommunityFollowerView,
+      community_moderator_view::CommunityModeratorView,
+    },
     post_view::PostQueryBuilder,
     site_view::SiteView,
     user_mention_view::{UserMentionQueryBuilder, UserMentionView},
index cacb54eefab5cfc677a6a9ffbf29ee8c991b5ef9..534da5cb70dda19f00fe12e2d143182422304714 100644 (file)
@@ -4,7 +4,11 @@ use activitystreams::{
   base::{AnyBase, ExtendsExt},
 };
 use anyhow::Context;
-use lemmy_db::{source::community::Community, views::community_view::CommunityView, ApubObject};
+use lemmy_db::{
+  source::community::Community,
+  views::community::community_view::CommunityView,
+  ApubObject,
+};
 use lemmy_structs::{blocking, community::CommunityResponse};
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
index 8596fc4e3de3376992158c844e3075a968c96332..96152fa0d4b9d1e43caf84cc23a47ea5a27c4c40 100644 (file)
@@ -25,7 +25,7 @@ use anyhow::Context;
 use itertools::Itertools;
 use lemmy_db::{
   source::community::Community,
-  views::community_follower_view::CommunityFollowerView,
+  views::community::community_follower_view::CommunityFollowerView,
   DbPool,
 };
 use lemmy_structs::blocking;
index 08735b4c287597e7fed4c59701d6ef98658e3363..61cdbd47ab4b63e5c8d696e1452a20b1fe38013f 100644 (file)
@@ -22,7 +22,7 @@ use lemmy_db::{
   },
   views::{
     comment_view::CommentView,
-    community_view::CommunityView,
+    community::community_view::CommunityView,
     post_view::PostView,
     user_view::UserViewSafe,
   },
index 3caaf6613b6190c0f009a2e162f4ae2e76398896..a17e2abf91e5b71bccbbe7a2a173e1d9a7feec80 100644 (file)
@@ -11,7 +11,7 @@ use activitystreams::{
 use actix_web::{body::Body, web, HttpResponse};
 use lemmy_db::{
   source::{community::Community, post::Post},
-  views::community_follower_view::CommunityFollowerView,
+  views::community::community_follower_view::CommunityFollowerView,
 };
 use lemmy_structs::blocking;
 use lemmy_utils::LemmyError;
index 82df26bea8d00aa3d1f1a2697f35032c0b3e1860..a2bed621cc9a41eb69fe7dbc03df1891f6da9a6a 100644 (file)
@@ -31,7 +31,7 @@ use lemmy_db::{
     community::{Community, CommunityFollower, CommunityFollowerForm},
     user::User_,
   },
-  views::community_user_ban_view::CommunityUserBanView,
+  views::community::community_user_ban_view::CommunityUserBanView,
   ApubObject,
   DbPool,
   Followable,
index 3bd47560efefeeafa638a2964a94a57244e3cda0..9d8210a6ac0112ce466868c12179ee1022fab67e 100644 (file)
@@ -25,7 +25,7 @@ use anyhow::Context;
 use lemmy_db::{
   naive_now,
   source::community::{Community, CommunityForm},
-  views::community_moderator_view::CommunityModeratorView,
+  views::community::community_moderator_view::CommunityModeratorView,
   DbPool,
 };
 use lemmy_structs::blocking;
index ba5dccdf671c8f51881571de77058c1617aa759f..8906f32c4fdded738e816a82c9392de05c9bf13f 100644 (file)
@@ -12,7 +12,6 @@ use serde::{Deserialize, Serialize};
 use std::{env, env::VarError};
 
 pub mod comment_report;
-pub mod moderator_views;
 pub mod post_report;
 pub mod private_message_view;
 
diff --git a/lemmy_db/src/moderator_views.rs b/lemmy_db/src/moderator_views.rs
deleted file mode 100644 (file)
index efa949a..0000000
+++ /dev/null
@@ -1,513 +0,0 @@
-use crate::limit_and_offset;
-use diesel::{result::Error, *};
-use serde::Serialize;
-
-table! {
-  mod_remove_post_view (id) {
-    id -> Int4,
-    mod_user_id -> Int4,
-    post_id -> Int4,
-    reason -> Nullable<Text>,
-    removed -> Nullable<Bool>,
-    when_ -> Timestamp,
-    mod_user_name -> Varchar,
-    post_name -> Varchar,
-    community_id -> Int4,
-    community_name -> Varchar,
-  }
-}
-
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
-#[table_name = "mod_remove_post_view"]
-pub struct ModRemovePostView {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub post_id: i32,
-  pub reason: Option<String>,
-  pub removed: Option<bool>,
-  pub when_: chrono::NaiveDateTime,
-  pub mod_user_name: String,
-  pub post_name: String,
-  pub community_id: i32,
-  pub community_name: String,
-}
-
-impl ModRemovePostView {
-  pub fn list(
-    conn: &PgConnection,
-    from_community_id: Option<i32>,
-    from_mod_user_id: Option<i32>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
-    use super::moderator_views::mod_remove_post_view::dsl::*;
-    let mut query = mod_remove_post_view.into_boxed();
-
-    let (limit, offset) = limit_and_offset(page, limit);
-
-    if let Some(from_community_id) = from_community_id {
-      query = query.filter(community_id.eq(from_community_id));
-    };
-
-    if let Some(from_mod_user_id) = from_mod_user_id {
-      query = query.filter(mod_user_id.eq(from_mod_user_id));
-    };
-
-    query
-      .limit(limit)
-      .offset(offset)
-      .order_by(when_.desc())
-      .load::<Self>(conn)
-  }
-}
-
-table! {
-  mod_lock_post_view (id) {
-    id -> Int4,
-    mod_user_id -> Int4,
-    post_id -> Int4,
-    locked -> Nullable<Bool>,
-    when_ -> Timestamp,
-    mod_user_name -> Varchar,
-    post_name -> Varchar,
-    community_id -> Int4,
-    community_name -> Varchar,
-  }
-}
-
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
-#[table_name = "mod_lock_post_view"]
-pub struct ModLockPostView {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub post_id: i32,
-  pub locked: Option<bool>,
-  pub when_: chrono::NaiveDateTime,
-  pub mod_user_name: String,
-  pub post_name: String,
-  pub community_id: i32,
-  pub community_name: String,
-}
-
-impl ModLockPostView {
-  pub fn list(
-    conn: &PgConnection,
-    from_community_id: Option<i32>,
-    from_mod_user_id: Option<i32>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
-    use super::moderator_views::mod_lock_post_view::dsl::*;
-    let mut query = mod_lock_post_view.into_boxed();
-
-    let (limit, offset) = limit_and_offset(page, limit);
-
-    if let Some(from_community_id) = from_community_id {
-      query = query.filter(community_id.eq(from_community_id));
-    };
-
-    if let Some(from_mod_user_id) = from_mod_user_id {
-      query = query.filter(mod_user_id.eq(from_mod_user_id));
-    };
-
-    query
-      .limit(limit)
-      .offset(offset)
-      .order_by(when_.desc())
-      .load::<Self>(conn)
-  }
-}
-
-table! {
-  mod_sticky_post_view (id) {
-    id -> Int4,
-    mod_user_id -> Int4,
-    post_id -> Int4,
-    stickied -> Nullable<Bool>,
-    when_ -> Timestamp,
-    mod_user_name -> Varchar,
-    post_name -> Varchar,
-    community_id -> Int4,
-    community_name -> Varchar,
-  }
-}
-
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
-#[table_name = "mod_sticky_post_view"]
-pub struct ModStickyPostView {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub post_id: i32,
-  pub stickied: Option<bool>,
-  pub when_: chrono::NaiveDateTime,
-  pub mod_user_name: String,
-  pub post_name: String,
-  pub community_id: i32,
-  pub community_name: String,
-}
-
-impl ModStickyPostView {
-  pub fn list(
-    conn: &PgConnection,
-    from_community_id: Option<i32>,
-    from_mod_user_id: Option<i32>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
-    use super::moderator_views::mod_sticky_post_view::dsl::*;
-    let mut query = mod_sticky_post_view.into_boxed();
-
-    let (limit, offset) = limit_and_offset(page, limit);
-
-    if let Some(from_community_id) = from_community_id {
-      query = query.filter(community_id.eq(from_community_id));
-    };
-
-    if let Some(from_mod_user_id) = from_mod_user_id {
-      query = query.filter(mod_user_id.eq(from_mod_user_id));
-    };
-
-    query
-      .limit(limit)
-      .offset(offset)
-      .order_by(when_.desc())
-      .load::<Self>(conn)
-  }
-}
-
-table! {
-  mod_remove_comment_view (id) {
-    id -> Int4,
-    mod_user_id -> Int4,
-    comment_id -> Int4,
-    reason -> Nullable<Text>,
-    removed -> Nullable<Bool>,
-    when_ -> Timestamp,
-    mod_user_name -> Varchar,
-    comment_user_id -> Int4,
-    comment_user_name -> Varchar,
-    comment_content -> Text,
-    post_id -> Int4,
-    post_name -> Varchar,
-    community_id -> Int4,
-    community_name -> Varchar,
-  }
-}
-
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
-#[table_name = "mod_remove_comment_view"]
-pub struct ModRemoveCommentView {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub comment_id: i32,
-  pub reason: Option<String>,
-  pub removed: Option<bool>,
-  pub when_: chrono::NaiveDateTime,
-  pub mod_user_name: String,
-  pub comment_user_id: i32,
-  pub comment_user_name: String,
-  pub comment_content: String,
-  pub post_id: i32,
-  pub post_name: String,
-  pub community_id: i32,
-  pub community_name: String,
-}
-
-impl ModRemoveCommentView {
-  pub fn list(
-    conn: &PgConnection,
-    from_community_id: Option<i32>,
-    from_mod_user_id: Option<i32>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
-    use super::moderator_views::mod_remove_comment_view::dsl::*;
-    let mut query = mod_remove_comment_view.into_boxed();
-
-    let (limit, offset) = limit_and_offset(page, limit);
-
-    if let Some(from_community_id) = from_community_id {
-      query = query.filter(community_id.eq(from_community_id));
-    };
-
-    if let Some(from_mod_user_id) = from_mod_user_id {
-      query = query.filter(mod_user_id.eq(from_mod_user_id));
-    };
-
-    query
-      .limit(limit)
-      .offset(offset)
-      .order_by(when_.desc())
-      .load::<Self>(conn)
-  }
-}
-
-table! {
-  mod_remove_community_view (id) {
-    id -> Int4,
-    mod_user_id -> Int4,
-    community_id -> Int4,
-    reason -> Nullable<Text>,
-    removed -> Nullable<Bool>,
-    expires -> Nullable<Timestamp>,
-    when_ -> Timestamp,
-    mod_user_name -> Varchar,
-    community_name -> Varchar,
-  }
-}
-
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
-#[table_name = "mod_remove_community_view"]
-pub struct ModRemoveCommunityView {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub community_id: i32,
-  pub reason: Option<String>,
-  pub removed: Option<bool>,
-  pub expires: Option<chrono::NaiveDateTime>,
-  pub when_: chrono::NaiveDateTime,
-  pub mod_user_name: String,
-  pub community_name: String,
-}
-
-impl ModRemoveCommunityView {
-  pub fn list(
-    conn: &PgConnection,
-    from_mod_user_id: Option<i32>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
-    use super::moderator_views::mod_remove_community_view::dsl::*;
-    let mut query = mod_remove_community_view.into_boxed();
-
-    let (limit, offset) = limit_and_offset(page, limit);
-
-    if let Some(from_mod_user_id) = from_mod_user_id {
-      query = query.filter(mod_user_id.eq(from_mod_user_id));
-    };
-
-    query
-      .limit(limit)
-      .offset(offset)
-      .order_by(when_.desc())
-      .load::<Self>(conn)
-  }
-}
-
-table! {
-  mod_ban_from_community_view (id) {
-    id -> Int4,
-    mod_user_id -> Int4,
-    other_user_id -> Int4,
-    community_id -> Int4,
-    reason -> Nullable<Text>,
-    banned -> Nullable<Bool>,
-    expires -> Nullable<Timestamp>,
-    when_ -> Timestamp,
-    mod_user_name -> Varchar,
-    other_user_name -> Varchar,
-    community_name -> Varchar,
-  }
-}
-
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
-#[table_name = "mod_ban_from_community_view"]
-pub struct ModBanFromCommunityView {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub other_user_id: i32,
-  pub community_id: i32,
-  pub reason: Option<String>,
-  pub banned: Option<bool>,
-  pub expires: Option<chrono::NaiveDateTime>,
-  pub when_: chrono::NaiveDateTime,
-  pub mod_user_name: String,
-  pub other_user_name: String,
-  pub community_name: String,
-}
-
-impl ModBanFromCommunityView {
-  pub fn list(
-    conn: &PgConnection,
-    from_community_id: Option<i32>,
-    from_mod_user_id: Option<i32>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
-    use super::moderator_views::mod_ban_from_community_view::dsl::*;
-    let mut query = mod_ban_from_community_view.into_boxed();
-
-    let (limit, offset) = limit_and_offset(page, limit);
-
-    if let Some(from_community_id) = from_community_id {
-      query = query.filter(community_id.eq(from_community_id));
-    };
-
-    if let Some(from_mod_user_id) = from_mod_user_id {
-      query = query.filter(mod_user_id.eq(from_mod_user_id));
-    };
-
-    query
-      .limit(limit)
-      .offset(offset)
-      .order_by(when_.desc())
-      .load::<Self>(conn)
-  }
-}
-
-table! {
-  mod_ban_view (id) {
-    id -> Int4,
-    mod_user_id -> Int4,
-    other_user_id -> Int4,
-    reason -> Nullable<Text>,
-    banned -> Nullable<Bool>,
-    expires -> Nullable<Timestamp>,
-    when_ -> Timestamp,
-    mod_user_name -> Varchar,
-    other_user_name -> Varchar,
-  }
-}
-
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
-#[table_name = "mod_ban_view"]
-pub struct ModBanView {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub other_user_id: i32,
-  pub reason: Option<String>,
-  pub banned: Option<bool>,
-  pub expires: Option<chrono::NaiveDateTime>,
-  pub when_: chrono::NaiveDateTime,
-  pub mod_user_name: String,
-  pub other_user_name: String,
-}
-
-impl ModBanView {
-  pub fn list(
-    conn: &PgConnection,
-    from_mod_user_id: Option<i32>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
-    use super::moderator_views::mod_ban_view::dsl::*;
-    let mut query = mod_ban_view.into_boxed();
-
-    let (limit, offset) = limit_and_offset(page, limit);
-
-    if let Some(from_mod_user_id) = from_mod_user_id {
-      query = query.filter(mod_user_id.eq(from_mod_user_id));
-    };
-
-    query
-      .limit(limit)
-      .offset(offset)
-      .order_by(when_.desc())
-      .load::<Self>(conn)
-  }
-}
-
-table! {
-  mod_add_community_view (id) {
-    id -> Int4,
-    mod_user_id -> Int4,
-    other_user_id -> Int4,
-    community_id -> Int4,
-    removed -> Nullable<Bool>,
-    when_ -> Timestamp,
-    mod_user_name -> Varchar,
-    other_user_name -> Varchar,
-    community_name -> Varchar,
-  }
-}
-
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
-#[table_name = "mod_add_community_view"]
-pub struct ModAddCommunityView {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub other_user_id: i32,
-  pub community_id: i32,
-  pub removed: Option<bool>,
-  pub when_: chrono::NaiveDateTime,
-  pub mod_user_name: String,
-  pub other_user_name: String,
-  pub community_name: String,
-}
-
-impl ModAddCommunityView {
-  pub fn list(
-    conn: &PgConnection,
-    from_community_id: Option<i32>,
-    from_mod_user_id: Option<i32>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
-    use super::moderator_views::mod_add_community_view::dsl::*;
-    let mut query = mod_add_community_view.into_boxed();
-
-    let (limit, offset) = limit_and_offset(page, limit);
-
-    if let Some(from_community_id) = from_community_id {
-      query = query.filter(community_id.eq(from_community_id));
-    };
-
-    if let Some(from_mod_user_id) = from_mod_user_id {
-      query = query.filter(mod_user_id.eq(from_mod_user_id));
-    };
-
-    query
-      .limit(limit)
-      .offset(offset)
-      .order_by(when_.desc())
-      .load::<Self>(conn)
-  }
-}
-
-table! {
-  mod_add_view (id) {
-    id -> Int4,
-    mod_user_id -> Int4,
-    other_user_id -> Int4,
-    removed -> Nullable<Bool>,
-    when_ -> Timestamp,
-    mod_user_name -> Varchar,
-    other_user_name -> Varchar,
-  }
-}
-
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
-#[table_name = "mod_add_view"]
-pub struct ModAddView {
-  pub id: i32,
-  pub mod_user_id: i32,
-  pub other_user_id: i32,
-  pub removed: Option<bool>,
-  pub when_: chrono::NaiveDateTime,
-  pub mod_user_name: String,
-  pub other_user_name: String,
-}
-
-impl ModAddView {
-  pub fn list(
-    conn: &PgConnection,
-    from_mod_user_id: Option<i32>,
-    page: Option<i64>,
-    limit: Option<i64>,
-  ) -> Result<Vec<Self>, Error> {
-    use super::moderator_views::mod_add_view::dsl::*;
-    let mut query = mod_add_view.into_boxed();
-
-    let (limit, offset) = limit_and_offset(page, limit);
-
-    if let Some(from_mod_user_id) = from_mod_user_id {
-      query = query.filter(mod_user_id.eq(from_mod_user_id));
-    };
-
-    query
-      .limit(limit)
-      .offset(offset)
-      .order_by(when_.desc())
-      .load::<Self>(conn)
-  }
-}
index 84db0c7c418c70f5056a69a867b0ae8a23123d99..0ad90da287c9f99fd1c6c691f80f5cdd562196cd 100644 (file)
@@ -1,6 +1,7 @@
 use crate::{
   naive_now,
   schema::{community, community_follower, community_moderator, community_user_ban},
+  views::{community::community_moderator_view::CommunityModeratorView, user_view::UserViewSafe},
   ApubObject,
   Bannable,
   Crud,
@@ -223,7 +224,6 @@ impl Community {
   }
 
   fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error> {
-    use crate::views::{community_moderator_view::CommunityModeratorView, user_view::UserViewSafe};
     let mut mods_and_admins: Vec<i32> = Vec::new();
     mods_and_admins.append(
       &mut CommunityModeratorView::for_community(conn, community_id)
index 1be3e31b8f677bce0476e0a4fef0820ac13ce4b0..766c17fc57860dbafff4752206acab85b13ce1fe 100644 (file)
@@ -13,8 +13,9 @@ use crate::{
   Crud,
 };
 use diesel::{dsl::*, result::Error, *};
+use serde::Serialize;
 
-#[derive(Queryable, Identifiable, PartialEq, Debug)]
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "mod_remove_post"]
 pub struct ModRemovePost {
   pub id: i32,
@@ -55,7 +56,7 @@ impl Crud<ModRemovePostForm> for ModRemovePost {
   }
 }
 
-#[derive(Queryable, Identifiable, PartialEq, Debug)]
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "mod_lock_post"]
 pub struct ModLockPost {
   pub id: i32,
@@ -94,7 +95,7 @@ impl Crud<ModLockPostForm> for ModLockPost {
   }
 }
 
-#[derive(Queryable, Identifiable, PartialEq, Debug)]
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "mod_sticky_post"]
 pub struct ModStickyPost {
   pub id: i32,
@@ -133,7 +134,7 @@ impl Crud<ModStickyPostForm> for ModStickyPost {
   }
 }
 
-#[derive(Queryable, Identifiable, PartialEq, Debug)]
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "mod_remove_comment"]
 pub struct ModRemoveComment {
   pub id: i32,
@@ -174,7 +175,7 @@ impl Crud<ModRemoveCommentForm> for ModRemoveComment {
   }
 }
 
-#[derive(Queryable, Identifiable, PartialEq, Debug)]
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "mod_remove_community"]
 pub struct ModRemoveCommunity {
   pub id: i32,
@@ -221,7 +222,7 @@ impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
   }
 }
 
-#[derive(Queryable, Identifiable, PartialEq, Debug)]
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "mod_ban_from_community"]
 pub struct ModBanFromCommunity {
   pub id: i32,
@@ -270,7 +271,7 @@ impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
   }
 }
 
-#[derive(Queryable, Identifiable, PartialEq, Debug)]
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "mod_ban"]
 pub struct ModBan {
   pub id: i32,
@@ -311,7 +312,7 @@ impl Crud<ModBanForm> for ModBan {
   }
 }
 
-#[derive(Queryable, Identifiable, PartialEq, Debug)]
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "mod_add_community"]
 pub struct ModAddCommunity {
   pub id: i32,
@@ -352,7 +353,7 @@ impl Crud<ModAddCommunityForm> for ModAddCommunity {
   }
 }
 
-#[derive(Queryable, Identifiable, PartialEq, Debug)]
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "mod_add"]
 pub struct ModAdd {
   pub id: i32,
diff --git a/lemmy_db/src/views/community/mod.rs b/lemmy_db/src/views/community/mod.rs
new file mode 100644 (file)
index 0000000..491dde7
--- /dev/null
@@ -0,0 +1,4 @@
+pub mod community_follower_view;
+pub mod community_moderator_view;
+pub mod community_user_ban_view;
+pub mod community_view;
index 2516caeb0fac2c160fc2f8637f59f2e9b1e15ea7..28323fca2811efacf852f5c1bd9f46c935580111 100644 (file)
@@ -1,8 +1,6 @@
 pub mod comment_view;
-pub mod community_follower_view;
-pub mod community_moderator_view;
-pub mod community_user_ban_view;
-pub mod community_view;
+pub mod community;
+pub mod moderator;
 pub mod post_view;
 pub mod site_view;
 pub mod user_mention_view;
diff --git a/lemmy_db/src/views/moderator/mod.rs b/lemmy_db/src/views/moderator/mod.rs
new file mode 100644 (file)
index 0000000..827dd14
--- /dev/null
@@ -0,0 +1,9 @@
+pub mod mod_add_community_view;
+pub mod mod_add_view;
+pub mod mod_ban_from_community_view;
+pub mod mod_ban_view;
+pub mod mod_lock_post_view;
+pub mod mod_remove_comment_view;
+pub mod mod_remove_community_view;
+pub mod mod_remove_post_view;
+pub mod mod_sticky_post_view;
diff --git a/lemmy_db/src/views/moderator/mod_add_community_view.rs b/lemmy_db/src/views/moderator/mod_add_community_view.rs
new file mode 100644 (file)
index 0000000..402c5fe
--- /dev/null
@@ -0,0 +1,78 @@
+use crate::{
+  limit_and_offset,
+  schema::{community, mod_add_community, user_, user_alias_1},
+  source::{
+    community::{Community, CommunitySafe},
+    moderator::ModAddCommunity,
+    user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
+  },
+  views::ViewToVec,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use serde::Serialize;
+
+#[derive(Debug, Serialize, Clone)]
+pub struct ModAddCommunityView {
+  pub mod_add_community: ModAddCommunity,
+  pub moderator: UserSafe,
+  pub community: CommunitySafe,
+  pub modded_user: UserSafeAlias1,
+}
+
+type ModAddCommunityViewTuple = (ModAddCommunity, UserSafe, CommunitySafe, UserSafeAlias1);
+
+impl ModAddCommunityView {
+  pub fn list(
+    conn: &PgConnection,
+    community_id: Option<i32>,
+    mod_user_id: Option<i32>,
+    page: Option<i64>,
+    limit: Option<i64>,
+  ) -> Result<Vec<Self>, Error> {
+    let mut query = mod_add_community::table
+      .inner_join(user_::table.on(mod_add_community::mod_user_id.eq(user_::id)))
+      .inner_join(community::table)
+      .inner_join(user_alias_1::table.on(mod_add_community::other_user_id.eq(user_::id)))
+      .select((
+        mod_add_community::all_columns,
+        User_::safe_columns_tuple(),
+        Community::safe_columns_tuple(),
+        UserAlias1::safe_columns_tuple(),
+      ))
+      .into_boxed();
+
+    if let Some(mod_user_id) = mod_user_id {
+      query = query.filter(mod_add_community::mod_user_id.eq(mod_user_id));
+    };
+
+    if let Some(community_id) = community_id {
+      query = query.filter(mod_add_community::community_id.eq(community_id));
+    };
+
+    let (limit, offset) = limit_and_offset(page, limit);
+
+    let res = query
+      .limit(limit)
+      .offset(offset)
+      .order_by(mod_add_community::when_.desc())
+      .load::<ModAddCommunityViewTuple>(conn)?;
+
+    Ok(Self::to_vec(res))
+  }
+}
+
+impl ViewToVec for ModAddCommunityView {
+  type DbTuple = ModAddCommunityViewTuple;
+  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
+    mrp
+      .iter()
+      .map(|a| Self {
+        mod_add_community: a.0.to_owned(),
+        moderator: a.1.to_owned(),
+        community: a.2.to_owned(),
+        modded_user: a.3.to_owned(),
+      })
+      .collect::<Vec<Self>>()
+  }
+}
diff --git a/lemmy_db/src/views/moderator/mod_add_view.rs b/lemmy_db/src/views/moderator/mod_add_view.rs
new file mode 100644 (file)
index 0000000..fc1993d
--- /dev/null
@@ -0,0 +1,68 @@
+use crate::{
+  limit_and_offset,
+  schema::{mod_add, user_, user_alias_1},
+  source::{
+    moderator::ModAdd,
+    user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
+  },
+  views::ViewToVec,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use serde::Serialize;
+
+#[derive(Debug, Serialize, Clone)]
+pub struct ModAddView {
+  pub mod_add: ModAdd,
+  pub moderator: UserSafe,
+  pub modded_user: UserSafeAlias1,
+}
+
+type ModAddViewTuple = (ModAdd, UserSafe, UserSafeAlias1);
+
+impl ModAddView {
+  pub fn list(
+    conn: &PgConnection,
+    mod_user_id: Option<i32>,
+    page: Option<i64>,
+    limit: Option<i64>,
+  ) -> Result<Vec<Self>, Error> {
+    let mut query = mod_add::table
+      .inner_join(user_::table.on(mod_add::mod_user_id.eq(user_::id)))
+      .inner_join(user_alias_1::table.on(mod_add::other_user_id.eq(user_::id)))
+      .select((
+        mod_add::all_columns,
+        User_::safe_columns_tuple(),
+        UserAlias1::safe_columns_tuple(),
+      ))
+      .into_boxed();
+
+    if let Some(mod_user_id) = mod_user_id {
+      query = query.filter(mod_add::mod_user_id.eq(mod_user_id));
+    };
+
+    let (limit, offset) = limit_and_offset(page, limit);
+
+    let res = query
+      .limit(limit)
+      .offset(offset)
+      .order_by(mod_add::when_.desc())
+      .load::<ModAddViewTuple>(conn)?;
+
+    Ok(Self::to_vec(res))
+  }
+}
+
+impl ViewToVec for ModAddView {
+  type DbTuple = ModAddViewTuple;
+  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
+    mrp
+      .iter()
+      .map(|a| Self {
+        mod_add: a.0.to_owned(),
+        moderator: a.1.to_owned(),
+        modded_user: a.2.to_owned(),
+      })
+      .collect::<Vec<Self>>()
+  }
+}
diff --git a/lemmy_db/src/views/moderator/mod_ban_from_community_view.rs b/lemmy_db/src/views/moderator/mod_ban_from_community_view.rs
new file mode 100644 (file)
index 0000000..6ad232e
--- /dev/null
@@ -0,0 +1,78 @@
+use crate::{
+  limit_and_offset,
+  schema::{community, mod_ban_from_community, user_, user_alias_1},
+  source::{
+    community::{Community, CommunitySafe},
+    moderator::ModBanFromCommunity,
+    user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
+  },
+  views::ViewToVec,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use serde::Serialize;
+
+#[derive(Debug, Serialize, Clone)]
+pub struct ModBanFromCommunityView {
+  pub mod_ban_from_community: ModBanFromCommunity,
+  pub moderator: UserSafe,
+  pub community: CommunitySafe,
+  pub banned_user: UserSafeAlias1,
+}
+
+type ModBanFromCommunityViewTuple = (ModBanFromCommunity, UserSafe, CommunitySafe, UserSafeAlias1);
+
+impl ModBanFromCommunityView {
+  pub fn list(
+    conn: &PgConnection,
+    community_id: Option<i32>,
+    mod_user_id: Option<i32>,
+    page: Option<i64>,
+    limit: Option<i64>,
+  ) -> Result<Vec<Self>, Error> {
+    let mut query = mod_ban_from_community::table
+      .inner_join(user_::table.on(mod_ban_from_community::mod_user_id.eq(user_::id)))
+      .inner_join(community::table)
+      .inner_join(user_alias_1::table.on(mod_ban_from_community::other_user_id.eq(user_::id)))
+      .select((
+        mod_ban_from_community::all_columns,
+        User_::safe_columns_tuple(),
+        Community::safe_columns_tuple(),
+        UserAlias1::safe_columns_tuple(),
+      ))
+      .into_boxed();
+
+    if let Some(mod_user_id) = mod_user_id {
+      query = query.filter(mod_ban_from_community::mod_user_id.eq(mod_user_id));
+    };
+
+    if let Some(community_id) = community_id {
+      query = query.filter(mod_ban_from_community::community_id.eq(community_id));
+    };
+
+    let (limit, offset) = limit_and_offset(page, limit);
+
+    let res = query
+      .limit(limit)
+      .offset(offset)
+      .order_by(mod_ban_from_community::when_.desc())
+      .load::<ModBanFromCommunityViewTuple>(conn)?;
+
+    Ok(Self::to_vec(res))
+  }
+}
+
+impl ViewToVec for ModBanFromCommunityView {
+  type DbTuple = ModBanFromCommunityViewTuple;
+  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
+    mrp
+      .iter()
+      .map(|a| Self {
+        mod_ban_from_community: a.0.to_owned(),
+        moderator: a.1.to_owned(),
+        community: a.2.to_owned(),
+        banned_user: a.3.to_owned(),
+      })
+      .collect::<Vec<Self>>()
+  }
+}
diff --git a/lemmy_db/src/views/moderator/mod_ban_view.rs b/lemmy_db/src/views/moderator/mod_ban_view.rs
new file mode 100644 (file)
index 0000000..28214d2
--- /dev/null
@@ -0,0 +1,68 @@
+use crate::{
+  limit_and_offset,
+  schema::{mod_ban, user_, user_alias_1},
+  source::{
+    moderator::ModBan,
+    user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
+  },
+  views::ViewToVec,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use serde::Serialize;
+
+#[derive(Debug, Serialize, Clone)]
+pub struct ModBanView {
+  pub mod_ban: ModBan,
+  pub moderator: UserSafe,
+  pub banned_user: UserSafeAlias1,
+}
+
+type ModBanViewTuple = (ModBan, UserSafe, UserSafeAlias1);
+
+impl ModBanView {
+  pub fn list(
+    conn: &PgConnection,
+    mod_user_id: Option<i32>,
+    page: Option<i64>,
+    limit: Option<i64>,
+  ) -> Result<Vec<Self>, Error> {
+    let mut query = mod_ban::table
+      .inner_join(user_::table.on(mod_ban::mod_user_id.eq(user_::id)))
+      .inner_join(user_alias_1::table.on(mod_ban::other_user_id.eq(user_::id)))
+      .select((
+        mod_ban::all_columns,
+        User_::safe_columns_tuple(),
+        UserAlias1::safe_columns_tuple(),
+      ))
+      .into_boxed();
+
+    if let Some(mod_user_id) = mod_user_id {
+      query = query.filter(mod_ban::mod_user_id.eq(mod_user_id));
+    };
+
+    let (limit, offset) = limit_and_offset(page, limit);
+
+    let res = query
+      .limit(limit)
+      .offset(offset)
+      .order_by(mod_ban::when_.desc())
+      .load::<ModBanViewTuple>(conn)?;
+
+    Ok(Self::to_vec(res))
+  }
+}
+
+impl ViewToVec for ModBanView {
+  type DbTuple = ModBanViewTuple;
+  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
+    mrp
+      .iter()
+      .map(|a| Self {
+        mod_ban: a.0.to_owned(),
+        moderator: a.1.to_owned(),
+        banned_user: a.2.to_owned(),
+      })
+      .collect::<Vec<Self>>()
+  }
+}
diff --git a/lemmy_db/src/views/moderator/mod_lock_post_view.rs b/lemmy_db/src/views/moderator/mod_lock_post_view.rs
new file mode 100644 (file)
index 0000000..8182b54
--- /dev/null
@@ -0,0 +1,79 @@
+use crate::{
+  limit_and_offset,
+  schema::{community, mod_lock_post, post, user_},
+  source::{
+    community::{Community, CommunitySafe},
+    moderator::ModLockPost,
+    post::Post,
+    user::{UserSafe, User_},
+  },
+  views::ViewToVec,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use serde::Serialize;
+
+#[derive(Debug, Serialize, Clone)]
+pub struct ModLockPostView {
+  pub mod_lock_post: ModLockPost,
+  pub moderator: UserSafe,
+  pub post: Post,
+  pub community: CommunitySafe,
+}
+
+type ModLockPostViewTuple = (ModLockPost, UserSafe, Post, CommunitySafe);
+
+impl ModLockPostView {
+  pub fn list(
+    conn: &PgConnection,
+    community_id: Option<i32>,
+    mod_user_id: Option<i32>,
+    page: Option<i64>,
+    limit: Option<i64>,
+  ) -> Result<Vec<Self>, Error> {
+    let mut query = mod_lock_post::table
+      .inner_join(user_::table)
+      .inner_join(post::table)
+      .inner_join(community::table.on(post::community_id.eq(community::id)))
+      .select((
+        mod_lock_post::all_columns,
+        User_::safe_columns_tuple(),
+        post::all_columns,
+        Community::safe_columns_tuple(),
+      ))
+      .into_boxed();
+
+    if let Some(community_id) = community_id {
+      query = query.filter(post::community_id.eq(community_id));
+    };
+
+    if let Some(mod_user_id) = mod_user_id {
+      query = query.filter(mod_lock_post::mod_user_id.eq(mod_user_id));
+    };
+
+    let (limit, offset) = limit_and_offset(page, limit);
+
+    let res = query
+      .limit(limit)
+      .offset(offset)
+      .order_by(mod_lock_post::when_.desc())
+      .load::<ModLockPostViewTuple>(conn)?;
+
+    Ok(Self::to_vec(res))
+  }
+}
+
+impl ViewToVec for ModLockPostView {
+  type DbTuple = ModLockPostViewTuple;
+  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
+    mrp
+      .iter()
+      .map(|a| Self {
+        mod_lock_post: a.0.to_owned(),
+        moderator: a.1.to_owned(),
+        post: a.2.to_owned(),
+        community: a.3.to_owned(),
+      })
+      .collect::<Vec<Self>>()
+  }
+}
diff --git a/lemmy_db/src/views/moderator/mod_remove_comment_view.rs b/lemmy_db/src/views/moderator/mod_remove_comment_view.rs
new file mode 100644 (file)
index 0000000..fb4b777
--- /dev/null
@@ -0,0 +1,95 @@
+use crate::{
+  limit_and_offset,
+  schema::{comment, community, mod_remove_comment, post, user_, user_alias_1},
+  source::{
+    comment::Comment,
+    community::{Community, CommunitySafe},
+    moderator::ModRemoveComment,
+    post::Post,
+    user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
+  },
+  views::ViewToVec,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use serde::Serialize;
+
+#[derive(Debug, Serialize, Clone)]
+pub struct ModRemoveCommentView {
+  pub mod_remove_comment: ModRemoveComment,
+  pub moderator: UserSafe,
+  pub comment: Comment,
+  pub commenter: UserSafeAlias1,
+  pub post: Post,
+  pub community: CommunitySafe,
+}
+
+type ModRemoveCommentViewTuple = (
+  ModRemoveComment,
+  UserSafe,
+  Comment,
+  UserSafeAlias1,
+  Post,
+  CommunitySafe,
+);
+
+impl ModRemoveCommentView {
+  pub fn list(
+    conn: &PgConnection,
+    community_id: Option<i32>,
+    mod_user_id: Option<i32>,
+    page: Option<i64>,
+    limit: Option<i64>,
+  ) -> Result<Vec<Self>, Error> {
+    let mut query = mod_remove_comment::table
+      .inner_join(user_::table)
+      .inner_join(comment::table)
+      .inner_join(user_alias_1::table.on(comment::creator_id.eq(user_alias_1::id)))
+      .inner_join(post::table.on(comment::post_id.eq(post::id)))
+      .inner_join(community::table.on(post::community_id.eq(community::id)))
+      .select((
+        mod_remove_comment::all_columns,
+        User_::safe_columns_tuple(),
+        comment::all_columns,
+        UserAlias1::safe_columns_tuple(),
+        post::all_columns,
+        Community::safe_columns_tuple(),
+      ))
+      .into_boxed();
+
+    if let Some(community_id) = community_id {
+      query = query.filter(post::community_id.eq(community_id));
+    };
+
+    if let Some(mod_user_id) = mod_user_id {
+      query = query.filter(mod_remove_comment::mod_user_id.eq(mod_user_id));
+    };
+
+    let (limit, offset) = limit_and_offset(page, limit);
+
+    let res = query
+      .limit(limit)
+      .offset(offset)
+      .order_by(mod_remove_comment::when_.desc())
+      .load::<ModRemoveCommentViewTuple>(conn)?;
+
+    Ok(Self::to_vec(res))
+  }
+}
+
+impl ViewToVec for ModRemoveCommentView {
+  type DbTuple = ModRemoveCommentViewTuple;
+  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
+    mrp
+      .iter()
+      .map(|a| Self {
+        mod_remove_comment: a.0.to_owned(),
+        moderator: a.1.to_owned(),
+        comment: a.2.to_owned(),
+        commenter: a.3.to_owned(),
+        post: a.4.to_owned(),
+        community: a.5.to_owned(),
+      })
+      .collect::<Vec<Self>>()
+  }
+}
diff --git a/lemmy_db/src/views/moderator/mod_remove_community_view.rs b/lemmy_db/src/views/moderator/mod_remove_community_view.rs
new file mode 100644 (file)
index 0000000..daaf6d7
--- /dev/null
@@ -0,0 +1,69 @@
+use crate::{
+  limit_and_offset,
+  schema::{community, mod_remove_community, user_},
+  source::{
+    community::{Community, CommunitySafe},
+    moderator::ModRemoveCommunity,
+    user::{UserSafe, User_},
+  },
+  views::ViewToVec,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use serde::Serialize;
+
+#[derive(Debug, Serialize, Clone)]
+pub struct ModRemoveCommunityView {
+  pub mod_remove_community: ModRemoveCommunity,
+  pub moderator: UserSafe,
+  pub community: CommunitySafe,
+}
+
+type ModRemoveCommunityTuple = (ModRemoveCommunity, UserSafe, CommunitySafe);
+
+impl ModRemoveCommunityView {
+  pub fn list(
+    conn: &PgConnection,
+    mod_user_id: Option<i32>,
+    page: Option<i64>,
+    limit: Option<i64>,
+  ) -> Result<Vec<Self>, Error> {
+    let mut query = mod_remove_community::table
+      .inner_join(user_::table)
+      .inner_join(community::table)
+      .select((
+        mod_remove_community::all_columns,
+        User_::safe_columns_tuple(),
+        Community::safe_columns_tuple(),
+      ))
+      .into_boxed();
+
+    if let Some(mod_user_id) = mod_user_id {
+      query = query.filter(mod_remove_community::mod_user_id.eq(mod_user_id));
+    };
+
+    let (limit, offset) = limit_and_offset(page, limit);
+
+    let res = query
+      .limit(limit)
+      .offset(offset)
+      .order_by(mod_remove_community::when_.desc())
+      .load::<ModRemoveCommunityTuple>(conn)?;
+
+    Ok(Self::to_vec(res))
+  }
+}
+
+impl ViewToVec for ModRemoveCommunityView {
+  type DbTuple = ModRemoveCommunityTuple;
+  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
+    mrp
+      .iter()
+      .map(|a| Self {
+        mod_remove_community: a.0.to_owned(),
+        moderator: a.1.to_owned(),
+        community: a.2.to_owned(),
+      })
+      .collect::<Vec<Self>>()
+  }
+}
diff --git a/lemmy_db/src/views/moderator/mod_remove_post_view.rs b/lemmy_db/src/views/moderator/mod_remove_post_view.rs
new file mode 100644 (file)
index 0000000..613a8a5
--- /dev/null
@@ -0,0 +1,79 @@
+use crate::{
+  limit_and_offset,
+  schema::{community, mod_remove_post, post, user_},
+  source::{
+    community::{Community, CommunitySafe},
+    moderator::ModRemovePost,
+    post::Post,
+    user::{UserSafe, User_},
+  },
+  views::ViewToVec,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use serde::Serialize;
+
+#[derive(Debug, Serialize, Clone)]
+pub struct ModRemovePostView {
+  pub mod_remove_post: ModRemovePost,
+  pub moderator: UserSafe,
+  pub post: Post,
+  pub community: CommunitySafe,
+}
+
+type ModRemovePostViewTuple = (ModRemovePost, UserSafe, Post, CommunitySafe);
+
+impl ModRemovePostView {
+  pub fn list(
+    conn: &PgConnection,
+    community_id: Option<i32>,
+    mod_user_id: Option<i32>,
+    page: Option<i64>,
+    limit: Option<i64>,
+  ) -> Result<Vec<Self>, Error> {
+    let mut query = mod_remove_post::table
+      .inner_join(user_::table)
+      .inner_join(post::table)
+      .inner_join(community::table.on(post::community_id.eq(community::id)))
+      .select((
+        mod_remove_post::all_columns,
+        User_::safe_columns_tuple(),
+        post::all_columns,
+        Community::safe_columns_tuple(),
+      ))
+      .into_boxed();
+
+    if let Some(community_id) = community_id {
+      query = query.filter(post::community_id.eq(community_id));
+    };
+
+    if let Some(mod_user_id) = mod_user_id {
+      query = query.filter(mod_remove_post::mod_user_id.eq(mod_user_id));
+    };
+
+    let (limit, offset) = limit_and_offset(page, limit);
+
+    let res = query
+      .limit(limit)
+      .offset(offset)
+      .order_by(mod_remove_post::when_.desc())
+      .load::<ModRemovePostViewTuple>(conn)?;
+
+    Ok(Self::to_vec(res))
+  }
+}
+
+impl ViewToVec for ModRemovePostView {
+  type DbTuple = ModRemovePostViewTuple;
+  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
+    mrp
+      .iter()
+      .map(|a| Self {
+        mod_remove_post: a.0.to_owned(),
+        moderator: a.1.to_owned(),
+        post: a.2.to_owned(),
+        community: a.3.to_owned(),
+      })
+      .collect::<Vec<Self>>()
+  }
+}
diff --git a/lemmy_db/src/views/moderator/mod_sticky_post_view.rs b/lemmy_db/src/views/moderator/mod_sticky_post_view.rs
new file mode 100644 (file)
index 0000000..9a3d118
--- /dev/null
@@ -0,0 +1,79 @@
+use crate::{
+  limit_and_offset,
+  schema::{community, mod_sticky_post, post, user_},
+  source::{
+    community::{Community, CommunitySafe},
+    moderator::ModStickyPost,
+    post::Post,
+    user::{UserSafe, User_},
+  },
+  views::ViewToVec,
+  ToSafe,
+};
+use diesel::{result::Error, *};
+use serde::Serialize;
+
+#[derive(Debug, Serialize, Clone)]
+pub struct ModStickyPostView {
+  pub mod_sticky_post: ModStickyPost,
+  pub moderator: UserSafe,
+  pub post: Post,
+  pub community: CommunitySafe,
+}
+
+type ModStickyPostViewTuple = (ModStickyPost, UserSafe, Post, CommunitySafe);
+
+impl ModStickyPostView {
+  pub fn list(
+    conn: &PgConnection,
+    community_id: Option<i32>,
+    mod_user_id: Option<i32>,
+    page: Option<i64>,
+    limit: Option<i64>,
+  ) -> Result<Vec<Self>, Error> {
+    let mut query = mod_sticky_post::table
+      .inner_join(user_::table)
+      .inner_join(post::table)
+      .inner_join(community::table.on(post::community_id.eq(community::id)))
+      .select((
+        mod_sticky_post::all_columns,
+        User_::safe_columns_tuple(),
+        post::all_columns,
+        Community::safe_columns_tuple(),
+      ))
+      .into_boxed();
+
+    if let Some(community_id) = community_id {
+      query = query.filter(post::community_id.eq(community_id));
+    };
+
+    if let Some(mod_user_id) = mod_user_id {
+      query = query.filter(mod_sticky_post::mod_user_id.eq(mod_user_id));
+    };
+
+    let (limit, offset) = limit_and_offset(page, limit);
+
+    let res = query
+      .limit(limit)
+      .offset(offset)
+      .order_by(mod_sticky_post::when_.desc())
+      .load::<ModStickyPostViewTuple>(conn)?;
+
+    Ok(Self::to_vec(res))
+  }
+}
+
+impl ViewToVec for ModStickyPostView {
+  type DbTuple = ModStickyPostViewTuple;
+  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
+    mrp
+      .iter()
+      .map(|a| Self {
+        mod_sticky_post: a.0.to_owned(),
+        moderator: a.1.to_owned(),
+        post: a.2.to_owned(),
+        community: a.3.to_owned(),
+      })
+      .collect::<Vec<Self>>()
+  }
+}
index c107084bb92beb6d967ed88446cd5e2115f8cc84..ac7837c52c2198e46792a25f5ca13ac10de7f5e6 100644 (file)
@@ -1,7 +1,9 @@
 use lemmy_db::views::{
-  community_follower_view::CommunityFollowerView,
-  community_moderator_view::CommunityModeratorView,
-  community_view::CommunityView,
+  community::{
+    community_follower_view::CommunityFollowerView,
+    community_moderator_view::CommunityModeratorView,
+    community_view::CommunityView,
+  },
   user_view::UserViewSafe,
 };
 use serde::{Deserialize, Serialize};
index eea107a7ead840a19111f3b10d2d3bec2f63b417..bf0af2f8afaf6c3e45563a046c48ca376bcd1f5a 100644 (file)
@@ -2,8 +2,7 @@ use lemmy_db::{
   post_report::PostReportView,
   views::{
     comment_view::CommentView,
-    community_moderator_view::CommunityModeratorView,
-    community_view::CommunityView,
+    community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
     post_view::PostView,
   },
 };
index f32b841346563987343b237876aeeff0fa97881e..9209a54202cd2325e8c921800fd4d38c6dccee95 100644 (file)
@@ -1,10 +1,20 @@
 use lemmy_db::{
   aggregates::site_aggregates::SiteAggregates,
-  moderator_views::*,
   source::{category::*, user::*},
   views::{
     comment_view::CommentView,
-    community_view::CommunityView,
+    community::community_view::CommunityView,
+    moderator::{
+      mod_add_community_view::ModAddCommunityView,
+      mod_add_view::ModAddView,
+      mod_ban_from_community_view::ModBanFromCommunityView,
+      mod_ban_view::ModBanView,
+      mod_lock_post_view::ModLockPostView,
+      mod_remove_comment_view::ModRemoveCommentView,
+      mod_remove_community_view::ModRemoveCommunityView,
+      mod_remove_post_view::ModRemovePostView,
+      mod_sticky_post_view::ModStickyPostView,
+    },
     post_view::PostView,
     site_view::SiteView,
     user_view::UserViewSafe,
index 9ebb14f4c32961398ddde8838f0aae1087ad09d3..1bd320cd0b3d54f93e91de247fd3be8c18df871e 100644 (file)
@@ -2,8 +2,10 @@ use lemmy_db::{
   private_message_view::PrivateMessageView,
   views::{
     comment_view::CommentView,
-    community_follower_view::CommunityFollowerView,
-    community_moderator_view::CommunityModeratorView,
+    community::{
+      community_follower_view::CommunityFollowerView,
+      community_moderator_view::CommunityModeratorView,
+    },
     post_view::PostView,
     user_mention_view::UserMentionView,
     user_view::{UserViewDangerous, UserViewSafe},