Skip to content

Commit

Permalink
✨ feat (student): Implemented basic functionality to enroll courses
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanprince committed Feb 28, 2024
1 parent 632d632 commit 13069a3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
7 changes: 7 additions & 0 deletions apps/student/src/app/api/courses/route.ts
Original file line number Diff line number Diff line change
@@ -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 });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use client";

import { GraduationCap } from "lucide-react";

import { Button } from "~/components/ui/button";

export const EnrollCourseButton = () => {
return (
<Button onClick={() => console.log("Enrolled!")}>
<GraduationCap className="mr-2 size-4" />
Enroll
</Button>
);
};
12 changes: 4 additions & 8 deletions apps/student/src/app/dashboard/courses/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -61,10 +60,7 @@ function CourseCard({ course }: { course: Course }) {
<h2 className="text-sm text-muted-foreground">Fee</h2>
<p>£ {course.fee}</p>
</div>
<Button>
<GraduationCap className="mr-2 size-4" />
Enroll
</Button>
<EnrollCourseButton />
</div>
</div>
);
Expand Down
2 changes: 2 additions & 0 deletions apps/student/src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},

/**
Expand All @@ -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
Expand Down

0 comments on commit 13069a3

Please sign in to comment.