Skip to content

Commit

Permalink
Merge pull request microservices-patterns#97 from dartartem/development
Browse files Browse the repository at this point in the history
Improved swagger documentation.
  • Loading branch information
cer authored Apr 30, 2020
2 parents f9809a6 + 999fe3e commit 8db1160
Show file tree
Hide file tree
Showing 25 changed files with 77 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.eventuate.local.java.spring.javaclient.driver.EventuateDriverConfiguration;
import io.eventuate.tram.spring.commands.producer.TramCommandProducerConfiguration;
import io.eventuate.tram.spring.jdbckafka.TramJdbcKafkaConfiguration;
import net.chrisrichardson.eventstore.examples.customersandorders.commonswagger.CommonSwaggerConfiguration;
import net.chrisrichardson.ftgo.accountingservice.messaging.AccountingMessagingConfiguration;
import net.chrisrichardson.ftgo.accountingservice.web.AccountingWebConfiguration;
import org.springframework.boot.SpringApplication;
Expand All @@ -15,7 +16,8 @@
@Import({AccountingMessagingConfiguration.class, AccountingWebConfiguration.class,
TramCommandProducerConfiguration.class,
EventuateDriverConfiguration.class,
TramJdbcKafkaConfiguration.class})
TramJdbcKafkaConfiguration.class,
CommonSwaggerConfiguration.class})
public class AccountingServiceMain {

public static void main(String[] args) {
Expand Down
3 changes: 3 additions & 0 deletions ftgo-delivery-service-api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
compile project(":ftgo-common")
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package net.chrisrichardson.ftgo.deliveryservice.api.web;

public class ActionInfo {
private String type;
private DeliveryActionType type;

public ActionInfo() {
}

public ActionInfo(String type) {
public ActionInfo(DeliveryActionType type) {
this.type = type;
}

public String getType() {
public DeliveryActionType getType() {
return type;
}

public void setType(String type) {
public void setType(DeliveryActionType type) {
this.type = type;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package net.chrisrichardson.ftgo.deliveryservice.api.web;

public enum DeliveryActionType { PICKUP, DROPOFF
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
public class DeliveryInfo {

private long id;
private String state;
private DeliveryState state;

public DeliveryInfo() {
}

public DeliveryInfo(long id, String state) {
public DeliveryInfo(long id, DeliveryState state) {

this.id = id;
this.state = state;
Expand All @@ -22,11 +22,11 @@ public void setId(long id) {
this.id = id;
}

public String getState() {
public DeliveryState getState() {
return state;
}

public void setState(String state) {
public void setState(DeliveryState state) {
this.state = state;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.chrisrichardson.ftgo.deliveryservice.domain;
package net.chrisrichardson.ftgo.deliveryservice.api.web;

public enum DeliveryState {
CANCELLED, SCHEDULED, PENDING
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package net.chrisrichardson.ftgo.deliveryservice.domain;

import net.chrisrichardson.ftgo.deliveryservice.api.web.DeliveryActionType;
import net.chrisrichardson.ftgo.common.Address;

import javax.persistence.Embeddable;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import java.time.LocalDateTime;

@Embeddable
public class Action {

@Enumerated(EnumType.STRING)
private ActionType type;
private DeliveryActionType type;
private Address address;
private LocalDateTime time;

Expand All @@ -21,7 +21,7 @@ public class Action {
private Action() {
}

public Action(ActionType type, long deliveryId, Address address, LocalDateTime time) {
public Action(DeliveryActionType type, long deliveryId, Address address, LocalDateTime time) {
this.type = type;
this.deliveryId = deliveryId;
this.address = address;
Expand All @@ -33,15 +33,15 @@ public boolean actionFor(long deliveryId) {
}

public static Action makePickup(long deliveryId, Address pickupAddress, LocalDateTime pickupTime) {
return new Action(ActionType.PICKUP, deliveryId, pickupAddress, pickupTime);
return new Action(DeliveryActionType.PICKUP, deliveryId, pickupAddress, pickupTime);
}

public static Action makeDropoff(long deliveryId, Address deliveryAddress, LocalDateTime deliveryTime) {
return new Action(ActionType.DROPOFF, deliveryId, deliveryAddress, deliveryTime);
return new Action(DeliveryActionType.DROPOFF, deliveryId, deliveryAddress, deliveryTime);
}


public ActionType getType() {
public DeliveryActionType getType() {
return type;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.chrisrichardson.ftgo.deliveryservice.domain;

import net.chrisrichardson.ftgo.common.Address;
import net.chrisrichardson.ftgo.deliveryservice.api.web.DeliveryState;

import javax.persistence.*;
import java.time.LocalDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ private DeliveryStatus makeDeliveryStatus(Delivery delivery, Long assignedCourie
}

private DeliveryInfo makeDeliveryInfo(Delivery delivery) {
return new DeliveryInfo(delivery.getId(), delivery.getState().name());
return new DeliveryInfo(delivery.getId(), delivery.getState());
}

private ActionInfo makeActionInfo(Action action) {
return new ActionInfo(action.getType().name());
return new ActionInfo(action.getType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ public DeliveryServiceController(DeliveryService deliveryService) {
}

@RequestMapping(path="/couriers/{courierId}/availability", method= RequestMethod.POST)
public ResponseEntity<String> updateCourierLocation(@PathVariable long courierId, @RequestBody CourierAvailability availability) {
public void updateCourierLocation(@PathVariable long courierId, @RequestBody CourierAvailability availability) {
deliveryService.updateAvailability(courierId, availability.isAvailable());
return new ResponseEntity<>(HttpStatus.OK);
}

@RequestMapping(path="/deliveries/{deliveryId}", method= RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.chrisrichardson.ftgo.deliveryservice.domain;

import net.chrisrichardson.ftgo.deliveryservice.api.web.DeliveryActionType;
import net.chrisrichardson.ftgo.deliveryservice.api.web.DeliveryState;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
Expand Down Expand Up @@ -86,9 +88,9 @@ public void shouldScheduleDelivery() {

List<Action> actions = courier.getPlan().getActions();
assertEquals(2, actions.size());
assertEquals(ActionType.PICKUP, actions.get(0).getType());
assertEquals(DeliveryActionType.PICKUP, actions.get(0).getType());
assertEquals(DeliveryServiceTestData.PICKUP_ADDRESS, actions.get(0).getAddress());
assertEquals(ActionType.DROPOFF, actions.get(1).getType());
assertEquals(DeliveryActionType.DROPOFF, actions.get(1).getType());
assertEquals(DeliveryServiceTestData.DELIVERY_ADDRESS, actions.get(1).getAddress());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private void verifyOrderRevised(int orderId) {

private void reviseOrder(int orderId) {
given().
body(new ReviseOrderRequest(new RevisedOrderLineItem[] {new RevisedOrderLineItem(revisedQuantityOfChickenVindaloo, CHICKED_VINDALOO_MENU_ITEM_ID)}))
body(new ReviseOrderRequest(Collections.singletonList(new RevisedOrderLineItem(revisedQuantityOfChickenVindaloo, CHICKED_VINDALOO_MENU_ITEM_ID))))
.contentType("application/json").
when().
post(orderBaseUrl(Integer.toString(orderId), "revise")).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import io.eventuate.tram.commands.common.Command;
import net.chrisrichardson.ftgo.common.RevisedOrderLineItem;

import java.util.List;
import java.util.Map;

public class BeginReviseTicketCommand implements Command {
private long restaurantId;
private Long orderId;
private RevisedOrderLineItem[] revisedOrderLineItems;
private List<RevisedOrderLineItem> revisedOrderLineItems;

private BeginReviseTicketCommand() {
}

public BeginReviseTicketCommand(long restaurantId, Long orderId, RevisedOrderLineItem[] revisedOrderLineItems) {
public BeginReviseTicketCommand(long restaurantId, Long orderId, List<RevisedOrderLineItem> revisedOrderLineItems) {
this.restaurantId = restaurantId;
this.orderId = orderId;
this.revisedOrderLineItems = revisedOrderLineItems;
Expand All @@ -35,11 +36,11 @@ public void setOrderId(Long orderId) {
this.orderId = orderId;
}

public RevisedOrderLineItem[] getRevisedOrderLineItems() {
public List<RevisedOrderLineItem> getRevisedOrderLineItems() {
return revisedOrderLineItems;
}

public void setRevisedOrderLineItems(RevisedOrderLineItem[] revisedOrderLineItems) {
public void setRevisedOrderLineItems(List<RevisedOrderLineItem> revisedOrderLineItems) {
this.revisedOrderLineItems = revisedOrderLineItems;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import io.eventuate.tram.commands.common.Command;
import net.chrisrichardson.ftgo.common.RevisedOrderLineItem;

import java.util.Map;
import java.util.List;

public class ConfirmReviseTicketCommand implements Command {
private long restaurantId;
private long orderId;
private RevisedOrderLineItem[] revisedOrderLineItems;
private List<RevisedOrderLineItem> revisedOrderLineItems;

private ConfirmReviseTicketCommand() {
}

public ConfirmReviseTicketCommand(long restaurantId, Long orderId, RevisedOrderLineItem[] revisedOrderLineItems) {
public ConfirmReviseTicketCommand(long restaurantId, Long orderId, List<RevisedOrderLineItem> revisedOrderLineItems) {

this.restaurantId = restaurantId;
this.orderId = orderId;
Expand All @@ -36,11 +36,11 @@ public void setRestaurantId(long restaurantId) {
this.restaurantId = restaurantId;
}

public RevisedOrderLineItem[] getRevisedOrderLineItems() {
public List<RevisedOrderLineItem> getRevisedOrderLineItems() {
return revisedOrderLineItems;
}

public void setRevisedOrderLineItems(RevisedOrderLineItem[] revisedOrderLineItems) {
public void setRevisedOrderLineItems(List<RevisedOrderLineItem> revisedOrderLineItems) {
this.revisedOrderLineItems = revisedOrderLineItems;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void undoCancel(long restaurantId, long ticketId) {

}

public void beginReviseOrder(long restaurantId, Long ticketId, RevisedOrderLineItem[] revisedOrderLineItems) {
public void beginReviseOrder(long restaurantId, Long ticketId, List<RevisedOrderLineItem> revisedOrderLineItems) {
Ticket ticket = ticketRepository.findById(ticketId)
.orElseThrow(() -> new TicketNotFoundException(ticketId));
// TODO - verify restaurant id
Expand All @@ -106,7 +106,7 @@ public void undoBeginReviseOrder(long restaurantId, Long ticketId) {
domainEventPublisher.publish(ticket, events);
}

public void confirmReviseTicket(long restaurantId, long ticketId, RevisedOrderLineItem[] revisedOrderLineItems) {
public void confirmReviseTicket(long restaurantId, long ticketId, List<RevisedOrderLineItem> revisedOrderLineItems) {
Ticket ticket = ticketRepository.findById(ticketId)
.orElseThrow(() -> new TicketNotFoundException(ticketId));
// TODO - verify restaurant id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public List<TicketDomainEvent> undoCancel() {
}
}

public List<TicketDomainEvent> beginReviseOrder(RevisedOrderLineItem[] revisedOrderLineItems) {
public List<TicketDomainEvent> beginReviseOrder(List<RevisedOrderLineItem> revisedOrderLineItems) {
switch (state) {
case AWAITING_ACCEPTANCE:
case ACCEPTED:
Expand All @@ -196,7 +196,7 @@ public List<TicketDomainEvent> undoBeginReviseOrder() {
}
}

public List<TicketDomainEvent> confirmReviseTicket(RevisedOrderLineItem[] revisedOrderLineItems) {
public List<TicketDomainEvent> confirmReviseTicket(List<RevisedOrderLineItem> revisedOrderLineItems) {
switch (state) {
case REVISION_PENDING:
this.state = this.previousState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public KitchenController(KitchenService kitchenService) {
}

@RequestMapping(path="/tickets/{ticketId}/accept", method= RequestMethod.POST)
public ResponseEntity<String> acceptTicket(@PathVariable long ticketId, @RequestBody TicketAcceptance ticketAcceptance) {
public void acceptTicket(@PathVariable long ticketId, @RequestBody TicketAcceptance ticketAcceptance) {
kitchenService.accept(ticketId, ticketAcceptance.getReadyBy());
return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

import net.chrisrichardson.ftgo.common.RevisedOrderLineItem;

import java.util.List;

public class ReviseOrderRequest {
private RevisedOrderLineItem[] revisedOrderLineItems;
private List<RevisedOrderLineItem> revisedOrderLineItems;

private ReviseOrderRequest() {
}

public ReviseOrderRequest(RevisedOrderLineItem[] revisedOrderLineItems) {
public ReviseOrderRequest(List<RevisedOrderLineItem> revisedOrderLineItems) {
this.revisedOrderLineItems = revisedOrderLineItems;
}

public RevisedOrderLineItem[] getRevisedOrderLineItems() {
public List<RevisedOrderLineItem> getRevisedOrderLineItems() {
return revisedOrderLineItems;
}

public void setRevisedOrderLineItems(RevisedOrderLineItem[] revisedOrderLineItems) {
public void setRevisedOrderLineItems(List<RevisedOrderLineItem> revisedOrderLineItems) {
this.revisedOrderLineItems = revisedOrderLineItems;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public List<OrderDomainEvent> confirmRevision(OrderRevision orderRevision) {

orderRevision.getDeliveryInformation().ifPresent(newDi -> this.deliveryInformation = newDi);

if (orderRevision.getRevisedOrderLineItems() != null && orderRevision.getRevisedOrderLineItems().length > 0) {
if (orderRevision.getRevisedOrderLineItems() != null && orderRevision.getRevisedOrderLineItems().size() > 0) {
orderLineItems.updateLineItems(orderRevision);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;

@Embeddable
public class OrderLineItems {
Expand Down Expand Up @@ -40,20 +38,20 @@ OrderLineItem findOrderLineItem(String lineItemId) {
}

Money changeToOrderTotal(OrderRevision orderRevision) {
AtomicReference<Money> delta = new AtomicReference<>(Money.ZERO);

Arrays.asList(orderRevision.getRevisedOrderLineItems()).forEach(item -> {
OrderLineItem lineItem = findOrderLineItem(item.getMenuItemId());
delta.set(delta.get().add(lineItem.deltaForChangedQuantity(item.getQuantity())));
});
return delta.get();
return orderRevision
.getRevisedOrderLineItems()
.stream()
.map(item -> {
OrderLineItem lineItem = findOrderLineItem(item.getMenuItemId());
return lineItem.deltaForChangedQuantity(item.getQuantity());
})
.reduce(new Money(0), Money::add);
}

void updateLineItems(OrderRevision orderRevision) {
getLineItems().stream().forEach(li -> {

Optional<Integer> revised = Arrays
.asList(orderRevision.getRevisedOrderLineItems())
Optional<Integer> revised = orderRevision.getRevisedOrderLineItems()
.stream()
.filter(item -> Objects.equals(li.getMenuItemId(), item.getMenuItemId()))
.map(RevisedOrderLineItem::getQuantity)
Expand Down
Loading

0 comments on commit 8db1160

Please sign in to comment.