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 f6bdd0a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 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'),]
31 changes: 26 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,38 @@ 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()})


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 +73,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({'count': messages})
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,42 @@
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
this.open = response.data.open
this.my_open = response.data.my_open
this.new_messages = response.data.new_messages
this.unassigned = response.data.count
})
},
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.count
})
},
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.count
})
},
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.count
})
}
}
Expand Down

0 comments on commit f6bdd0a

Please sign in to comment.