WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Module LessonController

    HTTP controller for comprehensive lesson management within the WayrApp language learning platform.

    This controller serves as the primary REST API interface for lesson operations, providing complete CRUD functionality and exercise assignment management within the content management system. It handles HTTP request processing, parameter validation, authentication integration, and response formatting for all lesson-related endpoints in the WayrApp backend architecture.

    The controller manages lessons as part of the hierarchical content structure: Course → Level → Section → Module → Lesson → Exercise. Each lesson belongs to a specific module and can contain multiple exercises in a defined order. The controller integrates seamlessly with Express middleware for authentication, authorization, validation, and error handling while delegating business logic to the service layer.

    Key architectural responsibilities include HTTP request processing for lesson CRUD operations, parameter extraction and validation from URL paths and request bodies, authentication and authorization enforcement through middleware integration, standardized API response formatting, comprehensive error handling with proper HTTP status codes, exercise-to-lesson assignment management, and pagination support for lesson retrieval operations.

    The controller follows RESTful conventions and provides endpoints for creating lessons within modules, retrieving individual lessons and paginated lesson lists, updating lesson properties with validation, deleting lessons with dependency management, assigning exercises to lessons with order management, retrieving lesson exercises in their defined sequence, unassigning exercises from lessons, and reordering exercises within lessons.

    Exequiel Trujillo

    1.0.0

    // Initialize controller with Prisma client and integrate with Express routes
    import { Router } from 'express';
    import { PrismaClient } from '@prisma/client';
    import { LessonController } from './LessonController';

    const router = Router();
    const prisma = new PrismaClient();
    const lessonController = new LessonController(prisma);

    // Lesson CRUD endpoints
    router.post('/modules/:moduleId/lessons', lessonController.createLesson);
    router.get('/modules/:moduleId/lessons/:id', lessonController.getLesson);
    router.get('/modules/:moduleId/lessons', lessonController.getLessonsByModule);
    router.put('/modules/:moduleId/lessons/:id', lessonController.updateLesson);
    router.delete('/modules/:moduleId/lessons/:id', lessonController.deleteLesson);

    // Exercise assignment endpoints
    router.get('/lessons/:lessonId/exercises', lessonController.getLessonExercises);
    router.post('/lessons/:lessonId/exercises', lessonController.assignExerciseToLesson);
    router.delete('/lessons/:lessonId/exercises/:exerciseId', lessonController.unassignExerciseFromLesson);
    router.put('/lessons/:lessonId/exercises/reorder', lessonController.reorderLessonExercises);

    Classes

    LessonController