Changeset f25d07e for phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneOfferService.java
- Timestamp:
- 09/07/22 00:51:50 (2 years ago)
- Branches:
- master
- Children:
- 527b93f
- Parents:
- dbd4834
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneOfferService.java
rdbd4834 rf25d07e 7 7 8 8 import java.util.ArrayList; 9 import java.util.Comparator; 9 10 import java.util.List; 11 import java.util.stream.Collectors; 10 12 11 13 @Service … … 24 26 throw new IllegalStateException("Phone with id "+phoneId+" does not exist"); 25 27 26 return phoneRepository.findById(phoneId).get().getPhoneOffers(); 28 return phoneRepository.findById(phoneId).get().getPhoneOffers() 29 .stream().sorted(Comparator.comparing(PhoneOffer::getPrice)).collect(Collectors.toList()); 27 30 } 31 32 public List<String> getShops() { 33 return phoneOfferRepository.findAll().stream() 34 .map(PhoneOffer::getOffer_shop) 35 .distinct() 36 .collect(Collectors.toList()); 37 } 38 39 40 public int getLowestPrice() { 41 return phoneOfferRepository.findAll() 42 .stream().sorted(Comparator.comparing(PhoneOffer::getPrice)) 43 .collect(Collectors.toList()).get(0).getPrice(); 44 } 45 46 public int getHighestPrice() { 47 return phoneOfferRepository.findAll() 48 .stream().sorted(Comparator.comparing(PhoneOffer::getPrice).reversed()) 49 .collect(Collectors.toList()).get(0).getPrice(); 50 } 51 28 52 }
Note:
See TracChangeset
for help on using the changeset viewer.