Skip to content

Commit

Permalink
feat: logging for create methods
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 39eb752 commit 75e3298
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions application/backend/projects/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.forms import ValidationError
from rest_framework import viewsets
from rest_framework.response import Response
from rest_framework import status
Expand Down Expand Up @@ -34,15 +35,21 @@ def retrieve(self, request, *args, **kwargs):
#Create

def create(self,request,*args,**kwargs):
logging.info(f"{request},{request.data}")
data = {
'first_name': request.data.get('first_name'),
'last_name': request.data.get('last_name')
}
serializer = Employee_Serializer(data = data)
if serializer.is_valid():
try:
serializer = Employee_Serializer(data = data)
serializer.is_valid()
logging.info('data is valid')
serializer.save()
logging.info('data is saved')
return Response(serializer.data,status=status.HTTP_201_CREATED)
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)
except ValidationError:
logging.exception('Data is not valid')
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)

# Delete

Expand Down Expand Up @@ -89,6 +96,7 @@ def retrieve(self, request, *args, **kwargs):

# create project
def create(self,request,*args,**kwargs):
logging.info(f"{request},{request.data}")
data = {
'project_name': request.data.get('project_name'),
'project_discription': request.data.get('project_discription'),
Expand All @@ -97,10 +105,16 @@ def create(self,request,*args,**kwargs):
'employee': request.data.get('employee')
}
serializer = Project_Serializer(data = data)
if serializer.is_valid():
try:
serializer = Employee_Serializer(data = data)
serializer.is_valid()
logging.info('data is valid')
serializer.save()
logging.info('data is saved')
return Response(serializer.data,status=status.HTTP_201_CREATED)
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)
except ValidationError:
logging.exception('Data is not valid')
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)

# delete project by id
def destroy(self,request,*args,**kwargs):
Expand Down Expand Up @@ -147,6 +161,7 @@ def retrieve(self, request, *args, **kwargs):

# Create the Report with given data
def create(self,request,*args,**kwargs):
logging.info(f"{request},{request.data}")
data = {
'report_name': request.data.get('report_name'),
'report_start': request.data.get('report_start'),
Expand All @@ -163,10 +178,16 @@ def create(self,request,*args,**kwargs):

serializer = Report_Serializer(data=data)

if serializer.is_valid():
try:
serializer = Employee_Serializer(data = data)
serializer.is_valid()
logging.info('data is valid')
serializer.save()
logging.info('data is saved')
return Response(serializer.data,status=status.HTTP_201_CREATED)
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)
except ValidationError:
logging.exception('Data is not valid')
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)

# Delete report by ID
def destroy(self,request,*args,**kwargs):
Expand Down Expand Up @@ -196,18 +217,25 @@ def list(self,request,*args,**kards):
return Response(serializer.data,status=status.HTTP_200_OK)

# Create the Objective for this report
def create(self,requset,*args,**kwargs):
def create(self,request,*args,**kwargs):
logging.info(f"{request},{request.data}")
data = {
'objective_id': requset.data.get('objective_id'),
'objective_name': requset.data.get('objective_name'),
'objective_color': requset.data.get('objective_color'),
'related_report': requset.data.get('related_report'),
'objective_id': request.data.get('objective_id'),
'objective_name': request.data.get('objective_name'),
'objective_color': request.data.get('objective_color'),
'related_report': request.data.get('related_report'),
}
serializer = Objective_Serializer(data = data)
if serializer.is_valid():
try:
serializer = Employee_Serializer(data = data)
serializer.is_valid()
logging.info('data is valid')
serializer.save()
logging.info('data is saved')
return Response(serializer.data,status=status.HTTP_201_CREATED)
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)
except ValidationError:
logging.exception('Data is not valid')
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)

#read objective by id
def retrieve(self, request, *args, **kwargs):
Expand Down

0 comments on commit 75e3298

Please sign in to comment.