From fc6ccd27174e6410e9ed34bcd7b4567ca3a6b345 Mon Sep 17 00:00:00 2001 From: Nicolas Setton Date: Fri, 21 Jul 2017 15:59:27 -0400 Subject: [PATCH] Complete the view of a single example. --- compile_server/app/views.py | 13 +++++++++---- design/notes.txt | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/compile_server/app/views.py b/compile_server/app/views.py index 0c18dae..db81023 100644 --- a/compile_server/app/views.py +++ b/compile_server/app/views.py @@ -63,12 +63,17 @@ def examples(request): @api_view(['GET']) def example(request, name): # TODO: create an example serializer - # TODO: catch case where the example does not exist - e = Example.objects.filter(name=name)[0] + matches = Example.objects.filter(name=name) + if not matches: + return Response() + + e = matches[0] resources = [] for r in e.resources.all(): serializer = ResourceSerializer(r) resources.append(serializer.data) - # TODO: add example metadata to the result - result = {'resources': resources} + + result = {'name': e.name, + 'description': e.description, + 'resources': resources} return Response(result) diff --git a/design/notes.txt b/design/notes.txt index 09bfb30..583fd61 100644 --- a/design/notes.txt +++ b/design/notes.txt @@ -13,4 +13,4 @@ Add -u : when using authentication curl -H 'Accept: application/json; indent=4' http://127.0.0.1:8000/check_program/ --data "{\"program\": \"hello\"}" --header "Content-Type:application/json" # get the examples - curl -H 'Accept: application/json; indent=4' http://127.0.0.1:8000/examples/ --header "Content-Type:application/json" +curl -H 'Accept: application/json; indent=4' http://127.0.0.1:8000/examples/ --header "Content-Type:application/json"