diff --git a/API.md b/API.md index a3bbfbf..b72f353 100644 --- a/API.md +++ b/API.md @@ -49,7 +49,7 @@ Example response: "website_description": "Website description", "tag_names": [ "tag1", - "tag2" + "tag2" ], "date_added": "2020-09-26T09:46:23.006313Z", "date_modified": "2020-09-26T16:01:14.275335Z" @@ -59,6 +59,16 @@ Example response: } ``` +**Archived** + +``` +GET /api/bookmarks/archived/ +``` + +List archived bookmarks. + +Parameters and response are the same as for the regular list endpoint. + **Retrieve** ``` diff --git a/bookmarks/api/routes.py b/bookmarks/api/routes.py index 696ddaa..f75a859 100644 --- a/bookmarks/api/routes.py +++ b/bookmarks/api/routes.py @@ -1,4 +1,6 @@ -from rest_framework import viewsets, mixins +from rest_framework import viewsets, mixins, status +from rest_framework.decorators import action +from rest_framework.response import Response from rest_framework.routers import DefaultRouter from bookmarks import queries @@ -27,6 +29,16 @@ class BookmarkViewSet(viewsets.GenericViewSet, def get_serializer_context(self): return {'user': self.request.user} + @action(methods=['get'], detail=False) + def archived(self, request): + user = request.user + query_string = request.GET.get('q') + query_set = queries.query_archived_bookmarks(user, query_string) + page = self.paginate_queryset(query_set) + serializer = self.get_serializer_class() + data = serializer(page, many=True).data + return self.get_paginated_response(data) + class TagViewSet(viewsets.GenericViewSet, mixins.ListModelMixin,