feat: #1316 Single Table Inheritance pattern implemented (#2632)

* implemented single table inheritance

* added the Java documentation for the pattern

* updated code files as per the standards

* added the puml and png diagram for the file

* added README.md

* #1316 Single Table Inheritance pattern implemented

* resolved the Checkstyle violations

* removed the tests due to build failure

* updated the code as per review

* resolved Checkstyle violations
This commit is contained in:
Ved Asole
2024-02-25 17:50:13 +05:30
committed by GitHub
parent 79d41d9336
commit b2c7410c03
16 changed files with 811 additions and 0 deletions
@@ -0,0 +1,71 @@
package com.iluwatar.service;
import com.iluwatar.entity.Vehicle;
import com.iluwatar.repository.VehicleRepository;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* A service class that is used to provide the business logic
* for the Vehicle class and connect to the database to
* perform the CRUD operations on the root Vehicle class.
*
* @see Vehicle
*/
@Service
@AllArgsConstructor
public class VehicleService {
private final VehicleRepository vehicleRepository;
/**
* A method to save all the vehicles to the database.
*
* @param vehicle Vehicle bbject
* @see Vehicle
*/
public Vehicle saveVehicle(Vehicle vehicle) {
return vehicleRepository.save(vehicle);
}
/**
* A method to get a specific vehicle from vehicle id.
*
* @param vehicleId Vehicle Id
* @see Vehicle
*/
public Vehicle getVehicle(int vehicleId) {
return vehicleRepository.findById(vehicleId).orElse(null);
}
/**
* A method to get all the vehicles saved in the database.
*
* @see Vehicle
*/
public List<Vehicle> getAllVehicles() {
return vehicleRepository.findAll();
}
/**
* A method to update a vehicle in the database.
*
* @param vehicle Vehicle object
* @see Vehicle
*/
public Vehicle updateVehicle(Vehicle vehicle) {
return vehicleRepository.save(vehicle);
}
/**
* A method to save all the vehicles to the database.
*
* @param vehicle Vehicle object
* @see Vehicle
*/
public void deleteVehicle(Vehicle vehicle) {
vehicleRepository.delete(vehicle);
}
}