Align controller backend and data with new presets
Update palettes, profiles, tabs, preset sending, and ESPNow message format to match the new preset defaults and driver short-field schema.
This commit is contained in:
@@ -8,14 +8,18 @@ palettes = Palette()
|
||||
@controller.get('')
|
||||
async def list_palettes(request):
|
||||
"""List all palettes."""
|
||||
return json.dumps(palettes), 200, {'Content-Type': 'application/json'}
|
||||
data = {}
|
||||
for pid in palettes.list():
|
||||
colors = palettes.read(pid)
|
||||
data[pid] = colors
|
||||
return json.dumps(data), 200, {'Content-Type': 'application/json'}
|
||||
|
||||
@controller.get('/<id>')
|
||||
async def get_palette(request, id):
|
||||
"""Get a specific palette by ID."""
|
||||
palette = palettes.read(id)
|
||||
if palette:
|
||||
return json.dumps(palette), 200, {'Content-Type': 'application/json'}
|
||||
return json.dumps({"colors": palette, "id": str(id)}), 200, {'Content-Type': 'application/json'}
|
||||
return json.dumps({"error": "Palette not found"}), 404
|
||||
|
||||
@controller.post('')
|
||||
@@ -23,12 +27,14 @@ async def create_palette(request):
|
||||
"""Create a new palette."""
|
||||
try:
|
||||
data = request.json or {}
|
||||
name = data.get("name", "")
|
||||
colors = data.get("colors", None)
|
||||
palette_id = palettes.create(name, colors)
|
||||
if data:
|
||||
palettes.update(palette_id, data)
|
||||
return json.dumps(palettes.read(palette_id)), 201, {'Content-Type': 'application/json'}
|
||||
# Palette no longer needs a name; only colors are stored.
|
||||
palette_id = palettes.create("", colors)
|
||||
palette = palettes.read(palette_id) or {}
|
||||
# Include the ID in the response payload so clients can link it.
|
||||
palette_with_id = {"id": str(palette_id)}
|
||||
palette_with_id.update(palette)
|
||||
return json.dumps(palette_with_id), 201, {'Content-Type': 'application/json'}
|
||||
except Exception as e:
|
||||
return json.dumps({"error": str(e)}), 400
|
||||
|
||||
@@ -36,9 +42,15 @@ async def create_palette(request):
|
||||
async def update_palette(request, id):
|
||||
"""Update an existing palette."""
|
||||
try:
|
||||
data = request.json
|
||||
data = request.json or {}
|
||||
# Ignore any name field; only colors are relevant.
|
||||
if "name" in data:
|
||||
data.pop("name", None)
|
||||
if palettes.update(id, data):
|
||||
return json.dumps(palettes.read(id)), 200, {'Content-Type': 'application/json'}
|
||||
palette = palettes.read(id) or {}
|
||||
palette_with_id = {"id": str(id)}
|
||||
palette_with_id.update(palette)
|
||||
return json.dumps(palette_with_id), 200, {'Content-Type': 'application/json'}
|
||||
return json.dumps({"error": "Palette not found"}), 404
|
||||
except Exception as e:
|
||||
return json.dumps({"error": str(e)}), 400
|
||||
|
||||
Reference in New Issue
Block a user