Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 2 #40

Open
wants to merge 2 commits into
base: lesson-2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/api/resources/playlist/playlist.restRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 12 additions & 0 deletions src/api/resources/song/song.restRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 4 additions & 1 deletion src/api/resources/user/user.restRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ 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)

userRouter.route('/:id')
.get(userController.getOne)
.put(userController.updateOne)
.delete(userController.createOne)
.delete(userController.deleteOne)
2 changes: 2 additions & 0 deletions src/api/restRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 8 additions & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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