Update Query API
Change the OrderedProduct model such that it contains a map of products having the count as its value, instead of a single product. #BAEL-4767
This commit is contained in:
parent
a9812052df
commit
2b2aff5ceb
@ -1,16 +1,18 @@
|
|||||||
package com.baeldung.axon.coreapi.queries;
|
package com.baeldung.axon.coreapi.queries;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class OrderedProduct {
|
public class OrderedProduct {
|
||||||
|
|
||||||
private final String orderId;
|
private final String orderId;
|
||||||
private final String product;
|
private final Map<String, Integer> products;
|
||||||
private OrderStatus orderStatus;
|
private OrderStatus orderStatus;
|
||||||
|
|
||||||
public OrderedProduct(String orderId, String product) {
|
public OrderedProduct(String orderId) {
|
||||||
this.orderId = orderId;
|
this.orderId = orderId;
|
||||||
this.product = product;
|
this.products = new HashMap<>();
|
||||||
orderStatus = OrderStatus.PLACED;
|
orderStatus = OrderStatus.PLACED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,14 +20,31 @@ public class OrderedProduct {
|
|||||||
return orderId;
|
return orderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProduct() {
|
public Map<String, Integer> getProducts() {
|
||||||
return product;
|
return products;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderStatus getOrderStatus() {
|
public OrderStatus getOrderStatus() {
|
||||||
return orderStatus;
|
return orderStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addProduct(String productId) {
|
||||||
|
products.putIfAbsent(productId, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incrementProductInstance(String productId) {
|
||||||
|
products.computeIfPresent(productId, (id, count) -> ++count);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decrementProductInstance(String productId) {
|
||||||
|
products.computeIfPresent(productId, (id, count) -> --count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void removeProduct(String productId) {
|
||||||
|
products.remove(productId);
|
||||||
|
}
|
||||||
|
|
||||||
public void setOrderConfirmed() {
|
public void setOrderConfirmed() {
|
||||||
this.orderStatus = OrderStatus.CONFIRMED;
|
this.orderStatus = OrderStatus.CONFIRMED;
|
||||||
}
|
}
|
||||||
@ -35,29 +54,28 @@ public class OrderedProduct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public boolean equals(Object o) {
|
||||||
return Objects.hash(orderId, product, orderStatus);
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
OrderedProduct that = (OrderedProduct) o;
|
||||||
|
return Objects.equals(orderId, that.orderId) && Objects.equals(products, that.products)
|
||||||
|
&& orderStatus == that.orderStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public int hashCode() {
|
||||||
if (this == obj) {
|
return Objects.hash(orderId, products, orderStatus);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null || getClass() != obj.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final OrderedProduct other = (OrderedProduct) obj;
|
|
||||||
return Objects.equals(this.orderId, other.orderId)
|
|
||||||
&& Objects.equals(this.product, other.product)
|
|
||||||
&& Objects.equals(this.orderStatus, other.orderStatus);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "OrderedProduct{" +
|
return "OrderedProduct{" +
|
||||||
"orderId='" + orderId + '\'' +
|
"orderId='" + orderId + '\'' +
|
||||||
", product='" + product + '\'' +
|
", products=" + products +
|
||||||
", orderStatus=" + orderStatus +
|
", orderStatus=" + orderStatus +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user