diff --git a/.codex-tasks/tenant-architecture-epic/PROGRESS.md b/.codex-tasks/tenant-architecture-epic/PROGRESS.md index 706250e..1af33b5 100644 --- a/.codex-tasks/tenant-architecture-epic/PROGRESS.md +++ b/.codex-tasks/tenant-architecture-epic/PROGRESS.md @@ -14,6 +14,7 @@ - `CustomerSessionController` 和 `AdminSessionController` 已迁移到 `modules/session/session.controller.ts`。 - `AdminBookingController` 已迁移到 `modules/admin/admin-booking.controller.ts`。 - `CustomerBookingController` 已迁移到 `modules/customer/customer-booking.controller.ts`。 +- `PublicController`、`PublicTrustContentController`、`PublicTemplateController` 已迁移到 `modules/public/public.controller.ts`。 - 新增 `GET /admin/brands` 和 `POST /admin/brands/:brandId/switch`,切换由 membership 服务端校验。 - seed 已增加第二个独立品牌 `林境门作`(slug:`linjing-doors`),并绑定同一管理员的独立 membership。 - 修复多品牌出现后 `findFirst()` 导致默认品牌串线的问题,默认公开品牌和客户会话现在使用 `DEFAULT_BRAND_ID`。 diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 6a45059..6119543 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -48,6 +48,11 @@ import { import { AdminBookingController } from "./modules/admin/admin-booking.controller.js"; import { CustomerBookingController } from "./modules/customer/customer-booking.controller.js"; import { TenantController } from "./modules/tenant/tenant.controller.js"; +import { + PublicController, + PublicTemplateController, + PublicTrustContentController, +} from "./modules/public/public.controller.js"; import type { RuntimeInquiryField, RuntimeOffering, @@ -63,87 +68,6 @@ export class HealthController { } } -@Controller("public") -export class PublicController { - constructor(private readonly prisma: PrismaService) {} - - @Get("brand") - async brand(): Promise { - return this.prisma.brandProfile.findUnique({ - where: { - id: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001", - }, - select: { - id: true, - name: true, - templateKey: true, - tagline: true, - description: true, - avatarUrl: true, - coverUrl: true, - hours: true, - address: true, - deliveryNote: true, - contactPhone: true, - contactWechat: true, - }, - }); - } -} - -@Controller("public/trust-content") -export class PublicTrustContentController { - constructor(private readonly prisma: PrismaService) {} - @Get() - list(): Promise { - return this.prisma.trustContent.findMany({ - where: { - brandId: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001", - isPublished: true, - }, - orderBy: [{ type: "asc" }, { sortOrder: "asc" }], - }); - } -} - -@Controller("public/templates") -export class PublicTemplateController { - @Get() - list(): unknown { - return { industries: Object.values(brandTemplates), visuals: Object.values(visualTemplates) }; - } - @Get("preview") - preview( - @Query("industry") industry = "personal", - @Query("visual") visual = "linjing-editorial", - ): unknown { - const industryTemplate = getBrandTemplate(industry); - const visualTemplate = getVisualTemplate(visual) ?? getVisualTemplate("linjing-editorial"); - if (!industryTemplate || !visualTemplate) throw new BadRequestException("模板组合不存在"); - return { - industry: industryTemplate, - visual: visualTemplate, - runtime: { - schemaVersion: "1.0.0", - modules: industryTemplate.modules.map((module) => ({ - key: module.key, - type: module.type, - title: module.title, - variant: visualTemplate.variants[module.type] ?? "default", - })), - capabilities: resolveCapabilities(industryTemplate.capabilities), - theme: visualTemplate.theme, - }, - }; - } - @Get(":key") - get(@Param("key") key: string): unknown { - const template = getBrandTemplate(key); - if (!template) throw new BadRequestException("行业模板不存在"); - return template; - } -} - @Controller("public/workspace") export class PublicWorkspaceController { constructor(private readonly prisma: PrismaService) {} diff --git a/apps/api/src/modules/public/public.controller.ts b/apps/api/src/modules/public/public.controller.ts new file mode 100644 index 0000000..704d42b --- /dev/null +++ b/apps/api/src/modules/public/public.controller.ts @@ -0,0 +1,93 @@ +import { BadRequestException, Controller, Get, Param, Query } from "@nestjs/common"; +import { PrismaService } from "../../prisma.service.js"; +import { + brandTemplates, + getBrandTemplate, + getVisualTemplate, + resolveCapabilities, + visualTemplates, +} from "@personal-brand/config"; + +@Controller("public") +export class PublicController { + constructor(private readonly prisma: PrismaService) {} + + @Get("brand") + async brand(): Promise { + return this.prisma.brandProfile.findUnique({ + where: { + id: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001", + }, + select: { + id: true, + name: true, + templateKey: true, + tagline: true, + description: true, + avatarUrl: true, + coverUrl: true, + hours: true, + address: true, + deliveryNote: true, + contactPhone: true, + contactWechat: true, + }, + }); + } +} + +@Controller("public/trust-content") +export class PublicTrustContentController { + constructor(private readonly prisma: PrismaService) {} + + @Get() + list(): Promise { + return this.prisma.trustContent.findMany({ + where: { + brandId: process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001", + isPublished: true, + }, + orderBy: [{ type: "asc" }, { sortOrder: "asc" }], + }); + } +} + +@Controller("public/templates") +export class PublicTemplateController { + @Get() + list(): unknown { + return { industries: Object.values(brandTemplates), visuals: Object.values(visualTemplates) }; + } + + @Get("preview") + preview( + @Query("industry") industry = "personal", + @Query("visual") visual = "linjing-editorial", + ): unknown { + const industryTemplate = getBrandTemplate(industry); + const visualTemplate = getVisualTemplate(visual) ?? getVisualTemplate("linjing-editorial"); + if (!industryTemplate || !visualTemplate) throw new BadRequestException("模板组合不存在"); + return { + industry: industryTemplate, + visual: visualTemplate, + runtime: { + schemaVersion: "1.0.0", + modules: industryTemplate.modules.map((module) => ({ + key: module.key, + type: module.type, + title: module.title, + variant: visualTemplate.variants[module.type] ?? "default", + })), + capabilities: resolveCapabilities(industryTemplate.capabilities), + theme: visualTemplate.theme, + }, + }; + } + + @Get(":key") + get(@Param("key") key: string): unknown { + const template = getBrandTemplate(key); + if (!template) throw new BadRequestException("行业模板不存在"); + return template; + } +}