feat(simulations): GET /simulations — liste paginée des productions (Sprint 3.7)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
14d8d73991
commit
a394ce8429
3 changed files with 357 additions and 0 deletions
|
|
@ -151,6 +151,47 @@ simulations.patch('/:id/sujet', authMiddleware, async (c) => {
|
|||
return c.json(result.data, 200)
|
||||
})
|
||||
|
||||
// Sprint 3.7 — liste paginée des productions de l'utilisateur connecté.
|
||||
// `GET /` est distinct de `GET /:id` côté routeur Hono (match par (méthode, chemin)).
|
||||
simulations.get('/', authMiddleware, async (c) => {
|
||||
const rawPage = c.req.query('page')
|
||||
const rawLimit = c.req.query('limit')
|
||||
|
||||
const page = rawPage === undefined ? 1 : Number(rawPage)
|
||||
const limit = rawLimit === undefined ? 20 : Number(rawLimit)
|
||||
|
||||
if (!Number.isInteger(page) || page < 1) {
|
||||
return c.json(
|
||||
{
|
||||
error: true,
|
||||
code: 'VALIDATION_ERROR',
|
||||
message: '`page` doit être un entier supérieur ou égal à 1.',
|
||||
},
|
||||
400
|
||||
)
|
||||
}
|
||||
|
||||
if (!Number.isInteger(limit) || limit < 1 || limit > 50) {
|
||||
return c.json(
|
||||
{
|
||||
error: true,
|
||||
code: 'VALIDATION_ERROR',
|
||||
message: '`limit` doit être un entier entre 1 et 50.',
|
||||
},
|
||||
400
|
||||
)
|
||||
}
|
||||
|
||||
const profile = c.get('profile')
|
||||
const result = await simulationController.list({ page, limit }, profile)
|
||||
|
||||
if ('error' in result) {
|
||||
return c.json(result, result.status as 500)
|
||||
}
|
||||
|
||||
return c.json(result.data, 200)
|
||||
})
|
||||
|
||||
// GET /:id en dernier — route catch-all par id, ne doit pas masquer les routes plus spécifiques.
|
||||
simulations.get('/:id', authMiddleware, async (c) => {
|
||||
// `:id` est garanti présent par le pattern de route Hono
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue