[b68ae8d] | 1 | package finki.it.phoneluxbackend.controllers;
|
---|
| 2 |
|
---|
| 3 | import finki.it.phoneluxbackend.entities.Phone;
|
---|
| 4 | import finki.it.phoneluxbackend.entities.PhoneOffer;
|
---|
[f25d07e] | 5 | import finki.it.phoneluxbackend.services.PhoneOfferService;
|
---|
[b68ae8d] | 6 | import finki.it.phoneluxbackend.services.PhoneService;
|
---|
[f25d07e] | 7 | import lombok.AllArgsConstructor;
|
---|
[ffd50db] | 8 | import org.apache.coyote.Response;
|
---|
[b68ae8d] | 9 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
[ffd50db] | 10 | import org.springframework.http.MediaType;
|
---|
| 11 | import org.springframework.http.ResponseEntity;
|
---|
[b68ae8d] | 12 | import org.springframework.web.bind.annotation.*;
|
---|
| 13 |
|
---|
[f25d07e] | 14 | import java.util.Comparator;
|
---|
[b68ae8d] | 15 | import java.util.List;
|
---|
[f25d07e] | 16 | import java.util.stream.Collectors;
|
---|
[b68ae8d] | 17 |
|
---|
| 18 | @RestController
|
---|
[f25d07e] | 19 | @AllArgsConstructor
|
---|
[b68ae8d] | 20 | @RequestMapping(path = "/")
|
---|
| 21 | public class PhoneController {
|
---|
| 22 | private final PhoneService phoneService;
|
---|
| 23 |
|
---|
[f25d07e] | 24 | @GetMapping(path = "/phones")
|
---|
[e5b84dc] | 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,
|
---|
[34950c6] | 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);
|
---|
[b68ae8d] | 42 | }
|
---|
| 43 |
|
---|
[f25d07e] | 44 | @GetMapping(path = "/phones/{phoneId}")
|
---|
| 45 | public Phone getPhoneById(@PathVariable("phoneId") Long phoneId)
|
---|
| 46 | {
|
---|
| 47 | return phoneService.getPhoneById(phoneId);
|
---|
| 48 | }
|
---|
[dfd5d87] | 49 |
|
---|
[f25d07e] | 50 | @GetMapping(path = "/brands")
|
---|
| 51 | public List<String> getBrands(){
|
---|
| 52 | return phoneService.getBrands();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[ffd50db] | 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 |
|
---|
[b68ae8d] | 85 | }
|
---|