Commit 972e11d7 authored by Thomas's avatar Thomas
Browse files

Expanding Vehicle microservice functionality

parent 70df6ac1
package edu.microserviceslab.vehiclemicroservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class VehicleApplication {
public static void main(String[] args) {
SpringApplication.run(VehicleApplication.class, args);
}
}
......@@ -2,9 +2,7 @@ package edu.microserviceslab.vehiclemicroservice.controller;
import edu.microserviceslab.vehiclemicroservice.entity.Vehicle;
import edu.microserviceslab.vehiclemicroservice.service.interfaces.VehicleService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -23,4 +21,10 @@ public class VehicleController {
public List<Vehicle> listAllVehicles() {
return vehicleService.getAllVehicles();
}
@ResponseBody
@RequestMapping("/licensePlate/{vehicleId}")
public String getVehicleLicensePlate(@PathVariable("vehicleId") Long vehicleId) {
return vehicleService.getVehicleLicensePlate(vehicleId);
}
}
......@@ -5,7 +5,6 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import javax.persistence.*;
import java.time.Year;
@Entity
public class Vehicle {
......
package edu.microserviceslab.vehiclemicroservice.service;
import edu.microserviceslab.vehiclemicroservice.entity.Registration;
import edu.microserviceslab.vehiclemicroservice.entity.Vehicle;
import edu.microserviceslab.vehiclemicroservice.repo.VehicleRepo;
import edu.microserviceslab.vehiclemicroservice.service.interfaces.VehicleService;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class VehicleServiceImpl implements VehicleService {
......@@ -20,4 +22,19 @@ public class VehicleServiceImpl implements VehicleService {
public List<Vehicle> getAllVehicles() {
return vehicleRepo.findAll();
}
@Override
public String getVehicleLicensePlate(Long vehicleId) {
Optional<Vehicle> vehicle = vehicleRepo.findById(vehicleId);
String toReturn = null;
if (vehicle.isPresent()) {
Registration registration = vehicle.get().getRegistration();
if (registration != null) {
toReturn = registration.getLicensePlate();
}
}
return toReturn;
}
}
......@@ -7,4 +7,6 @@ import java.util.List;
public interface VehicleService {
List<Vehicle> getAllVehicles();
String getVehicleLicensePlate(Long vehicleId);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment