JAVA-16264: review module names (#13136)
This commit is contained in:
+51
@@ -0,0 +1,51 @@
|
||||
package com.baeldung.dddcontexts.ordercontext.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CustomerOrder {
|
||||
private int orderId;
|
||||
private String paymentMethod;
|
||||
private String address;
|
||||
private List<OrderItem> orderItems;
|
||||
|
||||
public CustomerOrder() {
|
||||
|
||||
}
|
||||
|
||||
public float calculateTotalPrice() {
|
||||
return orderItems.stream().map(OrderItem::getTotalPrice)
|
||||
.reduce(0F, Float::sum);
|
||||
}
|
||||
|
||||
public void setOrderItems(List<OrderItem> orderItems) {
|
||||
this.orderItems = orderItems;
|
||||
}
|
||||
|
||||
public int getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public List<OrderItem> getOrderItems() {
|
||||
return orderItems;
|
||||
}
|
||||
|
||||
public void setOrderId(int orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public String getPaymentMethod() {
|
||||
return paymentMethod;
|
||||
}
|
||||
|
||||
public void setPaymentMethod(String paymentMethod) {
|
||||
this.paymentMethod = paymentMethod;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.baeldung.dddcontexts.ordercontext.model;
|
||||
|
||||
public class OrderItem {
|
||||
private int productId;
|
||||
private int quantity;
|
||||
private float unitPrice;
|
||||
private float unitWeight;
|
||||
|
||||
public OrderItem(int productId, int quantity, float unitPrice, float unitWeight) {
|
||||
this.productId = productId;
|
||||
this.quantity = quantity;
|
||||
this.unitPrice = unitPrice;
|
||||
this.unitWeight = unitWeight;
|
||||
}
|
||||
|
||||
public int getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(int productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public int getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(int quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public float getTotalPrice() {
|
||||
return this.quantity * this.unitPrice;
|
||||
}
|
||||
|
||||
public void setUnitPrice(float unitPrice) {
|
||||
this.unitPrice = unitPrice;
|
||||
}
|
||||
|
||||
public float getUnitWeight() {
|
||||
return unitWeight;
|
||||
}
|
||||
|
||||
public float getUnitPrice() {
|
||||
return unitPrice;
|
||||
}
|
||||
|
||||
public void setUnitWeight(float unitWeight) {
|
||||
this.unitWeight = unitWeight;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.baeldung.dddcontexts.ordercontext.repository;
|
||||
|
||||
import com.baeldung.dddcontexts.ordercontext.model.CustomerOrder;
|
||||
|
||||
public interface CustomerOrderRepository {
|
||||
void saveCustomerOrder(CustomerOrder order);
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.baeldung.dddcontexts.ordercontext.service;
|
||||
|
||||
import com.baeldung.dddcontexts.ordercontext.model.CustomerOrder;
|
||||
import com.baeldung.dddcontexts.ordercontext.repository.CustomerOrderRepository;
|
||||
import com.baeldung.dddcontexts.sharedkernel.events.ApplicationEvent;
|
||||
import com.baeldung.dddcontexts.sharedkernel.events.EventBus;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CustomerOrderService implements OrderService {
|
||||
public static final String EVENT_ORDER_READY_FOR_SHIPMENT = "OrderReadyForShipmentEvent";
|
||||
|
||||
private CustomerOrderRepository orderRepository;
|
||||
private EventBus eventBus;
|
||||
|
||||
@Override
|
||||
public void placeOrder(CustomerOrder order) {
|
||||
this.orderRepository.saveCustomerOrder(order);
|
||||
Map<String, String> payload = new HashMap<>();
|
||||
payload.put("order_id", String.valueOf(order.getOrderId()));
|
||||
ApplicationEvent event = new ApplicationEvent(payload) {
|
||||
@Override
|
||||
public String getType() {
|
||||
return EVENT_ORDER_READY_FOR_SHIPMENT;
|
||||
}
|
||||
};
|
||||
this.eventBus.publish(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventBus getEventBus() {
|
||||
return eventBus;
|
||||
}
|
||||
|
||||
public void setOrderRepository(CustomerOrderRepository orderRepository) {
|
||||
this.orderRepository = orderRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEventBus(EventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.dddcontexts.ordercontext.service;
|
||||
|
||||
import com.baeldung.dddcontexts.ordercontext.model.CustomerOrder;
|
||||
import com.baeldung.dddcontexts.ordercontext.repository.CustomerOrderRepository;
|
||||
import com.baeldung.dddcontexts.sharedkernel.service.ApplicationService;
|
||||
|
||||
public interface OrderService extends ApplicationService {
|
||||
void placeOrder(CustomerOrder order);
|
||||
|
||||
void setOrderRepository(CustomerOrderRepository orderRepository);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
module com.baeldung.dddcontexts.ordercontext {
|
||||
requires com.baeldung.dddcontexts.sharedkernel;
|
||||
exports com.baeldung.dddcontexts.ordercontext.service;
|
||||
exports com.baeldung.dddcontexts.ordercontext.model;
|
||||
exports com.baeldung.dddcontexts.ordercontext.repository;
|
||||
provides com.baeldung.dddcontexts.ordercontext.service.OrderService
|
||||
with com.baeldung.dddcontexts.ordercontext.service.CustomerOrderService;
|
||||
}
|
||||
Reference in New Issue
Block a user