I developed the API following the MSC (model-service-controller) architecture.
The API is a dropshipping sales management system where you can create, view, delete and update products and sales. MySQL database is used for data management. Unit tests were also developed for all application layers. Also, the API is RESTful.
Express was used to create the routes and manage them, Sinon was used to mocha the functions, both internal and database access. The Chai was used to create the tests.
Installation instructions
git clone git@github.com:lucas-da-silva/project-store-manager.git
cd project-store-manager
docker-compose up -d
docker exec -it store_manager bash
npm install
npm run migration
npm run seed
npm start
You can use Thunder Client or Insomnia (or whatever) to check the API.
npm test
docker-compose down
As the MSC software architecture was used, the database access functions are in the Model layer, the business rules validations are in the Service layer, and the contact with request and return are in the Controller layer.
In the routes directory we have the definition of all routes. And they are the following:
-
GET /products
: all products are returned; -
GET /products/:id
: only the product with theid
present in the URL is returned; -
GET /products/search
: returns products based onq
from the database, if it exists;The query params of the request should follow the format below:
http://localhost:PORT/products/search?q=Martelo
-
DELETE /products/:id
: only the product with theid
present in the URL is deleted; -
PUT /products/:id
: only the product with theid
present in the URL is updated;The request body should follow the format below
{ "name": "Martelo do Batman" }
-
POST /products
: register a new product in the database;The request body should follow the format below
{ "name": "ProdutoX" }
-
GET /sales
: all sales are returned; -
GET /sales/:id
: only the sale with theid
present in the URL is returned; -
DELETE /products/:id
: only the sale with theid
present in the URL is deleted; -
PUT /sales/:id
: only the sale with theid
present in the URL is updated;The request body should follow the format below
[ { "productId": 1, "quantity": 10 }, { "productId": 2, "quantity": 50 } ]
-
POST /sales
: register a new sale, being possible to register several products through the same request;The request body should follow the format below
{ "name": "ProdutoX" }
There are middlewares that were created to validate the data sent in the requests.
And also, unit tests for each of these routes, middlewares and validations in the tests/unit directory.
I got the badges from github from Iuri;