Skip to content

Commit

Permalink
Modified event handler to save invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
Lam-Pui Chan committed Apr 10, 2018
1 parent 5af28c3 commit 2d43429
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Binary file modified libs/trip-management-common-1.0.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public TripEventHandler() {}
public void on(TripCreatedEvent event) {
LOG.trace("Creating trip: {}", event.getId());
tripRepository.save(new Trip(event.getId(), event.getUserId(),
event.getOriginAddress(), event.getDestinationAddress(), TripStatus.CREATED));
event.getOriginAddress(), event.getDestinationAddress(), event.getTripInvoice(), TripStatus.CREATED));
LOG.info("Trip created: {}", event.getId());
}

Expand Down Expand Up @@ -55,12 +55,19 @@ public void on(TripCompletedEvent event) {

@EventHandler
public void on(TripUpdatedEvent event) {
LOG.trace("Completing trip: {}", event.getId());
LOG.trace("Updating trip: {}", event.getId());
Trip trip = tripRepository.findOne(event.getId());
trip.setStatus(TripStatus.COMPLETED);
if(!trip.getOriginAddress().equals(event.getOriginAddress())) {
LOG.info("Origin address updated: {}", event.getOriginAddress());
}
if(!trip.getDestinationAddress().equals(event.getDestinationAddress())) {
LOG.info("Destination address updated: {}", event.getDestinationAddress());
}
trip.setStatus(TripStatus.UPDATED);
trip.setOriginAddress(event.getOriginAddress());
trip.setDestinationAddress(event.getDestinationAddress());
trip.setTripInvoice(event.getTripInvoice());
tripRepository.save(trip);
LOG.info("Trip completed: {}", event.getId());
LOG.info("Trip updated: {}", event.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@
import java.util.UUID;
import javax.validation.constraints.NotNull;
import org.aitesting.microservices.tripmanagement.common.events.TripStatus;
import org.aitesting.microservices.tripmanagement.common.models.TripInvoice;

public class Trip {
@NotNull
private UUID id;
private UUID userId;
private String originAddress;
private String destinationAddress;

private TripInvoice tripInvoice;
private TripStatus status;

public Trip(UUID id, UUID userId, String originAddress, String destinationAddress, TripStatus status) {
public Trip(UUID id, UUID userId, String originAddress, String destinationAddress, TripInvoice tripInvoice, TripStatus status) {
this.id = id;
this.userId = userId;
this.originAddress = originAddress;
this.destinationAddress = destinationAddress;
this.tripInvoice = tripInvoice;
this.status = status;
}

Expand Down Expand Up @@ -52,4 +54,6 @@ public void setDestinationAddress(String destinationAddress) {
public void setStatus(TripStatus status) {
this.status = status;
}

public void setTripInvoice(TripInvoice tripInvoice) { this.tripInvoice = tripInvoice; }
}

0 comments on commit 2d43429

Please sign in to comment.