mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-01 02:00:01 +00:00
0aeb78b8f3
* Showing # of unread comments for posts. Fixes #2134 * Fix lint. * Forgot to remove comment list update. * Fix clippy
27 lines
811 B
Rust
27 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)
|
|
}
|
|
}
|