Ignore:
Timestamp:
09/17/22 01:23:47 (2 years ago)
Author:
Marko <Marko@…>
Branches:
master
Children:
7e88e46
Parents:
e5b84dc
Message:

Added more controllers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneOfferService.java

    re5b84dc r775e15e  
    99import java.util.Comparator;
    1010import java.util.List;
     11import java.util.Objects;
    1112import java.util.stream.Collectors;
    1213
     
    6061    }
    6162
     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    }
    6278}
Note: See TracChangeset for help on using the changeset viewer.