Skip to content

garciaagui/car-shop

Repository files navigation

Project Car Shop 🚙🛵

🇧🇷 Clique aqui para acessar a versão em português.

Summary

  1. Description
  2. Technologies
  3. Features
  4. How to Run
  5. Endpoints
  6. About Trybe
  7. Contact

Description

27th project of the Trybe Web Development course.

In this project, an API for managing a vehicle dealership was developed, which allows the creation, viewing, updating, and deletion (CRUD) of cars and motorcycles.

The application was developed using Node.js and TypeScript, and the chosen database was MongoDB. The connection to the database was made through the Mongoose framework, an Object-Document Mapping (ODM) that facilitates interactions with MongoDB.

To ensure code quality, important software development principles such as OOP (Object-Oriented Programming), SOLID and DDD (Domain Driven Design) were applied. This makes the application more scalable and performant.

To guarantee that the code works properly, unit tests were created with the BDD (Behavior-driven development) approach. This process ensures that the application is always in good condition and ready to receive updates.


Technologies

💻 Development

🧪 Testing

✨ Code alignment and quality


Features

  • Create, list, update, and delete cars.
  • Create, list, update, and delete motorcycles.

How to Run

To run the project, follow the steps below.

  1. Clone the repository;
git clone [email protected]:garciaagui/car-shop.git
  1. Navigate to the project root;
cd car-shop/

⚠️ Now, decide whether the project will be run locally or via Docker.

💽 Locally
  1. Make sure you have Node.js installed in version 16 or higher. Check out the official documentation for more information.

  2. In the project root, install the project dependencies.

npm install
  1. Configure the environment variables:
  • Rename the .env.example file (available in the project root) to .env;
  • Set the variables for your local environment.
  1. Start the server:
npm run dev
  • To run the tests, you can use the two commands below.
// Command 1
npm run test:mocha

// Command 2 - In this command you have access to the test coverage
npm run test:coverage
🐋 Docker
  1. Make sure you have docker-compose installed in version 1.29 or higher. Useful links if you need to install or update: DigitalOcean Tutorial and official documentation;

  2. Bring up the containers by running the command below. Two containers will be initialized: car_shop (node) and car_shop_db (mysql).

docker-compose up -d --build
  1. Access the CLI of the car_shop container with the command below or open it in VS Code. For the latter option, I recommend the Microsoft extension Dev Containers.
docker exec -it car_shop bash

⚠️ From now on, ALL commands (scripts) available in package.json (including npm install) must be executed INSIDE the car_shop container.

  1. Install the project dependencies.
npm install
  1. Start the server:
npm run dev
  • To run the tests, you can use the two commands below.
// Command 1
npm run test:mocha

// Command 2 - In this command you have access to the test coverage
npm run test:coverage
  • For the local test context, follow the steps below:
  1. Rename the .env.example file (available in the project root) to .env;
  2. Set the variables for your local environment.

Endpoints

Below you can find a breakdown of the endpoints used in the project. To make HTTP requests and check the behavior of each endpoint, you can use the Thunder Client extension.

ℹ️ For all endpoints that require the id of cars and motorcycles, note that the id is an ObjectId. Learn more about ObjectId here.

Cars

GET /cars

  • Returns all cars registered in the database.
  • URL: http://localhost:PORT/cars

POST /cars

  • Adds a new car to the database.
  • URL: http://localhost:PORT/cars
  • The request body must follow the format below:
{
  "model": "Marea",
  "year": 2002,
  "color": "Black",
  "status": true, // Not required. If not inserted, the value of status will be 'false'
  "buyValue": 15.990,
  "doorsQty": 4,
  "seatsQty": 5
}

GET /cars/:id

  • Returns the car whose id was passed in the URL.
  • Example URL: http://localhost:PORT/cars/634852326b35b59438fbea2f

PUT /cars/:id

  • Updates the car whose id was passed in the URL.
  • Example URL: http://localhost:PORT/cars/634852326b35b59438fbea2f
  • The request body must follow the format below:
{
  "model": "Marea",
  "year": 1992,
  "color": "Red",
  "status": true, // Not required. If not inserted, the value of status will be 'false'
  "buyValue": 12.000,
  "doorsQty": 2,
  "seatsQty": 5
}

DELETE /cars/:id

  • Removes from the database the car whose id was passed in the URL.
  • Example URL: http://localhost:PORT/cars/634852326b35b59438fbea2f

Motorcycles

GET /motorcycles

  • Returns all motorcycles registered in the database.
  • URL: http://localhost:PORT/motorcycles

POST /motorcycles

  • Adds a new motorcycle to the database.
  • URL: http://localhost:PORT/motorcycles
  • The request body must follow the format below:
{
  "model": "Honda Cb 600f Hornet",
  "year": 2005,
  "color": "Yellow",
  "status": true, // Not required. If not inserted, the value of status will be 'false'
  "buyValue": 30.000,
  "category": "Street", // Accepted values: "Street", "Custom" or "Trail"
  "engineCapacity": 600
}

GET /motorcycles/:id

  • Returns the motorcycle whose id was passed in the URL.
  • Example URL: http://localhost:PORT/motorcycles/634852326b35b59438fbea2f

PUT /motorcycles/:id

  • Updates the motorcycle whose id was passed in the URL.
  • Example URL: http://localhost:PORT/motorcycles/634852326b35b59438fbea2f
  • The request body must follow the format below:
{
  "model": "Honda Cb 600f Hornet",
  "year": 2014,
  "color": "Red",
  "status": true, // Not required. If not inserted, the value of status will be 'false'
  "buyValue": 45.000,
  "category": "Street", // Accepted values: "Street", "Custom" or "Trail"
  "engineCapacity": 600
}

DELETE /motorcycles/:id

  • Removes from the database the motorcycle whose id was passed in the URL.
  • Example URL: http://localhost:PORT/motorcycles/634852326b35b59438fbea2f


About Trybe

"Trybe is a future school for anyone who wants to improve their lives and build a successful career in technology, where the person only pays when they get a good job."

"The program features over 1,500 hours of online classes covering introduction to software development, front-end, back-end, computer science, software engineering, agile methodologies, and behavioral skills."


Contact

Project developed by Guilherme Garcia. Below are my social networks and means of contact. 🤘

Gmail Linkedin GitHub Instagram

Voltar ao topo