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 | private final PhoneOfferService phoneOfferService;
|
---|
21 |
|
---|
22 | // handle request parameters for filtering phones
|
---|
23 | @GetMapping(path = "/phones")
|
---|
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);
|
---|
31 | }
|
---|
32 |
|
---|
33 | @GetMapping(path = "/phones/{phoneId}")
|
---|
34 | public Phone getPhoneById(@PathVariable("phoneId") Long phoneId)
|
---|
35 | {
|
---|
36 | return phoneService.getPhoneById(phoneId);
|
---|
37 | }
|
---|
38 |
|
---|
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();
|
---|
47 | }
|
---|
48 |
|
---|
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 |
|
---|
62 | }
|
---|