-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathPricingService.java
30 lines (25 loc) · 1.14 KB
/
PricingService.java
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
package com.mayank.fooddelivery.services;
import com.mayank.fooddelivery.model.Bill;
import com.mayank.fooddelivery.model.CouponCode;
import com.mayank.fooddelivery.model.MenuItem;
import com.mayank.fooddelivery.strategy.PricingStrategy;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class PricingService {
private List<PricingStrategy> pricingStrategyList;
private CartService cartService;
@Autowired
public PricingService(List<PricingStrategy> pricingStrategyList, CartService cartService) {
this.pricingStrategyList = pricingStrategyList;
this.cartService = cartService;
}
public Bill getBill(@NonNull final String userId, @NonNull final String restaurantId,
@NonNull final CouponCode couponCode) {
List<MenuItem> menuItemList = cartService.getAllItemsOfCart(userId, restaurantId);
return pricingStrategyList.stream().filter(pricingStrategy -> pricingStrategy.isApplicable(couponCode))
.findAny().get().generateBill(menuItemList);
}
}