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 <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
ON CONFLICT (short_en) DO UPDATE SET status = EXCLUDED.status, published_at = COALESCE(languages.published_at, EXCLUDED.published_at)
|
||||||
`).catch(() => {});
|
`).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');
|
console.log('Migration complete');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -220,6 +220,20 @@ router.post('/:id/pictures/:pictureId', async (req, res, next) => {
|
|||||||
} catch (err) { next(err); }
|
} 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
|
// DELETE /api/objects/:id/pictures/:pictureId
|
||||||
router.delete('/:id/pictures/:pictureId', async (req, res, next) => {
|
router.delete('/:id/pictures/:pictureId', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user