Exemplo n.º 1
0
    def delete(self, animal_id):
        """ASWP-API Animal DELETE

        Args:
            animal_id (int): ID of Animal to delete

        Returns:
            dict: Dictionary with success message
            tuple: Tuple with error message and status code
        """
        center_id = get_jwt_identity()["center_id"]
        if not Animal.exists(animal_id):
            return {"error": "Animal not found"}, 404
        if not Animal.is_owner(animal_id, center_id):
            return {"error": "You are not allowed to delete this animal"}, 403
        Animal.delete(animal_id)
        return {"message": "Animal deleted successfully"}
Exemplo n.º 2
0
    def put(self, animal_id):
        """ASWP-API Animal PUT

        Args:
            animal_id (int): ID of Animal to update

        Returns:
            dict: Dictionary with success message
            tuple: Tuple with error message and status code
        """
        data = self.parse_request()
        center_id = get_jwt_identity()["center_id"]
        if not Animal.exists(animal_id):
            return {"error": "Animal not found"}, 404
        if not Animal.is_owner(animal_id, center_id):
            return {"error": "You are not allowed to update this animal"}, 403
        if "specie" in data:
            if not Specie.exists(data["specie"]):
                return {"error": "Specified specie does not exist"}, 409
        Animal.update(animal_id, data)
        return {"message": "Animal updated successfully"}