Refactor: Remove audio processing and game state management modules
This commit is contained in:
69
src/server-deno/presentation/routes/trackRoutes.ts
Normal file
69
src/server-deno/presentation/routes/trackRoutes.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { Router } from '@oak/oak';
|
||||
import type { Context } from '@oak/oak';
|
||||
import { TrackService } from '../../application/mod.ts';
|
||||
import { logger } from '../../shared/logger.ts';
|
||||
|
||||
/**
|
||||
* Track/Playlist routes
|
||||
*/
|
||||
export function createTrackRoutes(trackService: TrackService): Router {
|
||||
const router = new Router();
|
||||
|
||||
/**
|
||||
* GET /api/playlists
|
||||
* Get list of available playlists
|
||||
*/
|
||||
router.get('/api/playlists', async (ctx: Context) => {
|
||||
try {
|
||||
const playlists = await trackService.getAvailablePlaylists();
|
||||
ctx.response.body = { ok: true, playlists };
|
||||
ctx.response.status = 200;
|
||||
} catch (error) {
|
||||
logger.error(`Error fetching playlists: ${error}`);
|
||||
ctx.response.body = { ok: false, error: 'Failed to fetch playlists' };
|
||||
ctx.response.status = 500;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/tracks?playlist=<id>
|
||||
* Get tracks from a specific playlist
|
||||
*/
|
||||
router.get('/api/tracks', async (ctx: Context) => {
|
||||
try {
|
||||
const playlistId = ctx.request.url.searchParams.get('playlist') || 'default';
|
||||
const tracks = await trackService.loadPlaylistTracks(playlistId);
|
||||
|
||||
ctx.response.body = { ok: true, tracks, playlist: playlistId };
|
||||
ctx.response.status = 200;
|
||||
} catch (error) {
|
||||
logger.error(`Error fetching tracks: ${error}`);
|
||||
ctx.response.body = { ok: false, error: 'Failed to fetch tracks' };
|
||||
ctx.response.status = 500;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/reload-years?playlist=<id>
|
||||
* Reload years index for a playlist
|
||||
*/
|
||||
router.get('/api/reload-years', async (ctx: Context) => {
|
||||
try {
|
||||
const playlistId = ctx.request.url.searchParams.get('playlist') || 'default';
|
||||
const result = await trackService.reloadYearsIndex(playlistId);
|
||||
|
||||
ctx.response.body = {
|
||||
ok: true,
|
||||
count: result.count,
|
||||
playlist: playlistId
|
||||
};
|
||||
ctx.response.status = 200;
|
||||
} catch (error) {
|
||||
logger.error(`Error reloading years: ${error}`);
|
||||
ctx.response.body = { ok: false, error: 'Failed to reload years' };
|
||||
ctx.response.status = 500;
|
||||
}
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
Reference in New Issue
Block a user