mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-22 22:39:36 +02:00
refactor: Update API endpoint for fetching visited adventures
This commit is contained in:
parent
34f26b36dd
commit
cab7824510
8 changed files with 16 additions and 269 deletions
|
@ -61,6 +61,16 @@ class AdventureViewSet(viewsets.ModelViewSet):
|
|||
queryset = queryset.order_by(lower_name)
|
||||
adventures = self.paginate_and_respond(queryset, request)
|
||||
return adventures
|
||||
|
||||
@action(detail=False, methods=['get'])
|
||||
def all(self, request):
|
||||
# return error if user is not authenticated
|
||||
if not request.user.is_authenticated:
|
||||
return Response({"error": "User is not authenticated"}, status=400)
|
||||
queryset = Adventure.objects.filter(user_id=request.user.id).exclude(type='featured')
|
||||
serializer = self.get_serializer(queryset, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
def paginate_and_respond(self, queryset, request):
|
||||
paginator = self.pagination_class()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue