Skip to content

rvs1212/lvl-BP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Designing Filtering API

This project is built to demonstrates a clean, scalable, and maintainable Laravel 12 API for filtering users based on various criteria using SOLID principles.


πŸ”§ Tech Stack

  • PHP 8.2
  • Laravel 12 (Vue + Breeze Starter Kit)
  • MySQL (via phpMyAdmin)
  • Inertia (Vue front-end starter, not used for API)
  • Postman (for API testing)

βœ… Features

  • RESTful API to retrieve a list of users
  • Dynamic filtering via query parameters (e.g., gender, location)
  • Uses Form Request (FilterUsersRequest) for validation
  • Custom Filter classes following Open/Closed & Interface Segregation principles
  • Clean Eloquent UserQueryBuilder for base query logic
  • Many-to-many relationship between users and languages (can define more such relations)
  • Response formatted using Laravel's UserResource for consistency

πŸ“‚ Project Structure Overview

app/
β”œβ”€β”€ Contracts/Filters/           # FilterInterface
β”œβ”€β”€ Filters/UserFilters/         # LocationFilter, GenderFilter, etc.
β”œβ”€β”€ Http/
β”‚   β”œβ”€β”€ Controllers/Api/         # UserController.php
β”‚   β”œβ”€β”€ Requests/                # FilterUsersRequest.php
β”‚   └── Resources/               # UserResource.php
β”œβ”€β”€ Models/                      # User.php, Language.php
β”œβ”€β”€ Services/User/
β”‚   β”œβ”€β”€ UserFilterService.php    # Applies filters dynamically
β”‚   └── UserQueryBuilder.php     # Base query logic


πŸš€ API Usage

GET /api/v1/users

Sample Json response

{
    "data": [
        {
            "id": 1,
            "name": "Miss Bernadine Beatty",
            "age": 30,
            "gender": "other",
            "location": "Christiansenview",
            "bio": "Ut est esse molestias est rem maiores.",
            "languages": [
                "English",
                "German",
                "Spanish"
            ]
        },
        {
            "id": 2,
            "name": "Prof. Stanton Bauch V",
            "age": 33,
            "gender": "female",
            "location": "East Wilfridton",
            "bio": "Deserunt corrupti est earum sint.",
            "languages": [
                "English",
                "Dutch",
                "German"
            ]
        },
        {
            "id": 3,
            "name": "Felicita Larson",
            "age": 34,
            "gender": "female",
            "location": "East Jaunitaview",
            "bio": "Quis voluptatem eos consequatur architecto ut ea.",
            "languages": [
                "English",
                "Dutch"
            ]
        },
        ...
}

GET /api/v1/users?gender=female&location=East Wilfridton

Sample Json response

{
    "data": [
        {
            "id": 2,
            "name": "Prof. Stanton Bauch V",
            "age": 33,
            "gender": "female",
            "location": "East Wilfridton",
            "bio": "Deserunt corrupti est earum sint.",
            "languages": [
                "English",
                "Dutch",
                "German"
            ]
        }
    ]
}


πŸ› οΈ Setup Instructions

  1. Clone the repo

    • git clone <repo-url>
    • cd PjtFilter
  2. Install dependencies:

    • composer install
    • npm install
    • npm run build
  3. Create and configure .env file:

    • Set up your MySQL DB
    • Configure DB credentials
  4. Run migrations and seed data:

    • php artisan migrate:fresh --seed
  5. Serve the app:

    • composer run dev
    • or
    • php artisan serve
  6. Test API with Postman:

     GET http://127.0.0.1:8000/api/v1/users
    

πŸ™Œ Notes

  • New filters can be added (e.g., AgeFilter, UserTraits, etc) by creating a new class and updating the UserFilterService's $filters array.

  • This structure is designed to scale well as the application grows.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published