- fn read(conn: &mut PgConnection, community_id: CommunityId) -> Result<Self, Error> {
- use crate::schema::community::dsl::*;
- community.find(community_id).first::<Self>(conn)
- }
-
- fn delete(conn: &mut PgConnection, community_id: CommunityId) -> Result<usize, Error> {
- use crate::schema::community::dsl::*;
- diesel::delete(community.find(community_id)).execute(conn)
- }
-
- fn create(conn: &mut PgConnection, new_community: &CommunityForm) -> Result<Self, Error> {
- use crate::schema::community::dsl::*;
- let community_ = insert_into(community)
- .values(new_community)
- .get_result::<Self>(conn)?;
-
- let site_languages = SiteLanguage::read_local(conn);
- if let Ok(langs) = site_languages {
- // if site exists, init user with site languages
- CommunityLanguage::update(conn, langs, community_.id)?;
- } else {
- // otherwise, init with all languages (this only happens during tests)
- CommunityLanguage::update(conn, vec![], community_.id)?;
- }