Testing a simple API

This commit is contained in:
augustin64 2023-10-26 14:33:06 +02:00
parent 3b08f2e08c
commit 83b033a779
3 changed files with 30 additions and 6 deletions

View File

@ -131,7 +131,13 @@ def create_album():
except db.IntegrityError:
pass
return redirect(f"/albums/{uuid}")
if "response" in request.args and request.args["response"] == "json":
return {
"status": "ok",
"uuid": uuid
}
else:
return redirect(f"/albums/{uuid}")
flash(error)
return redirect(request.referrer)
@ -291,8 +297,14 @@ def add_partition(album_uuid):
except db.IntegrityError:
pass
flash(f"Partition {request.form['name']} ajoutée")
return redirect(f"/albums/{album.uuid}")
if "response" in request.args and request.args["response"] == "json":
return {
"status": "ok",
"uuid": partition_uuid
}
else:
flash(f"Partition {request.form['name']} ajoutée")
return redirect(f"/albums/{album.uuid}")
@bp.route("/add-partition", methods=["POST"])

View File

@ -89,7 +89,13 @@ def create_groupe():
except db.IntegrityError:
pass
return redirect(f"/groupe/{uuid}")
if "response" in request.args and request.args["response"] == "json":
return {
"status": "ok",
"uuid": uuid
}
else:
return redirect(f"/groupe/{uuid}")
flash(error)
return redirect(request.referrer)

View File

@ -99,8 +99,14 @@ def add_attachment(uuid):
except db.IntegrityError:
pass
return redirect(f"/partition/{partition.uuid}/attachments")
if "response" in request.args and request.args["response"] == "json":
return {
"status": "ok",
"uuid": attachment_uuid
}
else:
return redirect(f"/partition/{partition.uuid}/attachments")
@bp.route("/attachment/<uuid>.<filetype>")