source: phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneController.java@ e5b84dc

Last change on this file since e5b84dc was e5b84dc, checked in by Marko <Marko@…>, 22 months ago

Prototype version

  • Property mode set to 100644
File size: 2.0 KB
Line 
1package finki.it.phoneluxbackend.controllers;
2
3import finki.it.phoneluxbackend.entities.Phone;
4import finki.it.phoneluxbackend.entities.PhoneOffer;
5import finki.it.phoneluxbackend.services.PhoneOfferService;
6import finki.it.phoneluxbackend.services.PhoneService;
7import lombok.AllArgsConstructor;
8import org.springframework.beans.factory.annotation.Autowired;
9import org.springframework.web.bind.annotation.*;
10
11import java.util.Comparator;
12import java.util.List;
13import java.util.stream.Collectors;
14
15@RestController
16@AllArgsConstructor
17@RequestMapping(path = "/")
18public 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}
Note: See TracBrowser for help on using the repository browser.