Changeset f25d07e for phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneService.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/PhoneService.java
rdbd4834 rf25d07e 4 4 import finki.it.phoneluxbackend.entities.PhoneOffer; 5 5 import finki.it.phoneluxbackend.repositories.PhoneRepository; 6 import org.springframework.data.domain.PageRequest; 6 7 import org.springframework.data.domain.Sort; 7 8 import org.springframework.stereotype.Service; 8 9 10 import java.util.Comparator; 9 11 import java.util.List; 12 import java.util.stream.Collectors; 10 13 11 14 @Service … … 17 20 } 18 21 22 23 // TODO: insert logic to filter 19 24 public List<Phone> getPhones(){ 20 25 return phoneRepository.findAll(); 21 26 } 22 27 28 public List<String> getBrands(){ 29 return phoneRepository.findAll().stream() 30 .map(Phone::getBrand).distinct() 31 .collect(Collectors.toList()); 32 } 33 34 public Phone getPhoneById(Long phoneId) { 35 boolean exists = phoneRepository.existsById(phoneId); 36 if(!exists) 37 throw new IllegalStateException("Phone with id "+phoneId+" does not exist"); 38 return phoneRepository.findById(phoneId).get(); 39 } 23 40 }
Note:
See TracChangeset
for help on using the changeset viewer.