Skip to content

Commit

Permalink
feat: logging for destroy methods fix: retireve request info
Browse files Browse the repository at this point in the history
  • Loading branch information
avinogrado authored and the-homeless-god committed Aug 31, 2024
1 parent 66e320d commit 39eb752
Showing 1 changed file with 56 additions and 29 deletions.
85 changes: 56 additions & 29 deletions application/backend/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def list(self, request, *args, **kwargs):
# read one by ID

def retrieve(self, request, *args, **kwargs):

logging.info(f'{request} - id = {kwargs["pk"]}')
logging.info(f'{request},find - id = {kwargs["pk"]}')
try:
data = Employee.objects.filter(id = kwargs['pk'])[0]
serializer = Employee_Serializer(data)
Expand Down Expand Up @@ -48,12 +47,19 @@ def create(self,request,*args,**kwargs):
# Delete

def destroy(self,request,*args,**kwargs):
employe_data = Employee.objects.filter(id=kwargs['pk'])
if employe_data:
employe_data.delete()
return Response({"messege": "Employer was deleted"}, status = status.HTTP_201_CREATED)
else:
return Response(status= status.HTTP_404_NOT_FOUND)
logging.info(f'{request},delete - id = {kwargs["pk"]}')
try:
data = Employee.objects.filter(id = kwargs['pk'])[0]
logging.info('Object found')
data.delete()
logging.info('Object deleted')
return Response(status = status.HTTP_201_CREATED)
except Employee.DoesNotExist:
logging.exception('Object not found')
return Response(status=status.HTTP_404_NOT_FOUND)
except IndexError:
logging.exception("Index out of range")
return Response(status=status.HTTP_404_NOT_FOUND)

class Project_List_API_View(viewsets.ModelViewSet):
queryset = Project.objects.all()
Expand All @@ -68,7 +74,7 @@ def list(self,request,*args,**kwarfs):

# read one
def retrieve(self, request, *args, **kwargs):
logging.info(f'{request} - id = {kwargs["pk"]}')
logging.info(f'{request},find - id = {kwargs["pk"]}')
try:
data = Project.objects.filter(id = kwargs['pk'])[0]
serializer = Project_Serializer(data)
Expand Down Expand Up @@ -98,12 +104,19 @@ def create(self,request,*args,**kwargs):

# delete project by id
def destroy(self,request,*args,**kwargs):
project_data = Project.objects.filter(id=kwargs['pk'])
if project_data:
project_data.delete()
return Response({"messege": "Project was deleted"}, status = status.HTTP_201_CREATED)
else:
return Response(status= status.HTTP_404_NOT_FOUND)
logging.info(f'{request},delete - id = {kwargs["pk"]}')
try:
data = Project.objects.filter(id = kwargs['pk'])[0]
logging.info('Object found')
data.delete()
logging.info('Object deleted')
return Response(status = status.HTTP_201_CREATED)
except Employee.DoesNotExist:
logging.exception('Object not found')
return Response(status=status.HTTP_404_NOT_FOUND)
except IndexError:
logging.exception("Index out of range")
return Response(status=status.HTTP_404_NOT_FOUND)


class Report_List_API_View(viewsets.ModelViewSet):
Expand All @@ -119,7 +132,7 @@ def list(self,request,*args,**kwargs):

# read report by ID
def retrieve(self, request, *args, **kwargs):
logging.info(f'{request} - id = {kwargs["pk"]}')
logging.info(f'{request},find - id = {kwargs["pk"]}')
try:
data = Report.objects.filter(id = kwargs['pk'])[0]
serializer = Report_Serializer(data)
Expand Down Expand Up @@ -157,12 +170,19 @@ def create(self,request,*args,**kwargs):

# Delete report by ID
def destroy(self,request,*args,**kwargs):
report_data = Report.objects.filter(id=kwargs['pk'])
if report_data:
report_data.delete()
return Response({"messege": "Report was deleted"}, status = status.HTTP_201_CREATED)
else:
return Response(status= status.HTTP_404_NOT_FOUND)
logging.info(f'{request},delete - id = {kwargs["pk"]}')
try:
data = Report.objects.filter(id = kwargs['pk'])[0]
logging.info('Object found')
data.delete()
logging.info('Object deleted')
return Response(status = status.HTTP_201_CREATED)
except Employee.DoesNotExist:
logging.exception('Object not found')
return Response(status=status.HTTP_404_NOT_FOUND)
except IndexError:
logging.exception("Index out of range")
return Response(status=status.HTTP_404_NOT_FOUND)

class Objective_List_API_View(viewsets.ModelViewSet):

Expand Down Expand Up @@ -191,7 +211,7 @@ def create(self,requset,*args,**kwargs):

#read objective by id
def retrieve(self, request, *args, **kwargs):
logging.info(f'{request} - id = {kwargs["pk"]}')
logging.info(f'{request},find - id = {kwargs["pk"]}')
try:
data = Objective.objects.filter(id = kwargs['pk'])[0]
serializer = Objective_Serializer(data)
Expand All @@ -205,10 +225,17 @@ def retrieve(self, request, *args, **kwargs):
return Response(status=status.HTTP_404_NOT_FOUND)
# Delete report by ID
def destroy(self,request,*args,**kwargs):
objective_data = Report.objects.filter(id=kwargs['pk'])
if objective_data:
objective_data.delete()
return Response({"messege": "Objective was deleted"}, status = status.HTTP_201_CREATED)
else:
return Response(status= status.HTTP_404_NOT_FOUND)
logging.info(f'{request},delete - id = {kwargs["pk"]}')
try:
data = Objective.objects.filter(id = kwargs['pk'])[0]
logging.info('Object found')
data.delete()
logging.info('Object deleted')
return Response(status = status.HTTP_201_CREATED)
except Employee.DoesNotExist:
logging.exception('Object not found')
return Response(status=status.HTTP_404_NOT_FOUND)
except IndexError:
logging.exception("Index out of range")
return Response(status=status.HTTP_404_NOT_FOUND)

0 comments on commit 39eb752

Please sign in to comment.