Skip to content

Commit

Permalink
activity: Add getNews API to get with slug
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithpabbati committed Jun 19, 2020
1 parent 3a97787 commit 5c32964
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions activity/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .models import *
from framework.api.user import UserBasicObj
from django.db.models import F
from framework.api.APIException import APIException


class CategoryObj(graphene.ObjectType):
Expand Down Expand Up @@ -62,16 +63,21 @@ def resolve_cover(self, info):


class Query(graphene.ObjectType):
news = graphene.List(NewsObj, slug=graphene.String())
news = graphene.List(NewsObj)
getNews = graphene.Field(NewsObj, slug = graphene.String(required=True))
tags = graphene.List(TagObj)
categories = graphene.List(CategoryObj)

def resolve_news(self, info):
return reversed(News.objects.values().all().order_by('date'))

def resolve_news(self, info, **kwargs):
def resolve_getNews(self, info, **kwargs):
slug = kwargs.get('slug')
if slug is not None:
return News.objects.values().get(slug=slug)
else:
return News.objects.values().all()
raise APIException('Slug is required',
code='SLUG_IS_REQUIRED')

def resolve_tags(self, info):
return Tag.objects.values().all()
Expand Down

0 comments on commit 5c32964

Please sign in to comment.