Skip to content

This is a Laravel API I built to manage courses, categories, students, and enrollments. It uses the Repository Pattern, optimized queries, and includes a Postman collection for testing.

Notifications You must be signed in to change notification settings

ax-kill/Course-Management

Repository files navigation

Course Management Module

This is a Laravel API I built to manage courses, categories, students, and enrollments. It uses the Repository Pattern, optimized queries, and includes a Postman collection for testing.

What You Need PHP 8.1 or higher Composer MySQL Laravel 12.x

How to Set It Up

  1. Clone the Repository:
    git clone <repository-url>
    cd course-management
  2. Install Dependencies:
    composer install
  3. Configure Environment:
    • Copy .env.example to .env:
      cp .env.example .env
    • Update .env with your database credentials.
  4. Generate Application Key:
    php artisan key:generate
  5. Run Migrations:
    php artisan migrate
  6. Seed Database:
    php artisan db:seed
  7. Serve Application:
    php artisan serve
  8. Run Tests (optional):
    php artisan test
  9. API Testing:
    • Import CM.postman_collection.json into Postman.
    • Set baseUrl to http://127.0.0.1:8000.
    • Run the following requests:
      • GET /api/courses: Lists all courses with category name and enrollment count.
      • GET /api/courses/{courseId}/students: Lists students enrolled in the specified course.
      • GET /api/courses/filter?category_id={id}&search={term}: Filters courses by category and/or name.

API Endpoints

  • GET /api/courses: List all courses with category and enrollment count.
  • GET /api/courses/{courseId}/students: List students enrolled in a course.
  • GET /api/courses/filter?category_id={id}&search={term}: Filter courses by category and name.

Testing

  • Unit Tests: Run php artisan test to verify repository functionality. Tests confirm courses are fetched with category and enrollment data.
  • Postman Tests:
    • List All Courses: Verifies courses include category_name and enrollments_count, using DTOs and eager loading.
    • List Students in Course: Verifies students for a given course are returned with only id, name, and email. If empty, check enrollment data.
    • Filter Courses: Verifies filtering by category_id, search, or both, with correct DTO structure. Ensure valid category_id.
  • Query Optimization: Eager loading (with, withCount) and selective field loading (select) ensure no N+1 issues.

Project Structure

  • app/Models: Eloquent models for entities.
  • app/Repositories: Repository pattern implementation.
  • app/DTOs: Data Transfer Objects.
  • app/Http/Controllers: API controllers.
  • routes/api.php: API route definitions.
  • tests/Unit: Unit tests for repositories.

About

This is a Laravel API I built to manage courses, categories, students, and enrollments. It uses the Repository Pattern, optimized queries, and includes a Postman collection for testing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages