Skip to content

Commit

Permalink
corr: Alterando o funcionamento do metodo put do endpoint /usuarios/
Browse files Browse the repository at this point in the history
  • Loading branch information
WellingtonLFaria committed Sep 27, 2024
1 parent 2d498f8 commit 4271562
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/tupan/usuarios/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ def post(self, request, format=None):
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

def update(self, request, format=None):
serializer = UsuarioSerializer(data=request.data)
if serializer.is_valid():
user = Usuario.get(id=serializer.data.id)
user.email = serializer.data.email
user.password = serializer.data.password
def put(self, request, format=None):
try:
new_data = request.data
user = Usuario.objects.get(id=new_data["id"])
user.email = new_data["email"]
user.password = new_data["password"]
user.save()
return Response(user, status=status.HTTP_200_OK)
return Response("", status=status.HTTP_400_BAD_REQUEST)
serializer = UsuarioSerializer(user)
return Response(serializer.data, status=status.HTTP_200_OK)
except Usuario.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
except Exception as e:
return Response(str(e), status=status.HTTP_400_BAD_REQUEST)

0 comments on commit 4271562

Please sign in to comment.