예제 #1
0
    def unsubscribe(email, category_id):
        category = Category.by_id(category_id)

        subs = Subscription.find_subscription(email, category_id)
        subs.delete_instance()

        category.decrement()
예제 #2
0
def get_category(category_id=None):
    """
    Return a JSON version of the category.
    :param category_id:
    :return: Response
    """
    try:
        category = Category.by_id(category_id)
    except Exception:
        return jsonify(Category.all())
    else:
        return jsonify(category.to_dict())
예제 #3
0
    def subscribe(email, category_id):
        category = Category.by_id(category_id)

        try:
            Subscription.find_subscription(email, category_id)
        except Subscription.NotFound:
            subs = Subscription.create(user=User.get_user_by_email(email),
                                       category=category)
        else:
            raise Subscription.Duplicate

        category.increment()

        return subs
예제 #4
0
def edit_category(category_id):
    """
    Update the given category by the ID.
    :return:
    """
    try:
        name = request.json["name"]
    except KeyError:
        return make_json_response(status=400)
    else:
        try:
            category = Category.by_id(category_id)
        except Exception:
            return make_json_response(status=404)
        else:
            category.update_with(name)

            return jsonify(category.to_dict())