Class VehicleService

java.lang.Object
com.example.vehicletaxsystem.services.VehicleService

@Service public class VehicleService extends Object
Service class to handle the logic for vehicle queries.
  • Field Details

  • Constructor Details

  • Method Details

    • convertToVehicleDTO

      private VehicleDTO convertToVehicleDTO(Vehicle vehicle)
    • getAllVehicles

      public List<VehicleDTO> getAllVehicles()
      Method to find all vehicles
      Returns:
      List of all vehicles in the database
    • getVehiclesWithTaxOverDue

      public List<VehicleDTO> getVehiclesWithTaxOverDue()
      Method to find all vehicles which have a tax due date recorded as prior to the current day.
      Returns:
      List of vehicles
    • getVehicleDTOByRegNumber

      public VehicleDTO getVehicleDTOByRegNumber(String regNumber)
      Method to find a specific vehicle based on the registration number of the vehicle. First returns a list of all vehicles, not as efficient as findBy() I would assume, but mirrors lectures.
      Parameters:
      regNumber - string representing the registration to search for - case insensitive.
      Returns:
      vehicle from the database which matches the registration number being searched for if it exists, otherwise null.
    • addVehicle

      public VehicleDTO addVehicle(VehicleDTO vehicleDTO)
      Saves a new vehicle into the database.
      Parameters:
      vehicleDTO - vehicle that is to be saved into the database
      Returns:
      vehicle object saved into the database or null
    • updateVehicleTaxBand

      public VehicleDTO updateVehicleTaxBand(String regNumber, VehicleDTO vehicleDTO) throws InvalidTaxBandException
      Method for updating a vehicle's tax band - could be used in cases where a vehicle has been modified causing it to change bands, or if there's universal changes to bandings.
      Parameters:
      regNumber - registration number of the vehicle to be updated
      vehicleDTO - new details for the vehicle being updated
      Returns:
      updated vehicle
      Throws:
      InvalidTaxBandException - if the tax band within the updated vehicle is invalid