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:
1.3 KB
|
Line | |
---|
1 | package com.example.fooddeliverysystem.service.impl;
|
---|
2 |
|
---|
3 | import com.example.fooddeliverysystem.exceptions.FoodItemNotFoundException;
|
---|
4 | import com.example.fooddeliverysystem.model.FoodItem;
|
---|
5 | import com.example.fooddeliverysystem.model.Price;
|
---|
6 | import com.example.fooddeliverysystem.repository.PriceRepository;
|
---|
7 | import com.example.fooddeliverysystem.service.PriceService;
|
---|
8 | import org.springframework.stereotype.Service;
|
---|
9 |
|
---|
10 | import java.util.List;
|
---|
11 | import java.util.Optional;
|
---|
12 |
|
---|
13 | @Service
|
---|
14 | public class PriceServiceImpl implements PriceService {
|
---|
15 |
|
---|
16 | private final PriceRepository priceRepository;
|
---|
17 |
|
---|
18 | public PriceServiceImpl(PriceRepository priceRepository) {
|
---|
19 | this.priceRepository = priceRepository;
|
---|
20 | }
|
---|
21 |
|
---|
22 | @Override
|
---|
23 | public List<Price> findAllPrices() {
|
---|
24 | return this.priceRepository.findAll();
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public Price findCurrentPriceForFoodItem(FoodItem foodItem) throws FoodItemNotFoundException {
|
---|
29 | List<Price> pricesForFoodItem = this.priceRepository.findAllByPriceKey_FoodItem(foodItem);
|
---|
30 | Optional<Price> currentPrice = pricesForFoodItem.stream()
|
---|
31 | .sorted((price1, price2) -> (int) (price2.getPriceKey().getPriceNumber() - price1.getPriceKey().getPriceNumber()))
|
---|
32 | .findFirst();
|
---|
33 | return currentPrice.orElseThrow(() -> new FoodItemNotFoundException("food item cannot be found"));
|
---|
34 |
|
---|
35 | }
|
---|
36 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.