feat(api): add tRPC routers (auth + content) calling core controllers
This commit is contained in:
@@ -10,8 +10,14 @@
|
||||
"lint": "eslint .",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@repo/core": "workspace:*",
|
||||
"@trpc/server": "^11.1.0",
|
||||
"zod": "^3.24.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@repo/eslint-config": "workspace:*",
|
||||
"@repo/typescript-config": "workspace:*"
|
||||
"@repo/typescript-config": "workspace:*",
|
||||
"@types/node": "^22.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
// @repo/api — tRPC router definitions
|
||||
export {};
|
||||
export { appRouter, type AppRouter } from "./router/index.js";
|
||||
|
||||
38
packages/api/src/router/auth.router.ts
Normal file
38
packages/api/src/router/auth.router.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { z } from "zod";
|
||||
import { router, publicProcedure } from "../trpc.js";
|
||||
import {
|
||||
signInController,
|
||||
signUpController,
|
||||
signOutController,
|
||||
} from "@repo/core";
|
||||
|
||||
export const authRouter = router({
|
||||
signIn: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
username: z.string().min(3).max(31),
|
||||
password: z.string().min(6).max(255),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
return await signInController(input);
|
||||
}),
|
||||
|
||||
signUp: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
username: z.string().min(3).max(31),
|
||||
password: z.string().min(6).max(255),
|
||||
confirmPassword: z.string().min(6).max(255),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
return await signUpController(input);
|
||||
}),
|
||||
|
||||
signOut: publicProcedure
|
||||
.input(z.object({ sessionId: z.string() }))
|
||||
.mutation(async ({ input }) => {
|
||||
return await signOutController(input.sessionId);
|
||||
}),
|
||||
});
|
||||
33
packages/api/src/router/content.router.ts
Normal file
33
packages/api/src/router/content.router.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { z } from "zod";
|
||||
import { router, publicProcedure } from "../trpc.js";
|
||||
import { createArticleController, getArticlesController } from "@repo/core";
|
||||
|
||||
export const contentRouter = router({
|
||||
listArticles: publicProcedure
|
||||
.input(
|
||||
z
|
||||
.object({
|
||||
status: z.string().optional(),
|
||||
authorId: z.string().optional(),
|
||||
limit: z.number().optional(),
|
||||
offset: z.number().optional(),
|
||||
})
|
||||
.optional()
|
||||
)
|
||||
.query(async ({ input }) => {
|
||||
return await getArticlesController(input ?? {});
|
||||
}),
|
||||
|
||||
createArticle: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
title: z.string().min(1).max(255),
|
||||
content: z.string(),
|
||||
authorId: z.string(),
|
||||
slug: z.string().optional(),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
return await createArticleController(input);
|
||||
}),
|
||||
});
|
||||
10
packages/api/src/router/index.ts
Normal file
10
packages/api/src/router/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { router } from "../trpc.js";
|
||||
import { authRouter } from "./auth.router.js";
|
||||
import { contentRouter } from "./content.router.js";
|
||||
|
||||
export const appRouter = router({
|
||||
auth: authRouter,
|
||||
content: contentRouter,
|
||||
});
|
||||
|
||||
export type AppRouter = typeof appRouter;
|
||||
6
packages/api/src/trpc.ts
Normal file
6
packages/api/src/trpc.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { initTRPC } from "@trpc/server";
|
||||
|
||||
const t = initTRPC.create();
|
||||
|
||||
export const router = t.router;
|
||||
export const publicProcedure = t.procedure;
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "@repo/typescript-config/base.json",
|
||||
"compilerOptions": {
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
|
||||
Reference in New Issue
Block a user