From a361e496dbe88f71efd3279484c1520ec0479dc5 Mon Sep 17 00:00:00 2001 From: Ian Keane Date: Thu, 11 Jun 2026 14:12:28 -0400 Subject: [PATCH] Make instruments table expandable --- app/routes_instruments.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/routes_instruments.py b/app/routes_instruments.py index 23e3311..723422e 100644 --- a/app/routes_instruments.py +++ b/app/routes_instruments.py @@ -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/") +@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/") +@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 # ---------------------------------------------------------------------------