-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathOrderServiceImpl.java
More file actions
41 lines (32 loc) · 1.57 KB
/
Copy pathOrderServiceImpl.java
File metadata and controls
41 lines (32 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package mate.academy.service;
import java.math.BigDecimal;
import java.util.List;
import mate.academy.model.Order;
import mate.academy.model.Product;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class OrderServiceImpl implements OrderService {
private static final Logger logger =
LogManager.getLogger(OrderServiceImpl.class);
@Override
public Order completeOrder(Long userId) {
logger.info("Method completeOrder() was called for userId={}", userId);
List<Product> products = getAllProductsFromShoppingCart(userId);
Order order = new Order(products, userId);
// NOTE: In production ready code this order identifier should be generated by DB
// For test purpose we simplify this and return dummy data
order.setOrderId(1L);
logger.info("Order with id {} was successfully created", order.getOrderId());
return order;
}
private List<Product> getAllProductsFromShoppingCart(Long userId) {
// NOTE: In production ready code this method should fetch data from DB
// For test purpose we simplify this method and return dummy data
Product iphone = new Product("iPhone X", BigDecimal.valueOf(1199));
Product macBook = new Product("MacBook Air 2020", BigDecimal.valueOf(1399));
Product xiaomi = new Product("Xiaomi 12", BigDecimal.valueOf(499));
List<Product> products = List.of(iphone, macBook, xiaomi);
logger.info("Successfully fetched products from DB for userId={}", userId);
return products;
}
}