use crate::{
naive_now,
schema::{community, community_follower, community_moderator, community_user_ban},
+ ApubObject,
Bannable,
Crud,
Followable,
}
}
-impl Community {
- pub fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Self, Error> {
+impl ApubObject<CommunityForm> for Community {
+ fn read_from_apub_id(conn: &PgConnection, for_actor_id: &str) -> Result<Self, Error> {
use crate::schema::community::dsl::*;
community
- .filter(local.eq(true))
- .filter(name.eq(community_name))
+ .filter(actor_id.eq(for_actor_id))
.first::<Self>(conn)
}
- pub fn read_from_actor_id(conn: &PgConnection, for_actor_id: &str) -> Result<Self, Error> {
+ fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
+ use crate::schema::community::dsl::*;
+ insert_into(community)
+ .values(community_form)
+ .on_conflict(actor_id)
+ .do_update()
+ .set(community_form)
+ .get_result::<Self>(conn)
+ }
+}
+
+impl Community {
+ pub fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Self, Error> {
use crate::schema::community::dsl::*;
community
- .filter(actor_id.eq(for_actor_id))
+ .filter(local.eq(true))
+ .filter(name.eq(community_name))
.first::<Self>(conn)
}
.unwrap_or_default()
.contains(&user_id)
}
-
- pub fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
- use crate::schema::community::dsl::*;
- insert_into(community)
- .values(community_form)
- .on_conflict(actor_id)
- .do_update()
- .set(community_form)
- .get_result::<Self>(conn)
- }
}
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]