Skip to content

Commit

Permalink
Refactor puzzle dashboard to OpenAPI route
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Nov 23, 2023
1 parent b38fbaf commit de8bddd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 13 additions & 4 deletions worker/controller/puzzleDashboard.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { IRequest } from 'itty-router'
import { json } from '@worker/utils'
import * as schema from '@api/schema'
import { get } from '@worker/router'
import { Get } from '@worker/router'
import { GetPuzzleStats } from '@api/query'
import { OpenAPIRoute, OpenAPIRouteSchema } from '@cloudflare/itty-router-openapi'

export type PuzzleStatsRequest = {
getPuzzleStats: GetPuzzleStats
} & IRequest

export class PuzzleDashboard {
@get('/event/puzzle/dashboard')
async getStats({ getPuzzleStats, query }: PuzzleStatsRequest) {
@Get('/event/puzzle/dashboard')
export class DisplayPuzzleStats extends OpenAPIRoute {
static schema: OpenAPIRouteSchema = {
description: 'Get puzzle stats',
tags: ['Puzzle'],
parameters: {
event_id: schema.EventIdQuery,
},
}

async handle({ getPuzzleStats, query }: PuzzleStatsRequest) {
const stats = await getPuzzleStats.execute({ eventId: query.event_id as string })

return json<schema.PuzzleStats>([
Expand Down
6 changes: 1 addition & 5 deletions worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { withParams } from 'itty-router'
import { OpenAPIRouter } from '@cloudflare/itty-router-openapi'
import { withCommands, withTestability, withQueries } from '@worker/middlewares'
import { setup } from '@worker/router'
import * as Controller from '@worker/controller'
import '@worker/controller'

const router = OpenAPIRouter({
schema: {
Expand All @@ -21,8 +21,4 @@ const router = OpenAPIRouter({

router.all('*', withParams).all('*', withCommands).all('*', withQueries).all('*', withTestability)

const _Controllers = [Controller.PuzzleDashboard]

_Controllers.forEach((Controller: new () => object) => new Controller())

export default setup(router)

0 comments on commit de8bddd

Please sign in to comment.