File size: 11,658 Bytes
81b66b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import { Request, Response, NextFunction } from 'express';
import Resource from '../models/Resource';
import SkillGap from '../models/SkillGap';
import { AuthRequest } from '../types';

// Default resources data with REAL-WORLD URLs (will be seeded to DB)
const defaultResources = [
    {
        title: 'TypeScript Full Course for Beginners',
        description: 'Complete TypeScript tutorial covering types, interfaces, generics, decorators, and advanced patterns. Official freeCodeCamp course.',
        type: 'video',
        duration: '5h',
        difficulty: 'intermediate',
        rating: 4.9,
        author: 'freeCodeCamp',
        topics: ['TypeScript', 'JavaScript'],
        url: 'https://www.youtube.com/watch?v=30LWjhZzg50',
        thumbnailUrl: 'https://i.ytimg.com/vi/30LWjhZzg50/maxresdefault.jpg'
    },
    {
        title: 'React Official Documentation',
        description: 'The official React documentation with interactive examples, tutorials, and API reference. Learn React the right way.',
        type: 'article',
        duration: '2h read',
        difficulty: 'beginner',
        rating: 4.9,
        author: 'React Team',
        topics: ['React', 'JavaScript'],
        url: 'https://react.dev/learn',
        thumbnailUrl: 'https://react.dev/images/og-learn.png'
    },
    {
        title: 'React Hooks Tutorial - Complete Course',
        description: 'Master useState, useEffect, useContext, useReducer, useCallback, useMemo, useRef and custom hooks with practical examples.',
        type: 'video',
        duration: '1h 30m',
        difficulty: 'intermediate',
        rating: 4.8,
        author: 'Codevolution',
        topics: ['React', 'JavaScript'],
        url: 'https://www.youtube.com/watch?v=LlvBzyy-558',
        thumbnailUrl: 'https://i.ytimg.com/vi/LlvBzyy-558/maxresdefault.jpg'
    },
    {
        title: 'CSS Grid Layout Crash Course',
        description: 'Learn CSS Grid in under an hour. Cover grid containers, items, areas, and responsive layouts with hands-on examples.',
        type: 'video',
        duration: '48m',
        difficulty: 'beginner',
        rating: 4.7,
        author: 'Traversy Media',
        topics: ['CSS', 'Frontend'],
        url: 'https://www.youtube.com/watch?v=jV8B24rSN5o',
        thumbnailUrl: 'https://i.ytimg.com/vi/jV8B24rSN5o/maxresdefault.jpg'
    },
    {
        title: 'Node.js and Express.js Full Course',
        description: 'Build a complete REST API with Node.js and Express. Covers routing, middleware, authentication, MongoDB integration.',
        type: 'video',
        duration: '8h 16m',
        difficulty: 'intermediate',
        rating: 4.8,
        author: 'freeCodeCamp',
        topics: ['Node.js', 'Backend', 'APIs'],
        url: 'https://www.youtube.com/watch?v=Oe421EPjeBE',
        thumbnailUrl: 'https://i.ytimg.com/vi/Oe421EPjeBE/maxresdefault.jpg'
    },
    {
        title: 'Next.js 14 Full Course',
        description: 'Learn Next.js 14 App Router, Server Components, Server Actions, Authentication, and deployment to Vercel.',
        type: 'video',
        duration: '5h',
        difficulty: 'intermediate',
        rating: 4.9,
        author: 'JavaScript Mastery',
        topics: ['Next.js', 'React', 'TypeScript'],
        url: 'https://www.youtube.com/watch?v=wm5gMKuwSYk',
        thumbnailUrl: 'https://i.ytimg.com/vi/wm5gMKuwSYk/maxresdefault.jpg'
    },
    {
        title: 'MongoDB Crash Course',
        description: 'Learn MongoDB basics including CRUD operations, schemas, indexes, aggregation, and integration with Node.js.',
        type: 'video',
        duration: '1h 30m',
        difficulty: 'beginner',
        rating: 4.7,
        author: 'Traversy Media',
        topics: ['MongoDB', 'Backend', 'Database'],
        url: 'https://www.youtube.com/watch?v=ofme2o29ngU',
        thumbnailUrl: 'https://i.ytimg.com/vi/ofme2o29ngU/maxresdefault.jpg'
    },
    {
        title: 'JavaScript Algorithms and Data Structures',
        description: 'Master algorithms, data structures, and problem-solving for technical interviews. Includes 300+ coding challenges.',
        type: 'interactive',
        duration: '300h',
        difficulty: 'advanced',
        rating: 4.9,
        author: 'freeCodeCamp',
        topics: ['JavaScript', 'Algorithms'],
        url: 'https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/',
        thumbnailUrl: 'https://cdn.freecodecamp.org/platform/universal/fcc_meta_1920X1080-indigo.png'
    },
    {
        title: 'Tailwind CSS Crash Course',
        description: 'Learn Tailwind CSS utility-first framework. Build responsive, modern UIs without writing custom CSS.',
        type: 'video',
        duration: '30m',
        difficulty: 'beginner',
        rating: 4.6,
        author: 'Traversy Media',
        topics: ['CSS', 'Tailwind', 'Frontend'],
        url: 'https://www.youtube.com/watch?v=UBOj6rqRUME',
        thumbnailUrl: 'https://i.ytimg.com/vi/UBOj6rqRUME/maxresdefault.jpg'
    },
    {
        title: 'Git and GitHub for Beginners',
        description: 'Complete tutorial on version control with Git. Learn branches, merging, pull requests, and GitHub workflows.',
        type: 'video',
        duration: '1h',
        difficulty: 'beginner',
        rating: 4.8,
        author: 'freeCodeCamp',
        topics: ['Git', 'GitHub', 'DevOps'],
        url: 'https://www.youtube.com/watch?v=RGOj5yH7evk',
        thumbnailUrl: 'https://i.ytimg.com/vi/RGOj5yH7evk/maxresdefault.jpg'
    },
    {
        title: 'REST API Design Best Practices',
        description: 'Official Microsoft documentation on designing production-ready RESTful APIs with proper versioning and error handling.',
        type: 'article',
        duration: '45 min read',
        difficulty: 'intermediate',
        rating: 4.7,
        author: 'Microsoft',
        topics: ['APIs', 'Backend', 'Architecture'],
        url: 'https://learn.microsoft.com/en-us/azure/architecture/best-practices/api-design',
        thumbnailUrl: 'https://learn.microsoft.com/en-us/media/open-graph-image.png'
    },
    {
        title: 'The Modern JavaScript Tutorial',
        description: 'Comprehensive JavaScript tutorial from basics to advanced. Interactive examples and exercises included.',
        type: 'interactive',
        duration: '40h',
        difficulty: 'beginner',
        rating: 4.9,
        author: 'javascript.info',
        topics: ['JavaScript'],
        url: 'https://javascript.info/',
        thumbnailUrl: 'https://javascript.info/img/sitetoolbar__logo_en.svg'
    },
    {
        title: 'Docker Tutorial for Beginners',
        description: 'Learn Docker containerization. Build, ship, and run applications consistently across environments.',
        type: 'video',
        duration: '2h 46m',
        difficulty: 'intermediate',
        rating: 4.8,
        author: 'TechWorld with Nana',
        topics: ['Docker', 'DevOps', 'Backend'],
        url: 'https://www.youtube.com/watch?v=3c-iBn73dDE',
        thumbnailUrl: 'https://i.ytimg.com/vi/3c-iBn73dDE/maxresdefault.jpg'
    },
    {
        title: 'Python for Everybody',
        description: 'Complete Python course for beginners. Learn programming fundamentals, data structures, and web scraping.',
        type: 'course',
        duration: '13h',
        difficulty: 'beginner',
        rating: 4.9,
        author: 'Dr. Chuck (University of Michigan)',
        topics: ['Python', 'Programming'],
        url: 'https://www.youtube.com/watch?v=8DvywoWv6fI',
        thumbnailUrl: 'https://i.ytimg.com/vi/8DvywoWv6fI/maxresdefault.jpg'
    },
    {
        title: 'AWS Cloud Practitioner Essential',
        description: 'Official AWS training covering cloud concepts, AWS services, security, architecture, and pricing.',
        type: 'course',
        duration: '6h',
        difficulty: 'beginner',
        rating: 4.7,
        author: 'Amazon Web Services',
        topics: ['AWS', 'Cloud', 'DevOps'],
        url: 'https://explore.skillbuilder.aws/learn/course/134/aws-cloud-practitioner-essentials',
        thumbnailUrl: 'https://d1.awsstatic.com/training-and-certification/certification-badges/AWS-Certified-Cloud-Practitioner_badge.634f8a21af2e0e956ed8905a72366146ba22b74c.png'
    },
];

