This test is designed to assess your proficiency in Laravel, focusing on creating RESTful APIs, middleware, a custom Artisan command, and unit testing.
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).
- Clone the Repository
Clone this repository to your local environment:git clone [email protected]:robuedi/laravel-coding-test.git cd laravel-coding-test
- 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#/:
- Install the project dependencies:
-
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.
-
Middleware:
- Protect the
POST
andDELETE
routes using a custom token check. - Only requests with
Authorization: Bearer artificially-token
should succeed on these endpoints.
- Protect the
-
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.
- Ensure that the
-
Service Layer:
- Create a
FileService
class to handle file-related business logic (e.g., storing files, deleting files).
- Create a
-
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).
- A command, for example:
-
Unit Tests:
- Write tests to validate:
- Uploading a file.
- Retrieving the list of files.
- Middleware token protection.
- The custom Artisan command’s functionality.
- Write tests to validate:
-
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
-
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. -
Write Unit Tests
Write unit tests to validate the functionality of the API endpoints, middleware, and custom Artisan command.
Your submission will be evaluated based on:
- Code Quality
- Clean, readable code with appropriate comments.
- Proper use of Laravel features (controllers, services, middleware, storage, etc.).
- Functionality
- Complete, working endpoints (upload, list, delete, retrieve).
- Middleware that correctly restricts certain endpoints.
- Random file command working as expected.
- Testing
- Comprehensive coverage of the outlined features.
- Proper handling of edge cases.
- Documentation
- Clear and concise documentation in README.md on setup, usage, and testing steps.