Skip to content

Commit 9b78b1e

Browse files
committed
#8, add puzzle coupon endpoint
1 parent d33fe2a commit 9b78b1e

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

api/schema/puzzle.ts

+4
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ export const puzzleStatsSchema = z.array(puzzleItemStatSchema)
3333
export const puzzleRevokeResponseSchema = z.object({
3434
status: z.string().default('OK'),
3535
})
36+
37+
export const puzzleCouponRedeemResponseSchema = z.object({
38+
status: z.string().default('OK'),
39+
})

features/puzzle_coupon.feature

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Feature: Puzzle Coupon
2+
Scenario: PUT /event/puzzle/coupon to redeem a puzzle coupon
3+
Given there have some booths
4+
| token | name | event_id |
5+
| 1024914b-ee65-4728-b687-8341f5affa89 | COSCUP | SITCON |
6+
And there have some attendees
7+
| token | event_id | display_name |
8+
| f185f505-d8c0-43ce-9e7b-bb9e8909072d | SITCON | Aotoki |
9+
When I make a PUT request to "/event/puzzle/coupon?token=1024914b-ee65-4728-b687-8341f5affa89&event_id=SITCON":
10+
"""
11+
{}
12+
"""
13+
Then the response json should be:
14+
"""
15+
{
16+
"status": "OK"
17+
}
18+
"""
19+
And the response status should be 200

worker/controller/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * from './puzzleDeliverer'
77
export * from './puzzleDelivery'
88
export * from './puzzleDashboard'
99
export * from './revokePuzzle'
10+
export * from './useCoupon'

worker/controller/useCoupon.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { IRequest } from 'itty-router'
2+
import { OpenAPIRoute, OpenAPIRouteSchema } from '@cloudflare/itty-router-openapi'
3+
import { Put } from '@worker/router'
4+
import { json } from '@worker/utils'
5+
import * as schema from '@api/schema'
6+
7+
export type UseCouponRequest = IRequest
8+
9+
@Put('/event/puzzle/coupon')
10+
export class UseCoupon extends OpenAPIRoute {
11+
static schema: OpenAPIRouteSchema = {
12+
summary: "Use attendee's puzzle to redeem coupon",
13+
tags: ['Puzzle'],
14+
requestBody: {},
15+
parameters: {
16+
event_id: schema.EventIdQuery,
17+
token: schema.OptionalAttendeeTokenQuery,
18+
},
19+
responses: {
20+
'200': {
21+
description: 'Result of coupon redemption',
22+
schema: schema.puzzleCouponRedeemResponseSchema,
23+
},
24+
},
25+
}
26+
27+
async handle(_request: UseCouponRequest, _env: unknown, _context: unknown) {
28+
return json({ status: 'OK' })
29+
}
30+
}

0 commit comments

Comments
 (0)