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/*"]
|
||||
|
||||
23
pnpm-lock.yaml
generated
23
pnpm-lock.yaml
generated
@@ -107,6 +107,16 @@ importers:
|
||||
version: link:../../packages/typescript-config
|
||||
|
||||
packages/api:
|
||||
dependencies:
|
||||
'@repo/core':
|
||||
specifier: workspace:*
|
||||
version: link:../core
|
||||
'@trpc/server':
|
||||
specifier: ^11.1.0
|
||||
version: 11.16.0(typescript@5.9.3)
|
||||
zod:
|
||||
specifier: ^3.24.0
|
||||
version: 3.25.76
|
||||
devDependencies:
|
||||
'@repo/eslint-config':
|
||||
specifier: workspace:*
|
||||
@@ -114,6 +124,9 @@ importers:
|
||||
'@repo/typescript-config':
|
||||
specifier: workspace:*
|
||||
version: link:../typescript-config
|
||||
'@types/node':
|
||||
specifier: ^22.0.0
|
||||
version: 22.19.17
|
||||
|
||||
packages/api-client:
|
||||
devDependencies:
|
||||
@@ -1546,6 +1559,12 @@ packages:
|
||||
'@tokenizer/token@0.3.0':
|
||||
resolution: {integrity: sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A==}
|
||||
|
||||
'@trpc/server@11.16.0':
|
||||
resolution: {integrity: sha512-XgGuUMddrUTd04+za/WE5GFuZ1/YU9XQG0t3VL5WOIu2JspkOlq6k4RYEiqS6HSJt+S0RXaPdIoE2anIP/BBRQ==}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
typescript: '>=5.7.2'
|
||||
|
||||
'@turbo/darwin-64@2.9.4':
|
||||
resolution: {integrity: sha512-ZSlPqJ5Vqg/wgVw8P3AOVCIosnbBilOxLq7TMz3MN/9U46DUYfdG2jtfevNDufyxyrg98pcPs/GBgDRaaids6g==}
|
||||
cpu: [x64]
|
||||
@@ -4682,6 +4701,10 @@ snapshots:
|
||||
|
||||
'@tokenizer/token@0.3.0': {}
|
||||
|
||||
'@trpc/server@11.16.0(typescript@5.9.3)':
|
||||
dependencies:
|
||||
typescript: 5.9.3
|
||||
|
||||
'@turbo/darwin-64@2.9.4':
|
||||
optional: true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user