|
|
|
@ -4,6 +4,7 @@ from rest_framework.response import Response |
|
|
|
from rest_framework.permissions import IsAuthenticated |
|
|
|
from rest_framework.generics import CreateAPIView, DestroyAPIView |
|
|
|
from rest_framework.exceptions import ValidationError |
|
|
|
from drf_yasg.utils import swagger_auto_schema |
|
|
|
|
|
|
|
from apps.bookmark.models import Bookmark |
|
|
|
from apps.bookmark.serializers import BookmarkSerializer |
|
|
|
@ -17,6 +18,15 @@ class AddBookmarkView(CreateAPIView): |
|
|
|
permission_classes = [IsAuthenticated] |
|
|
|
serializer_class = BookmarkSerializer |
|
|
|
|
|
|
|
@swagger_auto_schema( |
|
|
|
operation_description="Add a bookmark for a specific content in a service. If the bookmark already exists but is inactive, it will be reactivated.", |
|
|
|
request_body=BookmarkSerializer, |
|
|
|
responses={ |
|
|
|
201: "Bookmark created successfully.", |
|
|
|
200: "Bookmark reactivated or already active.", |
|
|
|
400: "Invalid input." |
|
|
|
} |
|
|
|
) |
|
|
|
def create(self, request, *args, **kwargs): |
|
|
|
service = request.data.get('service') |
|
|
|
content_id = request.data.get('content_id') |
|
|
|
@ -67,6 +77,15 @@ class RemoveBookmarkView(DestroyAPIView): |
|
|
|
permission_classes = [IsAuthenticated] |
|
|
|
serializer_class = BookmarkSerializer |
|
|
|
|
|
|
|
@swagger_auto_schema( |
|
|
|
operation_description="Deactivate a bookmark by setting its status to False using content_id and user.", |
|
|
|
request_body=BookmarkSerializer, |
|
|
|
responses={ |
|
|
|
204: "Bookmark deactivated successfully.", |
|
|
|
400: "Invalid input.", |
|
|
|
404: "Bookmark not found or already inactive." |
|
|
|
} |
|
|
|
) |
|
|
|
def get_object(self): |
|
|
|
service = self.request.data.get('service') |
|
|
|
content_id = self.request.data.get('content_id') |
|
|
|
@ -99,6 +118,12 @@ class BookmarkStatusView(APIView): |
|
|
|
""" |
|
|
|
permission_classes = [IsAuthenticated] |
|
|
|
|
|
|
|
@swagger_auto_schema( |
|
|
|
operation_description="Return the count of bookmarks for each service for the current user.", |
|
|
|
responses={ |
|
|
|
200: "A list of bookmark counts for each service.", |
|
|
|
} |
|
|
|
) |
|
|
|
def get(self, request): |
|
|
|
# Get all active bookmarks for the current user |
|
|
|
user_bookmarks = Bookmark.objects.filter( |
|
|
|
|