Fixing forms.

This commit is contained in:
Dessalines 2024-11-12 16:09:26 -05:00
parent d955557f63
commit 3c76822465

View file

@ -280,11 +280,12 @@ impl Likeable for PostLike {
type IdType = PostId; type IdType = PostId;
async fn like(pool: &mut DbPool<'_>, post_like_form: &PostLikeForm) -> Result<Self, Error> { async fn like(pool: &mut DbPool<'_>, post_like_form: &PostLikeForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let post_like_form = (post_like_form, post_actions::liked.eq(now().nullable()));
insert_into(post_actions::table) insert_into(post_actions::table)
.values(post_like_form) .values(post_like_form)
.on_conflict((post_actions::post_id, post_actions::person_id)) .on_conflict((post_actions::post_id, post_actions::person_id))
.do_update() .do_update()
.set(post_actions::liked.eq(now().nullable())) .set(post_like_form)
.returning(Self::as_select()) .returning(Self::as_select())
.get_result::<Self>(conn) .get_result::<Self>(conn)
.await .await
@ -308,11 +309,12 @@ impl Saveable for PostSaved {
type Form = PostSavedForm; type Form = PostSavedForm;
async fn save(pool: &mut DbPool<'_>, post_saved_form: &PostSavedForm) -> Result<Self, Error> { async fn save(pool: &mut DbPool<'_>, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let post_saved_form = (post_saved_form, post_actions::saved.eq(now().nullable()));
insert_into(post_actions::table) insert_into(post_actions::table)
.values(post_saved_form) .values(post_saved_form)
.on_conflict((post_actions::post_id, post_actions::person_id)) .on_conflict((post_actions::post_id, post_actions::person_id))
.do_update() .do_update()
.set(post_actions::saved.eq(now().nullable())) .set(post_saved_form)
.returning(Self::as_select()) .returning(Self::as_select())
.get_result::<Self>(conn) .get_result::<Self>(conn)
.await .await
@ -337,13 +339,16 @@ impl PostRead {
) -> Result<usize, Error> { ) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let form = PostReadForm { post_id, person_id }; let form = (
&PostReadForm { post_id, person_id },
post_actions::read.eq(now().nullable()),
);
insert_into(post_actions::table) insert_into(post_actions::table)
.values(form) .values(form)
.on_conflict((post_actions::person_id, post_actions::post_id)) .on_conflict((post_actions::person_id, post_actions::post_id))
.do_update() .do_update()
.set(post_actions::read.eq(now().nullable())) .set(form)
.execute(conn) .execute(conn)
.await .await
} }
@ -374,12 +379,15 @@ impl PostHide {
) -> Result<usize, Error> { ) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let form = PostHideForm { post_id, person_id }; let form = (
&PostHideForm { post_id, person_id },
post_actions::hidden.eq(now().nullable()),
);
insert_into(post_actions::table) insert_into(post_actions::table)
.values(form) .values(form)
.on_conflict((post_actions::person_id, post_actions::post_id)) .on_conflict((post_actions::person_id, post_actions::post_id))
.do_update() .do_update()
.set(post_actions::hidden.eq(now().nullable())) .set(form)
.execute(conn) .execute(conn)
.await .await
} }