Skip to content

robuedi/laravel-coding-test

Repository files navigation

Laravel Coding Test

This test is designed to assess your proficiency in Laravel, focusing on creating RESTful APIs, middleware, a custom Artisan command, and unit testing.


Objective

You are tasked with building a File Management API. This API will allow users to manage files (upload, list, delete), and you must also create an Artisan command that randomly selects a file from storage and performs a simple action with it (e.g., log its details).


Testing the solution instructions

  1. Clone the Repository
    Clone this repository to your local environment:
    git clone [email protected]:robuedi/laravel-coding-test.git
    cd laravel-coding-test
  2. Setup the Project
    • Install the project dependencies:
      composer install
    • Create a new .env file:
      cp .env.example .env
    • Generate an application key:
      php artisan key:generate
    • Create a new SQLite database:
      touch database/database.sqlite
    • Run the database migrations:
      php artisan migrate
    • Run the app using the dev server:
      php artisan serve
    • Run UI tests using the docs at http://127.0.0.1:8000/docs/api#/: API DOCS

Requirements

1. API Features

  1. API Endpoints:

    • GET /files – Retrieve a list of all uploaded files.
    • POST /files – Upload a new file.
    • GET /files/{id} – Retrieve a single file for download/display.
    • DELETE /files/{id} – Delete a file.
  2. Middleware:

    • Protect the POST and DELETE routes using a custom token check.
    • Only requests with Authorization: Bearer artificially-token should succeed on these endpoints.
  3. Validation:

    • Ensure that the POST /files endpoint validates:
      • file (required, must be a valid file type).
    • Any additional metadata you collect about the file (e.g., name, description) should also be validated.
  4. Service Layer:

    • Create a FileService class to handle file-related business logic (e.g., storing files, deleting files).
  5. Custom Artisan Command:

    • A command, for example: php artisan file:random.
    • This command should:
      • Select a random file from your storage folder/database.
      • Perform an action (e.g., log its name and path, or print details to the console).
  6. Unit Tests:

    • Write tests to validate:
      • Uploading a file.
      • Retrieving the list of files.
      • Middleware token protection.
      • The custom Artisan command’s functionality.

Instructions

  1. Build the API
    Implement the API features outlined in the requirements section.

    • Create the necessary routes, controllers, middleware, and services.
    • Implement the custom Artisan command.
    • Implement file uploads and retrieval logic.
    • Enforce token-based authentication on the POST and DELETE routes via middleware
  2. Create Custom Artisan Command
    Create a custom Artisan command that selects a random file from your storage folder/database and performs an action with it.

  3. Write Unit Tests
    Write unit tests to validate the functionality of the API endpoints, middleware, and custom Artisan command.

Evaluation Criteria

Your submission will be evaluated based on:

  1. Code Quality
  • Clean, readable code with appropriate comments.
  • Proper use of Laravel features (controllers, services, middleware, storage, etc.).
  1. Functionality
  • Complete, working endpoints (upload, list, delete, retrieve).
  • Middleware that correctly restricts certain endpoints.
  • Random file command working as expected.
  1. Testing
  • Comprehensive coverage of the outlined features.
  • Proper handling of edge cases.
  1. Documentation
  • Clear and concise documentation in README.md on setup, usage, and testing steps.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages