Skip to content

Latest commit

 

History

History
217 lines (184 loc) · 8.03 KB

File metadata and controls

217 lines (184 loc) · 8.03 KB

Car Management System

Description

The Car Management System is a RESTful application designed to manage cars and their details, offering features like adding, updating, deleting, searching, pagination, and sorting. The system ensures data integrity through validations and provides a user-friendly interface for developers via APIs.

Note:

  • Use tools like Postman to interact with the Car Management System by sending requests and viewing responses in a user-friendly interface.
  • For command-line testing, cURL or similar tools can be used to simulate API requests.
  • Ensure the API endpoints are correctly configured to match the deployment URL:
    https://car-management-system-production.up.railway.app.
  • All API endpoints are mapped under the base path api/cars.
    For example:
    https://car-management-system-production.up.railway.app/api/cars/getAllCars.

Table of Contents

  1. API Endpoints
  2. Validations
  3. Technologies Used
  4. Running Locally

API Endpoints

1. Get All Cars

  • URL: https://car-management-system-production.up.railway.app/api/cars/getAllCars
  • Method: GET
  • Description: Fetches a list of all cars in the database.
  • Response: Returns a list of cars as CarDTO objects.

2. Add Cars

  • URL: https://car-management-system-production.up.railway.app/api/cars/addCars
  • Method: POST
  • Description: Adds a list of cars to the database.
  • Request Body:
    [
      {
        "carName": "Tesla Model S",
        "carModel": "Model S",
        "carColor": "White",
        "carPrice": 75000,
        "carYear": 2022,
        "carFuelType": "Electric"
      }
    ]
  • Response: Returns the added cars as CarDTO objects.
  • Validations:
    • carName: Cannot be blank.
    • carModel: Cannot be blank.
    • carColor: Cannot be blank.
    • carPrice: Must be a positive number.
    • carYear: Must be a valid 4-digit year and not exceed the current year.
    • carFuelType: Must be one of the following:
      • Petrol
      • Diesel
      • Electric
      • Hybrid
      • CNG
      • LPG
      • petrol
      • diesel
      • electric
      • hybrid
      • cng
      • lpg

3. Update Car by ID

  • URL: https://car-management-system-production.up.railway.app/api/cars/updateCarById/{id}
  • Method: PUT
  • Description: Updates the details of a car with the given ID.
  • Request Parameters:
    • id: The ID of the car to be updated.
  • Request Body:
    {
      "id":41,
      "carName": "Tesla Model X",
      "carModel": "Model X",
      "carColor": "Black",
      "carPrice": 85000,
      "carYear": 2023,
      "carFuelType": "Electric"
    }
  • Response: Updated car details as a CarDTO object.

4. Delete Car by ID

  • URL: https://car-management-system-production.up.railway.app/api/cars/deleteCarById/{id}
  • Method: DELETE
  • Description: Deletes a car with the given ID from the database.
  • Request Parameters:
    • id: The ID of the car to be deleted.
  • Response: Returns the details of the deleted car as a CarDTO object.

5. Search Cars

  • URL: https://car-management-system-production.up.railway.app/api/cars/search
  • Method: GET
  • Description: Searches for cars based on the provided criteria.
  • Request Parameters (Optional):
    • name: Name of the car.
    • model: Model of the car.
    • year: Year of manufacture.
    • color: Color of the car.
    • fuelType: Fuel type of the car.
  • Response: Returns a list of cars matching the criteria.

Sample Api

6. Get Cars with Pagination

  • URL: https://car-management-system-production.up.railway.app/api/cars/pagination
  • Method: GET
  • Description: Fetches cars with pagination.
  • Request Parameters:
    • page (default: 0): Page number (starts from 0).
    • size (default: 10): Number of records per page.
  • Response: Returns a paginated list of cars.

Sample Api

7. Get Cars with Sorting

  • URL: https://car-management-system-production.up.railway.app/api/cars/sorting
  • Method: GET
  • Description: Fetches cars sorted by a specified field.
  • Request Parameters:
    • sortBy (default: carName): Field to sort by.
    • order (default: asc): Sorting order. (asc or desc)
  • Response: Returns a sorted list of cars.

Sample Api

8. Get Cars with Pagination and Sorting

  • URL: https://car-management-system-production.up.railway.app/api/cars/pagination-sorting
  • Method: GET
  • Description: Fetches cars with both pagination and sorting.
  • Request Parameters:
    • page (default: 0): Page number.
    • size (default: 10): Number of records per page.
    • sortBy (default: carName): Field to sort by.
    • order (default: asc): Sorting order. (asc or desc)
  • Response: Returns a paginated and sorted list of cars.

Sample Api

Validations

CarDTO Validations:

  • carName: Cannot be blank.
  • carModel: Cannot be blank.
  • carColor: Cannot be blank.
  • carPrice: Must be a positive number.
  • carYear: Must be a valid year and not exceed the current year.
  • carFuelType: Must be one of the following:
    • Petrol
    • Diesel
    • Electric
    • Hybrid
    • CNG
    • LPG

Technologies Used

  • Spring Boot: For building the RESTful APIs.
  • Hibernate/JPA: For database interactions.
  • ModelMapper: For object mapping between entities and DTOs.
  • Jakarta Validation: For input validations.
  • Maven: For dependency management.
  • Mysql: For database management.

Running Locally

To run the Car Management System locally, follow these steps:

  1. Clone the Repository: Clone the project from your version control system (e.g., GitHub) to your local machine.

    git clone https://your-repository-link.git
  2. Navigate to the Project Directory: Open your terminal/command prompt and navigate to the project directory.

  3. Modify application.properties: Update the application.properties file with your local configuration settings (e.g., database URL, credentials):

    Example configuration for application.properties:

    spring.datasource.url=jdbc:mysql://localhost:3306/car_management
    spring.datasource.username=root
    spring.datasource.password=your_password
    spring.jpa.hibernate.ddl-auto=update
    spring.jpa.properties.hibernate.format_sql=true
  4. Build the Project: Use Maven to build the project.

    mvn clean install
  5. Run the Project: After building, you can run the application with the following command:

    mvn spring-boot:run
  6. Test the API Endpoints with Postman: Use Postman to test the API endpoints. The URLs will be the same as the ones mentioned earlier, but replace the deployment link with http://localhost:8080 if you are running it locally.

    Example:

    • URL: http://localhost:8080/api/cars/getAllCars
    • Method: GET

    Postman will allow you to interact with the REST API by sending requests and viewing responses in a user-friendly way.