feat(backend): 实现公开短链路由与秒级微官网详情 API (Task 08)

这个提交包含在:
wikiboss
2026-09-20 17:30:44 +08:00
父节点 2c3906b634
当前提交 7e0d9ee11b
共有 12 个文件被更改,包括 1935 次插入 和 1 次删除

查看文件

@@ -0,0 +1,68 @@
import { Inject, Provide, Get, Query, Param } from '@midwayjs/core';
import {
CoolController,
BaseController,
CoolTag,
TagTypes,
} from '@cool-midway/core';
import { CardPortalService } from '../../service/portal';
/**
* 访客端公开微官网与短链路由控制器 (免登录触达)
* 路由前缀: /open/card/portal
*/
@Provide()
@CoolController()
export class OpenCardPortalController extends BaseController {
@Inject()
cardPortalService: CardPortalService;
/**
* 获取公开名片微官网详情 (Query 方式)
* 接口地址: GET /open/card/portal/detail?id=123 或 ?slug=alex-zheng
*/
@CoolTag(TagTypes.IGNORE_TOKEN)
@Get('/detail', { summary: '公开微官网详情 (Query)' })
async detail(
@Query('id') id?: string | number,
@Query('slug') slug?: string,
@Query('slugOrId') slugOrId?: string
) {
const target = slug || id || slugOrId;
if (!target) {
return this.fail('缺少名片标识参数~', 1001);
}
try {
const data = await this.cardPortalService.getPortalDetail(target);
return this.ok(data);
} catch (err: any) {
return this.fail(
err?.message || '获取名片微官网失败',
err?.status || 1001
);
}
}
/**
* 根据自定义短链或 ID 获取微官网详情 (Path 参数方式)
* 接口地址: GET /open/card/portal/:slugOrId (如 /open/card/portal/alex-zheng)
*/
@CoolTag(TagTypes.IGNORE_TOKEN)
@Get('/:slugOrId', { summary: '公开微官网详情 (Path 短链/ID)' })
async getBySlugOrId(@Param('slugOrId') slugOrId: string) {
if (!slugOrId || slugOrId === 'detail') {
return this.fail('缺少名片标识参数~', 1001);
}
try {
const data = await this.cardPortalService.getPortalDetail(slugOrId);
return this.ok(data);
} catch (err: any) {
return this.fail(
err?.message || '获取名片微官网失败',
err?.status || 1001
);
}
}
}