text: from django.db.models import F, Sum
  from django.db.models.functions import Coalesce
  from django.shortcuts import get_object_or_404
  from rest_framework import views, status
  from rest_framework.response import Response
  
  from . import serializers
  from .models import Resource
  
  
  # noinspection PyUnusedLocal, PyMethodMayBeStatic, PyUnresolvedReferences
  class ResourceAPI(views.APIView):
  
      def get(self, request, *args, **kwargs):
          queryset = Resource.objects.all()
          serializer = serializers.AllResourcesSerializer(queryset)
          return Response(serializer.data, status=status.HTTP_200_OK)
  
      def post(self, request, *args, **kwargs):
          serializer = serializers.ResourceSerializer(data=request.data)
          if serializer.is_valid():
              serializer.save()
              return Response(serializer.data, status=status.HTTP_201_CREATED)
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
  
      def put(self, request, *args, **kwargs):
          instance = get_object_or_404(Resource, id=request.data.get('id'))
          serializer = serializers.ResourceSerializer(instance,
                                                      data=request.data)
          if serializer.is_valid():
              serializer.save()
              return Response(status=status.HTTP_204_NO_CONTENT)
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
  
      def patch(self, request, *args, **kwargs):
          instance = get_object_or_404(Resource, id=request.data.get('id'))
          serializer = serializers.ResourceSerializer(instance,
                                                      data=request.data,
                                                      partial=True)
          if serializer.is_valid():
              serializer.save()
              return Response(status=status.HTTP_204_NO_CONTENT)
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
  
      def delete(self, request, *args, **kwargs):
          instance = get_object_or_404(Resource, id=request.data.get('id'))
          instance.delete()
          return Response(status=status.HTTP_204_NO_CONTENT)
  
  
  # noinspection PyUnusedLocal, PyMethodMayBeStatic, PyUnresolvedReferences
  class TotalCostAPI(views.APIView):
      def get(self, *args, **kwargs):
          return Response(Resource.objects.aggregate(
              total_cost=Coalesce(Sum(F('price')*F('amount')), 0)),
              status=status.HTTP_200_OK)
  