lemmy/crates/db_schema/src/aggregates/person_post_aggregates.rs
Dessalines 0aeb78b8f3
Showing # of unread comments for posts. Fixes #2134 (#2393)
* Showing # of unread comments for posts. Fixes #2134

* Fix lint.

* Forgot to remove comment list update.

* Fix clippy
2022-09-27 16:45:46 +00:00

28 lines
811 B
Rust

use crate::{
aggregates::structs::{PersonPostAggregates, PersonPostAggregatesForm},
newtypes::{PersonId, PostId},
};
use diesel::{result::Error, *};
impl PersonPostAggregates {
pub fn upsert(conn: &mut PgConnection, form: &PersonPostAggregatesForm) -> Result<Self, Error> {
use crate::schema::person_post_aggregates::dsl::*;
insert_into(person_post_aggregates)
.values(form)
.on_conflict((person_id, post_id))
.do_update()
.set(form)
.get_result::<Self>(conn)
}
pub fn read(
conn: &mut PgConnection,
person_id_: PersonId,
post_id_: PostId,
) -> Result<Self, Error> {
use crate::schema::person_post_aggregates::dsl::*;
person_post_aggregates
.filter(post_id.eq(post_id_).and(person_id.eq(person_id_)))
.first::<Self>(conn)
}
}