-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
request form seeding & view all route
- Loading branch information
Showing
6 changed files
with
142 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createRoute } from "@hono/zod-openapi" | ||
import { viewAllRequestsResponseSchema, viewAllRequestsSchema } from "./schema" | ||
import { GenericResponses } from "@/v2/lib/response-schemas" | ||
|
||
export const getAllRequestsRoute = createRoute({ | ||
path: "/", | ||
method: "get", | ||
description: | ||
"Get all requests. This will also return all associated upvotes count.", | ||
tags: ["Requests"], | ||
request: { | ||
query: viewAllRequestsSchema, | ||
}, | ||
responses: { | ||
200: { | ||
description: "List of all submitted requests.", | ||
content: { | ||
"application/json": { | ||
schema: viewAllRequestsResponseSchema, | ||
}, | ||
}, | ||
}, | ||
...GenericResponses, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { OpenAPIHono } from "@hono/zod-openapi" | ||
import { getAllRequestsRoute } from "./openapi" | ||
import { RequestFormManager } from "@/v2/lib/managers/request-form/request-form-manager" | ||
import { getConnection } from "@/v2/db/turso" | ||
|
||
const handler = new OpenAPIHono<{ Bindings: Bindings; Variables: Variables }>() | ||
|
||
handler.openapi(getAllRequestsRoute, async (ctx) => { | ||
const { offset } = ctx.req.valid("query") ?? { offset: "0" } | ||
|
||
const { drizzle } = await getConnection(ctx.env) | ||
|
||
const requestFormManager = new RequestFormManager(drizzle) | ||
|
||
const allRequests = await requestFormManager.getRequestFormEntries( | ||
parseInt(offset) | ||
) | ||
|
||
return ctx.json( | ||
{ | ||
success: true, | ||
requests: allRequests, | ||
}, | ||
200 | ||
) | ||
}) | ||
|
||
export default handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { z } from "@hono/zod-openapi" | ||
import { selectRequestFormSchema } from "@/v2/db/schema" | ||
|
||
export const viewAllRequestsSchema = z | ||
.object({ | ||
offset: z.string().openapi({ | ||
param: { | ||
description: | ||
"The offset of requests to return. This is used for pagination.", | ||
name: "offset", | ||
example: "0", | ||
in: "query", | ||
required: false, | ||
}, | ||
}), | ||
}) | ||
.partial() | ||
|
||
const requestFormSchema = z.object({ | ||
...selectRequestFormSchema.shape, | ||
upvotesCount: z.number().optional(), | ||
}) | ||
|
||
export const viewAllRequestsResponseSchema = z.object({ | ||
success: z.literal(true), | ||
requests: z.array(requestFormSchema), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { OpenAPIHono } from "@hono/zod-openapi" | ||
import RequestFormCreateRoute from "@/v2/routes/requests/form/create/route" | ||
import RequestFormDeleteRoute from "@/v2/routes/requests/form/delete/[id]/route" | ||
import ViewAllRequestsRoute from "@/v2/routes/requests/form/view/all/route" | ||
|
||
const handler = new OpenAPIHono<{ Bindings: Bindings; Variables: Variables }>() | ||
|
||
handler.route("/create/form", RequestFormCreateRoute) | ||
handler.route("/delete/form", RequestFormDeleteRoute) | ||
handler.route("/view/all", ViewAllRequestsRoute) | ||
|
||
export default handler |