From 13069a34c9947ee9cca027bd5b914e8aa203275c Mon Sep 17 00:00:00 2001 From: Aryan Prince Date: Wed, 28 Feb 2024 02:27:26 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat=20(student):=20Implemented=20b?= =?UTF-8?q?asic=20functionality=20to=20enroll=20courses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/student/src/app/api/courses/route.ts | 7 +++++++ .../courses/[id]/enroll-course-button.tsx | 14 ++++++++++++++ .../src/app/dashboard/courses/[id]/page.tsx | 12 ++++-------- apps/student/src/env.js | 2 ++ 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 apps/student/src/app/api/courses/route.ts create mode 100644 apps/student/src/app/dashboard/courses/[id]/enroll-course-button.tsx diff --git a/apps/student/src/app/api/courses/route.ts b/apps/student/src/app/api/courses/route.ts new file mode 100644 index 0000000..40b28d5 --- /dev/null +++ b/apps/student/src/app/api/courses/route.ts @@ -0,0 +1,7 @@ +import { db } from "~/server/db"; + +export async function GET(_request: Request) { + const allCourses = await db.query.course.findMany(); + + return Response.json(allCourses, { status: 200 }); +} diff --git a/apps/student/src/app/dashboard/courses/[id]/enroll-course-button.tsx b/apps/student/src/app/dashboard/courses/[id]/enroll-course-button.tsx new file mode 100644 index 0000000..5285b7e --- /dev/null +++ b/apps/student/src/app/dashboard/courses/[id]/enroll-course-button.tsx @@ -0,0 +1,14 @@ +"use client"; + +import { GraduationCap } from "lucide-react"; + +import { Button } from "~/components/ui/button"; + +export const EnrollCourseButton = () => { + return ( + + ); +}; diff --git a/apps/student/src/app/dashboard/courses/[id]/page.tsx b/apps/student/src/app/dashboard/courses/[id]/page.tsx index 9330f76..5b66b0e 100644 --- a/apps/student/src/app/dashboard/courses/[id]/page.tsx +++ b/apps/student/src/app/dashboard/courses/[id]/page.tsx @@ -1,14 +1,13 @@ -import { GraduationCap } from "lucide-react"; - import type { course } from "~/server/db/schema"; import { Badge } from "~/components/ui/badge"; -import { Button } from "~/components/ui/button"; +import { env } from "~/env"; +import { EnrollCourseButton } from "./enroll-course-button"; type Course = typeof course.$inferSelect; export default async function Page({ params }: { params: { id: string } }) { const response = await fetch( - `http://localhost:3001/api/courses/${params.id}`, + `${env.NEXT_PUBLIC_API_BASE_URL}/api/courses/${params.id}`, ); const course = (await response.json()) as Course; @@ -61,10 +60,7 @@ function CourseCard({ course }: { course: Course }) {

Fee

£ {course.fee}

- + ); diff --git a/apps/student/src/env.js b/apps/student/src/env.js index c0c3094..3bd5209 100644 --- a/apps/student/src/env.js +++ b/apps/student/src/env.js @@ -30,6 +30,7 @@ export const env = createEnv({ ), NEXTAUTH_GITHUB_CLIENT_ID: z.string(), NEXTAUTH_GITHUB_CLIENT_SECRET: z.string(), + NEXT_PUBLIC_API_BASE_URL: z.string().url(), }, /** @@ -52,6 +53,7 @@ export const env = createEnv({ NEXTAUTH_URL: process.env.NEXTAUTH_URL, NEXTAUTH_GITHUB_CLIENT_ID: process.env.NEXTAUTH_GITHUB_CLIENT_ID, NEXTAUTH_GITHUB_CLIENT_SECRET: process.env.NEXTAUTH_GITHUB_CLIENT_SECRET, + NEXT_PUBLIC_API_BASE_URL: process.env.NEXT_PUBLIC_API_BASE_URL, }, /** * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially