Simplifying forms.

This commit is contained in:
Dessalines 2024-11-12 15:11:53 -05:00
parent c3d0bca6a6
commit d955557f63

View file

@ -280,12 +280,11 @@ impl Likeable for PostLike {
type IdType = PostId;
async fn like(pool: &mut DbPool<'_>, post_like_form: &PostLikeForm) -> Result<Self, Error> {
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)
.values(post_like_form)
.on_conflict((post_actions::post_id, post_actions::person_id))
.do_update()
.set(post_like_form)
.set(post_actions::liked.eq(now().nullable()))
.returning(Self::as_select())
.get_result::<Self>(conn)
.await
@ -309,12 +308,11 @@ impl Saveable for PostSaved {
type Form = PostSavedForm;
async fn save(pool: &mut DbPool<'_>, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
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)
.values(post_saved_form)
.on_conflict((post_actions::post_id, post_actions::person_id))
.do_update()
.set(post_saved_form)
.set(post_actions::saved.eq(now().nullable()))
.returning(Self::as_select())
.get_result::<Self>(conn)
.await