Skip to content

Commit

Permalink
fix: manager counter api
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Nov 18, 2024
1 parent 5b60ef2 commit 7b63c4f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
5 changes: 4 additions & 1 deletion uniticket/api_rest/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
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/count/', manager.TicketAPICounter.as_view(), name='api-manager-tickets-count'),
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'),
path(f'api/{slugify(MANAGEMENT_URL_PREFIX["manager"])}/<slug:structure_slug>/tickets/messages/count/', manager.TicketAPIMessagesCounter.as_view(), name='api-manager-tickets-messages-count'),

# operator
path(f'api/{slugify(MANAGEMENT_URL_PREFIX["operator"])}/<slug:structure_slug>/tickets/count/', operator.TicketAPICounter.as_view(), name='api-operator-tickets-count'),]
32 changes: 27 additions & 5 deletions uniticket/api_rest/views/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
logger = logging.getLogger(__name__)


class TicketAPICounter(TicketAPIBaseView):
class TicketAPIUnassignedCounter(TicketAPIBaseView):
def get(self, request, structure_slug, *args, **kwargs):
structure = get_object_or_404(OrganizationalStructure, slug=structure_slug)
if not user_is_manager(request.user, structure): raise PermissionDenied
Expand All @@ -33,14 +33,39 @@ def get(self, request, structure_slug, *args, **kwargs):
closed=False,
taken=False)

return Response({'count': unassigned_tickets.count()})


class TicketAPIOpenCounter(TicketAPIBaseView):
def get(self, request, structure_slug, *args, **kwargs):
structure = get_object_or_404(OrganizationalStructure, slug=structure_slug)
if not user_is_manager(request.user, structure): raise PermissionDenied

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

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


class TicketAPIMyOpenCounter(TicketAPIBaseView):
def get(self, request, structure_slug, *args, **kwargs):
structure = get_object_or_404(OrganizationalStructure, slug=structure_slug)
if not user_is_manager(request.user, structure): raise PermissionDenied

my_open_tickets = TicketAssignment.get_ticket_per_structure(structure=structure,
closed=False,
taken=True,
taken_by=request.user)
return Response({'count': my_open_tickets.count(),
'new_messages': messages})


class TicketAPIMessagesCounter(TicketAPIBaseView):
def get(self, request, structure_slug, *args, **kwargs):
structure = get_object_or_404(OrganizationalStructure, slug=structure_slug)
if not user_is_manager(request.user, structure): raise PermissionDenied

ticket_ids = TicketAssignment.objects.filter(
office__organizational_structure=structure,
office__is_active=True,
Expand All @@ -49,7 +74,4 @@ def get(self, request, structure_slug, *args, **kwargs):
).values_list('ticket__pk', flat=True).distinct()
messages = TicketReply.get_unread_messages_count(ticket_ids=ticket_ids)

return Response({'unassigned': unassigned_tickets.count(),
'open': open_tickets.count(),
'my_open': my_open_tickets.count(),
'new_messages': messages})
return Response({'new_messages': messages})
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,41 @@
clearInterval(this.interval)
},
mounted () {
this.getCounters()
this.getUnassigned()
this.getOpen()
this.getMyOpen()
this.getMessages()
},
methods: {
getCounters() {
api_url = '{% url "api_rest:api-manager-tickets-count" structure_slug=structure.slug %}'
getUnassigned() {
api_url = '{% url "api_rest:api-manager-tickets-unassigned-count" structure_slug=structure.slug %}'
axios
.get(api_url)
.then(response => {
this.unassigned = response.data.unassigned
})
},
getOpen() {
api_url = '{% url "api_rest:api-manager-tickets-open-count" structure_slug=structure.slug %}'
axios
.get(api_url)
.then(response => {
this.open = response.data.open
})
}
getMyOpen() {
api_url = '{% url "api_rest:api-manager-tickets-my-open-count" structure_slug=structure.slug %}'
axios
.get(api_url)
.then(response => {
this.my_open = response.data.my_open
})
}
getMessages() {
api_url = '{% url "api_rest:api-manager-tickets-messages-count" structure_slug=structure.slug %}'
axios
.get(api_url)
.then(response => {
this.new_messages = response.data.new_messages
})
}
Expand Down

0 comments on commit 7b63c4f

Please sign in to comment.