Skip to content

Commit

Permalink
feat: add remove api
Browse files Browse the repository at this point in the history
  • Loading branch information
junha-ahn committed Oct 24, 2023
1 parent 6da1a86 commit 23b704c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/api/routes/ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,25 @@ 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!`)
}),
)
}
7 changes: 7 additions & 0 deletions src/services/ticketStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,11 @@ module.exports = class TicketStore {
async getLengthOfRunning(eventId) {
return await this._length(this.getRunningKeyByEventId(eventId))
}

async removeticketFromWaiting(eventId, userId) {
return this.redis.zRem(this.getWaitingKeyByEventId(eventId), userId)
}
async removeTicketFromRunning(eventId, userId) {
return this.redis.zRem(this.getRunningKeyByEventId(eventId), userId)
}
}
34 changes: 34 additions & 0 deletions test/integrationTest/api/ticket.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,38 @@ 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)
})
})
})
})

0 comments on commit 23b704c

Please sign in to comment.