Changeset 775e15e for phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneOfferService.java
- Timestamp:
- 09/17/22 01:23:47 (2 years ago)
- Branches:
- master
- Children:
- 7e88e46
- Parents:
- e5b84dc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneOfferService.java
re5b84dc r775e15e 9 9 import java.util.Comparator; 10 10 import java.util.List; 11 import java.util.Objects; 11 12 import java.util.stream.Collectors; 12 13 … … 60 61 } 61 62 63 public List<PhoneOffer> getCheaperOffers(Long offerId) { 64 boolean exists = phoneOfferRepository.existsById(offerId); 65 66 if(!exists) 67 throw new IllegalStateException("Phone offer with id "+offerId+" does not exist"); 68 69 PhoneOffer offer = phoneOfferRepository.findById(offerId).get(); 70 71 return phoneOfferRepository.findAll() 72 .stream().filter(phoneOffer -> 73 Objects.equals(phoneOffer.getPhone().getModel(), offer.getPhone().getModel()) 74 && phoneOffer.getPrice() < offer.getPrice()) 75 .sorted(Comparator.comparing(PhoneOffer::getPrice).reversed()) 76 .collect(Collectors.toList()); 77 } 62 78 }
Note:
See TracChangeset
for help on using the changeset viewer.