import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from '@nestjs/common'; import { ApiTags, ApiBearerAuth, ApiOperation, ApiBody, ApiQuery } from '@nestjs/swagger'; import { NotificationsService } from './notifications.service'; @ApiTags('admin-notifications') @ApiBearerAuth() @Controller('admin-api/notifications') export class AdminNotificationsController { constructor(private readonly service: NotificationsService) {} // ═══ Templates ═══ @Get('templates') @ApiOperation({ summary: '通知模板列表' }) async getTemplates() { return this.service.getTemplates(); } @Post('templates') @ApiOperation({ summary: '创建通知模板' }) @ApiBody({ schema: { type: 'object', required: ['name', 'type', 'title', 'content'], properties: { name: { type: 'string' }, type: { type: 'string' }, title: { type: 'string' }, content: { type: 'string' }, channel: { type: 'string', enum: ['in_app', 'push', 'email'] }, } } }) async createTemplate(@Body() dto: { name: string; type: string; title: string; content: string; channel?: string }) { return this.service.createTemplate(dto); } @Patch('templates/:id') @ApiOperation({ summary: '更新通知模板' }) async updateTemplate(@Param('id') id: string, @Body() dto: Record) { return this.service.updateTemplate(id, dto); } @Delete('templates/:id') @ApiOperation({ summary: '删除通知模板' }) async deleteTemplate(@Param('id') id: string) { return this.service.deleteTemplate(id); } // ═══ Send Log ═══ @Get('send-log') @ApiOperation({ summary: '通知发送日志' }) @ApiQuery({ name: 'limit', required: false }) async getSendLog(@Query('limit') limit?: string) { return this.service.getSendLogs(Number(limit) || 100); } }