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