Make instruments table expandable
This commit is contained in:
parent
d1e99c51de
commit
a361e496db
1 changed files with 33 additions and 0 deletions
|
|
@ -16,6 +16,39 @@ def list_instruments():
|
|||
db.session.query(Instrument).order_by(Instrument.name).all()])
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Instruments lookup (create / update / delete)
|
||||
# ---------------------------------------------------------------------------
|
||||
@instruments_bp.post("/instruments")
|
||||
@require_api_key
|
||||
def create_instrument():
|
||||
data = request.get_json(force=True)
|
||||
instrument = Instrument(name=data["name"])
|
||||
db.session.add(instrument)
|
||||
db.session.commit()
|
||||
return jsonify(instrument.to_dict()), 201
|
||||
|
||||
|
||||
@instruments_bp.patch("/instruments/<int:instrument_id>")
|
||||
@require_api_key
|
||||
def update_instrument(instrument_id):
|
||||
instrument = db.get_or_404(Instrument, instrument_id)
|
||||
data = request.get_json(force=True)
|
||||
if "name" in data:
|
||||
instrument.name = data["name"]
|
||||
db.session.commit()
|
||||
return jsonify(instrument.to_dict())
|
||||
|
||||
|
||||
@instruments_bp.delete("/instruments/<int:instrument_id>")
|
||||
@require_api_key
|
||||
def delete_instrument(instrument_id):
|
||||
instrument = db.get_or_404(Instrument, instrument_id)
|
||||
db.session.delete(instrument)
|
||||
db.session.commit()
|
||||
return jsonify({"deleted": instrument_id})
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# List all tune_by_instrument entries for a tune
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue