You've already forked code_examples_server
mirror of
https://github.com/AdaCore/code_examples_server.git
synced 2026-02-12 12:45:18 -08:00
Complete the view of a single example.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -13,4 +13,4 @@ Add -u <login>:<password> 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"
|
||||
|
||||
Reference in New Issue
Block a user