-impl ViewToVec for CommunityView {
- type DbTuple = CommunityViewTuple;
- fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
- items
- .into_iter()
- .map(|a| Self {
- community: a.0,
- counts: a.1,
- subscribed: CommunityFollower::to_subscribed_type(&a.2),
- blocked: a.3.is_some(),
- })
- .collect::<Vec<Self>>()
+#[derive(Default)]
+pub struct CommunityQuery<'a> {
+ pub listing_type: Option<ListingType>,
+ pub sort: Option<SortType>,
+ pub local_user: Option<&'a LocalUser>,
+ pub search_term: Option<String>,
+ pub is_mod_or_admin: Option<bool>,
+ pub show_nsfw: Option<bool>,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
+}
+
+impl<'a> CommunityQuery<'a> {
+ pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<CommunityView>, Error> {
+ queries().list(pool, self).await
+ }
+}
+
+impl JoinView for CommunityView {
+ type JoinTuple = CommunityViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ community: a.0,
+ counts: a.1,
+ subscribed: a.2,
+ blocked: a.3,
+ }