Added new completed project api route

This commit is contained in:
2023-01-29 15:07:51 -06:00
parent 47d8531554
commit 1e9a3dc6a3
6 changed files with 62 additions and 51 deletions

View File

@@ -1,5 +1,4 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Prisma docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
@@ -7,32 +6,23 @@ generator client {
datasource db {
provider = "sqlite"
// NOTE: When using postgresql, mysql or sqlserver, uncomment the @db.Text annotations in model Account below
// Further reading:
// https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
url = env("DATABASE_URL")
}
model Example {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
// === Auth ==============================================================
// Necessary for Next auth
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? // @db.Text
access_token String? // @db.Text
refresh_token String?
access_token String?
expires_at Int?
token_type String?
scope String?
id_token String? // @db.Text
id_token String?
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@ -64,3 +54,14 @@ model VerificationToken {
@@unique([identifier, token])
}
// === Parallel ==========================================================
model Project {
id String @id @default(cuid())
title String
isComplete Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

View File

@@ -8,8 +8,8 @@ const Home: NextPage = () => {
return (
<Container>
<Hero />
<About />
<VideoCounter />
<About />
</Container>
);
};
@@ -18,20 +18,43 @@ export default Home;
const About = () => {
return (
<Box sx={{ my: 20 }}>
<Box sx={{ my: 4 }}>
<Typography variant="h2">About Parallel</Typography>
<Typography variant="body1" color="textSecondary">
<span
style={{
color: theme.palette.primary.main,
fontWeight: 500,
}}
>
Parallel
</span>{" "}
is a revolutionary platform that connects field experts with
top-notch content creators to produce high-quality, educational
content. Whether you're an educator looking to bring your
lessons to life or an animator looking to bring your passion to
the masses, Parallel is the perfect place for you. Our platform
offers a user-friendly and intuitive experience that streamlines
the collaboration process, making it easier than ever to create
engaging and effective educational content. With advanced
analytics and metrics, real-time collaboration tools, and
priority matching, educators can focus on what they do best, and
content creators can bring their skills to a wider audience.
Join the Parallel community today and see the impact that a
dedicated platform for education can have!
</Typography>
</Box>
);
};
const VideoCounter = () => {
const hello = api.example.hello.useQuery({ text: "from tRPC" });
const count = api.parallelStats.countCompletedVideos.useQuery();
return (
<Divider>
<Box sx={{ mx: 4, my: 10 }}>
<Typography variant="h4" color="secondary">
0 videos
{count.data} videos
</Typography>
<Typography variant="body2">
created through Parallel

View File

@@ -1,16 +1,13 @@
import { createTRPCRouter } from "./trpc";
import { exampleRouter } from "./routers/example";
import { projectRouter } from "./routers/projects";
import { parallelStatsRouter } from "./routers/parallel";
/**
* This is the primary router for your server.
*
* All routers added in /api/routers should be manually added here
/*
* All newly created routers should be added here
*/
export const appRouter = createTRPCRouter({
example: exampleRouter,
parallelStats: parallelStatsRouter,
projects: projectRouter,
});
// export type definition of API
export type AppRouter = typeof appRouter;

View File

@@ -1,21 +0,0 @@
import { z } from "zod";
import { createTRPCRouter, publicProcedure, protectedProcedure } from "../trpc";
export const exampleRouter = createTRPCRouter({
hello: publicProcedure
.input(z.object({ text: z.string() }))
.query(({ input }) => {
return {
greeting: `Hello ${input.text}`,
};
}),
getAll: publicProcedure.query(({ ctx }) => {
return ctx.prisma.example.findMany();
}),
getSecretMessage: protectedProcedure.query(() => {
return "you can now see this secret message!";
}),
});

View File

@@ -0,0 +1,14 @@
import { z } from "zod";
import type { PrismaPromise } from "@prisma/client";
import { createTRPCRouter, publicProcedure, protectedProcedure } from "../trpc";
export const parallelStatsRouter = createTRPCRouter({
countCompletedVideos: publicProcedure.query(({ ctx }) => {
const completedProjectCount: PrismaPromise<number> =
ctx.prisma.project.count({
where: { isComplete: { equals: true } },
});
return completedProjectCount;
}),
});

View File

@@ -1,9 +1,6 @@
import { z } from "zod";
import { createTRPCRouter, publicProcedure, protectedProcedure } from "../trpc";
export const projectRouter = createTRPCRouter({
countCompletedVideos: publicProcedure.query(({ ctx }) => {
return ctx.prisma.example.findMany();
}),
// countCompletedVideos: publicProcedure.query(({ ctx }) => 0),
});