feat: implement ROMs management UI (Phase 8)

Backend (Phase 8.1):
- Add ROMs endpoints: GET, GET/:id, PUT/:id/game, DELETE
- Add metadata search endpoint using IGDB/RAWG/TGDB
- Implement RomsController with ROM CRUD logic
- Add 12 comprehensive ROM endpoint tests
- Configure Vitest to run tests sequentially (threads: false)
- Auto-apply Prisma migrations in test setup

Frontend (Phase 8.2 + 8.3):
- Create ROM types: RomFile, Artwork, EnrichedGame
- Extend API client with roms and metadata namespaces
- Implement 5 custom hooks with TanStack Query
- Create ScanDialog, MetadataSearchDialog, RomCard components
- Rewrite roms.tsx page with table and all actions
- Add 37 comprehensive component and page tests

All 122 tests passing: 63 backend + 59 frontend
Lint: 0 errors, only unused directive warnings
This commit is contained in:
2026-02-12 19:52:59 +01:00
parent 630ebe0dc8
commit 571ac97f00
22 changed files with 2221 additions and 4 deletions

View File

@@ -0,0 +1,48 @@
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
import * as metadataService from '../services/metadataService';
import { z } from 'zod';
import { ZodError } from 'zod';
// Esquema de validación para parámetros de búsqueda
const searchMetadataSchema = z.object({
q: z.string().min(1, 'El parámetro de búsqueda es requerido'),
platform: z.string().optional(),
});
async function metadataRoutes(app: FastifyInstance) {
/**
* GET /api/metadata/search?q=query&platform=optional
* Buscar metadata de juegos
*/
app.get<{ Querystring: any; Reply: any[] }>('/metadata/search', async (request, reply) => {
try {
// Validar parámetros de query con Zod
const validated = searchMetadataSchema.parse(request.query);
// Llamar a metadataService
const result = await metadataService.enrichGame({
title: validated.q,
platform: validated.platform,
});
// Si hay resultado, devolver como array; si no, devolver array vacío
return reply.code(200).send(result ? [result] : []);
} catch (error) {
if (error instanceof ZodError) {
return reply.code(400).send({
error: 'Parámetros de búsqueda inválidos',
details: error.errors,
});
}
throw error;
}
});
}
export default metadataRoutes;
/**
* Metadatos:
* Autor: GitHub Copilot
* Última actualización: 2026-02-11
*/

View File

@@ -0,0 +1,95 @@
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
import { RomsController } from '../controllers/romsController';
import { linkGameSchema } from '../validators/romValidator';
import { ZodError } from 'zod';
async function romsRoutes(app: FastifyInstance) {
/**
* GET /api/roms
* Listar todos los ROMs
*/
app.get<{ Reply: any[] }>('/roms', async (request, reply) => {
const roms = await RomsController.listRoms();
return reply.code(200).send(roms);
});
/**
* GET /api/roms/:id
* Obtener un ROM por ID
*/
app.get<{ Params: { id: string }; Reply: any }>('/roms/:id', async (request, reply) => {
try {
const rom = await RomsController.getRomById(request.params.id);
return reply.code(200).send(rom);
} catch (error) {
if (error instanceof Error && error.message.includes('no encontrado')) {
return reply.code(404).send({
error: 'ROM no encontrado',
});
}
throw error;
}
});
/**
* PUT /api/roms/:id/game
* Vincular un juego a un ROM
*/
app.put<{ Params: { id: string }; Body: any; Reply: any }>(
'/roms/:id/game',
async (request, reply) => {
try {
// Validar entrada con Zod
const validated = linkGameSchema.parse(request.body);
const rom = await RomsController.linkGameToRom(request.params.id, validated.gameId);
return reply.code(200).send(rom);
} catch (error) {
if (error instanceof ZodError) {
return reply.code(400).send({
error: 'Validación fallida',
details: error.errors,
});
}
if (error instanceof Error) {
if (error.message.includes('ROM no encontrado')) {
return reply.code(404).send({
error: 'ROM no encontrado',
});
}
if (error.message.includes('Juego no encontrado')) {
return reply.code(400).send({
error: 'Game ID inválido o no encontrado',
});
}
}
throw error;
}
}
);
/**
* DELETE /api/roms/:id
* Eliminar un ROM
*/
app.delete<{ Params: { id: string }; Reply: any }>('/roms/:id', async (request, reply) => {
try {
await RomsController.deleteRom(request.params.id);
return reply.code(204).send();
} catch (error) {
if (error instanceof Error && error.message.includes('no encontrado')) {
return reply.code(404).send({
error: 'ROM no encontrado',
});
}
throw error;
}
});
}
export default romsRoutes;
/**
* Metadatos:
* Autor: GitHub Copilot
* Última actualización: 2026-02-11
*/