Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,404 changes: 2,197 additions & 3,207 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

27 changes: 8 additions & 19 deletions src/app/api/courses/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import { edgeLog, CDN_CACHE_HEADERS } from '@/../infra/edge-config';
import { validateBody } from '@/lib/validation';
import { CourseByIdParamsSchema } from '@/types/api/courses.dto';
import type { CourseResponseDTO } from '@/types/api/courses.dto';
import { getCourseById } from '@/lib/course-config';

export const runtime = 'edge';

// ---------------------------------------------------------------------------
// GET /api/courses/[id]
// ---------------------------------------------------------------------------

export async function GET(
request: Request,
{ params }: { params: Promise<{ id: string }> },
Expand All @@ -26,21 +23,13 @@ export async function GET(
const result = validateBody(CourseByIdParamsSchema, rawParams);
if (!result.ok) return addHeaders(result.error) as NextResponse<CourseResponseDTO>;

// Mock course lookup — replace with real DB query
const course = {
id: result.data.id,
title: 'Web3 UX Design Principles',
description: 'Create intuitive interfaces for decentralized applications',
instructor: 'Sarah Johnson',
duration: '24 hours',
totalLessons: 12,
progress: 68,
category: 'Design',
size: '250MB',
thumbnailUrl:
'https://thumbs.dreamstime.com/b/matrix-style-digital-rain-green-binary-code-falling-downward-direction-abstract-background-depicting-effect-stream-397887374.jpg',
downloaded: false,
};
const course = getCourseById(result.data.id);
if (!course) {
const notFound = addHeaders(
NextResponse.json({ data: null as unknown as CourseResponseDTO['data'], success: false, message: 'Course not found' }, { status: 404 }),
);
return notFound as NextResponse<CourseResponseDTO>;
}

const response = addHeaders(
NextResponse.json({
Expand Down
41 changes: 13 additions & 28 deletions src/app/api/courses/downloadable/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextResponse } from 'next/server';
import { withRateLimit } from '@/lib/ratelimit';
import { edgeLog } from '@/../infra/edge-config';
import { getAllCourses } from '@/lib/course-config';

export const runtime = 'edge';

Expand All @@ -11,34 +12,18 @@ export async function GET(request: Request) {
return rateLimitResponse;
}

const courses = [
{
id: '1',
title: 'Web3 UX Design Principles',
description: 'Create intuitive interfaces for decentralized applications',
instructor: 'Sarah Johnson',
duration: '24 hours',
totalLessons: 12,
progress: 68,
size: '250MB',
thumbnailUrl:
'https://thumbs.dreamstime.com/b/matrix-style-digital-rain-green-binary-code-falling-downward-direction-abstract-background-depicting-effect-stream-397887374.jpg',
downloaded: false,
},
{
id: '2',
title: 'Smart Contract Security Best Practices',
description: 'Learn to secure your Cairo smart contracts against vulnerabilities',
instructor: 'Michael Chen',
duration: '36 hours',
totalLessons: 18,
progress: 45,
size: '380MB',
thumbnailUrl:
'https://static.vecteezy.com/system/resources/previews/053/715/379/non_2x/abstract-green-digital-rain-with-matrix-code-in-futuristic-cyber-background-perfect-for-technology-and-data-themed-visuals-png.png',
downloaded: false,
},
];
const courses = getAllCourses().map(({ id, title, description, instructor, duration, totalLessons, progress, size, thumbnailUrl }) => ({
id,
title,
description,
instructor,
duration,
totalLessons,
progress,
size,
thumbnailUrl,
downloaded: false,
}));

return addHeaders(
NextResponse.json({
Expand Down
59 changes: 6 additions & 53 deletions src/app/api/courses/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { edgeLog, CDN_CACHE_HEADERS } from '@/../infra/edge-config';
import { validateQuery } from '@/lib/validation';
import { CourseListQuerySchema } from '@/types/api/courses.dto';
import type { CourseListResponseDTO } from '@/types/api/courses.dto';
import { getPaginatedCourses } from '@/lib/course-config';

export const runtime = 'edge';

Expand All @@ -18,63 +19,15 @@ export async function GET(request: Request): Promise<NextResponse<CourseListResp
const { searchParams } = new URL(request.url);
const result = validateQuery(CourseListQuerySchema, searchParams);
if (!result.ok) return addHeaders(result.error) as NextResponse<CourseListResponseDTO>;
const { limit, cursor } = result.data as { limit: number; cursor?: string };
const { limit, cursor, featured } = result.data as { limit: number; cursor?: string; featured?: boolean };

const courses = [
{
id: '1',
title: 'Web3 UX Design Principles',
description: 'Create intuitive interfaces for decentralized applications',
instructor: 'Sarah Johnson',
duration: '24 hours',
totalLessons: 12,
progress: 68,
category: 'Design',
size: '250MB',
thumbnailUrl:
'https://thumbs.dreamstime.com/b/matrix-style-digital-rain-green-binary-code-falling-downward-direction-abstract-background-depicting-effect-stream-397887374.jpg',
downloaded: false,
},
{
id: '2',
title: 'Smart Contract Security Best Practices',
description: 'Learn to secure your Cairo smart contracts against vulnerabilities',
instructor: 'Michael Chen',
duration: '36 hours',
totalLessons: 18,
progress: 45,
category: 'Security',
size: '380MB',
thumbnailUrl:
'https://static.vecteezy.com/system/resources/previews/053/715/379/non_2x/abstract-green-digital-rain-with-matrix-code-in-futuristic-cyber-background-perfect-for-technology-and-data-themed-visuals-png.png',
downloaded: true,
},
{
id: '3',
title: 'Scaling DAPps on Starknet',
description: 'Techniques for building scalable decentralized applications',
instructor: 'Alex Rivera',
duration: '48 hours',
totalLessons: 24,
progress: 12,
category: 'Engineering',
size: '520MB',
thumbnailUrl:
'https://thumbs.dreamstime.com/b/futuristic-laptop-glowing-digital-waves-emerging-screen-dark-setting-399809314.jpg',
downloaded: false,
},
];

const startIndex = cursor ? parseInt(cursor, 10) : 0;
const page = courses.slice(startIndex, startIndex + limit);
const nextIndex = startIndex + limit;
const nextCursor = nextIndex < courses.length ? String(nextIndex) : undefined;
const paginated = getPaginatedCourses(limit, cursor, { featured });

const response = addHeaders(
NextResponse.json({
data: page,
total: courses.length,
nextCursor,
data: paginated.data,
total: paginated.total,
nextCursor: paginated.nextCursor,
}),
);
response.headers.set('Cache-Control', CDN_CACHE_HEADERS.public);
Expand Down
96 changes: 58 additions & 38 deletions src/app/components/dashboard/widgets/RecommendedCoursesWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useState } from 'react';
import { motion } from 'framer-motion';
import { BookOpen, Star, Clock, Users, Settings } from 'lucide-react';
import { getAllCourses } from '@/lib/course-config';

interface Course {
id: string;
Expand Down Expand Up @@ -28,6 +29,62 @@ interface RecommendedCoursesWidgetProps {
onUpdateTitle: (title: string) => void;
}

function buildRecommendedCourses() {
const configCourses = getAllCourses();
if (configCourses.length >= 3) {
return configCourses.slice(0, 3).map((c, i) => ({
id: c.id,
title: c.title,
instructor: c.instructor,
rating: (4.5 + i * 0.2) as 4.7 | 4.8 | 4.9,
students: [12450, 8920, 15680][i] ?? 10000,
duration: c.duration,
level: (i === 2 ? 'beginner' : i === 1 ? 'intermediate' : 'advanced') as 'beginner' | 'intermediate' | 'advanced',
category: c.category,
image: c.thumbnailUrl ?? `https://via.placeholder.com/300x200/${['3B82F6', '10B981', '8B5CF6'][i]}/ffffff?text=${encodeURIComponent(c.title.split(' ')[0])}`,
price: [89, 129, 69][i] ?? 99,
}));
}
return [
{
id: '1',
title: 'Advanced React Patterns',
instructor: 'Sarah Johnson',
rating: 4.8 as const,
students: 12450,
duration: '8 hours',
level: 'advanced' as const,
category: 'Web Development',
image: 'https://via.placeholder.com/300x200/3B82F6/ffffff?text=React',
price: 89,
},
{
id: '2',
title: 'Machine Learning Fundamentals',
instructor: 'Dr. Michael Chen',
rating: 4.9 as const,
students: 8920,
duration: '12 hours',
level: 'intermediate' as const,
category: 'Data Science',
image: 'https://via.placeholder.com/300x200/10B981/ffffff?text=ML',
price: 129,
},
{
id: '3',
title: 'UI/UX Design Principles',
instructor: 'Emma Davis',
rating: 4.7 as const,
students: 15680,
duration: '6 hours',
level: 'beginner' as const,
category: 'Design',
image: 'https://via.placeholder.com/300x200/8B5CF6/ffffff?text=Design',
price: 69,
},
];
}

export const RecommendedCoursesWidget: React.FC<RecommendedCoursesWidgetProps> = ({
id,
title,
Expand Down Expand Up @@ -68,44 +125,7 @@ export const RecommendedCoursesWidget: React.FC<RecommendedCoursesWidgetProps> =
};
}, [id]);

const recommendedCourses: Course[] = [
{
id: '1',
title: 'Advanced React Patterns',
instructor: 'Sarah Johnson',
rating: 4.8,
students: 12450,
duration: '8 hours',
level: 'advanced',
category: 'Web Development',
image: 'https://via.placeholder.com/300x200/3B82F6/ffffff?text=React',
price: 89,
},
{
id: '2',
title: 'Machine Learning Fundamentals',
instructor: 'Dr. Michael Chen',
rating: 4.9,
students: 8920,
duration: '12 hours',
level: 'intermediate',
category: 'Data Science',
image: 'https://via.placeholder.com/300x200/10B981/ffffff?text=ML',
price: 129,
},
{
id: '3',
title: 'UI/UX Design Principles',
instructor: 'Emma Davis',
rating: 4.7,
students: 15680,
duration: '6 hours',
level: 'beginner',
category: 'Design',
image: 'https://via.placeholder.com/300x200/8B5CF6/ffffff?text=Design',
price: 69,
},
];
const recommendedCourses = buildRecommendedCourses();

const getLevelColor = (level: string) => {
switch (level) {
Expand Down
Loading