From b8802baf36ef073e85d88a2b331c32c9a08f2f99 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 25 May 2026 21:29:55 +0200 Subject: [PATCH] Add bbox PATCH endpoint + seed watermelon test bbox - PATCH /api/objects/:id/pictures/:pictureId sets bounding box values - Migration seeds bbox for watermelon test object (x=0.08, y=0.10, w=0.78, h=0.76) Co-Authored-By: Claude Sonnet 4.6 --- src/db-migrate.js | 9 +++++++++ src/routes/objects.js | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/db-migrate.js b/src/db-migrate.js index b3381e0..09721ac 100644 --- a/src/db-migrate.js +++ b/src/db-migrate.js @@ -485,6 +485,15 @@ async function migrate() { ON CONFLICT (short_en) DO UPDATE SET status = EXCLUDED.status, published_at = COALESCE(languages.published_at, EXCLUDED.published_at) `).catch(() => {}); + // Seed bbox for watermelon test object (only if bbox_x is still NULL) + await query(` + UPDATE object_pictures + SET bbox_x = 0.08, bbox_y = 0.10, bbox_w = 0.78, bbox_h = 0.76 + WHERE object_id = '67a609af-55c9-4560-ba63-c8ef93429ec0' + AND picture_id = 'fa776286-1df1-4b47-a29c-fc6e83e6e2da' + AND bbox_x IS NULL + `).catch(() => {}); + console.log('Migration complete'); } diff --git a/src/routes/objects.js b/src/routes/objects.js index 825cc7f..04ba0af 100644 --- a/src/routes/objects.js +++ b/src/routes/objects.js @@ -220,6 +220,20 @@ router.post('/:id/pictures/:pictureId', async (req, res, next) => { } catch (err) { next(err); } }); +// PATCH /api/objects/:id/pictures/:pictureId — set bounding box (0–1 percentages) +router.patch('/:id/pictures/:pictureId', async (req, res, next) => { + try { + const { bbox_x, bbox_y, bbox_w, bbox_h } = req.body; + await query( + `UPDATE object_pictures + SET bbox_x = $3, bbox_y = $4, bbox_w = $5, bbox_h = $6 + WHERE object_id = $1 AND picture_id = $2`, + [req.params.id, req.params.pictureId, bbox_x ?? null, bbox_y ?? null, bbox_w ?? null, bbox_h ?? null] + ); + res.status(204).end(); + } catch (err) { next(err); } +}); + // DELETE /api/objects/:id/pictures/:pictureId router.delete('/:id/pictures/:pictureId', async (req, res, next) => { try {