source: src/main/java/com/example/fooddeliverysystem/service/impl/HasFoodServiceImpl.java

Last change on this file was 8d11f8c, checked in by jovanmanchev <jovanmanchev3003@…>, 20 months ago

code added, trial 2

  • Property mode set to 100644
File size: 2.0 KB
Line 
1package com.example.fooddeliverysystem.service.impl;
2
3import com.example.fooddeliverysystem.model.FoodItem;
4import com.example.fooddeliverysystem.model.OrderHasFood;
5import com.example.fooddeliverysystem.model.objects.FoodItemsWithQuantity;
6import com.example.fooddeliverysystem.repository.FoodItemRepository;
7import com.example.fooddeliverysystem.repository.OrderHasFoodRepository;
8import com.example.fooddeliverysystem.service.FoodItemService;
9import com.example.fooddeliverysystem.service.HasFoodService;
10import org.springframework.stereotype.Service;
11
12import java.util.ArrayList;
13import java.util.List;
14
15@Service
16public 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}
Note: See TracBrowser for help on using the repository browser.