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"