-impl ViewToVec for CommentView {
- type DbTuple = CommentViewTuple;
- fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
- items
- .into_iter()
- .map(|a| Self {
- comment: a.0,
- creator: a.1,
- post: a.2,
- community: a.3,
- counts: a.4,
- creator_banned_from_community: a.5.is_some(),
- subscribed: CommunityFollower::to_subscribed_type(&a.6),
- saved: a.7.is_some(),
- creator_blocked: a.8.is_some(),
- my_vote: a.9,
- })
- .collect::<Vec<Self>>()
+#[derive(Default)]
+pub struct CommentQuery<'a> {
+ pub listing_type: Option<ListingType>,
+ pub sort: Option<CommentSortType>,
+ pub community_id: Option<CommunityId>,
+ pub post_id: Option<PostId>,
+ pub parent_path: Option<Ltree>,
+ pub creator_id: Option<PersonId>,
+ pub local_user: Option<&'a LocalUserView>,
+ pub search_term: Option<String>,
+ pub saved_only: Option<bool>,
+ pub liked_only: Option<bool>,
+ pub disliked_only: Option<bool>,
+ pub is_profile_view: bool,
+ pub page: Option<i64>,
+ pub limit: Option<i64>,
+ pub max_depth: Option<i32>,
+}
+
+impl<'a> CommentQuery<'a> {
+ pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<CommentView>, Error> {
+ queries().list(pool, self).await
+ }
+}
+
+impl JoinView for CommentView {
+ type JoinTuple = CommentViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ comment: a.0,
+ creator: a.1,
+ post: a.2,
+ community: a.3,
+ counts: a.4,
+ creator_banned_from_community: a.5,
+ subscribed: a.6,
+ saved: a.7,
+ creator_blocked: a.8,
+ my_vote: a.9,
+ }