feat: 支持 push
This commit is contained in:
104
src/push-notifications/push-template.controller.ts
Normal file
104
src/push-notifications/push-template.controller.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { Controller, Get, Post, Put, Delete, Body, Param, Query, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiResponse, ApiParam, ApiQuery } from '@nestjs/swagger';
|
||||
import { PushTemplateService } from './push-template.service';
|
||||
import { CreatePushTemplateDto } from './dto/create-push-template.dto';
|
||||
import { UpdatePushTemplateDto } from './dto/update-push-template.dto';
|
||||
import { PushTemplate } from './models/push-template.model';
|
||||
import { CurrentUser } from '../common/decorators/current-user.decorator';
|
||||
import { AccessTokenPayload } from '../users/services/apple-auth.service';
|
||||
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
|
||||
|
||||
@ApiTags('推送模板')
|
||||
@Controller('push-notifications/templates')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
export class PushTemplateController {
|
||||
constructor(private readonly pushTemplateService: PushTemplateService) { }
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: '获取所有推送模板' })
|
||||
@ApiResponse({ status: 200, description: '获取成功', type: [PushTemplate] })
|
||||
async getAllTemplates(): Promise<PushTemplate[]> {
|
||||
return this.pushTemplateService.getAllTemplates();
|
||||
}
|
||||
|
||||
@Get('active')
|
||||
@ApiOperation({ summary: '获取所有活跃推送模板' })
|
||||
@ApiResponse({ status: 200, description: '获取成功', type: [PushTemplate] })
|
||||
async getActiveTemplates(): Promise<PushTemplate[]> {
|
||||
return this.pushTemplateService.getActiveTemplates();
|
||||
}
|
||||
|
||||
@Get(':templateKey')
|
||||
@ApiOperation({ summary: '获取推送模板' })
|
||||
@ApiParam({ name: 'templateKey', description: '模板键' })
|
||||
@ApiResponse({ status: 200, description: '获取成功', type: PushTemplate })
|
||||
async getTemplate(@Param('templateKey') templateKey: string): Promise<PushTemplate> {
|
||||
return this.pushTemplateService.getTemplate(templateKey);
|
||||
}
|
||||
|
||||
@Get('id/:id')
|
||||
@ApiOperation({ summary: '根据ID获取推送模板' })
|
||||
@ApiParam({ name: 'id', description: '模板ID' })
|
||||
@ApiResponse({ status: 200, description: '获取成功', type: PushTemplate })
|
||||
async getTemplateById(@Param('id') id: string): Promise<PushTemplate> {
|
||||
return this.pushTemplateService.getTemplateById(id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: '创建推送模板' })
|
||||
@ApiResponse({ status: 201, description: '创建成功', type: PushTemplate })
|
||||
async createTemplate(
|
||||
@Body() createTemplateDto: CreatePushTemplateDto,
|
||||
): Promise<PushTemplate> {
|
||||
return this.pushTemplateService.createTemplate(createTemplateDto);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@ApiOperation({ summary: '更新推送模板' })
|
||||
@ApiParam({ name: 'id', description: '模板ID' })
|
||||
@ApiResponse({ status: 200, description: '更新成功', type: PushTemplate })
|
||||
async updateTemplate(
|
||||
@Param('id') id: string,
|
||||
@Body() updateTemplateDto: UpdatePushTemplateDto,
|
||||
): Promise<PushTemplate> {
|
||||
return this.pushTemplateService.updateTemplate(id, updateTemplateDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: '删除推送模板' })
|
||||
@ApiParam({ name: 'id', description: '模板ID' })
|
||||
@ApiResponse({ status: 200, description: '删除成功' })
|
||||
async deleteTemplate(@Param('id') id: string): Promise<void> {
|
||||
return this.pushTemplateService.deleteTemplate(id);
|
||||
}
|
||||
|
||||
@Put(':id/toggle')
|
||||
@ApiOperation({ summary: '激活/停用模板' })
|
||||
@ApiParam({ name: 'id', description: '模板ID' })
|
||||
@ApiResponse({ status: 200, description: '操作成功', type: PushTemplate })
|
||||
async toggleTemplateStatus(
|
||||
@Param('id') id: string,
|
||||
@Body() body: { isActive: boolean },
|
||||
): Promise<PushTemplate> {
|
||||
return this.pushTemplateService.toggleTemplateStatus(id, body.isActive);
|
||||
}
|
||||
|
||||
@Post('validate')
|
||||
@ApiOperation({ summary: '验证模板变量' })
|
||||
@ApiResponse({ status: 200, description: '验证成功' })
|
||||
async validateTemplateVariables(
|
||||
@Body() body: { template: string; requiredVariables: string[] },
|
||||
): Promise<{ isValid: boolean; missingVariables: string[] }> {
|
||||
return this.pushTemplateService.validateTemplateVariables(body.template, body.requiredVariables);
|
||||
}
|
||||
|
||||
@Post('extract-variables')
|
||||
@ApiOperation({ summary: '提取模板变量' })
|
||||
@ApiResponse({ status: 200, description: '提取成功' })
|
||||
async extractTemplateVariables(
|
||||
@Body() body: { template: string },
|
||||
): Promise<{ variables: string[] }> {
|
||||
const variables = this.pushTemplateService.extractTemplateVariables(body.template);
|
||||
return { variables };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user