Skip to content

Commit

Permalink
Add feed title to latest posts API
Browse files Browse the repository at this point in the history
  • Loading branch information
olarid7852 committed Dec 18, 2024
1 parent 6ef28af commit 80c5b19
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions apps/obstracts_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,25 @@ def list(self, *args, **kwargs):
page = self.request.query_params.get("page")
title = self.request.query_params.get("title")
sort = self.request.query_params.get("sort", "pubdate_descending")
feeds = []
feed_title_dict = {}
feed_ids = None
if team_id:
feeds = FeedSubsription.objects.filter(team_id=team_id)
feed_ids = [feed.feed_id for feed in feeds]
subscriptions = FeedSubsription.objects.filter(team_id=team_id).select_related('feed')
feed_ids = [subscription.feed_id for subscription in subscriptions]
for subscription in subscriptions:
feed_title_dict[subscription.feed_id] = subscription.feed.obstract_feed_metadata.get('title')
else:
if not self.request.user.is_staff:
raise PermissionDenied()

response = get_latest_posts(feed_ids, sort, title, page)
posts = response['posts']
if feed_ids == None:
post_feed_ids = [post['feed_id'] for post in posts]
feeds = Feed.objects.filter(id__in=post_feed_ids)
for feed in feeds:
feed_title_dict[feed_id] = feed.obstract_feed_metadata.get('title')
for post in posts:
post['feed_title'] = feed_title_dict.get(post['feed_id'])
return Response(response)


Expand Down

0 comments on commit 80c5b19

Please sign in to comment.