-use crate::{newtypes::CommentId, schema::comment_aggregates};
+use crate::{
+ aggregates::structs::CommentAggregates,
+ newtypes::CommentId,
+ schema::comment_aggregates,
+};
use diesel::{result::Error, *};
-use serde::{Deserialize, Serialize};
-
-#[derive(
- Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize, Clone,
-)]
-#[table_name = "comment_aggregates"]
-pub struct CommentAggregates {
- pub id: i32,
- pub comment_id: CommentId,
- pub score: i64,
- pub upvotes: i64,
- pub downvotes: i64,
- pub published: chrono::NaiveDateTime,
-}
impl CommentAggregates {
pub fn read(conn: &PgConnection, comment_id: CommentId) -> Result<Self, Error> {
mod tests {
use crate::{
aggregates::comment_aggregates::CommentAggregates,
- establish_unpooled_connection,
source::{
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
community::{Community, CommunityForm},
post::{Post, PostForm},
},
traits::{Crud, Likeable},
+ utils::establish_unpooled_connection,
};
use serial_test::serial;
let new_person = PersonForm {
name: "thommy_comment_agg".into(),
+ public_key: Some("pubkey".to_string()),
..PersonForm::default()
};
let another_person = PersonForm {
name: "jerry_comment_agg".into(),
+ public_key: Some("pubkey".to_string()),
..PersonForm::default()
};
let new_community = CommunityForm {
name: "TIL_comment_agg".into(),
title: "nada".to_owned(),
+ public_key: Some("pubkey".to_string()),
..CommunityForm::default()
};
..CommentForm::default()
};
- let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
+ let inserted_comment = Comment::create(&conn, &comment_form, None).unwrap();
let child_comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_person.id,
post_id: inserted_post.id,
- parent_id: Some(inserted_comment.id),
..CommentForm::default()
};
- let _inserted_child_comment = Comment::create(&conn, &child_comment_form).unwrap();
+ let _inserted_child_comment =
+ Comment::create(&conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
let comment_like = CommentLikeForm {
comment_id: inserted_comment.id,