Exemple #1
0
    def patch(self, business_id):
        """
        Update a single business
        """

        # To do check if user is admin
        schema = BusinessSchema(partial=True)

        update_data = request.get_json()

        validated_update_data, errors = schema.load(update_data)

        if errors:
            return dict(status="fail", message=errors), 400

        business = Business.get_by_id(business_id)

        if not business:
            return dict(
                status="fail",
                message=f"Business with id {business_id} not found"), 404

        updated_business = Business.update(business, **validated_update_data)

        if not updated_business:
            return dict(status='fail', message='Internal Server Error'), 500

        return dict(status="success",
                    message="Business updated successfully"), 200
Exemple #2
0
    def delete(self, business_id):
        """
        Delete a single business
        """

        business = Business.get_by_id(business_id)

        if not business:
            return dict(
                status="fail",
                message=f"Business with id {business_id} not found"), 404

        deleted_business = business.delete()

        if not deleted_business:
            return dict(status='fail', message='Internal Server Error'), 500

        return dict(status='success', message="Successfully deleted"), 200
Exemple #3
0
    def get(self, business_id):
        """
        Getting individual business
        """
        schema = BusinessSchema()

        business = Business.get_by_id(business_id)

        if not business:
            return dict(
                status="fail",
                message=f"Business with id {business_id} not found"), 404

        business_data, errors = schema.dumps(business)

        if errors:
            return dict(status="fail", message=errors), 500

        return dict(status='success',
                    data=dict(business=json.loads(business_data))), 200