Skip to content

Commit

Permalink
Added API endpoint to update team details. (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
taranjeet authored and deshraj committed Nov 19, 2016
1 parent 9df0c0a commit e56a0c9
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions apps/teams/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def team_list(request, challenge_pk):
return Response(serializer.errors, status.HTTP_400_BAD_REQUEST)


@api_view(['GET'])
@api_view(['GET', 'PUT', 'PATCH'])
@permission_classes((permissions.IsAuthenticated,))
@authentication_classes((TokenAuthentication,))
def team_detail(request, challenge_pk, pk):
try:
Challenge.objects.get(pk=challenge_pk)
challenge = Challenge.objects.get(pk=challenge_pk)
except Challenge.DoesNotExist:
response_data = {'error': 'Challenge does not exist'}
return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
Expand All @@ -61,6 +61,20 @@ def team_detail(request, challenge_pk, pk):
response_data = {'error': 'Team does not exist'}
return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)

serializer = TeamChallengeSerializer(team)
response_data = serializer.data
return Response(response_data, status=status.HTTP_200_OK)
if request.method == 'GET':
serializer = TeamChallengeSerializer(team)
response_data = serializer.data
return Response(response_data, status=status.HTTP_200_OK)

elif request.method in ['PUT', 'PATCH']:

if request.method == 'PATCH':
serializer = TeamSerializer(team, data=request.data, context={'challenge': challenge}, partial=True)
else:
serializer = TeamSerializer(team, data=request.data, context={'challenge': challenge})
if serializer.is_valid():
serializer.save()
response_data = serializer.data
return Response(response_data, status=status.HTTP_200_OK)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

0 comments on commit e56a0c9

Please sign in to comment.