From b50f8f5d61ba360809075a4347c87599ff23a58b Mon Sep 17 00:00:00 2001 From: junha-ahn Date: Tue, 17 Oct 2023 19:53:20 +0900 Subject: [PATCH] feat: add ticket routes --- src/api/index.js | 22 +++------------------- src/api/routes/ticket.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 src/api/routes/ticket.js diff --git a/src/api/index.js b/src/api/index.js index e4d8a24..768a9f9 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -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( '/', @@ -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 } diff --git a/src/api/routes/ticket.js b/src/api/routes/ticket.js new file mode 100644 index 0000000..5d1ecfa --- /dev/null +++ b/src/api/routes/ticket.js @@ -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!`) + }), + ) +}; \ No newline at end of file