def post(self, request, location_id):
        """
        Adds a measurement. Returns created and serialised measurement.

        Parameter
        ---------
        request : rest_framework.request.Request
            Object representing the request.
        location_id : int
            Identifies the location in the database.

        Returns
        -------
        rest_framework.reponse.Response
            Contains the serialised measurement or an error message.
        """

        user = request.user
        data = request.data

        try:
            location = AirQualityLocation.objects.get(pk=location_id)
        except AirQualityLocation.DoesNotExist:
            return Response(
                {'error': 'Location not found.'},
                status=status.HTTP_404_NOT_FOUND
            )

        if request.user != location.creator:
            return Response(
                {'error': 'You have no rights to add a new measurement.'},
                status=status.HTTP_403_FORBIDDEN
            )

        serializer = MeasurementSerializer(
            data=data, context={
                'user': user,
                'location': location,
                'data': data
            }
        )

        if serializer.is_valid(raise_exception=True):
            serializer.save()

            data = serializer.data
            instance = serializer.instance

            if self.submit_measurement(request, data, instance):
                return Response(status=status.HTTP_204_NO_CONTENT)

            return Response(serializer.data, status=status.HTTP_201_CREATED)
    def patch(self, request, location_id, measurement_id):
        """
        Updates a single measurement created by the user.

        Parameters
        ----------
        request : rest_framework.request.Request
            Represents the request.
        location_id : int
            Identifies the location in the database.
        measurement_id : int
            Identifies the measurement in the database.

        Returns
        -------
        rest_framework.response.Response
            Contains the serialised measurement or an error message.
        """

        user = request.user
        data = request.data

        try:
            measurement = AirQualityMeasurement.objects.get(pk=measurement_id)
        except AirQualityMeasurement.DoesNotExist:
            return Response(
                {'error': 'Measurement not found.'},
                status=status.HTTP_404_NOT_FOUND
            )

        if user != measurement.creator:
            return Response(
                {'error': 'You have no rights to update this measurement.'},
                status=status.HTTP_403_FORBIDDEN
            )

        serializer = MeasurementSerializer(
            measurement, data=data, context={'user': user, 'data': data}
        )

        if serializer.is_valid(raise_exception=True):
            serializer.save()

            data = serializer.data
            instance = serializer.instance

            if self.submit_measurement(request, data, instance):
                return Response(status=status.HTTP_204_NO_CONTENT)

            return Response(data, status=status.HTTP_200_OK)