[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;
|
---|
| 20 |
|
---|
[f25d07e] | 21 | @GetMapping(path = "/phones")
|
---|
[e5b84dc] | 22 | public List<Phone> getPhones(@RequestParam(name = "shops", required = false) String shops,
|
---|
| 23 | @RequestParam(name = "brands", required = false) String brands,
|
---|
| 24 | @RequestParam(name = "sortBy", required = false) String sortBy,
|
---|
| 25 | @RequestParam(name = "priceRange", required = false) String priceRange,
|
---|
[34950c6] | 26 | @RequestParam(name = "searchValue", required = false) String searchValue,
|
---|
| 27 | @RequestParam(name = "ram", required = false) String ram,
|
---|
| 28 | @RequestParam(name = "rom", required = false) String rom,
|
---|
| 29 | @RequestParam(name = "frontcamera", required = false) String frontcamera,
|
---|
| 30 | @RequestParam(name = "backcamera", required = false) String backcamera,
|
---|
| 31 | @RequestParam(name = "chipset", required = false) String chipset,
|
---|
| 32 | @RequestParam(name = "cpu", required = false) String cpu,
|
---|
| 33 | @RequestParam(name = "operatingsystem", required = false) String operatingsystem,
|
---|
| 34 | @RequestParam(name = "color", required = false) String color,
|
---|
| 35 | @RequestParam(name = "battery", required = false) String battery){
|
---|
| 36 |
|
---|
| 37 | return phoneService.getPhones(shops,brands,sortBy,priceRange,searchValue,
|
---|
| 38 | ram, rom, frontcamera, backcamera, chipset, cpu, operatingsystem, color, battery);
|
---|
[b68ae8d] | 39 | }
|
---|
| 40 |
|
---|
[f25d07e] | 41 | @GetMapping(path = "/phones/{phoneId}")
|
---|
| 42 | public Phone getPhoneById(@PathVariable("phoneId") Long phoneId)
|
---|
| 43 | {
|
---|
| 44 | return phoneService.getPhoneById(phoneId);
|
---|
| 45 | }
|
---|
[dfd5d87] | 46 |
|
---|
[f25d07e] | 47 | @GetMapping(path = "/brands")
|
---|
| 48 | public List<String> getBrands(){
|
---|
| 49 | return phoneService.getBrands();
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[b68ae8d] | 52 | }
|
---|