Table of Contents
You're tasked to create a simple REST web service application for a fictional e-commerce business using Laravel.
You need to develop the following REST APIs:
- Products list
- Product detail
- Create product
- Update product
- Delete product
A product needs to have the following information:
- Product name
- Product description
- Product price
- Created at
- Updated at
- Products list API
- The products list API must be paginated.
- Create and Update product API
- The product name, description, and price must be required.
- The product name must accept a maximum of 255 characters.
- The product price must be numeric in type and must accept up to two decimal places.
- The created at and updated at fields must be in timestamp format.
Others:
- You are required to use MYSQL for the database storage in this test.
- You are free to use any library or component just as long as it can be installed using Composer.
- Don't forget to provide instructions on how to set the application up.
- Git
- Composer
- PHP ^8.0.2
- MySQL
Click here to generate a new repository from this template.
- Select your GitHub username as the owner.
- Name the repository
{FIRST NAME}-{LAST NAME}-coding-test
. (e.g.john-doe-coding-test
) - Make sure to set the repository visibility to Public.
- Clone your generated repository.
If automatically generating a new repository does not work, follow these steps instead.
- Click here to download the ZIP archive of the test.
- Create a new repository named
{FIRST NAME}-{LAST NAME}-coding-test
. (e.g.john-doe-coding-test
) - Push your code to the new repository.
- Cache the response of the Product detail API. You are free to use any cache driver.
- Use the Service layer and Repository design patterns.
- Create automated tests for the app.
Q: The management requested a new feature where in the fictional e-commerce app must have a "featured products" section. How would you go about implementing this feature in the backend?
A: The possible solution is to create a product_featured
table with columns of id
(pk), and product_id
(fk to products.id
). When a product is featured, we insert a record in the product_featured.product_id
with specified products.id
and when it is no longer featured, then we will remove the product_id
in the product_featured
table.
In retrieving this featured products in the backend, we can make join queries with this implementation in Laravel.
Product::join('product_featured', 'product_featured.product_id', '=', 'products.id')->all();
- run
composer install
(requires Composer: https://getcomposer.org) - configure
.env.example
to.env
please (also see: .env-backup) - run
php artisan key:generate
- run migrations
php artisan migrate:fresh --seed
- run development server
php artisan serve