// @desc    Get all resources (with filters)
// @route   GET /api/resources
// @access  Public
export const getResources = async (
    req: Request,
    res: Response,
    next: NextFunction
): Promise<void> => {
    try {
        const { type, difficulty, topic, search } = req.query;

        // Check if resources exist, if not seed them
        let count = await Resource.countDocuments();
        if (count === 0) {
            await Resource.insertMany(defaultResources);
        }

        // Build query
        const query: Record<string, unknown> = {};

        if (type) query.type = type;
        if (difficulty) query.difficulty = difficulty;
        if (topic) query.topics = { $in: [topic] };
        if (search) {
            query.$text = { $search: search as string };
        }

        const resources = await Resource.find(query).sort({ rating: -1 });

        res.status(200).json({
            success: true,
            count: resources.length,
            data: resources,
        });
    } catch (error) {
        next(error);
    }
};

// @desc    Get AI-recommended resources based on skill gaps
// @route   GET /api/resources/recommended
// @access  Private
export const getRecommendedResources = async (
    req: AuthRequest,
    res: Response,
    next: NextFunction
): Promise<void> => {
    try {
        // Get user's skill gaps
        const skillGap = await SkillGap.findOne({ userId: req.user?._id });

        // Get high priority skill gaps
        const weakTopics = skillGap?.skills
            .filter(s => s.priority === 'high' || s.gap > 30)
            .map(s => s.topic) || ['TypeScript', 'APIs'];

        // Find resources matching weak topics
        const matchedResources = await Resource.find({
            topics: { $in: weakTopics },
        }).sort({ rating: -1 }).limit(4);

        // Get other popular resources
        const otherResources = await Resource.find({
            topics: { $nin: weakTopics },
        }).sort({ rating: -1 }).limit(6);

        res.status(200).json({
            success: true,
            data: {
                matched: matchedResources.map(r => ({ ...r.toObject(), matched: true })),
                popular: otherResources.map(r => ({ ...r.toObject(), matched: false })),
            },
        });
    } catch (error) {
        next(error);
    }
};

// @desc    Get single resource
// @route   GET /api/resources/:id
// @access  Public
export const getResource = async (
    req: Request,
    res: Response,
    next: NextFunction
): Promise<void> => {
    try {
        const resource = await Resource.findById(req.params.id);

        if (!resource) {
            res.status(404).json({
                success: false,
                error: 'Resource not found',
            });
            return;
        }

        res.status(200).json({
            success: true,
            data: resource,
        });
    } catch (error) {
        next(error);
    }
};

// @desc    Create new resource
// @route   POST /api/resources
// @access  Private (Admin)
export const createResource = async (
    req: Request,
    res: Response,
    next: NextFunction
): Promise<void> => {
    try {
        const resource = await Resource.create(req.body);

        res.status(201).json({
            success: true,
            data: resource,
        });
    } catch (error) {
        next(error);
    }
};