Adding community_view to PostResponse.
- Changing to_vec function name.
This commit is contained in:
parent
e5a65d5807
commit
58281208b9
22 changed files with 77 additions and 64 deletions
|
@ -14,7 +14,7 @@ use lemmy_db::{
|
|||
source::post::Post_,
|
||||
views::{
|
||||
comment_view::CommentQueryBuilder,
|
||||
community::community_moderator_view::CommunityModeratorView,
|
||||
community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
|
||||
post_report_view::{PostReportQueryBuilder, PostReportView},
|
||||
post_view::{PostQueryBuilder, PostView},
|
||||
},
|
||||
|
@ -201,6 +201,16 @@ impl Perform for GetPost {
|
|||
})
|
||||
.await??;
|
||||
|
||||
// Necessary for the sidebar
|
||||
let community_view = match blocking(context.pool(), move |conn| {
|
||||
CommunityView::read(conn, community_id, user_id)
|
||||
})
|
||||
.await?
|
||||
{
|
||||
Ok(community) => community,
|
||||
Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
|
||||
};
|
||||
|
||||
let online = context
|
||||
.chat_server()
|
||||
.send(GetPostUsersOnline { post_id: data.id })
|
||||
|
@ -210,6 +220,7 @@ impl Perform for GetPost {
|
|||
// Return the jwt
|
||||
Ok(GetPostResponse {
|
||||
post_view,
|
||||
community_view,
|
||||
comments,
|
||||
moderators,
|
||||
online,
|
||||
|
|
|
@ -167,14 +167,14 @@ impl<'a> CommentReportQueryBuilder<'a> {
|
|||
.offset(offset)
|
||||
.load::<CommentReportViewTuple>(self.conn)?;
|
||||
|
||||
Ok(CommentReportView::to_vec(res))
|
||||
Ok(CommentReportView::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for CommentReportView {
|
||||
type DbTuple = CommentReportViewTuple;
|
||||
fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
posts
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
comment_report: a.0.to_owned(),
|
||||
|
|
|
@ -391,14 +391,14 @@ impl<'a> CommentQueryBuilder<'a> {
|
|||
.offset(offset)
|
||||
.load::<CommentViewTuple>(self.conn)?;
|
||||
|
||||
Ok(CommentView::to_vec(res))
|
||||
Ok(CommentView::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for CommentView {
|
||||
type DbTuple = CommentViewTuple;
|
||||
fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
posts
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
comment: a.0.to_owned(),
|
||||
|
|
|
@ -27,7 +27,7 @@ impl CommunityFollowerView {
|
|||
.order_by(community_follower::published)
|
||||
.load::<CommunityFollowerViewTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
|
||||
pub fn for_user(conn: &PgConnection, user_id: i32) -> Result<Vec<Self>, Error> {
|
||||
|
@ -39,14 +39,14 @@ impl CommunityFollowerView {
|
|||
.order_by(community_follower::published)
|
||||
.load::<CommunityFollowerViewTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for CommunityFollowerView {
|
||||
type DbTuple = CommunityFollowerViewTuple;
|
||||
fn to_vec(users: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
users
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
community: a.0.to_owned(),
|
||||
|
|
|
@ -27,7 +27,7 @@ impl CommunityModeratorView {
|
|||
.order_by(community_moderator::published)
|
||||
.load::<CommunityModeratorViewTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
|
||||
pub fn for_user(conn: &PgConnection, user_id: i32) -> Result<Vec<Self>, Error> {
|
||||
|
@ -39,14 +39,14 @@ impl CommunityModeratorView {
|
|||
.order_by(community_moderator::published)
|
||||
.load::<CommunityModeratorViewTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for CommunityModeratorView {
|
||||
type DbTuple = CommunityModeratorViewTuple;
|
||||
fn to_vec(community_moderators: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
community_moderators
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
community: a.0.to_owned(),
|
||||
|
|
|
@ -185,14 +185,14 @@ impl<'a> CommunityQueryBuilder<'a> {
|
|||
.filter(community::deleted.eq(false))
|
||||
.load::<CommunityViewTuple>(self.conn)?;
|
||||
|
||||
Ok(CommunityView::to_vec(res))
|
||||
Ok(CommunityView::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for CommunityView {
|
||||
type DbTuple = CommunityViewTuple;
|
||||
fn to_vec(communities: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
communities
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
community: a.0.to_owned(),
|
||||
|
|
|
@ -11,7 +11,7 @@ pub mod user_view;
|
|||
|
||||
pub(crate) trait ViewToVec {
|
||||
type DbTuple;
|
||||
fn to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
|
||||
fn from_tuple_to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
|
|
@ -56,14 +56,14 @@ impl ModAddCommunityView {
|
|||
.order_by(mod_add_community::when_.desc())
|
||||
.load::<ModAddCommunityViewTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModAddCommunityView {
|
||||
type DbTuple = ModAddCommunityViewTuple;
|
||||
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
mrp
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
mod_add_community: a.0.to_owned(),
|
||||
|
|
|
@ -47,14 +47,14 @@ impl ModAddView {
|
|||
.order_by(mod_add::when_.desc())
|
||||
.load::<ModAddViewTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModAddView {
|
||||
type DbTuple = ModAddViewTuple;
|
||||
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
mrp
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
mod_add: a.0.to_owned(),
|
||||
|
|
|
@ -56,14 +56,14 @@ impl ModBanFromCommunityView {
|
|||
.order_by(mod_ban_from_community::when_.desc())
|
||||
.load::<ModBanFromCommunityViewTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModBanFromCommunityView {
|
||||
type DbTuple = ModBanFromCommunityViewTuple;
|
||||
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
mrp
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
mod_ban_from_community: a.0.to_owned(),
|
||||
|
|
|
@ -47,14 +47,14 @@ impl ModBanView {
|
|||
.order_by(mod_ban::when_.desc())
|
||||
.load::<ModBanViewTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModBanView {
|
||||
type DbTuple = ModBanViewTuple;
|
||||
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
mrp
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
mod_ban: a.0.to_owned(),
|
||||
|
|
|
@ -57,14 +57,14 @@ impl ModLockPostView {
|
|||
.order_by(mod_lock_post::when_.desc())
|
||||
.load::<ModLockPostViewTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModLockPostView {
|
||||
type DbTuple = ModLockPostViewTuple;
|
||||
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
mrp
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
mod_lock_post: a.0.to_owned(),
|
||||
|
|
|
@ -71,14 +71,14 @@ impl ModRemoveCommentView {
|
|||
.order_by(mod_remove_comment::when_.desc())
|
||||
.load::<ModRemoveCommentViewTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModRemoveCommentView {
|
||||
type DbTuple = ModRemoveCommentViewTuple;
|
||||
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
mrp
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
mod_remove_comment: a.0.to_owned(),
|
||||
|
|
|
@ -48,14 +48,14 @@ impl ModRemoveCommunityView {
|
|||
.order_by(mod_remove_community::when_.desc())
|
||||
.load::<ModRemoveCommunityTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModRemoveCommunityView {
|
||||
type DbTuple = ModRemoveCommunityTuple;
|
||||
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
mrp
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
mod_remove_community: a.0.to_owned(),
|
||||
|
|
|
@ -57,14 +57,14 @@ impl ModRemovePostView {
|
|||
.order_by(mod_remove_post::when_.desc())
|
||||
.load::<ModRemovePostViewTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModRemovePostView {
|
||||
type DbTuple = ModRemovePostViewTuple;
|
||||
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
mrp
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
mod_remove_post: a.0.to_owned(),
|
||||
|
|
|
@ -57,14 +57,14 @@ impl ModStickyPostView {
|
|||
.order_by(mod_sticky_post::when_.desc())
|
||||
.load::<ModStickyPostViewTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(res))
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModStickyPostView {
|
||||
type DbTuple = ModStickyPostViewTuple;
|
||||
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
mrp
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
mod_sticky_post: a.0.to_owned(),
|
||||
|
|
|
@ -153,14 +153,14 @@ impl<'a> PostReportQueryBuilder<'a> {
|
|||
.offset(offset)
|
||||
.load::<PostReportViewTuple>(self.conn)?;
|
||||
|
||||
Ok(PostReportView::to_vec(res))
|
||||
Ok(PostReportView::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for PostReportView {
|
||||
type DbTuple = PostReportViewTuple;
|
||||
fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
posts
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
post_report: a.0.to_owned(),
|
||||
|
|
|
@ -380,14 +380,14 @@ impl<'a> PostQueryBuilder<'a> {
|
|||
.filter(community::deleted.eq(false))
|
||||
.load::<PostViewTuple>(self.conn)?;
|
||||
|
||||
Ok(PostView::to_vec(res))
|
||||
Ok(PostView::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for PostView {
|
||||
type DbTuple = PostViewTuple;
|
||||
fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
posts
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
post: a.0.to_owned(),
|
||||
|
|
|
@ -109,14 +109,15 @@ impl<'a> PrivateMessageQueryBuilder<'a> {
|
|||
.order_by(private_message::published.desc())
|
||||
.load::<PrivateMessageViewTuple>(self.conn)?;
|
||||
|
||||
Ok(PrivateMessageView::to_vec(res))
|
||||
Ok(PrivateMessageView::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for PrivateMessageView {
|
||||
type DbTuple = PrivateMessageViewTuple;
|
||||
fn to_vec(pm: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
pm.iter()
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
private_message: a.0.to_owned(),
|
||||
creator: a.1.to_owned(),
|
||||
|
|
|
@ -293,14 +293,14 @@ impl<'a> UserMentionQueryBuilder<'a> {
|
|||
.offset(offset)
|
||||
.load::<UserMentionViewTuple>(self.conn)?;
|
||||
|
||||
Ok(UserMentionView::to_vec(res))
|
||||
Ok(UserMentionView::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for UserMentionView {
|
||||
type DbTuple = UserMentionViewTuple;
|
||||
fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
posts
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
user_mention: a.0.to_owned(),
|
||||
|
|
|
@ -58,7 +58,7 @@ impl UserViewSafe {
|
|||
.order_by(user_::published)
|
||||
.load::<UserViewSafeTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(admins))
|
||||
Ok(Self::from_tuple_to_vec(admins))
|
||||
}
|
||||
|
||||
pub fn banned(conn: &PgConnection) -> Result<Vec<Self>, Error> {
|
||||
|
@ -68,7 +68,7 @@ impl UserViewSafe {
|
|||
.filter(user_::banned.eq(true))
|
||||
.load::<UserViewSafeTuple>(conn)?;
|
||||
|
||||
Ok(Self::to_vec(banned))
|
||||
Ok(Self::from_tuple_to_vec(banned))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,14 +149,14 @@ impl<'a> UserQueryBuilder<'a> {
|
|||
|
||||
let res = query.load::<UserViewSafeTuple>(self.conn)?;
|
||||
|
||||
Ok(UserViewSafe::to_vec(res))
|
||||
Ok(UserViewSafe::from_tuple_to_vec(res))
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for UserViewSafe {
|
||||
type DbTuple = UserViewSafeTuple;
|
||||
fn to_vec(users: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
users
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.iter()
|
||||
.map(|a| Self {
|
||||
user: a.0.to_owned(),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use lemmy_db::views::{
|
||||
comment_view::CommentView,
|
||||
community::community_moderator_view::CommunityModeratorView,
|
||||
community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
|
||||
post_report_view::PostReportView,
|
||||
post_view::PostView,
|
||||
};
|
||||
|
@ -30,6 +30,7 @@ pub struct GetPost {
|
|||
#[derive(Serialize)]
|
||||
pub struct GetPostResponse {
|
||||
pub post_view: PostView,
|
||||
pub community_view: CommunityView,
|
||||
pub comments: Vec<CommentView>,
|
||||
pub moderators: Vec<CommunityModeratorView>,
|
||||
pub online: usize,
|
||||
|
|
Loading…
Reference in a new issue