Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
othmanel
MicroservicesLab
Commits
972e11d7
Commit
972e11d7
authored
Nov 16, 2018
by
Thomas
Browse files
Expanding Vehicle microservice functionality
parent
70df6ac1
Changes
5
Hide whitespace changes
Inline
Side-by-side
vehicle-microservice/src/main/java/edu/microserviceslab/vehiclemicroservice/VehicleApplication.java
0 → 100644
View file @
972e11d7
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
);
}
}
vehicle-microservice/src/main/java/edu/microserviceslab/vehiclemicroservice/controller/VehicleController.java
View file @
972e11d7
...
...
@@ -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
);
}
}
vehicle-microservice/src/main/java/edu/microserviceslab/vehiclemicroservice/entity/Vehicle.java
View file @
972e11d7
...
...
@@ -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
{
...
...
vehicle-microservice/src/main/java/edu/microserviceslab/vehiclemicroservice/service/VehicleServiceImpl.java
View file @
972e11d7
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
;
}
}
vehicle-microservice/src/main/java/edu/microserviceslab/vehiclemicroservice/service/interfaces/VehicleService.java
View file @
972e11d7
...
...
@@ -7,4 +7,6 @@ import java.util.List;
public
interface
VehicleService
{
List
<
Vehicle
>
getAllVehicles
();
String
getVehicleLicensePlate
(
Long
vehicleId
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment