Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update Tasks API
  • Loading branch information
aswinshenoy committed Apr 27, 2019
1 parent 87d8f89 commit 4a21832
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
7 changes: 6 additions & 1 deletion framework/settings.py
Expand Up @@ -149,6 +149,11 @@
'sass_processor.finders.CssFinder',
]

CORS_ORIGIN_WHITELIST = ( 'http://localhost:8000/' )
CORS_ORIGIN_WHITELIST =CORS_ORIGIN_WHITELIST = (
'amfoss.surge.sh',
'amfoss.in',
'localhost:5000',
'127.0.0.1:5000',
)


36 changes: 34 additions & 2 deletions tasks/schema.py
Expand Up @@ -22,12 +22,44 @@ class Meta:


class Query(object):
tasks = graphene.List(TaskObj)
streams = graphene.List(StreamObj, stream_type=graphene.String(required=False))
tasks = graphene.List(TaskObj,
stream=graphene.String(required=False),
max_points=graphene.Int(required=False),
min_points=graphene.Int(required=False),
max_difficulty=graphene.Int(required=False),
min_difficulty=graphene.Int(required=False),
)
task = graphene.Field(TaskObj, id=graphene.String(required=True), token=graphene.String(required=True))
tasks_log = graphene.List(TaskObj, username=graphene.String(required=False), token=graphene.String(required=True))

def resolve_streams(self, info, **kwargs):
stream_type = kwargs.get('stream_type')
streams = Stream.objects.all()
if stream_type is not None:
streams = Stream.objects.filter(type=stream_type)
return streams

def resolve_tasks(self, info, **kwargs):
return Task.objects.all()
stream = kwargs.get('stream')
max_points = kwargs.get('max_points')
min_points = kwargs.get('min_points')
max_difficulty = kwargs.get('max_difficulty')
min_difficulty = kwargs.get('min_difficulty')

tasks = Task.objects.all()
if stream is not None:
s = Stream.objects.get(slug=stream)
tasks = Task.objects.filter(stream=s)
if max_points is not None:
tasks = Task.objects.filter(points__lte=max_points)
if min_points is not None:
tasks = Task.objects.filter(points__gte=min_points)
if max_difficulty is not None:
tasks = Task.objects.filter(difficulty__lte=max_difficulty)
if min_difficulty is not None:
tasks = Task.objects.filter(difficulty__gte=min_difficulty)
return tasks

def resolve_task(self, info, **kwargs):
id = kwargs.get('id')
Expand Down

0 comments on commit 4a21832

Please sign in to comment.