Skip to content

Commit

Permalink
feat: add ticket routes
Browse files Browse the repository at this point in the history
  • Loading branch information
junha-ahn committed Oct 17, 2023
1 parent 04e4f24 commit b50f8f5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/api/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const { Router } = require('express')
const logger = $require('loaders/logger')
const redis = $require('loaders/redis')
const { CustomResponse, validator, container } = $require('api/middlewares')
const TicketStoreService = $require('services/ticketStore')
const { CustomResponse, container } = $require('api/middlewares')

module.exports = () => {
module.exports = (app) => {
const router = Router()
const ticketStoreService = new TicketStoreService(redis)

router.get(
'/',
Expand All @@ -22,20 +18,8 @@ module.exports = () => {
}),
)

router.post(
'/ticket',
validator.mw([
validator.body('eventId').isInt(),
validator.body('userId').isInt(),
]),
container(async (req) => {
logger.debug('Calling POST /ticket with body: %o', req.body)
const { eventId, userId } = req.body
require('./routes/ticket')(router);

await ticketStoreService.push(eventId, userId)
return CustomResponse(201, `Created!`)
}),
)

return router
}
25 changes: 25 additions & 0 deletions src/api/routes/ticket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const router = require('express').Router();
const logger = $require('loaders/logger')
const redis = $require('loaders/redis')
const { CustomResponse, validator, container } = $require('api/middlewares')
const TicketStoreService = $require('services/ticketStore')
module.exports = app => {
app.use('/ticket', router);


router.post(
'/',
validator.mw([
validator.body('eventId').isInt(),
validator.body('userId').isInt(),
]),
container(async (req) => {
logger.debug('Calling POST /ticket with body: %o', req.body)
const { eventId, userId } = req.body

const ticketStoreService = new TicketStoreService(redis)
await ticketStoreService.push(eventId, userId)
return CustomResponse(201, `Created!`)
}),
)
};

0 comments on commit b50f8f5

Please sign in to comment.