diff --git a/src/controllers/trackController.js b/src/controllers/trackController.js new file mode 100644 index 0000000..657388c --- /dev/null +++ b/src/controllers/trackController.js @@ -0,0 +1,12 @@ +import Track from '../models/Track.js'; + +export const trackController = { + async list(req, res, next) { + try { + const tracks = await Track.find().sort({ createdAt: -1 }).lean(); + res.json({ success: true, data: tracks }); + } catch (error) { + next(error); + } + }, +}; diff --git a/src/routes/index.js b/src/routes/index.js index c2e5171..d70e120 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -1,6 +1,7 @@ import { Router } from 'express'; import authRoutes from './auths.js'; import adminRoutes from './admins.js'; +import trackRoutes from './tracks.js'; const router = Router(); @@ -16,5 +17,6 @@ router.get('/health', (req, res) => { router.use('/auth', authRoutes); router.use('/admin', adminRoutes); +router.use('/tracks', trackRoutes); export default router; diff --git a/src/routes/tracks.js b/src/routes/tracks.js new file mode 100644 index 0000000..ea309b2 --- /dev/null +++ b/src/routes/tracks.js @@ -0,0 +1,8 @@ +import { Router } from 'express'; +import { trackController } from '../controllers/trackController.js'; + +const router = Router(); + +router.get('/', trackController.list); + +export default router;