forked from yoone/API
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { Controller, Inject, Param, Post, Get, Query } from '@midwayjs/core';
|
|
import { ApiOkResponse } from '@midwayjs/swagger';
|
|
import { SubscriptionService } from '../service/subscription.service';
|
|
import { errorResponse, successResponse } from '../utils/response.util';
|
|
import { BooleanRes, SubscriptionListRes } from '../dto/reponse.dto';
|
|
import { QuerySubscriptionDTO } from '../dto/subscription.dto';
|
|
|
|
@Controller('/subscription')
|
|
export class SubscriptionController {
|
|
@Inject()
|
|
subscriptionService: SubscriptionService;
|
|
|
|
// 同步订阅:根据站点 ID 拉取并更新本地订阅数据
|
|
@ApiOkResponse({ type: BooleanRes })
|
|
@Post('/sync/:siteId')
|
|
async sync(@Param('siteId') siteId: number) {
|
|
try {
|
|
const result = await this.subscriptionService.syncSubscriptions(siteId);
|
|
return successResponse(result);
|
|
} catch (error) {
|
|
return errorResponse(error?.message || '同步失败');
|
|
}
|
|
}
|
|
|
|
// 订阅列表:分页 + 筛选
|
|
@ApiOkResponse({ type: SubscriptionListRes })
|
|
@Get('/list')
|
|
async list(@Query() query: QuerySubscriptionDTO) {
|
|
try {
|
|
const data = await this.subscriptionService.getSubscriptionList(query);
|
|
return successResponse(data);
|
|
} catch (error) {
|
|
return errorResponse(error?.message || '获取失败');
|
|
}
|
|
}
|
|
} |