1 | package com.example.fooddeliverysystem.service.impl;
|
---|
2 |
|
---|
3 | import com.example.fooddeliverysystem.model.FoodItem;
|
---|
4 | import com.example.fooddeliverysystem.model.OrderHasFood;
|
---|
5 | import com.example.fooddeliverysystem.model.objects.FoodItemsWithQuantity;
|
---|
6 | import com.example.fooddeliverysystem.repository.FoodItemRepository;
|
---|
7 | import com.example.fooddeliverysystem.repository.OrderHasFoodRepository;
|
---|
8 | import com.example.fooddeliverysystem.service.FoodItemService;
|
---|
9 | import com.example.fooddeliverysystem.service.HasFoodService;
|
---|
10 | import org.springframework.stereotype.Service;
|
---|
11 |
|
---|
12 | import java.util.ArrayList;
|
---|
13 | import java.util.List;
|
---|
14 |
|
---|
15 | @Service
|
---|
16 | public class HasFoodServiceImpl implements HasFoodService {
|
---|
17 |
|
---|
18 |
|
---|
19 | private final OrderHasFoodRepository orderHasFoodRepository;
|
---|
20 | private final FoodItemRepository foodItemRepository;
|
---|
21 | public HasFoodServiceImpl(OrderHasFoodRepository orderHasFoodRepository, FoodItemRepository foodItemRepository) {
|
---|
22 | this.orderHasFoodRepository = orderHasFoodRepository;
|
---|
23 | this.foodItemRepository = foodItemRepository;
|
---|
24 | }
|
---|
25 | @Override
|
---|
26 | public List<OrderHasFood> findAllFoodsInOrder(Long orderId) {
|
---|
27 | return this.orderHasFoodRepository.findAllByOrderHasFoodKeyOrderId(orderId);
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public List<FoodItemsWithQuantity> findAllFoodnamesInOrder(Long orderId) {
|
---|
32 | List<FoodItemsWithQuantity> foodNamesAndQuantites = new ArrayList<>();
|
---|
33 |
|
---|
34 | List<OrderHasFood> orderHasFoodList = this.orderHasFoodRepository.findAll();
|
---|
35 | for(OrderHasFood orderHasFood: orderHasFoodList){
|
---|
36 | if(orderId.equals(orderHasFood.getOrderHasFoodKey().getOrderId())){
|
---|
37 | FoodItem foodItem = this.foodItemRepository.findById(orderHasFood.getOrderHasFoodKey().getFoodItemId()).get();
|
---|
38 | String name = foodItem.getFoodItemName();
|
---|
39 | Integer quantity = orderHasFood.getQuantity();
|
---|
40 | foodNamesAndQuantites.add(new FoodItemsWithQuantity(name, quantity));
|
---|
41 |
|
---|
42 | }
|
---|
43 |
|
---|
44 |
|
---|
45 | }
|
---|
46 |
|
---|
47 | return foodNamesAndQuantites;
|
---|
48 | }
|
---|
49 | }
|
---|