Created a skeleton of the api
This commit is contained in:
10
src/lib/data/list-variants.ts
Normal file
10
src/lib/data/list-variants.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export const VARIANT = {
|
||||
standard: "Standard",
|
||||
checklist: "Checklist",
|
||||
project: "Project",
|
||||
} as const;
|
||||
|
||||
export const VARIANTS = Object.values(VARIANT) as unknown as readonly [
|
||||
string,
|
||||
...string[],
|
||||
];
|
||||
13
src/lib/data/task-labels.ts
Normal file
13
src/lib/data/task-labels.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export const LABEL = {
|
||||
feature: "Feature",
|
||||
bug: "Bug",
|
||||
docs: "Docs",
|
||||
chore: "Chore",
|
||||
refactor: "Refactor",
|
||||
build: "Build",
|
||||
} as const;
|
||||
|
||||
export const LABELS = Object.values(LABEL) as unknown as readonly [
|
||||
string,
|
||||
...string[],
|
||||
];
|
||||
10
src/lib/data/task-priority.ts
Normal file
10
src/lib/data/task-priority.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export const PRIORITY = {
|
||||
high: "High",
|
||||
medium: "Medium",
|
||||
low: "Low",
|
||||
} as const;
|
||||
|
||||
export const PRIORITIES = Object.values(PRIORITY) as unknown as readonly [
|
||||
string,
|
||||
...string[],
|
||||
];
|
||||
12
src/lib/data/task-status.ts
Normal file
12
src/lib/data/task-status.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export const STATUS = {
|
||||
backlog: "Backlog",
|
||||
todo: "Todo",
|
||||
inProgress: "In Progress",
|
||||
done: "Done",
|
||||
canceled: "Canceled",
|
||||
} as const;
|
||||
|
||||
export const STATUSES = Object.values(STATUS) as unknown as readonly [
|
||||
string,
|
||||
...string[],
|
||||
];
|
||||
13
src/lib/schemas/list-creation-form.ts
Normal file
13
src/lib/schemas/list-creation-form.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { z } from "zod";
|
||||
import { LABELS } from "~/lib/data/task-labels";
|
||||
import { VARIANTS } from "~/lib/data/list-variants";
|
||||
|
||||
export const listNameSchema = z.string().max(128);
|
||||
|
||||
export const listCreationFormSchema = z.object({
|
||||
name: listNameSchema, // Text
|
||||
variant: z.union([z.enum(VARIANTS).optional(), z.literal("")]), // Radio group
|
||||
labels: z.array(z.enum(LABELS)), // Checkbox group
|
||||
id: z.boolean(), // Checkbox
|
||||
idPrefix: z.string().max(8), // Text
|
||||
});
|
||||
3
src/lib/schemas/task-creation-form.ts
Normal file
3
src/lib/schemas/task-creation-form.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const taskCreationFormSchema = z.object({});
|
||||
@@ -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