|
| 1 | +/** AUTOGENERATED - DO NOT EDIT **/ |
| 2 | +/* tslint:disable */ |
| 3 | +/* eslint-disable */ |
| 4 | + |
| 5 | +import { |
| 6 | + t_DeleteTodoListByIdParamSchema, |
| 7 | + t_Error, |
| 8 | + t_GetTodoListByIdParamSchema, |
| 9 | + t_TodoList, |
| 10 | + t_UpdateTodoListByIdBodySchema, |
| 11 | + t_UpdateTodoListByIdParamSchema, |
| 12 | +} from "../../../../lib/models" |
| 13 | +import { s_CreateUpdateTodoList } from "../../../../lib/schemas" |
| 14 | +import { |
| 15 | + KoaRuntimeError, |
| 16 | + RequestInputType, |
| 17 | +} from "@nahkies/typescript-koa-runtime/errors" |
| 18 | +import { |
| 19 | + KoaRuntimeResponder, |
| 20 | + KoaRuntimeResponse, |
| 21 | + StatusCode, |
| 22 | + StatusCode4xx, |
| 23 | +} from "@nahkies/typescript-koa-runtime/server" |
| 24 | +import { Params, parseRequestInput } from "@nahkies/typescript-koa-runtime/zod" |
| 25 | +import { NextRequest } from "next/server" |
| 26 | +import { z } from "zod" |
| 27 | + |
| 28 | +//region safe-edit-region-header |
| 29 | + |
| 30 | +//endregion safe-edit-region-header |
| 31 | +export type GetTodoListByIdResponder = { |
| 32 | + with200(): KoaRuntimeResponse<t_TodoList> |
| 33 | + withStatusCode4xx(status: StatusCode4xx): KoaRuntimeResponse<t_Error> |
| 34 | + withDefault(status: StatusCode): KoaRuntimeResponse<void> |
| 35 | +} & KoaRuntimeResponder |
| 36 | + |
| 37 | +export type GetTodoListById = ( |
| 38 | + params: Params<t_GetTodoListByIdParamSchema, void, void>, |
| 39 | + respond: GetTodoListByIdResponder, |
| 40 | + ctx: { request: NextRequest }, |
| 41 | +) => Promise<KoaRuntimeResponse<unknown>> |
| 42 | + |
| 43 | +export type UpdateTodoListByIdResponder = { |
| 44 | + with200(): KoaRuntimeResponse<t_TodoList> |
| 45 | + withStatusCode4xx(status: StatusCode4xx): KoaRuntimeResponse<t_Error> |
| 46 | + withDefault(status: StatusCode): KoaRuntimeResponse<void> |
| 47 | +} & KoaRuntimeResponder |
| 48 | + |
| 49 | +export type UpdateTodoListById = ( |
| 50 | + params: Params< |
| 51 | + t_UpdateTodoListByIdParamSchema, |
| 52 | + void, |
| 53 | + t_UpdateTodoListByIdBodySchema |
| 54 | + >, |
| 55 | + respond: UpdateTodoListByIdResponder, |
| 56 | + ctx: { request: NextRequest }, |
| 57 | +) => Promise<KoaRuntimeResponse<unknown>> |
| 58 | + |
| 59 | +export type DeleteTodoListByIdResponder = { |
| 60 | + with204(): KoaRuntimeResponse<void> |
| 61 | + withStatusCode4xx(status: StatusCode4xx): KoaRuntimeResponse<t_Error> |
| 62 | + withDefault(status: StatusCode): KoaRuntimeResponse<void> |
| 63 | +} & KoaRuntimeResponder |
| 64 | + |
| 65 | +export type DeleteTodoListById = ( |
| 66 | + params: Params<t_DeleteTodoListByIdParamSchema, void, void>, |
| 67 | + respond: DeleteTodoListByIdResponder, |
| 68 | + ctx: { request: NextRequest }, |
| 69 | +) => Promise<KoaRuntimeResponse<unknown>> |
| 70 | + |
| 71 | +const getTodoListByIdParamSchema = z.object({ listId: z.string() }) |
| 72 | + |
| 73 | +export const GET = async ( |
| 74 | + request: NextRequest, |
| 75 | + { params }: { params: unknown }, |
| 76 | +): Promise<Response> => { |
| 77 | + const input = { |
| 78 | + params: parseRequestInput( |
| 79 | + getTodoListByIdParamSchema, |
| 80 | + params, |
| 81 | + RequestInputType.RouteParam, |
| 82 | + ), |
| 83 | + // TODO: this swallows repeated parameters |
| 84 | + query: undefined, |
| 85 | + body: undefined, |
| 86 | + } |
| 87 | + |
| 88 | + const responder = { |
| 89 | + with200() { |
| 90 | + return new KoaRuntimeResponse<t_TodoList>(200) |
| 91 | + }, |
| 92 | + withStatusCode4xx(status: StatusCode4xx) { |
| 93 | + return new KoaRuntimeResponse<t_Error>(status) |
| 94 | + }, |
| 95 | + withDefault(status: StatusCode) { |
| 96 | + return new KoaRuntimeResponse<void>(status) |
| 97 | + }, |
| 98 | + withStatus(status: StatusCode) { |
| 99 | + return new KoaRuntimeResponse(status) |
| 100 | + }, |
| 101 | + } |
| 102 | + |
| 103 | + const { status, body } = await import("@/lib/api/list/[listId]/route") |
| 104 | + .then((it) => it.GET(input, responder, { request })) |
| 105 | + .then((it) => it.unpack()) |
| 106 | + .catch((err) => { |
| 107 | + throw KoaRuntimeError.HandlerError(err) |
| 108 | + }) |
| 109 | + |
| 110 | + return Response.json(body, { status }) |
| 111 | +} |
| 112 | + |
| 113 | +const updateTodoListByIdParamSchema = z.object({ listId: z.string() }) |
| 114 | + |
| 115 | +const updateTodoListByIdBodySchema = s_CreateUpdateTodoList |
| 116 | + |
| 117 | +export const PUT = async ( |
| 118 | + request: NextRequest, |
| 119 | + { params }: { params: unknown }, |
| 120 | +): Promise<Response> => { |
| 121 | + const input = { |
| 122 | + params: parseRequestInput( |
| 123 | + updateTodoListByIdParamSchema, |
| 124 | + params, |
| 125 | + RequestInputType.RouteParam, |
| 126 | + ), |
| 127 | + // TODO: this swallows repeated parameters |
| 128 | + query: undefined, |
| 129 | + body: parseRequestInput( |
| 130 | + updateTodoListByIdBodySchema, |
| 131 | + await request.json(), |
| 132 | + RequestInputType.RequestBody, |
| 133 | + ), |
| 134 | + } |
| 135 | + |
| 136 | + const responder = { |
| 137 | + with200() { |
| 138 | + return new KoaRuntimeResponse<t_TodoList>(200) |
| 139 | + }, |
| 140 | + withStatusCode4xx(status: StatusCode4xx) { |
| 141 | + return new KoaRuntimeResponse<t_Error>(status) |
| 142 | + }, |
| 143 | + withDefault(status: StatusCode) { |
| 144 | + return new KoaRuntimeResponse<void>(status) |
| 145 | + }, |
| 146 | + withStatus(status: StatusCode) { |
| 147 | + return new KoaRuntimeResponse(status) |
| 148 | + }, |
| 149 | + } |
| 150 | + |
| 151 | + const { status, body } = await import("@/lib/api/list/[listId]/route") |
| 152 | + .then((it) => it.GET(input, responder, { request })) |
| 153 | + .then((it) => it.unpack()) |
| 154 | + .catch((err) => { |
| 155 | + throw KoaRuntimeError.HandlerError(err) |
| 156 | + }) |
| 157 | + |
| 158 | + return Response.json(body, { status }) |
| 159 | +} |
| 160 | + |
| 161 | +const deleteTodoListByIdParamSchema = z.object({ listId: z.string() }) |
| 162 | + |
| 163 | +export const DELETE = async ( |
| 164 | + request: NextRequest, |
| 165 | + { params }: { params: unknown }, |
| 166 | +): Promise<Response> => { |
| 167 | + const input = { |
| 168 | + params: parseRequestInput( |
| 169 | + deleteTodoListByIdParamSchema, |
| 170 | + params, |
| 171 | + RequestInputType.RouteParam, |
| 172 | + ), |
| 173 | + // TODO: this swallows repeated parameters |
| 174 | + query: undefined, |
| 175 | + body: undefined, |
| 176 | + } |
| 177 | + |
| 178 | + const responder = { |
| 179 | + with204() { |
| 180 | + return new KoaRuntimeResponse<void>(204) |
| 181 | + }, |
| 182 | + withStatusCode4xx(status: StatusCode4xx) { |
| 183 | + return new KoaRuntimeResponse<t_Error>(status) |
| 184 | + }, |
| 185 | + withDefault(status: StatusCode) { |
| 186 | + return new KoaRuntimeResponse<void>(status) |
| 187 | + }, |
| 188 | + withStatus(status: StatusCode) { |
| 189 | + return new KoaRuntimeResponse(status) |
| 190 | + }, |
| 191 | + } |
| 192 | + |
| 193 | + const { status, body } = await import("@/lib/api/list/[listId]/route") |
| 194 | + .then((it) => it.GET(input, responder, { request })) |
| 195 | + .then((it) => it.unpack()) |
| 196 | + .catch((err) => { |
| 197 | + throw KoaRuntimeError.HandlerError(err) |
| 198 | + }) |
| 199 | + |
| 200 | + return Response.json(body, { status }) |
| 201 | +} |
0 commit comments