A tech challenge, based on a Store API with Users, Consumers, Products and Sales, developed in PHP 8 + Laravel 8 with Sqlite.
This test was developed in Laradock project, but can be used in any other development or production environment prepared for Laravel 8. For more instructions to use Laradock, please access Laradock website.
To install this project, follow these steps :
- Clone this repository into the desired path;
- Run the command "composer install" to add all project depencies;
- Create a new .env file based on .env.example using "cp .env.example .env"
- Setup the .env as you like, you can use sqlite or mysql as database driver
- Run the command "php artisan migrate" to create all database structure
- If you want some test data, run the command "php artisan db:seed"
- In the end, run the command "php artisan key:generate"
With this, the application should be available in the domain that you choosed on your nginx
This API has four modules with basic CRUD operation : Customers, Products, Users, Sales. All of them are protected by authentication, to access, get the Bearer token using the login endpoint with the master admin and add to all your requests :
password | |
---|---|
[email protected] | masterpassword |
All requests must have Accept: application/json
in their headers.
In case of POST/PUT method, add too the Content-Type: application/json
header and send all body data in JSON format.
All endpoins will be displayed below and how to use them. If you're using Postman, you can import the API collection file using this : Collectionfile
Endpoint to retrieve Bearer token to access others api operations.
POST /login
{
"email" : "[email protected]",
"password" : "masterpassword"
}
Endpoint to logout user and destroy the active token
POST /logout
{
}
Endpoint to retrieve authenticated user
GET /me
Endpoint to retrieve all customers paginated.
GET /customers
Param | Description |
---|---|
page | Selected Page index |
Endpoint to retrieve a specific customer
GET /customers/:id
Param | Description |
---|---|
:id | UUID of an active customer |
Endpoint to create a customer
POST /customers
{
"name": "Bruno de Souza Rocha",
"tax_number": "111.111.111-12",
"birth_date": "1993-06-02"
}
Endpoint to update a customer
PUT /customers/:id
Param | Description |
---|---|
:id | UUID of an active customer |
{
"name": "Bruno de Souza Rocha",
"tax_number": "111.111.111-12",
"birth_date": "1993-06-02"
}
Endpoint to delete a customer
DELETE /customers/:id
Param | Description |
---|---|
:id | UUID of an active customer |
Endpoint to retrieve all products paginated.
GET /products
Param | Description |
---|---|
page | Selected Page index |
Endpoint to retrieve a specific product
GET /products/:id
Param | Description |
---|---|
:id | UUID of an active product |
Endpoint to create a product
POST /products
{
"name": "Cool Shoe",
"custom_id": "58455214541",
"batch_number": 202546,
"color": "Yellow",
"description": "A cool yellow shoe",
"value": 8001.00
}
Endpoint to update a product
PUT /products/:id
Param | Description |
---|---|
:id | UUID of an active product |
{
"name": "Cool Shoe",
"custom_id": "58455214541",
"batch_number": 202546,
"color": "Yellow",
"description": "A cool yellow shoe",
"value": 8002.00
}
Endpoint to delete a product
DELETE /products/:id
Param | Description |
---|---|
:id | UUID of an active product |
Endpoint to retrieve all batches from a product paginated.
GET /products/:product_id/batches
Param | Description |
---|---|
:product_id | UUID of an active product |
:id | UUID of an active product batch |
Param | Description |
---|---|
page | Selected Page index |
Endpoint to retrieve a specific product batch
GET /products/:product_id/batches/:id
Param | Description |
---|---|
:product_id | UUID of an active product |
:id | UUID of an active product batch |
Endpoint to create a product batch
POST /products/:product_id/batches
Param | Description |
---|---|
:product_id | UUID of an active product |
:id | UUID of an active product batch |
{
"custom_id": "58455214541",
"manufactured_at": "2016-12-14 06:44:05",
"batch_quantity": 202546
}
Endpoint to update a product batch
PUT /products/:product_id/batches/:id
Param | Description |
---|---|
:product_id | UUID of an active product |
:id | UUID of an active product batch |
Param | Description |
---|---|
:product_id | UUID of an active product |
:id | UUID of an active product batch |
{
"custom_id": "58455214541",
"manufactured_at": "2016-12-14 06:44:05",
"batch_quantity": 202546
}
Endpoint to delete a product batch
DELETE /products/:product_id/batches/:id
Param | Description |
---|---|
:product_id | UUID of an active product |
:id | UUID of an active product batch |
Endpoint to retrieve all users paginated.
GET /users
Param | Description |
---|---|
page | Selected Page index |
Endpoint to retrieve a specific user
GET /users/:id
Param | Description |
---|---|
:id | UUID of an active user |
Endpoint to create a user
POST /users
{
"name": "Joe Doe",
"email": "[email protected]",
"password": "password"
}
Endpoint to update a user
PUT /users/:id
Param | Description |
---|---|
:id | UUID of an active user |
{
"name": "Joe Doe",
"email": "[email protected]",
"password": "password"
}
Endpoint to delete a user
DELETE /users/:id
Param | Description |
---|---|
:id | UUID of an active user |
Endpoint to retrieve all sales paginated.
GET /sales
Param | Description |
---|---|
page | Selected Page index |
report | Activate report mode, with detailed data from sales. Set true to activate |
sort | Sort sales by field : created_at, value |
direction | Sort direction : asc, desc |
Endpoint to retrieve a specific sale
GET /sales/:id
Param | Description |
---|---|
:id | UUID of an active sale |
Endpoint to create a sale
POST /sales
{
"customer_id": "00df0b41-435e-4677-b896-c0234f9311a6",
"seller_id": "31b84cfe-4c67-484e-86d8-1c6065528942"
}
Endpoint to update a sale
PUT /sales/:id
Param | Description |
---|---|
:id | UUID of an active sale |
{
"customer_id": "00df0b41-435e-4677-b896-c0234f9311a6",
"seller_id": "31b84cfe-4c67-484e-86d8-1c6065528942"
}
Endpoint to delete a sale
DELETE /sales/:id
Param | Description |
---|---|
:id | UUID of an active sale |
Endpoint to retrieve all products from a sale paginated.
GET /sales/:sale_id/products
Param | Description |
---|---|
:sale_id | UUID of an active sale |
:id | UUID of an active sale product |
Param | Description |
---|---|
page | Selected Page index |
Endpoint to retrieve a specific sale product
GET /sales/:sale_id/products/:id
Param | Description |
---|---|
:sale_id | UUID of an active sale |
:id | UUID of an active sale product |
Endpoint to create a sale product
POST /sales/:sale_id/products
Param | Description |
---|---|
:sale_id | UUID of an active sale |
:id | UUID of an active sale product |
{
"product_id" : "f59cdd22-d4ef-4408-81c9-eb1e01abe229",
"quantity" : 500
}
Endpoint to update a sale product
PUT /sales/:sale_id/products/:id
Param | Description |
---|---|
:sale_id | UUID of an active sale |
:id | UUID of an active sale product |
Param | Description |
---|---|
:sale_id | UUID of an active sale |
:id | UUID of an active sale product |
{
"product_id" : "f59cdd22-d4ef-4408-81c9-eb1e01abe229",
"quantity" : 500
}
Endpoint to delete a sale product
DELETE /sales/:sale_id/products/:id
Param | Description |
---|---|
:sale_id | UUID of an active sale |
:id | UUID of an active sale product |
Create basic CRUD operations for each module below:
- customers
- products
- users
- sales
Both products and sales modules will gain more complex layers, making possible to control batches and detailing which product was sold
Now all operations will need an user, password Trying to use Laravel Sanctum or OAuth
Add options to return customer and product details into sales GET endpoint using Laravel Resource Collection
Convert project responses into JSON API patterns
Write units for each module created
Create a Dockerfile for this project