Skip to content

Commit

Permalink
fix: test api pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Nov 19, 2024
1 parent 22a582b commit 5a2ea3c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions uniticket/api_rest/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
path('api/ticket/close/<str:ticket_id>/', user.TicketAPIClose.as_view(), name='api-ticket-close'),

# manager
path(f'api/{slugify(MANAGEMENT_URL_PREFIX["manager"])}/<slug:structure_slug>/tickets/open/', manager.TicketAPIOpen.as_view(), name='api-manager-tickets-open'),

path(f'api/{slugify(MANAGEMENT_URL_PREFIX["manager"])}/<slug:structure_slug>/tickets/unassigned/count/', manager.TicketAPIUnassignedCounter.as_view(), name='api-manager-tickets-unassigned-count'),
path(f'api/{slugify(MANAGEMENT_URL_PREFIX["manager"])}/<slug:structure_slug>/tickets/open/count/', manager.TicketAPIOpenCounter.as_view(), name='api-manager-tickets-open-count'),
path(f'api/{slugify(MANAGEMENT_URL_PREFIX["manager"])}/<slug:structure_slug>/tickets/my-open/count/', manager.TicketAPIMyOpenCounter.as_view(), name='api-manager-tickets-my-open-count'),
Expand Down
34 changes: 33 additions & 1 deletion uniticket/api_rest/views/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,43 @@
from organizational_area.models import OrganizationalStructure

from . generic import *

from .. serializers import TicketSerializer

logger = logging.getLogger(__name__)


from rest_framework.pagination import PageNumberPagination
from collections import OrderedDict

class MyPaginator(PageNumberPagination):
page_size = 100
page_size_query_param = 'page_size'
max_page_size = 1000

def get_paginated_response(self, data):
return Response(OrderedDict([
('next', self.get_next_link()),
('previous', self.get_previous_link()),
('results', data)
]))


class TicketAPIOpen(generics.ListAPIView):
pagination_class = MyPaginator
serializer_class = TicketSerializer

def get_queryset(self, *args, **kwargs):
structure = get_object_or_404(OrganizationalStructure, slug='servizi-didattici')
if not user_is_manager(self.request.user, structure): raise PermissionDenied

open_tickets = TicketAssignment.get_ticket_per_structure(structure=structure,
closed=False,
taken=True)

return open_tickets
# return Response({'count': open_tickets})


class TicketAPIUnassignedCounter(TicketAPIBaseView):
def get(self, request, structure_slug, *args, **kwargs):
structure = get_object_or_404(OrganizationalStructure, slug=structure_slug)
Expand Down
1 change: 0 additions & 1 deletion uniticket/uni_ticket/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,6 @@ def get_ticket_per_structure(structure,
ordering_list.remove("priority")

tickets = Ticket.objects.filter(pk__in=ticket_assignments)\
.values_list('pk',flat=True)\
.order_by(*ordering_list)

if closed is not None:
Expand Down

0 comments on commit 5a2ea3c

Please sign in to comment.