Update Command API

- Adjust PlaceOrderCommand to only construct the order
- Introduce AddProductCommand to be able to add several products to an
order
- Introduce IncrementProductCountCommand to increase the number of
product instances for a given Order
- Introduce DecrementProductCountCommand to increase the number of
product instances for a given Order

#BAEL-4767
This commit is contained in:
Steven van Beelen 2021-03-19 10:55:15 +01:00
parent b585b6eb7b
commit 10c0f2302e
4 changed files with 164 additions and 22 deletions

View File

@ -0,0 +1,50 @@
package com.baeldung.axon.coreapi.commands;
import org.axonframework.modelling.command.TargetAggregateIdentifier;
import java.util.Objects;
public class AddProductCommand {
@TargetAggregateIdentifier
private final String orderId;
private final String productId;
public AddProductCommand(String orderId, String productId) {
this.orderId = orderId;
this.productId = productId;
}
public String getOrderId() {
return orderId;
}
public String getProductId() {
return productId;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AddProductCommand that = (AddProductCommand) o;
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
}
@Override
public int hashCode() {
return Objects.hash(orderId, productId);
}
@Override
public String toString() {
return "AddProductCommand{" +
"orderId='" + orderId + '\'' +
", productId='" + productId + '\'' +
'}';
}
}

View File

@ -0,0 +1,50 @@
package com.baeldung.axon.coreapi.commands;
import org.axonframework.modelling.command.TargetAggregateIdentifier;
import java.util.Objects;
public class DecrementProductCountCommand {
@TargetAggregateIdentifier
private final String orderId;
private final String productId;
public DecrementProductCountCommand(String orderId, String productId) {
this.orderId = orderId;
this.productId = productId;
}
public String getOrderId() {
return orderId;
}
public String getProductId() {
return productId;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DecrementProductCountCommand that = (DecrementProductCountCommand) o;
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
}
@Override
public int hashCode() {
return Objects.hash(orderId, productId);
}
@Override
public String toString() {
return "DecrementProductCountCommand{" +
"orderId='" + orderId + '\'' +
", productId='" + productId + '\'' +
'}';
}
}

View File

@ -0,0 +1,50 @@
package com.baeldung.axon.coreapi.commands;
import org.axonframework.modelling.command.TargetAggregateIdentifier;
import java.util.Objects;
public class IncrementProductCountCommand {
@TargetAggregateIdentifier
private final String orderId;
private final String productId;
public IncrementProductCountCommand(String orderId, String productId) {
this.orderId = orderId;
this.productId = productId;
}
public String getOrderId() {
return orderId;
}
public String getProductId() {
return productId;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
IncrementProductCountCommand that = (IncrementProductCountCommand) o;
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
}
@Override
public int hashCode() {
return Objects.hash(orderId, productId);
}
@Override
public String toString() {
return "IncrementProductCountCommand{" +
"orderId='" + orderId + '\'' +
", productId='" + productId + '\'' +
'}';
}
}

View File

@ -1,51 +1,43 @@
package com.baeldung.axon.coreapi.commands;
import java.util.Objects;
import org.axonframework.modelling.command.TargetAggregateIdentifier;
import java.util.Objects;
public class PlaceOrderCommand {
@TargetAggregateIdentifier
private final String orderId;
private final String product;
public PlaceOrderCommand(String orderId, String product) {
public PlaceOrderCommand(String orderId) {
this.orderId = orderId;
this.product = product;
}
public String getOrderId() {
return orderId;
}
public String getProduct() {
return product;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PlaceOrderCommand that = (PlaceOrderCommand) o;
return Objects.equals(orderId, that.orderId);
}
@Override
public int hashCode() {
return Objects.hash(orderId, product);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final PlaceOrderCommand other = (PlaceOrderCommand) obj;
return Objects.equals(this.orderId, other.orderId)
&& Objects.equals(this.product, other.product);
return Objects.hash(orderId);
}
@Override
public String toString() {
return "PlaceOrderCommand{" +
"orderId='" + orderId + '\'' +
", product='" + product + '\'' +
'}';
}
}