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

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

Edited registration and login services

  • Property mode set to 100644
File size: 1.7 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(){
25 return phoneService.getPhones().stream()
26 .sorted(Comparator.comparing(Phone::getTotal_offers).reversed())
27 .collect(Collectors.toList());
28 }
29
30 @GetMapping(path = "/phones/{phoneId}")
31 public Phone getPhoneById(@PathVariable("phoneId") Long phoneId)
32 {
33 return phoneService.getPhoneById(phoneId);
34 }
35
36 @GetMapping(path = "/brands")
37 public List<String> getBrands(){
38 return phoneService.getBrands();
39 }
40
41 @GetMapping(path = "/shops")
42 public List<String> getShops(){
43 return phoneOfferService.getShops();
44 }
45
46 @GetMapping(path = "/lowestPrice")
47 public int getLowestPrice()
48 {
49 return phoneOfferService.getLowestPrice();
50 }
51
52 @GetMapping(path = "/highestPrice")
53 public int getHighestPrice()
54 {
55 return phoneOfferService.getHighestPrice();
56 }
57
58
59}
Note: See TracBrowser for help on using the repository browser.