From b822914db33d78ac90390a384dc251047d31c764 Mon Sep 17 00:00:00 2001 From: moanos Date: Fri, 21 Mar 2025 16:11:58 +0100 Subject: [PATCH] feat: Allow updating existing rescue organizations --- src/fellchensammlung/api/views.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/fellchensammlung/api/views.py b/src/fellchensammlung/api/views.py index f7c9897..df59d5d 100644 --- a/src/fellchensammlung/api/views.py +++ b/src/fellchensammlung/api/views.py @@ -205,6 +205,30 @@ class RescueOrganizationApiView(APIView): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + @transaction.atomic + @extend_schema( + request=RescueOrgSerializer, + responses={200: 'Rescue organization updated successfully!'} + ) + def patch(self, request, *args, **kwargs): + """ + Partially update a rescue organization. + """ + org_id = kwargs.get("id") + if not org_id: + return Response({"error": "ID is required for updating."}, status=status.HTTP_400_BAD_REQUEST) + + try: + organization = RescueOrganization.objects.get(pk=org_id) + except RescueOrganization.DoesNotExist: + return Response({"error": "Organization not found."}, status=status.HTTP_404_NOT_FOUND) + + serializer = RescueOrgSerializer(organization, data=request.data, partial=True, context={"request": request}) + if serializer.is_valid(): + serializer.save() + return Response({"message": "Rescue organization updated successfully!"}, status=status.HTTP_200_OK) + + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) class AddImageApiView(APIView): permission_classes = [IsAuthenticated]