Refactor code structure for improved readability and maintainability
Some checks failed
CI / lint (push) Failing after 1m4s
CI / test-backend (push) Has been skipped
CI / test-frontend (push) Has been skipped
CI / test-e2e (push) Has been skipped

This commit is contained in:
2026-02-22 18:18:46 +01:00
parent c27e9bec7a
commit 0c9c408564
98 changed files with 8207 additions and 5250 deletions

View File

@@ -1,64 +0,0 @@
import { Game, CreateGameInput, UpdateGameInput } from '../types/game';
import { RomFile, EnrichedGame, ScanResult } from '../types/rom';
const API_BASE = '/api';
async function request<T>(endpoint: string, options?: RequestInit): Promise<T> {
const response = await fetch(`${API_BASE}${endpoint}`, {
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
...options,
});
if (!response.ok) {
throw new Error(`API error: ${response.status} ${response.statusText}`);
}
return response.json();
}
export const api = {
games: {
list: () => request<Game[]>('/games'),
create: (data: CreateGameInput) =>
request<Game>('/games', {
method: 'POST',
body: JSON.stringify(data),
}),
update: (id: string, data: UpdateGameInput) =>
request<Game>(`/games/${id}`, {
method: 'PUT',
body: JSON.stringify(data),
}),
delete: (id: string) =>
request<void>(`/games/${id}`, {
method: 'DELETE',
}),
},
roms: {
list: () => request<RomFile[]>('/roms'),
getById: (id: string) => request<RomFile>(`/roms/${id}`),
linkGame: (romId: string, gameId: string) =>
request<RomFile>(`/roms/${romId}/game`, {
method: 'PUT',
body: JSON.stringify({ gameId }),
}),
delete: (id: string) => request<void>(`/roms/${id}`, { method: 'DELETE' }),
},
metadata: {
search: (query: string) =>
request<EnrichedGame[]>('/metadata/search?q=' + encodeURIComponent(query)),
},
import: {
scan: (dir: string) =>
request<ScanResult>('/import/scan', {
method: 'POST',
body: JSON.stringify({ dir }),
}),
},
};