Class VehicleService
java.lang.Object
com.example.vehicletaxsystem.services.VehicleService
Service class to handle the logic for vehicle queries.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DriverRepositoryprivate final TaxBandRepositoryprivate final VehicleRepository -
Constructor Summary
ConstructorsConstructorDescriptionVehicleService(VehicleRepository vehicleRepository, DriverRepository driverRepository, TaxBandRepository taxBandRepository) -
Method Summary
Modifier and TypeMethodDescriptionaddVehicle(VehicleDTO vehicleDTO) Saves a new vehicle into the database.private VehicleDTOconvertToVehicleDTO(Vehicle vehicle) Method to find all vehiclesgetVehicleDTOByRegNumber(String regNumber) Method to find a specific vehicle based on the registration number of the vehicle.Method to find all vehicles which have a tax due date recorded as prior to the current day.updateVehicleTaxBand(String regNumber, VehicleDTO vehicleDTO) 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.
-
Field Details
-
vehicleRepository
-
driverRepository
-
taxBandRepository
-
-
Constructor Details
-
VehicleService
public VehicleService(VehicleRepository vehicleRepository, DriverRepository driverRepository, TaxBandRepository taxBandRepository)
-
-
Method Details
-
convertToVehicleDTO
-
getAllVehicles
Method to find all vehicles- Returns:
- List of all vehicles in the database
-
getVehiclesWithTaxOverDue
Method to find all vehicles which have a tax due date recorded as prior to the current day.- Returns:
- List of vehicles
-
getVehicleDTOByRegNumber
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
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 updatedvehicleDTO- new details for the vehicle being updated- Returns:
- updated vehicle
- Throws:
InvalidTaxBandException- if the tax band within the updated vehicle is invalid
-