-use crate::{newtypes::CommunityId, schema::community_aggregates};
+use crate::{
+ aggregates::structs::CommunityAggregates,
+ newtypes::CommunityId,
+ schema::community_aggregates,
+};
use diesel::{result::Error, *};
-use serde::{Deserialize, Serialize};
-
-#[derive(
- Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Deserialize, Clone,
-)]
-#[table_name = "community_aggregates"]
-pub struct CommunityAggregates {
- pub id: i32,
- pub community_id: CommunityId,
- pub subscribers: i64,
- pub posts: i64,
- pub comments: i64,
- pub published: chrono::NaiveDateTime,
- pub users_active_day: i64,
- pub users_active_week: i64,
- pub users_active_month: i64,
- pub users_active_half_year: i64,
-}
impl CommunityAggregates {
pub fn read(conn: &PgConnection, community_id: CommunityId) -> Result<Self, Error> {
mod tests {
use crate::{
aggregates::community_aggregates::CommunityAggregates,
- establish_unpooled_connection,
source::{
comment::{Comment, CommentForm},
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
post::{Post, PostForm},
},
traits::{Crud, Followable},
+ utils::establish_unpooled_connection,
};
use serial_test::serial;
let first_person_follow = CommunityFollowerForm {
community_id: inserted_community.id,
person_id: inserted_person.id,
- pending: false,
+ pending: Some(false),
};
CommunityFollower::follow(&conn, &first_person_follow).unwrap();
let second_person_follow = CommunityFollowerForm {
community_id: inserted_community.id,
person_id: another_inserted_person.id,
- pending: false,
+ pending: Some(false),
};
CommunityFollower::follow(&conn, &second_person_follow).unwrap();
let another_community_follow = CommunityFollowerForm {
community_id: another_inserted_community.id,
person_id: inserted_person.id,
- pending: false,
+ pending: Some(false),
};
CommunityFollower::follow(&conn, &another_community_follow).unwrap();