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

Last change on this file was ffd50db, checked in by Marko <Marko@…>, 21 months ago

Added few methods in PhoneOffer service

  • Property mode set to 100644
File size: 4.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.apache.coyote.Response;
9import org.springframework.beans.factory.annotation.Autowired;
10import org.springframework.http.MediaType;
11import org.springframework.http.ResponseEntity;
12import org.springframework.web.bind.annotation.*;
13
14import java.util.Comparator;
15import java.util.List;
16import java.util.stream.Collectors;
17
18@RestController
19@AllArgsConstructor
20@RequestMapping(path = "/")
21public class PhoneController {
22 private final PhoneService phoneService;
23
24 @GetMapping(path = "/phones")
25 public List<Phone> getPhones(@RequestParam(name = "shops", required = false) String shops,
26 @RequestParam(name = "brands", required = false) String brands,
27 @RequestParam(name = "sortBy", required = false) String sortBy,
28 @RequestParam(name = "priceRange", required = false) String priceRange,
29 @RequestParam(name = "searchValue", required = false) String searchValue,
30 @RequestParam(name = "ram", required = false) String ram,
31 @RequestParam(name = "rom", required = false) String rom,
32 @RequestParam(name = "frontcamera", required = false) String frontcamera,
33 @RequestParam(name = "backcamera", required = false) String backcamera,
34 @RequestParam(name = "chipset", required = false) String chipset,
35 @RequestParam(name = "cpu", required = false) String cpu,
36 @RequestParam(name = "operatingsystem", required = false) String operatingsystem,
37 @RequestParam(name = "color", required = false) String color,
38 @RequestParam(name = "battery", required = false) String battery){
39
40 return phoneService.getPhones(shops,brands,sortBy,priceRange,searchValue,
41 ram, rom, frontcamera, backcamera, chipset, cpu, operatingsystem, color, battery);
42 }
43
44 @GetMapping(path = "/phones/{phoneId}")
45 public Phone getPhoneById(@PathVariable("phoneId") Long phoneId)
46 {
47 return phoneService.getPhoneById(phoneId);
48 }
49
50 @GetMapping(path = "/brands")
51 public List<String> getBrands(){
52 return phoneService.getBrands();
53 }
54
55 @GetMapping(path = "/totaloffers/{phoneModel}")
56 public Long getTotalOffersForPhone(@PathVariable("phoneModel") String phoneModel){
57 return phoneService.getTotalOffersForPhone(phoneModel);
58 }
59
60 @PutMapping(path = "/settotaloffers/{phoneId}/{totaloffers}")
61 public ResponseEntity<Object> setTotalOffersForPhone(@PathVariable("phoneId") Long phoneId,
62 @PathVariable("totaloffers") int totaloffers){
63 return phoneService.setTotalOffersForPhone(phoneId,totaloffers);
64 }
65
66 @PutMapping(path = "/setlowestprice/{phoneId}/{lowestPrice}")
67 public ResponseEntity<Object> setLowestPriceForPhone(@PathVariable("phoneId") Long phoneId,
68 @PathVariable("lowestPrice") int lowestPrice){
69 return phoneService.setLowestPriceForPhone(phoneId,lowestPrice);
70 }
71
72 @PutMapping(path = "/setimageurl/{phoneId}", consumes = {
73 MediaType.APPLICATION_JSON_VALUE,
74 MediaType.APPLICATION_XML_VALUE
75 }, produces = {
76 MediaType.APPLICATION_JSON_VALUE,
77 MediaType.APPLICATION_XML_VALUE
78 })
79 public ResponseEntity<Object> setImageUrlForPhone(@PathVariable("phoneId") Long phoneId,
80 @RequestBody String newImageUrl){
81 return phoneService.setImageUrlForPhone(phoneId,newImageUrl);
82 }
83
84
85}
Note: See TracBrowser for help on using the repository browser.