Ignore:
Timestamp:
09/07/22 00:51:50 (2 years ago)
Author:
Marko <Marko@…>
Branches:
master
Children:
527b93f
Parents:
dbd4834
Message:

Edited registration and login services

File:
1 edited

Legend:

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

    rdbd4834 rf25d07e  
    77
    88import java.util.ArrayList;
     9import java.util.Comparator;
    910import java.util.List;
     11import java.util.stream.Collectors;
    1012
    1113@Service
     
    2426            throw new IllegalStateException("Phone with id "+phoneId+" does not exist");
    2527
    26         return phoneRepository.findById(phoneId).get().getPhoneOffers();
     28        return phoneRepository.findById(phoneId).get().getPhoneOffers()
     29                .stream().sorted(Comparator.comparing(PhoneOffer::getPrice)).collect(Collectors.toList());
    2730    }
     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
    2852}
Note: See TracChangeset for help on using the changeset viewer.