Skip to content

Commit

Permalink
Implement archived bookmarks endpoint (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Ißbrücker committed Feb 14, 2021
1 parent 0db7610 commit b767622
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 11 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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**

```
Expand Down
14 changes: 13 additions & 1 deletion bookmarks/api/routes.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -27,6 +29,16 @@ def get_queryset(self):
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,
Expand Down

0 comments on commit b767622

Please sign in to comment.