Skip to content

Commit

Permalink
fix: operator counters API
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Dec 2, 2024
1 parent d947377 commit c0346fc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 21 deletions.
14 changes: 11 additions & 3 deletions uniticket/api_rest/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@

re_path('^openapi/$', get_schema_view(**{}), name='openapi-schema'),
re_path('^openapi.json/$', get_schema_view(renderer_classes = [JSONOpenAPIRenderer], **{}), name='openapi-schema-json'),
path('api/<slug:structure_slug>/<slug:category_slug>/ticket/new/', user.TicketAPIView.as_view(), name='api-new-ticket'),
path('api/ticket/<str:ticket_uid>/', user.TicketAPIDetail.as_view(), name='api-view-ticket'),

# generic
path('api/strutture/list/', generic.TicketAPIStruttureList.as_view(), name='api-strutture-list'),
path('api/ticket/category/list/', generic.TicketAPITicketCategoryList.as_view(),name='api-ticket-category-list'),

# user
path('api/<slug:structure_slug>/<slug:category_slug>/ticket/new/', user.TicketAPIView.as_view(), name='api-new-ticket'),
path('api/ticket/<str:ticket_uid>/', user.TicketAPIDetail.as_view(), name='api-view-ticket'),
path('api/ticket/user/list/', user.TicketAPIListCreated.as_view(), name='api-ticket-user-list'),
path('api/ticket/close/<str:ticket_id>/', user.TicketAPIClose.as_view(), name='api-ticket-close'),

Expand All @@ -37,4 +41,8 @@
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'),]
path(f'api/{slugify(MANAGEMENT_URL_PREFIX["operator"])}/<slug:structure_slug>/tickets/unassigned/count/', operator.TicketAPIUnassignedCounter.as_view(), name='api-operator-tickets-unassigned-count'),
path(f'api/{slugify(MANAGEMENT_URL_PREFIX["operator"])}/<slug:structure_slug>/tickets/open/count/', operator.TicketAPIOpenCounter.as_view(), name='api-operator-tickets-open-count'),
path(f'api/{slugify(MANAGEMENT_URL_PREFIX["operator"])}/<slug:structure_slug>/tickets/my-open/count/', operator.TicketAPIMyOpenCounter.as_view(), name='api-operator-tickets-my-open-count'),
path(f'api/{slugify(MANAGEMENT_URL_PREFIX["operator"])}/<slug:structure_slug>/tickets/messages/count/', operator.TicketAPIMessagesCounter.as_view(), name='api-operator-tickets-messages-count'),
]
31 changes: 23 additions & 8 deletions uniticket/api_rest/views/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,56 @@
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)
oe = user_is_operator(request.user, structure)
if not oe: raise PermissionDenied

unassigned_tickets = visible_tickets_to_user(user=request.user,
structure=structure,
office_employee=oe,
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)
oe = user_is_operator(request.user, structure)
if not oe: raise PermissionDenied
open_tickets = visible_tickets_to_user(user=request.user,
structure=structure,
office_employee=oe,
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)
oe = user_is_operator(request.user, structure)
if not oe: raise PermissionDenied
my_open_tickets = visible_tickets_to_user(user=request.user,
structure=structure,
office_employee=oe,
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)
oe = user_is_operator(request.user, structure)
if not oe: raise PermissionDenied
ticket_ids = visible_tickets_to_user(
user=request.user,
structure=structure,
office_employee=oe,
closed=False
)

messages = TicketReply.get_unread_messages_count(ticket_ids=ticket_ids)

return Response({'unassigned': len(unassigned_tickets),
'open': len(open_tickets),
'my_open': len(my_open_tickets),
'new_messages': messages})
return Response({'count': messages})
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<svg class="icon">
<use xlink:href="{% static 'svg/sprite.svg' %}#it-comment"></use>
</svg>
<span class="toolbar-label">{% trans 'Messaggi' %}</span></span>
<span class="toolbar-label">{% trans 'Messaggi' %}</span>
</a>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<svg class="icon icon-xs" v-else>
<use xlink:href="{% static 'svg/sprite.svg' %}#it-comment"></use>
</svg>
<span class="badge badge-primary" v-if="new_messages">{% trans "Nuovi" %}</span>{% trans "Nuovi" %}</span>
<span class="badge badge-primary" v-if="new_messages">{% trans "Nuovi" %}</span>
{% trans 'Messaggi' %}
</a>
</div>
Expand Down Expand Up @@ -80,7 +80,7 @@
<svg class="icon">
<use xlink:href="{% static 'svg/sprite.svg' %}#it-comment"></use>
</svg>
<span class="toolbar-label">{% trans 'Messaggi' %}</span></span>
<span class="toolbar-label">{% trans 'Messaggi' %}</span>
</a>
</li>
</ul>
Expand All @@ -100,24 +100,52 @@
},
created(){
this.interval = setInterval(() =>{
this.getCounters();
this.getUnassigned();
this.getOpen();
this.getMyOpen();
this.getMessages();
}, 20000)
},
destroyed(){
clearInterval(this.interval)
},
mounted () {
this.getCounters()
this.getUnassigned()
this.getOpen()
this.getMyOpen()
this.getMessages()
},
methods: {
getCounters() {
api_url = '{% url "api_rest:api-operator-tickets-count" structure_slug=structure.slug %}'
getUnassigned() {
api_url = '{% url "api_rest:api-operator-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.unassigned = response.data.count
})
},
getOpen() {
api_url = '{% url "api_rest:api-operator-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-operator-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-operator-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 c0346fc

Please sign in to comment.