Initial Commit
slip slop
This commit is contained in:
commit
064e672ab7
61 changed files with 3504 additions and 0 deletions
43
app/routes_tunings.py
Normal file
43
app/routes_tunings.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
"""Routes for the tunings lookup table."""
|
||||
from flask import Blueprint, jsonify, request
|
||||
from app.extensions import db
|
||||
from app.models import Tuning
|
||||
from app.auth import require_api_key
|
||||
|
||||
tunings_bp = Blueprint("tunings", __name__, url_prefix="/tunings")
|
||||
|
||||
|
||||
@tunings_bp.get("/")
|
||||
def list_tunings():
|
||||
return jsonify([t.to_dict() for t in
|
||||
db.session.query(Tuning).order_by(Tuning.name).all()])
|
||||
|
||||
|
||||
@tunings_bp.post("/")
|
||||
@require_api_key
|
||||
def create_tuning():
|
||||
data = request.get_json(force=True)
|
||||
tuning = Tuning(name=data["name"])
|
||||
db.session.add(tuning)
|
||||
db.session.commit()
|
||||
return jsonify(tuning.to_dict()), 201
|
||||
|
||||
|
||||
@tunings_bp.patch("/<int:tuning_id>")
|
||||
@require_api_key
|
||||
def update_tuning(tuning_id):
|
||||
tuning = db.get_or_404(Tuning, tuning_id)
|
||||
data = request.get_json(force=True)
|
||||
if "name" in data:
|
||||
tuning.name = data["name"]
|
||||
db.session.commit()
|
||||
return jsonify(tuning.to_dict())
|
||||
|
||||
|
||||
@tunings_bp.delete("/<int:tuning_id>")
|
||||
@require_api_key
|
||||
def delete_tuning(tuning_id):
|
||||
tuning = db.get_or_404(Tuning, tuning_id)
|
||||
db.session.delete(tuning)
|
||||
db.session.commit()
|
||||
return jsonify({"deleted": tuning_id})
|
||||
Loading…
Add table
Add a link
Reference in a new issue