feat(navigation): add controller + tRPC router + header global + barrel

This commit is contained in:
2026-05-05 08:34:37 +02:00
parent 19f32ec94d
commit 014dbc81ec
7 changed files with 78 additions and 1 deletions

View File

@@ -1 +1,2 @@
export {};
export type { Header, HeaderItem } from "./entities/header";
export { headerQuery } from "./ui/query";

View File

@@ -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<IHeaderRepository>(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);
});
});

View File

@@ -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;

View File

@@ -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 },
],
},
],
};

View File

@@ -0,0 +1 @@
export { header } from "./globals/header";

View File

@@ -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<Header> {
return getHeaderUseCase();
}

View File

@@ -0,0 +1,9 @@
type TrpcClient = {
navigation: {
header: { queryOptions: () => unknown };
};
};
export function headerQuery(client: TrpcClient) {
return client.navigation.header.queryOptions();
}