API for Compass Car to manage vehicles with CRUD and validation
- Register new cars
- Update car information
- Soft-delete cars
- List all available cars (with pagination)
- Search for cars by query
- Field validation (e.g., license plate, year, etc.)
- Node.js
- Express
- sequelize
- mysql
- dotenv
-
Clone the repository:
git clone https://github.com/your-username/ANMAR25_D01_COMPASSCAR.git cd aws-node-mar25-car-api -
Install dependencies
npm install
-
Database setup
This project uses MySQL as the relational database and Sequelize as the ORM (Object Relational Mapper).
You can use XAMPP or MySQL Workbench to setup a MySQL Database on your machine.
With MySQL Server running, create a new database before running the application
CREATE DATABASE compasscar
You must have MySQL Server installed and running on your machine before starting the project.
-
Environment setup
Create a
.envfile in the root of your project as shown in.env-examplePORT=your_server_port DB_NAME=your_database_name DB_USER=your_database_user DB_PASSWORD=your_database_password DB_DIALECT=mysql DB_HOST=localhostIf database credentials are not provided, the following will be used
PORT=3000 DB_NAME=compasscar DB_USER=root DB_PASSWORD= DB_DIALECT=mysql DB_HOST=localhost -
Run the application
To make sure the API is running as expected, run the command
npm run testTo start the server, run the command
npm run server
http://localhost:your_server_port/api/v1
Creates a new car
{ "brand": "Marca", "model": "Modelo", "year": 2018, "plate": "ABC-1D23" }201 Created: Returns the created car information400 Bad Request: If validation fails, returns an object with errors messages409 Conflict: Car already exists
Retrieves a paginated list of cars. Accepts optional query parameters for filtering and pagination:
page(number): The page number (default: 1)limit(number): Maximum number of items per page (default: 5)year(number): Filter by car yearfinal_plate(number): Filter by the last digit of the license plate (0-9)brand(string): Filter by brand name (partial match allowed)
200 OK: Returns the paginated list of cars
Retrieves a specific car.
200 OK: Returns car information404 Not Found: The requested resource could not be found on the server
Creates a new item or update an existing one if already exists
["Ar condicionado", "Trava Eletrica", "Vidro Eletrico"]204 No Content: No body is returned404 Not Found: The requested resource could not be found on the server400 Bad Request: If validation fails, returns an object with errors messages
Update a specific car information
{ "brand": "Fiat", "model": "Uno", "year": "2022", "plate": "ABC-1D23" }204 No Content: No body is returned404 Not Found: The requested resource could not be found on the server400 Bad Request: If validation fails, returns an object with errors messages409 Conflict: Car already exists with same plate
Delete a car and its items from the server
204 No Content: No body is returned404 Not Found: The requested resource could not be found on the server