Skip to content

Commit

Permalink
feat(core): Add ticket category API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc committed Sep 13, 2024
1 parent ded6a72 commit 2a31815
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/api/serializers/core/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Meta:
'id',
'assigned_teams',
'assigned_users',
'category',
'created',
'modified',
'status',
Expand Down
42 changes: 42 additions & 0 deletions app/api/serializers/core/ticket_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from django.urls import reverse

from rest_framework import serializers
from rest_framework.fields import empty

from api.serializers.core.ticket_comment import TicketCommentSerializer

from core.forms.validate_ticket import TicketValidation
from core.models.ticket.ticket_category import TicketCategory



class TicketCategorySerializer(
serializers.ModelSerializer,
):

url = serializers.HyperlinkedIdentityField(
view_name="API:_api_ticket_category-detail", format="html"
)


class Meta:

model = TicketCategory

fields = '__all__'

read_only_fields = [
'id',
'url',
]


def __init__(self, instance=None, data=empty, **kwargs):

if instance is not None:

self.fields.fields['parent'].queryset = self.fields.fields['parent'].queryset.exclude(
id=instance.id
)

super().__init__(instance=instance, data=data, **kwargs)
7 changes: 6 additions & 1 deletion app/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

from api.views import assistance, itim, project_management
from api.views.assistance import request_ticket
from api.views.core import ticket_comments as core_ticket_comments
from api.views.core import (
ticket_categories,
ticket_comments as core_ticket_comments
)
from api.views.itim import change_ticket, incident_ticket, problem_ticket
from api.views.project_management import projects, project_task

Expand Down Expand Up @@ -44,6 +47,8 @@
router.register('project_management/projects/(?P<project_id>[0-9]+)/tasks', project_task.View, basename='_api_project_tasks')
router.register('project_management/projects/(?P<project_id>[0-9]+)/tasks/(?P<ticket_id>[0-9]+)/comments', core_ticket_comments.View, basename='_api_project_tasks_comments')

router.register('settings/ticket_caategories', ticket_categories.View, basename='_api_ticket_category')

router.register('software', software.SoftwareViewSet, basename='software')


Expand Down
79 changes: 79 additions & 0 deletions app/api/views/core/ticket_categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from django.shortcuts import get_object_or_404

from drf_spectacular.utils import extend_schema, OpenApiResponse

from rest_framework import generics, viewsets

from access.mixin import OrganizationMixin

from api.serializers.core.ticket_category import TicketCategory, TicketCategorySerializer
from api.views.mixin import OrganizationPermissionAPI



class View(OrganizationMixin, viewsets.ModelViewSet):

permission_classes = [
OrganizationPermissionAPI
]

queryset = TicketCategory.objects.all()

serializer_class = TicketCategorySerializer


@extend_schema(
summary='Create a ticket category',
request = TicketCategorySerializer,
responses = {
201: OpenApiResponse(description='Ticket category created', response=TicketCategorySerializer),
403: OpenApiResponse(description='User tried to edit field they dont have access to'),
}
)
def create(self, request, *args, **kwargs):

return super().create(request, *args, **kwargs)


@extend_schema(
summary='Fetch all of a tickets category',
methods=["GET"],
responses = {
200: OpenApiResponse(description='Success', response=TicketCategorySerializer),
}
)
def list(self, request, *args, **kwargs):

return super().list(request, *args, **kwargs)


@extend_schema(
summary='Fetch the selected ticket category',
methods=["GET"],
responses = {
200: OpenApiResponse(description='Success', response=TicketCategorySerializer),
}
)
def retrieve(self, request, *args, **kwargs):

return super().retrieve(request, *args, **kwargs)


@extend_schema(
summary='Update a ticket category',
methods=["PUT"],
responses = {
200: OpenApiResponse(description='Ticket comment updated', response=TicketCategorySerializer),
403: OpenApiResponse(description='User tried to edit field they dont have access to'),
}
)
def update(self, request, *args, **kwargs):

return super().update(request, *args, **kwargs)


def get_view_name(self):
if self.detail:
return "Ticket Category"

return 'Ticket Categories'
3 changes: 2 additions & 1 deletion app/api/views/settings/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def get(self, request, *args, **kwargs):
status = Http.Status.OK

response_data: dict = {
"permissions": reverse('API:_settings_permissions', request=request)
"permissions": reverse('API:_settings_permissions', request=request),
"ticket_categories": reverse('API:_api_ticket_category-list', request=request)
}

return Response(data=response_data,status=status)
Expand Down
1 change: 1 addition & 0 deletions app/core/models/ticket/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ def __str__(self):
]

fields_project_task: list(str()) = common_fields + [
'category',
'status',
'urgency',
'priority',
Expand Down

0 comments on commit 2a31815

Please sign in to comment.