starry / backend /omr-service /src /routes /solutionCache.ts
k-l-lambda's picture
Initial deployment: frontend + omr-service + cluster-server + nginx proxy
6f1c297
import { FastifyInstance } from 'fastify';
import * as solutionCacheService from '../services/solutionCache.service.js';
interface BatchGetBody {
nameList: string[];
}
interface SetBody {
name: string;
value: any;
}
interface DeleteBody {
name: string;
}
export default async function solutionCacheRoutes(fastify: FastifyInstance) {
// Batch get solutions by hash keys
fastify.post<{ Body: BatchGetBody }>('/solutions/batchGet', async (request, reply) => {
const { nameList } = request.body || {};
if (!Array.isArray(nameList)) {
reply.code(400);
return { code: 400, message: 'nameList must be an array' };
}
const data = await solutionCacheService.batchGet(nameList);
return { code: 0, data };
});
// Set a solution
fastify.post<{ Body: SetBody }>('/solutions/set', async (request, reply) => {
const { name, value } = request.body || {};
if (!name || typeof name !== 'string') {
reply.code(400);
return { code: 400, message: 'name is required' };
}
await solutionCacheService.set(name, value);
return { code: 0, data: { success: true } };
});
// Delete a solution
fastify.post<{ Body: DeleteBody }>('/solutions/delete', async (request) => {
const { name } = request.body || {};
if (!name) {
return { code: 400, message: 'name is required' };
}
await solutionCacheService.remove(name);
return { code: 0, data: { success: true } };
});
}