From 6725b37eb56f1fbae6e2cd4e2717539440b5bf49 Mon Sep 17 00:00:00 2001 From: Emmanuel AKINDE Date: Sat, 13 Oct 2018 18:49:56 +0100 Subject: [PATCH 1/2] solutions --- src/api/resources/playlist/playlist.restRouter.js | 11 +++++++++++ src/api/resources/song/song.restRouter.js | 12 ++++++++++++ src/api/resources/user/user.restRouter.js | 3 +++ src/api/restRouter.js | 2 ++ src/server.js | 9 ++++++++- 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/api/resources/playlist/playlist.restRouter.js b/src/api/resources/playlist/playlist.restRouter.js index ec40b4f..468c99d 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.createOne) diff --git a/src/api/resources/song/song.restRouter.js b/src/api/resources/song/song.restRouter.js index 2e80604..0ce0230 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.createOne) diff --git a/src/api/resources/user/user.restRouter.js b/src/api/resources/user/user.restRouter.js index 6292857..c0eb51a 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) 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 From 3bad248c0c8cb4a65461b25c1111112157ea7d5e Mon Sep 17 00:00:00 2001 From: Emmanuel AKINDE Date: Sat, 13 Oct 2018 20:31:38 +0100 Subject: [PATCH 2/2] correction --- src/api/resources/playlist/playlist.restRouter.js | 10 +++++----- src/api/resources/song/song.restRouter.js | 2 +- src/api/resources/user/user.restRouter.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/api/resources/playlist/playlist.restRouter.js b/src/api/resources/playlist/playlist.restRouter.js index 468c99d..943ec69 100644 --- a/src/api/resources/playlist/playlist.restRouter.js +++ b/src/api/resources/playlist/playlist.restRouter.js @@ -6,10 +6,10 @@ export const playlistRouter = express.Router() playlistRouter.param('id', playlistController.findByParam) playlistRouter.route('/') - .get(playlistController.getAll) - .post(playlistController.createOne) + .get(playlistController.getAll) + .post(playlistController.createOne) playlistRouter.route('/:id') - .get(playlistController.getOne) - .put(playlistController.updateOne) - .delete(playlistController.createOne) + .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 0ce0230..e4cb172 100644 --- a/src/api/resources/song/song.restRouter.js +++ b/src/api/resources/song/song.restRouter.js @@ -13,4 +13,4 @@ songRouter.route('/') songRouter.route('/:id') .get(songController.getOne) .put(songController.updateOne) - .delete(songController.createOne) + .delete(songController.deleteOne) diff --git a/src/api/resources/user/user.restRouter.js b/src/api/resources/user/user.restRouter.js index c0eb51a..971a725 100644 --- a/src/api/resources/user/user.restRouter.js +++ b/src/api/resources/user/user.restRouter.js @@ -15,4 +15,4 @@ userRouter.route('/') userRouter.route('/:id') .get(userController.getOne) .put(userController.updateOne) - .delete(userController.createOne) + .delete(userController.deleteOne)