1 | package finki.it.phoneluxbackend.controllers;
|
---|
2 |
|
---|
3 | import finki.it.phoneluxbackend.entities.Phone;
|
---|
4 | import finki.it.phoneluxbackend.entities.PhoneOffer;
|
---|
5 | import finki.it.phoneluxbackend.services.PhoneOfferService;
|
---|
6 | import finki.it.phoneluxbackend.services.PhoneService;
|
---|
7 | import lombok.AllArgsConstructor;
|
---|
8 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
9 | import org.springframework.web.bind.annotation.*;
|
---|
10 |
|
---|
11 | import java.util.Comparator;
|
---|
12 | import java.util.List;
|
---|
13 | import java.util.stream.Collectors;
|
---|
14 |
|
---|
15 | @RestController
|
---|
16 | @AllArgsConstructor
|
---|
17 | @RequestMapping(path = "/")
|
---|
18 | public class PhoneController {
|
---|
19 | private final PhoneService phoneService;
|
---|
20 |
|
---|
21 | @GetMapping(path = "/phones")
|
---|
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,
|
---|
26 | @RequestParam(name = "searchValue", required = false) String searchValue){
|
---|
27 |
|
---|
28 | return phoneService.getPhones(shops,brands,sortBy,priceRange,searchValue);
|
---|
29 | }
|
---|
30 |
|
---|
31 | @GetMapping(path = "/phones/{phoneId}")
|
---|
32 | public Phone getPhoneById(@PathVariable("phoneId") Long phoneId)
|
---|
33 | {
|
---|
34 | return phoneService.getPhoneById(phoneId);
|
---|
35 | }
|
---|
36 |
|
---|
37 | @GetMapping(path = "/brands")
|
---|
38 | public List<String> getBrands(){
|
---|
39 | return phoneService.getBrands();
|
---|
40 | }
|
---|
41 |
|
---|
42 | }
|
---|