Ejemplo n.º 1
0
def tags_tag_id_delete(tag_id: int):
    tag = Tag.get_or_none(id=tag_id)

    if tag is None:
        return jsonify({"error":
                        f"tag with ID '{tag_id}' does not exist"}), 404

    if request.method == "PUT":
        payload = request.get_json(force=True)
        name = payload["name"]

        if Tag.select().where(Tag.name == name, Tag.id != tag_id).exists():
            return jsonify({"error":
                            f"tag with name '{name}' already exists"}), 400
        Tag.update(**payload).where(Tag.id == tag_id).execute()

    if request.method == "DELETE":
        tag.delete_instance(recursive=True)

    return jsonify({}), 204
Ejemplo n.º 2
0
def tags_get():
    query = Tag.select().order_by(Tag.id)
    result = list(query.dicts())

    return jsonify({"data": result})