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/PhoneService.java

    rdbd4834 rf25d07e  
    44import finki.it.phoneluxbackend.entities.PhoneOffer;
    55import finki.it.phoneluxbackend.repositories.PhoneRepository;
     6import org.springframework.data.domain.PageRequest;
    67import org.springframework.data.domain.Sort;
    78import org.springframework.stereotype.Service;
    89
     10import java.util.Comparator;
    911import java.util.List;
     12import java.util.stream.Collectors;
    1013
    1114@Service
     
    1720    }
    1821
     22
     23    // TODO: insert logic to filter
    1924    public List<Phone> getPhones(){
    2025        return phoneRepository.findAll();
    2126    }
    2227
     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    }
    2340}
Note: See TracChangeset for help on using the changeset viewer.