]> Untitled Git - lemmy.git/blob - lemmy_db/src/aggregates/comment_aggregates.rs
Beginning to add new comment_view.
[lemmy.git] / lemmy_db / src / aggregates / comment_aggregates.rs
1 use crate::schema::comment_aggregates;
2 use diesel::{result::Error, *};
3 use serde::Serialize;
4
5 #[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
6 #[table_name = "comment_aggregates"]
7 pub struct CommentAggregates {
8   pub id: i32,
9   pub comment_id: i32,
10   pub score: i64,
11   pub upvotes: i64,
12   pub downvotes: i64,
13 }
14
15 impl CommentAggregates {
16   pub fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> {
17     comment_aggregates::table
18       .filter(comment_aggregates::comment_id.eq(comment_id))
19       .first::<Self>(conn)
20   }
21 }
22
23 // TODO add tests here