diff --git a/src/api/routes/ticket.js b/src/api/routes/ticket.js index e0179d6..bfdf1f6 100644 --- a/src/api/routes/ticket.js +++ b/src/api/routes/ticket.js @@ -49,4 +49,19 @@ module.exports = (app) => { }) }) ) + + router.delete( + '/running/:eventId/:userId', + validator.mw([validator.param('eventId').isInt(), validator.param('userId').isInt()]), + container(async (req) => { + logger.debug('Calling DELETE /ticket with params: %o', req.params) + const { eventId, userId } = req.params + + const ticketStoreService = new TicketStoreService(redis) + const offset = await ticketStoreService.getOffsetFromRunning(eventId, userId) + if (offset == null) return CustomResponse(404, `Ticket Not Found!`) + await ticketStoreService.removeTicketFromRunning(eventId, userId) + return CustomResponse(200, `Success Delete!`) + }) + ) } diff --git a/src/services/ticketStore.js b/src/services/ticketStore.js index d6c8004..e4411ec 100644 --- a/src/services/ticketStore.js +++ b/src/services/ticketStore.js @@ -120,4 +120,7 @@ module.exports = class TicketStore { const results = await this._getByTimestamp(this.getEventListKey(), minTimestamp, maxTimestamp) return results.map((e) => Number(e)) } + async removeTicketFromRunning(eventId, userId) { + return this.redis.zRem(this.getRunningKeyByEventId(eventId), userId) + } } diff --git a/test/integrationTest/api/ticket.spec.js b/test/integrationTest/api/ticket.spec.js index 83aeec3..a72bd8e 100644 --- a/test/integrationTest/api/ticket.spec.js +++ b/test/integrationTest/api/ticket.spec.js @@ -145,4 +145,33 @@ describe('Ticket', () => { }) }) }) + + describe('DELETE /ticket/running/{eventId}/{userId} 은', () => { + describe('삭제 성공시', () => { + it('200을 리턴한다', async () => { + await ticketStoreService.pushIntoRunning(testEventId, testUserId) + + const res = await chai.request(server).del(`/ticket/running/${testEventId}/${testUserId}`) + expect(res).to.have.status(200) + expect(res.body.status).to.deep.equal(true) + }) + }) + describe('실패시', () => { + it('Running 티켓이 없을 경우 404 Not Found를 리턴한다', async () => { + const res = await chai.request(server).del(`/ticket/${testEventId}/${testUserId}`) + expect(res).to.have.status(404) + expect(res.body.status).to.deep.equal(false) + }) + it('Waiting 티켓이 존재해도, 입장 티켓이 없을 경우 404 Not Found를 리턴한다', async () => { + await chai.request(server).post('/ticket').send({ + eventId: testEventId, + userId: testUserId, + }) + + const res = await chai.request(server).del(`/ticket/running/${testEventId}/${testUserId}`) + expect(res).to.have.status(404) + expect(res.body.status).to.deep.equal(false) + }) + }) + }) })