fix: curate swap endpoint name, reorder date field, 404 on missing asset
- Rename /curate/retag to /curate/swap; response now includes new_tag - /curate/reorder: read body["order"] key (was ordered_ids); include date field - /curate/remove and /curate/swap: return 404 if asset_id not found - Update phase3.html JS fetch calls and reorder payload to match spec Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -28,31 +28,31 @@ def curate():
|
|||||||
def remove():
|
def remove():
|
||||||
body = request.get_json()
|
body = request.get_json()
|
||||||
state = load_state(body["album_id"], current_app)
|
state = load_state(body["album_id"], current_app)
|
||||||
for p in state.photos:
|
photo = next((p for p in state.photos if p.id == body["asset_id"]), None)
|
||||||
if p.id == body["asset_id"]:
|
if photo is None:
|
||||||
p.tag = "skip"
|
return jsonify({"ok": False, "error": "photo not found"}), 404
|
||||||
break
|
photo.tag = "skip"
|
||||||
save_state(state, current_app)
|
save_state(state, current_app)
|
||||||
return jsonify({"ok": True})
|
return jsonify({"ok": True})
|
||||||
|
|
||||||
|
|
||||||
@bp.post("/curate/retag")
|
@bp.post("/curate/swap")
|
||||||
def retag():
|
def swap():
|
||||||
body = request.get_json()
|
body = request.get_json()
|
||||||
state = load_state(body["album_id"], current_app)
|
state = load_state(body["album_id"], current_app)
|
||||||
for p in state.photos:
|
photo = next((p for p in state.photos if p.id == body["asset_id"]), None)
|
||||||
if p.id == body["asset_id"]:
|
if photo is None:
|
||||||
p.tag = "story" if p.tag == "journal" else "journal"
|
return jsonify({"ok": False, "error": "photo not found"}), 404
|
||||||
break
|
photo.tag = "story" if photo.tag == "journal" else "journal"
|
||||||
save_state(state, current_app)
|
save_state(state, current_app)
|
||||||
return jsonify({"ok": True})
|
return jsonify({"ok": True, "new_tag": photo.tag})
|
||||||
|
|
||||||
|
|
||||||
@bp.post("/curate/reorder")
|
@bp.post("/curate/reorder")
|
||||||
def reorder():
|
def reorder():
|
||||||
body = request.get_json()
|
body = request.get_json()
|
||||||
state = load_state(body["album_id"], current_app)
|
state = load_state(body["album_id"], current_app)
|
||||||
order_map = {aid: i for i, aid in enumerate(body["ordered_ids"])}
|
order_map = {aid: i for i, aid in enumerate(body["order"])}
|
||||||
for p in state.photos:
|
for p in state.photos:
|
||||||
if p.id in order_map:
|
if p.id in order_map:
|
||||||
p.order = order_map[p.id]
|
p.order = order_map[p.id]
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ async function removeFn(albumId, assetId, el) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function retag(albumId, assetId, el) {
|
async function retag(albumId, assetId, el) {
|
||||||
await fetch('/curate/retag', {
|
await fetch('/curate/swap', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({album_id: albumId, asset_id: assetId})
|
body: JSON.stringify({album_id: albumId, asset_id: assetId})
|
||||||
@@ -69,10 +69,11 @@ async function reorder(albumId, container) {
|
|||||||
var ids = Array.from(container.querySelectorAll('.photo-card')).map(function(e) {
|
var ids = Array.from(container.querySelectorAll('.photo-card')).map(function(e) {
|
||||||
return e.dataset.assetId;
|
return e.dataset.assetId;
|
||||||
});
|
});
|
||||||
|
var day = container.id.replace('day-', '');
|
||||||
await fetch('/curate/reorder', {
|
await fetch('/curate/reorder', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({album_id: albumId, ordered_ids: ids})
|
body: JSON.stringify({album_id: albumId, date: day, order: ids})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user