fix: PUT profile создаёт профиль если его нет (upsert)
This commit is contained in:
+2
-2
@@ -318,12 +318,12 @@ def register(app):
|
|||||||
|
|
||||||
@app.route("/api/v1/elm/profile/<mac>", methods=["PUT"])
|
@app.route("/api/v1/elm/profile/<mac>", methods=["PUT"])
|
||||||
def update_elm_profile(mac: str):
|
def update_elm_profile(mac: str):
|
||||||
"""Обновляет поля профиля (response_time_ms, elm_desc и т.д.)."""
|
"""Обновляет поля профиля (response_time_ms и т.д.). Если профиля нет — создаёт.'''
|
||||||
data = request.get_json(silent=True) or {}
|
data = request.get_json(silent=True) or {}
|
||||||
with Database() as db:
|
with Database() as db:
|
||||||
p = db.get_device_profile(mac)
|
p = db.get_device_profile(mac)
|
||||||
if p is None:
|
if p is None:
|
||||||
return jsonify({"error": "not found"}), 404
|
p = {"mac": mac, "level": 0, "supported": [], "unsupported": [], "errors": []}
|
||||||
p.update(data)
|
p.update(data)
|
||||||
_save_profile(mac, p)
|
_save_profile(mac, p)
|
||||||
return jsonify({"ok": True})
|
return jsonify({"ok": True})
|
||||||
|
|||||||
Reference in New Issue
Block a user