[b68ae8d] | 1 | package finki.it.phoneluxbackend.controllers;
|
---|
| 2 |
|
---|
| 3 | import finki.it.phoneluxbackend.entities.Phone;
|
---|
| 4 | import finki.it.phoneluxbackend.entities.PhoneOffer;
|
---|
[f25d07e] | 5 | import finki.it.phoneluxbackend.services.PhoneOfferService;
|
---|
[b68ae8d] | 6 | import finki.it.phoneluxbackend.services.PhoneService;
|
---|
[f25d07e] | 7 | import lombok.AllArgsConstructor;
|
---|
[b68ae8d] | 8 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
| 9 | import org.springframework.web.bind.annotation.*;
|
---|
| 10 |
|
---|
[f25d07e] | 11 | import java.util.Comparator;
|
---|
[b68ae8d] | 12 | import java.util.List;
|
---|
[f25d07e] | 13 | import java.util.stream.Collectors;
|
---|
[b68ae8d] | 14 |
|
---|
| 15 | @RestController
|
---|
[f25d07e] | 16 | @AllArgsConstructor
|
---|
[b68ae8d] | 17 | @RequestMapping(path = "/")
|
---|
| 18 | public class PhoneController {
|
---|
| 19 | private final PhoneService phoneService;
|
---|
[f25d07e] | 20 | private final PhoneOfferService phoneOfferService;
|
---|
[b68ae8d] | 21 |
|
---|
[f25d07e] | 22 | // handle request parameters for filtering phones
|
---|
| 23 | @GetMapping(path = "/phones")
|
---|
[e5b84dc] | 24 | public List<Phone> getPhones(@RequestParam(name = "shops", required = false) String shops,
|
---|
| 25 | @RequestParam(name = "brands", required = false) String brands,
|
---|
| 26 | @RequestParam(name = "sortBy", required = false) String sortBy,
|
---|
| 27 | @RequestParam(name = "priceRange", required = false) String priceRange,
|
---|
| 28 | @RequestParam(name = "searchValue", required = false) String searchValue){
|
---|
| 29 |
|
---|
| 30 | return phoneService.getPhones(shops,brands,sortBy,priceRange,searchValue);
|
---|
[b68ae8d] | 31 | }
|
---|
| 32 |
|
---|
[f25d07e] | 33 | @GetMapping(path = "/phones/{phoneId}")
|
---|
| 34 | public Phone getPhoneById(@PathVariable("phoneId") Long phoneId)
|
---|
| 35 | {
|
---|
| 36 | return phoneService.getPhoneById(phoneId);
|
---|
| 37 | }
|
---|
[dfd5d87] | 38 |
|
---|
[f25d07e] | 39 | @GetMapping(path = "/brands")
|
---|
| 40 | public List<String> getBrands(){
|
---|
| 41 | return phoneService.getBrands();
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | @GetMapping(path = "/shops")
|
---|
| 45 | public List<String> getShops(){
|
---|
| 46 | return phoneOfferService.getShops();
|
---|
[b68ae8d] | 47 | }
|
---|
| 48 |
|
---|
[f25d07e] | 49 | @GetMapping(path = "/lowestPrice")
|
---|
| 50 | public int getLowestPrice()
|
---|
| 51 | {
|
---|
| 52 | return phoneOfferService.getLowestPrice();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | @GetMapping(path = "/highestPrice")
|
---|
| 56 | public int getHighestPrice()
|
---|
| 57 | {
|
---|
| 58 | return phoneOfferService.getHighestPrice();
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
[b68ae8d] | 62 | }
|
---|