-impl DeleteableOrRemoveable for Community {
- fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.title = "".into();
- self.description = None;
- self.icon = None;
- self.banner = None;
- self
+impl Community {
+ /// Get the community which has a given moderators or featured url, also return the collection type
+ pub async fn get_by_collection_url(
+ pool: &mut DbPool<'_>,
+ url: &DbUrl,
+ ) -> Result<(Community, CollectionType), Error> {
+ use crate::schema::community::dsl::{featured_url, moderators_url};
+ use CollectionType::*;
+ let conn = &mut get_conn(pool).await?;
+ let res = community::table
+ .filter(moderators_url.eq(url))
+ .first::<Self>(conn)
+ .await;
+ if let Ok(c) = res {
+ return Ok((c, Moderators));
+ }
+ let res = community::table
+ .filter(featured_url.eq(url))
+ .first::<Self>(conn)
+ .await;
+ if let Ok(c) = res {
+ return Ok((c, Featured));
+ }
+ Err(diesel::NotFound)