A car dealership management RESTful API developed as a Trybe Project
This application is a RESTful CRUD API to car dealership management applying Object-Oriented Programming principles, built in Model-Service-Controller architecture. The services are create, list all, list specific, update specific and delete specific car or motorcycle. The API also has some unit tests implemented.
- OOP concepts: Inheritance, Encapsulation, Abstraction, Polymorphism and Composition
- Implementation of TypeScript Classes, Instances, Attributes, Methods and Objects
To start up the application, follow the next steps:
As the project is containerized, to run the application you will need to install both softwares. The Docker Compose version supported by the project is 1.29 or higher. You can see here or in the docs how to install it.
In project root, create a .env
file with the following content:
MONGO_DB_URL=mongodb://localhost:27017/CarShop
Two Docker containers must be created in the process. The container with MongoDB service must be named as car_shop_db
and the container with back-end service must be named as car_shop
.
In project root, run:
docker-compose up -d
You can remove the containers running:
docker-compose down
You will need to execute car_shop
container bash inside it.
For it, in project root, run:
docker exec -it car_shop bash
In container's bash, run:
npm run dev
To use the API services you will can use a web browser or a client for testing APIs, like Thunder Client or Insomnia. The API endpoints are listed in the table below, as well as some examples of request body before the table. The default database is empty, so you will need first to seed some data with the first endpoint below.
You will need database IDs to use some endpoints. MongoDB generate random IDs, thus after registering some data, you will need to consult it in database, which can be done in terminal or using some extension as MongoDB for VS Code
Request body example to register or update a car:
{
"model": "Marea",
"year": 2002,
"color": "Black",
"status": true,
"buyValue": 15.990,
"doorsQty": 4,
"seatsQty": 5
}
Request body example to register or update a motorcycle:
{
"model": "Honda Cb 600f Hornet",
"year": 2005,
"color": "Yellow",
"status": true,
"buyValue": 30.000,
"category": "Street",
"engineCapacity": 600
}
Services and endpoints:
Service | Method | Endpoint |
---|---|---|
Register a car | POST | http://localhost:3001/cars |
List all cars | GET | http://localhost:3001/cars |
List specific car | GET | http://localhost:3001/cars/:id |
Update specific car | PUT | http://localhost:3001/cars/:id |
Delete specific car | DELETE | http://localhost:3001/cars/:id |
Register a motorcycle | POST | http://localhost:3001/motorcycles |
List all motorcycles | GET | http://localhost:3001/motorcycles |
List specific motorcycle | GET | http://localhost:3001/motorcycles/:id |
Update specific motorcycle | PUT | http://localhost:3001/motorcycles/:id |
Delete specific motorcycle | DELETE | http://localhost:3001/motorcycles/:id |
For testing, optionally, you can stop car_shop_db
container, by running in a terminal:
docker stop car_shop_db
To execute the tests, in car_shop
container's bash, run:
npm run test:mocha
To execute the tests and see a coverage summary table, run:
npm run test:coverage