Changeset f25d07e for phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneController.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/controllers/PhoneController.java
rdbd4834 rf25d07e 3 3 import finki.it.phoneluxbackend.entities.Phone; 4 4 import finki.it.phoneluxbackend.entities.PhoneOffer; 5 import finki.it.phoneluxbackend.services.PhoneOfferService; 5 6 import finki.it.phoneluxbackend.services.PhoneService; 7 import lombok.AllArgsConstructor; 6 8 import org.springframework.beans.factory.annotation.Autowired; 7 9 import org.springframework.web.bind.annotation.*; 8 10 11 import java.util.Comparator; 9 12 import java.util.List; 13 import java.util.stream.Collectors; 10 14 11 15 @RestController 16 @AllArgsConstructor 12 17 @RequestMapping(path = "/") 13 18 public class PhoneController { 14 19 private final PhoneService phoneService; 20 private final PhoneOfferService phoneOfferService; 15 21 16 @Autowired 17 public PhoneController(PhoneService phoneService) { 18 this.phoneService = phoneService; 22 // handle request parameters for filtering phones 23 @GetMapping(path = "/phones") 24 public List<Phone> getPhones(){ 25 return phoneService.getPhones().stream() 26 .sorted(Comparator.comparing(Phone::getTotal_offers).reversed()) 27 .collect(Collectors.toList()); 28 } 29 30 @GetMapping(path = "/phones/{phoneId}") 31 public Phone getPhoneById(@PathVariable("phoneId") Long phoneId) 32 { 33 return phoneService.getPhoneById(phoneId); 34 } 35 36 @GetMapping(path = "/brands") 37 public List<String> getBrands(){ 38 return phoneService.getBrands(); 39 } 40 41 @GetMapping(path = "/shops") 42 public List<String> getShops(){ 43 return phoneOfferService.getShops(); 44 } 45 46 @GetMapping(path = "/lowestPrice") 47 public int getLowestPrice() 48 { 49 return phoneOfferService.getLowestPrice(); 50 } 51 52 @GetMapping(path = "/highestPrice") 53 public int getHighestPrice() 54 { 55 return phoneOfferService.getHighestPrice(); 19 56 } 20 57 21 58 22 // handle request parameters for filtering phones23 @GetMapping24 public List<Phone> getPhones(){25 return phoneService.getPhones();26 }27 28 59 }
Note:
See TracChangeset
for help on using the changeset viewer.