Created a skeleton of the api
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// import { postRouter } from "~/server/api/routers/post";
|
||||
import { listRouter } from "~/server/api/routers/lists";
|
||||
import { tasksRouter } from "~/server/api/routers/tasks";
|
||||
import { createCallerFactory, createTRPCRouter } from "~/server/api/trpc";
|
||||
|
||||
/**
|
||||
@@ -7,7 +8,8 @@ import { createCallerFactory, createTRPCRouter } from "~/server/api/trpc";
|
||||
* All routers added in /api/routers should be manually added here.
|
||||
*/
|
||||
export const appRouter = createTRPCRouter({
|
||||
// post: postRouter,
|
||||
list: listRouter,
|
||||
tasks: tasksRouter,
|
||||
});
|
||||
|
||||
// export type definition of API
|
||||
|
||||
43
src/server/api/routers/lists.ts
Normal file
43
src/server/api/routers/lists.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { z } from "zod";
|
||||
import {
|
||||
listCreationFormSchema,
|
||||
listNameSchema,
|
||||
} from "~/lib/schemas/list-creation-form";
|
||||
|
||||
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";
|
||||
|
||||
export const listRouter = createTRPCRouter({
|
||||
create: protectedProcedure
|
||||
.input(listCreationFormSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
return [];
|
||||
}),
|
||||
getAll: protectedProcedure.query(async ({ ctx }) => {
|
||||
return [
|
||||
{ id: 0, name: "Groceries" },
|
||||
{ id: 1, name: "Christmas" },
|
||||
{ id: 2, name: "Salt Seeker" },
|
||||
{ id: 3, name: "Maize Walker" },
|
||||
{ id: 4, name: "Sympathy for the Machine" },
|
||||
{
|
||||
id: 4,
|
||||
name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor elit incididunt ut labore et dolore magna aliqua.",
|
||||
},
|
||||
];
|
||||
}),
|
||||
get: protectedProcedure
|
||||
.input(z.object({ listId: z.number() }))
|
||||
.query(async ({ ctx, input }) => {
|
||||
return { name: "Groceries", data: [] };
|
||||
}),
|
||||
update: protectedProcedure
|
||||
.input(z.object({ listId: z.number(), name: listNameSchema }))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
return [];
|
||||
}),
|
||||
delete: protectedProcedure
|
||||
.input(z.object({ listId: z.number() }))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
return [];
|
||||
}),
|
||||
});
|
||||
@@ -1,39 +0,0 @@
|
||||
// import { z } from "zod";
|
||||
|
||||
// import {
|
||||
// createTRPCRouter,
|
||||
// protectedProcedure,
|
||||
// publicProcedure,
|
||||
// } from "~/server/api/trpc";
|
||||
// import { posts } from "~/server/db/schema";
|
||||
|
||||
// export const postRouter = createTRPCRouter({
|
||||
// hello: publicProcedure
|
||||
// .input(z.object({ text: z.string() }))
|
||||
// .query(({ input }) => {
|
||||
// return {
|
||||
// greeting: `Hello ${input.text}`,
|
||||
// };
|
||||
// }),
|
||||
|
||||
// create: protectedProcedure
|
||||
// .input(z.object({ name: z.string().min(1) }))
|
||||
// .mutation(async ({ ctx, input }) => {
|
||||
// await ctx.db.insert(posts).values({
|
||||
// name: input.name,
|
||||
// createdById: ctx.session.user.id,
|
||||
// });
|
||||
// }),
|
||||
|
||||
// getLatest: protectedProcedure.query(async ({ ctx }) => {
|
||||
// const post = await ctx.db.query.posts.findFirst({
|
||||
// orderBy: (posts, { desc }) => [desc(posts.createdAt)],
|
||||
// });
|
||||
|
||||
// return post ?? null;
|
||||
// }),
|
||||
|
||||
// getSecretMessage: protectedProcedure.query(() => {
|
||||
// return "you can now see this secret message!";
|
||||
// }),
|
||||
// });
|
||||
12
src/server/api/routers/tasks.ts
Normal file
12
src/server/api/routers/tasks.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { z } from "zod";
|
||||
import { taskCreationFormSchema } from "~/lib/schemas/task-creation-form";
|
||||
|
||||
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";
|
||||
|
||||
export const tasksRouter = createTRPCRouter({
|
||||
create: protectedProcedure
|
||||
.input(taskCreationFormSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
//
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user