Add archive endpoints

This commit is contained in:
Sascha Ißbrücker 2021-02-16 04:24:22 +01:00
parent 0980e6a2b2
commit 79dd4179d2
2 changed files with 30 additions and 1 deletions

18
API.md
View file

@ -59,7 +59,7 @@ Example response:
}
```
**Archived**
**List Archived**
```
GET /api/bookmarks/archived/
@ -121,6 +121,22 @@ Example payload:
}
```
**Archive**
```
POST /api/bookmarks/<id>/archive/
```
Archives a bookmark.
**Unarchive**
```
POST /api/bookmarks/<id>/unarchive/
```
Unarchives a bookmark.
**Delete**
```

View file

@ -6,6 +6,7 @@ from rest_framework.routers import DefaultRouter
from bookmarks import queries
from bookmarks.api.serializers import BookmarkSerializer, TagSerializer
from bookmarks.models import Bookmark, Tag
from bookmarks.services.bookmarks import archive_bookmark, unarchive_bookmark
class BookmarkViewSet(viewsets.GenericViewSet,
@ -39,6 +40,18 @@ class BookmarkViewSet(viewsets.GenericViewSet,
data = serializer(page, many=True).data
return self.get_paginated_response(data)
@action(methods=['post'], detail=True)
def archive(self, request, pk):
bookmark = self.get_object()
archive_bookmark(bookmark)
return Response(status=status.HTTP_204_NO_CONTENT)
@action(methods=['post'], detail=True)
def unarchive(self, request, pk):
bookmark = self.get_object()
unarchive_bookmark(bookmark)
return Response(status=status.HTTP_204_NO_CONTENT)
class TagViewSet(viewsets.GenericViewSet,
mixins.ListModelMixin,