diff --git a/packages/navigation/src/index.ts b/packages/navigation/src/index.ts index cb0ff5c..fb22ea6 100644 --- a/packages/navigation/src/index.ts +++ b/packages/navigation/src/index.ts @@ -1 +1,2 @@ -export {}; +export type { Header, HeaderItem } from "./entities/header"; +export { headerQuery } from "./ui/query"; diff --git a/packages/navigation/src/integrations/api/router.test.ts b/packages/navigation/src/integrations/api/router.test.ts new file mode 100644 index 0000000..6bc132b --- /dev/null +++ b/packages/navigation/src/integrations/api/router.test.ts @@ -0,0 +1,28 @@ +import { beforeEach, describe, expect, it } from "vitest"; +import { navigationContainer } from "@/di/container"; +import { NAVIGATION_SYMBOLS } from "@/di/symbols"; +import { MockHeaderRepository } from "@/infrastructure/repositories/mock-header.repository"; +import type { IHeaderRepository } from "@/application/repositories/header-repository.interface"; +import { navigationRouter } from "./router"; + +describe("navigationRouter", () => { + beforeEach(() => { + if (navigationContainer.isBound(NAVIGATION_SYMBOLS.IHeaderRepository)) { + navigationContainer.unbind(NAVIGATION_SYMBOLS.IHeaderRepository); + } + navigationContainer + .bind(NAVIGATION_SYMBOLS.IHeaderRepository) + .toConstantValue(new MockHeaderRepository()); + }); + + it("exposes header procedure", () => { + const names = Object.keys(navigationRouter._def.procedures); + expect(names).toContain("header"); + }); + + it("header returns 3 items", async () => { + const caller = navigationRouter.createCaller({}); + const result = await caller.header(); + expect(result.items).toHaveLength(3); + }); +}); diff --git a/packages/navigation/src/integrations/api/router.ts b/packages/navigation/src/integrations/api/router.ts new file mode 100644 index 0000000..42d9856 --- /dev/null +++ b/packages/navigation/src/integrations/api/router.ts @@ -0,0 +1,8 @@ +import { router, publicProcedure } from "@repo/core-shared/trpc/init"; +import { getHeaderController } from "../../interface-adapters/controllers/header.controller"; + +export const navigationRouter = router({ + header: publicProcedure.query(() => getHeaderController()), +}); + +export type NavigationRouter = typeof navigationRouter; diff --git a/packages/navigation/src/integrations/cms/globals/header.ts b/packages/navigation/src/integrations/cms/globals/header.ts new file mode 100644 index 0000000..ca89b7f --- /dev/null +++ b/packages/navigation/src/integrations/cms/globals/header.ts @@ -0,0 +1,24 @@ +import type { GlobalConfig } from "payload"; + +export const header: GlobalConfig = { + slug: "header", + admin: { + group: "Navigation", + }, + fields: [ + { + name: "logo", + type: "upload", + relationTo: "media", + }, + { + name: "items", + type: "array", + fields: [ + { name: "label", type: "text", required: true }, + { name: "href", type: "text", required: true }, + { name: "external", type: "checkbox", defaultValue: false }, + ], + }, + ], +}; diff --git a/packages/navigation/src/integrations/cms/index.ts b/packages/navigation/src/integrations/cms/index.ts new file mode 100644 index 0000000..424bc41 --- /dev/null +++ b/packages/navigation/src/integrations/cms/index.ts @@ -0,0 +1 @@ +export { header } from "./globals/header"; diff --git a/packages/navigation/src/interface-adapters/controllers/header.controller.ts b/packages/navigation/src/interface-adapters/controllers/header.controller.ts new file mode 100644 index 0000000..703e34e --- /dev/null +++ b/packages/navigation/src/interface-adapters/controllers/header.controller.ts @@ -0,0 +1,6 @@ +import type { Header } from "../../entities/header"; +import { getHeaderUseCase } from "../../application/use-cases/get-header.use-case"; + +export async function getHeaderController(): Promise
{ + return getHeaderUseCase(); +} diff --git a/packages/navigation/src/ui/query.ts b/packages/navigation/src/ui/query.ts new file mode 100644 index 0000000..579d70c --- /dev/null +++ b/packages/navigation/src/ui/query.ts @@ -0,0 +1,9 @@ +type TrpcClient = { + navigation: { + header: { queryOptions: () => unknown }; + }; +}; + +export function headerQuery(client: TrpcClient) { + return client.navigation.header.queryOptions(); +}