- Timestamp:
- 09/07/22 00:51:50 (2 years ago)
- Branches:
- master
- Children:
- 527b93f
- Parents:
- dbd4834
- Location:
- phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneController.java
rdbd4834 rf25d07e 3 3 import finki.it.phoneluxbackend.entities.Phone; 4 4 import finki.it.phoneluxbackend.entities.PhoneOffer; 5 import finki.it.phoneluxbackend.services.PhoneOfferService; 5 6 import finki.it.phoneluxbackend.services.PhoneService; 7 import lombok.AllArgsConstructor; 6 8 import org.springframework.beans.factory.annotation.Autowired; 7 9 import org.springframework.web.bind.annotation.*; 8 10 11 import java.util.Comparator; 9 12 import java.util.List; 13 import java.util.stream.Collectors; 10 14 11 15 @RestController 16 @AllArgsConstructor 12 17 @RequestMapping(path = "/") 13 18 public class PhoneController { 14 19 private final PhoneService phoneService; 20 private final PhoneOfferService phoneOfferService; 15 21 16 @Autowired 17 public PhoneController(PhoneService phoneService) { 18 this.phoneService = phoneService; 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(); 19 56 } 20 57 21 58 22 // handle request parameters for filtering phones23 @GetMapping24 public List<Phone> getPhones(){25 return phoneService.getPhones();26 }27 28 59 } -
phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneOfferController.java
rdbd4834 rf25d07e 1 1 package finki.it.phoneluxbackend.controllers; 2 2 3 import finki.it.phoneluxbackend.entities.Phone; 3 4 import finki.it.phoneluxbackend.entities.PhoneOffer; 4 5 import finki.it.phoneluxbackend.services.PhoneOfferService; 6 import finki.it.phoneluxbackend.services.PhoneService; 7 import lombok.AllArgsConstructor; 5 8 import org.springframework.beans.factory.annotation.Autowired; 6 9 import org.springframework.web.bind.annotation.GetMapping; … … 12 15 13 16 @RestController 14 @RequestMapping(path = "/phone/{phoneId}") 17 @AllArgsConstructor 18 @RequestMapping(path = "/phones/offers/{phoneId}") 15 19 public class PhoneOfferController { 16 20 private final PhoneOfferService phoneOfferService; 17 18 @Autowired 19 public PhoneOfferController(PhoneOfferService phoneOfferService) { 20 this.phoneOfferService = phoneOfferService; 21 } 21 private final PhoneService phoneService; 22 22 23 23 @GetMapping … … 25 25 return phoneOfferService.getPhoneOffersForPhone(phoneId); 26 26 } 27 27 28 } -
phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/RegistrationController.java
rdbd4834 rf25d07e 4 4 import finki.it.phoneluxbackend.services.RegistrationService; 5 5 import lombok.AllArgsConstructor; 6 import org.springframework.http.ResponseEntity; 6 7 import org.springframework.web.bind.annotation.*; 7 8 … … 13 14 14 15 @PostMapping 15 public StringRegisterRequest(@RequestBody RegistrationRequest request)16 public ResponseEntity<Object> RegisterRequest(@RequestBody RegistrationRequest request) 16 17 { 17 18 return registrationService.register(request);
Note:
See TracChangeset
for help on using the changeset viewer.