This is a marketplace API, pretty much like a shopping cart. No excuses but I did this in two weekend days, it's not perfect...
- You'll need a Postgres database called marketplace;
- If you want to run the tests of the application you will also need a database called marketplace_test;
- As it was instructed I generated the dump of the DB using pg_dump, you can find it on the root directory of the project;
- In order to create the markeplace DB run:
createdb -U postgres -h localhost -p 5432 marketplace
- Then to restore the dump run:
psql -U postgres -h localhost -p 5432 -d marketplace < dump.sql
- Clone the repository: git clone https://github.com/matheus-rodrigues00/php_marketplace
- Install the dependencies: composer install
- On the project root "/", start the API:
php -S localhost:8080 -t public
- Here is the project interface but don't worry, you don't need to clone it, https://github.com/matheus-rodrigues00/marketplace_vue;
- The build of the frontend it is already on the root directory of the project. To run do the following commands:
npm install -g serve
serve -s dist
- That's it, you can access the interface on http://localhost:3000 || http://localhost:5000 (maybe you will need to change the port if it is already in use)
- I've already created a user for testing but feel free to create your own:
admin@admin.com
123456
- On the dashboard you can take a look on the Products and ProductTypes which are the main entities of this project. Briefly the ProductTypes gives the Tax Rate to the products in order to calculate the total price of the sale;
- You can add the products on the Products tab after log in and add the products to your cart;
- You can see your cart on the Cart tab and modify the product quantity or remove it;
- Also you can create a new product as well as create a new Product Type which will be used to add Taxes over the products;
- The main thing is on the cart, where you can visualize the total price of the sale and the total taxes;
I have also created a Postman collection with all the endpoints, you can find it on the root directory of the project.
- GET /products: Returns a list of all products.
- POST /products: Creates a new product.
- GET /products/{id}: Returns the details of a single product.
- PUT /products/{id}: Updates an existing product.
- DELETE /products/{id}: Deletes an existing product.
- GET /product-types: Returns a list of all product types.
- POST /product-types: Creates a new product type.
- GET /product-types/{id}: Returns the details of a single product type.
- PUT /product-types/{id}: Updates an existing product type.
- DELETE /product-types/{id}: Deletes an existing product type.
- POST /sales: Creates a new sale.
- GET /sales/{id}: Returns the details of a single sale.
- POST /sales/items: Adds a new item to a sale.
- PUT /sales/items: Updates an existing item in a sale.
- To run the tests you need to create a database called marketplace_test. to isolate the test enviroment.
- Go to the root directory and run:
php vendor/bin/phpunit tests/
- bramus/router: routing library for PHP;
- phpunit/phpunit: a testing framework for PHP;
- id (integer, primary key, auto increment)
- name (string)
- price (decimal)
- product_type_id (integer, foreign key references product_types(id))
- id (integer, primary key, auto increment)
- name (string)
- tax_rate (decimal)
- id (integer, primary key, auto increment)
- total (decimal)
- total_tax (decimal)
- created_at (timestamp)
- id (integer, primary key, auto increment)
- user_id (integer, foreign key references users(id))
- name (string)
- email (string, unique)
- password (string)
- id (integer, primary key, auto increment)
- sale_id (integer, foreign key references sales(id))
- product_id (integer, foreign key references products(id))
- quantity (integer)
- price (decimal)
- tax (decimal)
The script I have used to create the database is on db_creation_script.sql, you can use it as a reference :D
I hope you enjoy it!