Last change
on this file since b68ae8d was b68ae8d, checked in by Marko <Marko@…>, 23 months ago |
Created spring app, edited setec_scrapper
|
-
Property mode
set to
100644
|
File size:
926 bytes
|
Rev | Line | |
---|
[b68ae8d] | 1 | package finki.it.phoneluxbackend.services;
|
---|
| 2 |
|
---|
| 3 | import finki.it.phoneluxbackend.entities.Phone;
|
---|
| 4 | import finki.it.phoneluxbackend.entities.PhoneOffer;
|
---|
| 5 | import finki.it.phoneluxbackend.repositories.PhoneRepository;
|
---|
| 6 | import org.springframework.data.domain.Sort;
|
---|
| 7 | import org.springframework.stereotype.Service;
|
---|
| 8 |
|
---|
| 9 | import java.util.List;
|
---|
| 10 |
|
---|
| 11 | @Service
|
---|
| 12 | public class PhoneService {
|
---|
| 13 | private final PhoneRepository phoneRepository;
|
---|
| 14 |
|
---|
| 15 | public PhoneService(PhoneRepository phoneRepository){
|
---|
| 16 | this.phoneRepository = phoneRepository;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | public List<Phone> getPhones(){
|
---|
| 20 | return phoneRepository.findAll();
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | public List<PhoneOffer> getOffersForPhone(Long phoneId) {
|
---|
| 24 | boolean exists = phoneRepository.existsById(phoneId);
|
---|
| 25 | if(!exists)
|
---|
| 26 | throw new IllegalStateException("Phone with id "+phoneId+" does not exist");
|
---|
| 27 |
|
---|
| 28 | return phoneRepository.findById(phoneId).get().getPhoneOffers();
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.