#31 API DELETE

* adds support for DELETE method for all relevant objects
* improves get_obj_from_db functionality
* drops custom compensation logic for get_obj_from_db due to improvement of base method
This commit is contained in:
2022-01-28 08:52:11 +01:00
parent 80896731a8
commit a47d4e8416
5 changed files with 59 additions and 26 deletions

View File

@@ -79,7 +79,7 @@ class AbstractAPIViewV1(AbstractAPIView):
id (str): The entries id
Returns:
response (JsonResponse)
"""
try:
body = request.body.decode("utf-8")
@@ -89,6 +89,27 @@ class AbstractAPIViewV1(AbstractAPIView):
return self.return_error_response(e, 500)
return JsonResponse({"id": updated_id})
def delete(self, request: HttpRequest, id=None):
""" Handles a DELETE request
Args:
request (HttpRequest): The incoming request
id (str): The object's id
Returns:
response (JsonResponse)
"""
try:
success = self.serializer.delete_entry(id, self.user)
except Exception as e:
return self.return_error_response(e, 500)
return JsonResponse(
{
"success": success,
}
)
class InterventionAPIViewV1(AbstractAPIViewV1):
serializer = InterventionAPISerializerV1