- 修复路由配置,实现根路径自动重定向到/project - 新增Gitea OAuth认证系统和相关组件 - 完善日志系统实现,包含pino日志工具和中间件 - 重构页面结构,分离项目管理和环境管理页面 - 新增CORS、Session等关键中间件 - 优化前端请求封装和类型定义 - 修复TypeScript类型错误和参数传递问题
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import type { Context } from 'koa';
|
|
import prisma from '../libs/db.ts';
|
|
import { log } from '../libs/logger.ts';
|
|
import { BusinessError } from '../middlewares/exception.ts';
|
|
import { Controller, Get } from '../decorators/route.ts';
|
|
|
|
@Controller('/application')
|
|
export class ApplicationController {
|
|
@Get('/list')
|
|
async list(ctx: Context) {
|
|
log.debug('app', 'session %o', ctx.session);
|
|
try {
|
|
const list = await prisma.application.findMany({
|
|
where: {
|
|
valid: 1,
|
|
},
|
|
});
|
|
|
|
// 直接返回数据,由路由中间件统一包装成响应格式
|
|
return list;
|
|
} catch (error) {
|
|
// 抛出业务异常,由全局异常处理中间件捕获
|
|
throw new BusinessError('获取应用列表失败', 1001, 500);
|
|
}
|
|
}
|
|
|
|
@Get('/detail/:id')
|
|
async detail(ctx: Context) {
|
|
const { id } = ctx.params;
|
|
const app = await prisma.application.findUnique({
|
|
where: { id: Number(id) },
|
|
});
|
|
|
|
if (!app) {
|
|
throw new BusinessError('应用不存在', 1002, 404);
|
|
}
|
|
|
|
return app;
|
|
}
|
|
}
|