Skip to content

Commit 7f87901

Browse files
committed
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
1 parent a04c2dc commit 7f87901

4 files changed

Lines changed: 163 additions & 21 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.baeldung.axon.coreapi.commands;
2+
3+
import org.axonframework.modelling.command.TargetAggregateIdentifier;
4+
5+
import java.util.Objects;
6+
7+
public class AddProductCommand {
8+
9+
@TargetAggregateIdentifier
10+
private final String orderId;
11+
private final String productId;
12+
13+
public AddProductCommand(String orderId, String productId) {
14+
this.orderId = orderId;
15+
this.productId = productId;
16+
}
17+
18+
public String getOrderId() {
19+
return orderId;
20+
}
21+
22+
public String getProductId() {
23+
return productId;
24+
}
25+
26+
@Override
27+
public boolean equals(Object o) {
28+
if (this == o) {
29+
return true;
30+
}
31+
if (o == null || getClass() != o.getClass()) {
32+
return false;
33+
}
34+
AddProductCommand that = (AddProductCommand) o;
35+
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
36+
}
37+
38+
@Override
39+
public int hashCode() {
40+
return Objects.hash(orderId, productId);
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return "AddProductCommand{" +
46+
"orderId='" + orderId + '\'' +
47+
", productId='" + productId + '\'' +
48+
'}';
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.baeldung.axon.coreapi.commands;
2+
3+
import org.axonframework.modelling.command.TargetAggregateIdentifier;
4+
5+
import java.util.Objects;
6+
7+
public class DecrementProductCountCommand {
8+
9+
@TargetAggregateIdentifier
10+
private final String orderId;
11+
private final String productId;
12+
13+
public DecrementProductCountCommand(String orderId, String productId) {
14+
this.orderId = orderId;
15+
this.productId = productId;
16+
}
17+
18+
public String getOrderId() {
19+
return orderId;
20+
}
21+
22+
public String getProductId() {
23+
return productId;
24+
}
25+
26+
@Override
27+
public boolean equals(Object o) {
28+
if (this == o) {
29+
return true;
30+
}
31+
if (o == null || getClass() != o.getClass()) {
32+
return false;
33+
}
34+
DecrementProductCountCommand that = (DecrementProductCountCommand) o;
35+
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
36+
}
37+
38+
@Override
39+
public int hashCode() {
40+
return Objects.hash(orderId, productId);
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return "DecrementProductCountCommand{" +
46+
"orderId='" + orderId + '\'' +
47+
", productId='" + productId + '\'' +
48+
'}';
49+
}
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.baeldung.axon.coreapi.commands;
2+
3+
import org.axonframework.modelling.command.TargetAggregateIdentifier;
4+
5+
import java.util.Objects;
6+
7+
public class IncrementProductCountCommand {
8+
9+
@TargetAggregateIdentifier
10+
private final String orderId;
11+
private final String productId;
12+
13+
public IncrementProductCountCommand(String orderId, String productId) {
14+
this.orderId = orderId;
15+
this.productId = productId;
16+
}
17+
18+
public String getOrderId() {
19+
return orderId;
20+
}
21+
22+
public String getProductId() {
23+
return productId;
24+
}
25+
26+
@Override
27+
public boolean equals(Object o) {
28+
if (this == o) {
29+
return true;
30+
}
31+
if (o == null || getClass() != o.getClass()) {
32+
return false;
33+
}
34+
IncrementProductCountCommand that = (IncrementProductCountCommand) o;
35+
return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
36+
}
37+
38+
@Override
39+
public int hashCode() {
40+
return Objects.hash(orderId, productId);
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return "IncrementProductCountCommand{" +
46+
"orderId='" + orderId + '\'' +
47+
", productId='" + productId + '\'' +
48+
'}';
49+
}
50+
}
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,43 @@
11
package com.baeldung.axon.coreapi.commands;
22

3-
import java.util.Objects;
4-
53
import org.axonframework.modelling.command.TargetAggregateIdentifier;
64

5+
import java.util.Objects;
6+
77
public class PlaceOrderCommand {
88

99
@TargetAggregateIdentifier
1010
private final String orderId;
11-
private final String product;
1211

13-
public PlaceOrderCommand(String orderId, String product) {
12+
public PlaceOrderCommand(String orderId) {
1413
this.orderId = orderId;
15-
this.product = product;
1614
}
1715

1816
public String getOrderId() {
1917
return orderId;
2018
}
2119

22-
public String getProduct() {
23-
return product;
24-
}
25-
26-
@Override
27-
public int hashCode() {
28-
return Objects.hash(orderId, product);
29-
}
30-
3120
@Override
32-
public boolean equals(Object obj) {
33-
if (this == obj) {
21+
public boolean equals(Object o) {
22+
if (this == o) {
3423
return true;
3524
}
36-
if (obj == null || getClass() != obj.getClass()) {
25+
if (o == null || getClass() != o.getClass()) {
3726
return false;
3827
}
39-
final PlaceOrderCommand other = (PlaceOrderCommand) obj;
40-
return Objects.equals(this.orderId, other.orderId)
41-
&& Objects.equals(this.product, other.product);
28+
PlaceOrderCommand that = (PlaceOrderCommand) o;
29+
return Objects.equals(orderId, that.orderId);
30+
}
31+
32+
@Override
33+
public int hashCode() {
34+
return Objects.hash(orderId);
4235
}
4336

4437
@Override
4538
public String toString() {
4639
return "PlaceOrderCommand{" +
4740
"orderId='" + orderId + '\'' +
48-
", product='" + product + '\'' +
4941
'}';
5042
}
5143
}

0 commit comments

Comments
 (0)