use crate::{
newtypes::{CommunityId, DbUrl, PersonId, PostId},
- schema::post::dsl::*,
+ schema::post::dsl::{
+ ap_id,
+ body,
+ community_id,
+ creator_id,
+ deleted,
+ featured_community,
+ name,
+ post,
+ published,
+ removed,
+ thumbnail_url,
+ updated,
+ url,
+ },
source::post::{
Post,
PostInsertForm,
utils::{get_conn, naive_now, DbPool, FETCH_LIMIT_MAX},
};
use ::url::Url;
-use diesel::{dsl::*, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
use diesel_async::RunQueryDsl;
#[async_trait]
.filter(community_id.eq(the_community_id))
.filter(deleted.eq(false))
.filter(removed.eq(false))
+ .then_order_by(featured_community.desc())
+ .then_order_by(published.desc())
+ .limit(FETCH_LIMIT_MAX)
+ .load::<Self>(conn)
+ .await
+ }
+
+ pub async fn list_featured_for_community(
+ pool: &DbPool,
+ the_community_id: CommunityId,
+ ) -> Result<Vec<Self>, Error> {
+ let conn = &mut get_conn(pool).await?;
+ post
+ .filter(community_id.eq(the_community_id))
+ .filter(deleted.eq(false))
+ .filter(removed.eq(false))
+ .filter(featured_community.eq(true))
.then_order_by(published.desc())
- .then_order_by(stickied.desc())
.limit(FETCH_LIMIT_MAX)
.load::<Self>(conn)
.await
pool: &DbPool,
for_creator_id: PersonId,
) -> Result<Vec<Self>, Error> {
- use crate::schema::post::dsl::*;
let conn = &mut get_conn(pool).await?;
let pictrs_search = "%pictrs/image%";
type Form = PostLikeForm;
type IdType = PostId;
async fn like(pool: &DbPool, post_like_form: &PostLikeForm) -> Result<Self, Error> {
- use crate::schema::post_like::dsl::*;
+ use crate::schema::post_like::dsl::{person_id, post_id, post_like};
let conn = &mut get_conn(pool).await?;
insert_into(post_like)
.values(post_like_form)
impl Saveable for PostSaved {
type Form = PostSavedForm;
async fn save(pool: &DbPool, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
- use crate::schema::post_saved::dsl::*;
+ use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
let conn = &mut get_conn(pool).await?;
insert_into(post_saved)
.values(post_saved_form)
.await
}
async fn unsave(pool: &DbPool, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
- use crate::schema::post_saved::dsl::*;
+ use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
let conn = &mut get_conn(pool).await?;
diesel::delete(
post_saved
impl Readable for PostRead {
type Form = PostReadForm;
async fn mark_as_read(pool: &DbPool, post_read_form: &PostReadForm) -> Result<Self, Error> {
- use crate::schema::post_read::dsl::*;
+ use crate::schema::post_read::dsl::{person_id, post_id, post_read};
let conn = &mut get_conn(pool).await?;
insert_into(post_read)
.values(post_read_form)
}
async fn mark_as_unread(pool: &DbPool, post_read_form: &PostReadForm) -> Result<usize, Error> {
- use crate::schema::post_read::dsl::*;
+ use crate::schema::post_read::dsl::{person_id, post_id, post_read};
let conn = &mut get_conn(pool).await?;
diesel::delete(
post_read
impl DeleteableOrRemoveable for Post {
fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.name = "".into();
+ self.name = String::new();
self.url = None;
self.body = None;
self.embed_title = None;
source::{
community::{Community, CommunityInsertForm},
instance::Instance,
- person::*,
- post::*,
+ person::{Person, PersonInsertForm},
+ post::{
+ Post,
+ PostInsertForm,
+ PostLike,
+ PostLikeForm,
+ PostRead,
+ PostReadForm,
+ PostSaved,
+ PostSavedForm,
+ PostUpdateForm,
+ },
},
traits::{Crud, Likeable, Readable, Saveable},
utils::build_db_pool_for_tests,
published: inserted_post.published,
removed: false,
locked: false,
- stickied: false,
nsfw: false,
deleted: false,
updated: None,
embed_description: None,
embed_video_url: None,
thumbnail_url: None,
- ap_id: inserted_post.ap_id.to_owned(),
+ ap_id: inserted_post.ap_id.clone(),
local: true,
language_id: Default::default(),
+ featured_community: false,
+ featured_local: false,
};
// Post Like