feat(api): add changelog public route
This commit is contained in:
parent
00ad96816f
commit
514a2d2003
54
apps/api/src/changelog/public/byId.ts
Normal file
54
apps/api/src/changelog/public/byId.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import { changelog, db } from '@boring.tools/database'
|
||||||
|
import { ChangelogByIdParams, ChangelogOutput } from '@boring.tools/schema'
|
||||||
|
import { createRoute } from '@hono/zod-openapi'
|
||||||
|
import { and, eq } from 'drizzle-orm'
|
||||||
|
import { HTTPException } from 'hono/http-exception'
|
||||||
|
|
||||||
|
export const route = createRoute({
|
||||||
|
method: 'get',
|
||||||
|
path: '/:id',
|
||||||
|
request: {
|
||||||
|
params: ChangelogByIdParams,
|
||||||
|
},
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
content: {
|
||||||
|
'application/json': {
|
||||||
|
schema: ChangelogOutput,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'Return changelog by id',
|
||||||
|
},
|
||||||
|
400: {
|
||||||
|
description: 'Bad Request',
|
||||||
|
},
|
||||||
|
500: {
|
||||||
|
description: 'Internal Server Error',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export const func = async ({ id }: { id: string }) => {
|
||||||
|
const result = await db.query.changelog.findFirst({
|
||||||
|
where: and(eq(changelog.id, id)),
|
||||||
|
with: {
|
||||||
|
versions: {
|
||||||
|
orderBy: (changelog_version, { desc }) => [
|
||||||
|
desc(changelog_version.createdAt),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
throw new HTTPException(404, { message: 'Not found' })
|
||||||
|
}
|
||||||
|
|
||||||
|
const { userId, createdAt, ...rest } = result
|
||||||
|
return rest
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
route,
|
||||||
|
func,
|
||||||
|
}
|
27
apps/api/src/changelog/public/index.ts
Normal file
27
apps/api/src/changelog/public/index.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { OpenAPIHono } from '@hono/zod-openapi'
|
||||||
|
import type { Variables } from '../..'
|
||||||
|
import { type ContextModule, captureSentry } from '../../utils/sentry'
|
||||||
|
import ById from './byId'
|
||||||
|
|
||||||
|
const app = new OpenAPIHono<{ Variables: Variables }>()
|
||||||
|
|
||||||
|
const module: ContextModule = {
|
||||||
|
name: 'changelog',
|
||||||
|
sub_module: 'public',
|
||||||
|
}
|
||||||
|
|
||||||
|
app.openapi(ById.route, async (c) => {
|
||||||
|
try {
|
||||||
|
const id = c.req.param('id')
|
||||||
|
const result = await ById.func({ id })
|
||||||
|
return c.json(result, 200)
|
||||||
|
} catch (error) {
|
||||||
|
return captureSentry({
|
||||||
|
c,
|
||||||
|
error,
|
||||||
|
module,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default app
|
@ -5,6 +5,7 @@ import { apiReference } from '@scalar/hono-api-reference'
|
|||||||
import { cors } from 'hono/cors'
|
import { cors } from 'hono/cors'
|
||||||
|
|
||||||
import changelog from './changelog'
|
import changelog from './changelog'
|
||||||
|
import changelogPublic from './changelog/public'
|
||||||
import version from './changelog/version'
|
import version from './changelog/version'
|
||||||
import user from './user'
|
import user from './user'
|
||||||
|
|
||||||
@ -32,6 +33,8 @@ app.route('/v1/user', user)
|
|||||||
app.route('/v1/changelog', changelog)
|
app.route('/v1/changelog', changelog)
|
||||||
app.route('/v1/changelog/version', version)
|
app.route('/v1/changelog/version', version)
|
||||||
|
|
||||||
|
app.route('/v1/changelog/public', changelogPublic)
|
||||||
|
|
||||||
app.doc('/openapi.json', {
|
app.doc('/openapi.json', {
|
||||||
openapi: '3.0.0',
|
openapi: '3.0.0',
|
||||||
info: {
|
info: {
|
||||||
|
Loading…
Reference in New Issue
Block a user