feat(F-048): completed feature
This commit is contained in:
16
project/src/modules/cache/api/cache.routes.ts
vendored
16
project/src/modules/cache/api/cache.routes.ts
vendored
@@ -1,6 +1,8 @@
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import type { FastifySchema } from 'fastify';
|
||||
import type { Authenticate } from '../../../shared/auth.js';
|
||||
import { requireRole } from '../../../shared/auth.js';
|
||||
import { errorSchema } from '../../../shared/swagger.js';
|
||||
import { CacheService } from '../application/cache-service.js';
|
||||
|
||||
export interface CacheRoutesDeps {
|
||||
@@ -12,13 +14,23 @@ export async function registerCacheRoutes(
|
||||
app: FastifyInstance,
|
||||
deps: CacheRoutesDeps,
|
||||
): Promise<void> {
|
||||
app.get('/cache/contracts', async (request, reply) => {
|
||||
const contractsSchema: FastifySchema = {
|
||||
tags: ['Admin'],
|
||||
summary: 'List cache contracts (admin)',
|
||||
response: { 401: errorSchema, 403: errorSchema },
|
||||
};
|
||||
app.get('/cache/contracts', { schema: contractsSchema }, async (request, reply) => {
|
||||
const user = await deps.authenticate(request);
|
||||
requireRole(user, 'admin');
|
||||
return reply.send({ items: deps.cache.listContracts() });
|
||||
});
|
||||
|
||||
app.get('/cache/metrics', async (request, reply) => {
|
||||
const cacheMetricsSchema: FastifySchema = {
|
||||
tags: ['Admin'],
|
||||
summary: 'Cache metrics',
|
||||
response: { 401: errorSchema },
|
||||
};
|
||||
app.get('/cache/metrics', { schema: cacheMetricsSchema }, async (request, reply) => {
|
||||
await deps.authenticate(request);
|
||||
return reply.send(deps.cache.metrics());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user