diff --git a/src/api/resources/playlist/playlist.restRouter.js b/src/api/resources/playlist/playlist.restRouter.js index ec40b4f..943ec69 100644 --- a/src/api/resources/playlist/playlist.restRouter.js +++ b/src/api/resources/playlist/playlist.restRouter.js @@ -2,3 +2,14 @@ import express from 'express' import playlistController from './playlist.controller' export const playlistRouter = express.Router() + +playlistRouter.param('id', playlistController.findByParam) + +playlistRouter.route('/') + .get(playlistController.getAll) + .post(playlistController.createOne) + +playlistRouter.route('/:id') + .get(playlistController.getOne) + .put(playlistController.updateOne) + .delete(playlistController.deleteOne) diff --git a/src/api/resources/song/song.restRouter.js b/src/api/resources/song/song.restRouter.js index 2e80604..e4cb172 100644 --- a/src/api/resources/song/song.restRouter.js +++ b/src/api/resources/song/song.restRouter.js @@ -2,3 +2,15 @@ import express from 'express' import songController from './song.controller' export const songRouter = express.Router() + +songRouter.param('id', songController.findByParam) + + +songRouter.route('/') + .get(songController.getAll) + .post(songController.createOne) + +songRouter.route('/:id') + .get(songController.getOne) + .put(songController.updateOne) + .delete(songController.deleteOne) diff --git a/src/api/resources/user/user.restRouter.js b/src/api/resources/user/user.restRouter.js index 6292857..971a725 100644 --- a/src/api/resources/user/user.restRouter.js +++ b/src/api/resources/user/user.restRouter.js @@ -5,6 +5,9 @@ export const userRouter = express.Router() userRouter.param('id', userController.findByParam) +//userRouter.get('/',dthdhr) <------ mutli routing without using .route +//userRouter.post('/',rhrdh) <------ mutli routing without using .route + userRouter.route('/') .get(userController.getAll) .post(userController.createOne) @@ -12,4 +15,4 @@ userRouter.route('/') userRouter.route('/:id') .get(userController.getOne) .put(userController.updateOne) - .delete(userController.createOne) + .delete(userController.deleteOne) diff --git a/src/api/restRouter.js b/src/api/restRouter.js index 160ed30..2f87083 100644 --- a/src/api/restRouter.js +++ b/src/api/restRouter.js @@ -6,3 +6,5 @@ import { playlistRouter } from './resources/playlist' export const restRouter = express.Router() restRouter.use('/user', userRouter) +restRouter.use('/song', songRouter) +restRouter.use('/playlist', playlistRouter) diff --git a/src/server.js b/src/server.js index 469df36..8d36f20 100644 --- a/src/server.js +++ b/src/server.js @@ -6,15 +6,22 @@ import { signin, protect } from './api/modules/auth' // Declare an app from express const app = express() +const apiRouter = express.Router() + +apiRouter.get('/', (req, res) => res.json({ apiPost: true })) +// apiRouter.all('*', (req, res) => res.json({ apiAll: true })) + setupMiddware(app) connect() // setup basic routing for index route app.use('/signin', signin) +app.use('/api', restRouter) // catch all +app.get('/', (req, res) => res.json({ first: true })) app.all('*', (req, res) => { - res.json({ok: true}) + res.json({ ok: true }) }) export default app