diff options
| author | 2018-08-16 21:49:19 +0200 | |
|---|---|---|
| committer | 2018-08-16 21:49:19 +0200 | |
| commit | c08f0761c5c49c666d22223ff18e1da5a6b73d37 (patch) | |
| tree | 1078351e6ab286802b52a77998100ca0e03343ae /api/viewsets.py | |
| parent | Add the `DocumentationLink` model. (diff) | |
Add a simple `list` / `retrieve` documentation link endpoint.
Diffstat (limited to '')
| -rw-r--r-- | api/viewsets.py | 44 | 
1 files changed, 40 insertions, 4 deletions
diff --git a/api/viewsets.py b/api/viewsets.py index 5e38bdc9..48b2f226 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -1,13 +1,49 @@ +from rest_framework.mixins import ListModelMixin, RetrieveModelMixin  from rest_framework.response import Response -from rest_framework.viewsets import ViewSet +from rest_framework.viewsets import GenericViewSet, ViewSet -from .models import SnakeName -from .serializers import SnakeNameSerializer +from .models import DocumentationLink, SnakeName +from .serializers import DocumentationLinkSerializer, SnakeNameSerializer + + +class DocumentationLinkViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet): +    """ +    View providing documentation links used in the bot's `Doc` cog. + +    ## Routes +    ### GET /bot/documentation-links +    Return all documentation links in the database in the following format: + +    >>> [ +    ...     { +    ...         'package': 'flask', +    ...         'base_url': 'https://flask.pocoo.org/docs/dev', +    ...         'inventory_url': 'https://flask.pocoo.org/docs/objects.inv' +    ...     }, +    ...     # ... +    ... ] + +    ### GET /bot/documentation-links/<package:str> +    Look up the documentation object for the given `package`. +    If an entry exists, return data in the following format: + +    >>> { +    ...     'package': 'flask', +    ...     'base_url': 'https://flask.pocoo.org/docs/dev', +    ...     'inventory_url': 'https://flask.pocoo.org/docs/objects.inv' +    ... } + +    Otherwise, if no entry for the given `package` exists, returns 404. +    """ + +    queryset = DocumentationLink.objects.all() +    serializer_class = DocumentationLinkSerializer +    lookup_field = 'package'  class SnakeNameViewSet(ViewSet):      """ -    View of snake names for the bot's snake cog from our first code jam's winners. +    View providing snake names for the bot's snake cog from our first code jam's winners.      ## Routes      ### GET /bot/snake-names  |