From 79dd4179d21fb4dbe9e0ff6e8e71798a450755b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Tue, 16 Feb 2021 04:24:22 +0100 Subject: [PATCH] Add archive endpoints --- API.md | 18 +++++++++++++++++- bookmarks/api/routes.py | 13 +++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/API.md b/API.md index b72f353..b856008 100644 --- a/API.md +++ b/API.md @@ -59,7 +59,7 @@ Example response: } ``` -**Archived** +**List Archived** ``` GET /api/bookmarks/archived/ @@ -121,6 +121,22 @@ Example payload: } ``` +**Archive** + +``` +POST /api/bookmarks//archive/ +``` + +Archives a bookmark. + +**Unarchive** + +``` +POST /api/bookmarks//unarchive/ +``` + +Unarchives a bookmark. + **Delete** ``` diff --git a/bookmarks/api/routes.py b/bookmarks/api/routes.py index f75a859..61ea8a0 100644 --- a/bookmarks/api/routes.py +++ b/bookmarks/api/routes.py @@ -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,