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.apache.coyote.Response;
|
---|
9 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
10 | import org.springframework.http.MediaType;
|
---|
11 | import org.springframework.http.ResponseEntity;
|
---|
12 | import org.springframework.web.bind.annotation.*;
|
---|
13 |
|
---|
14 | import java.util.Comparator;
|
---|
15 | import java.util.List;
|
---|
16 | import java.util.stream.Collectors;
|
---|
17 |
|
---|
18 | @RestController
|
---|
19 | @AllArgsConstructor
|
---|
20 | @RequestMapping(path = "/")
|
---|
21 | public 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 | }
|
---|