Ignore:
Timestamp:
09/07/22 00:51:50 (2 years ago)
Author:
Marko <Marko@…>
Branches:
master
Children:
527b93f
Parents:
dbd4834
Message:

Edited registration and login services

File:
1 edited

Legend:

Unmodified
Added
Removed
  • phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneController.java

    rdbd4834 rf25d07e  
    33import finki.it.phoneluxbackend.entities.Phone;
    44import finki.it.phoneluxbackend.entities.PhoneOffer;
     5import finki.it.phoneluxbackend.services.PhoneOfferService;
    56import finki.it.phoneluxbackend.services.PhoneService;
     7import lombok.AllArgsConstructor;
    68import org.springframework.beans.factory.annotation.Autowired;
    79import org.springframework.web.bind.annotation.*;
    810
     11import java.util.Comparator;
    912import java.util.List;
     13import java.util.stream.Collectors;
    1014
    1115@RestController
     16@AllArgsConstructor
    1217@RequestMapping(path = "/")
    1318public class PhoneController {
    1419    private final PhoneService phoneService;
     20    private final PhoneOfferService phoneOfferService;
    1521
    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();
    1956    }
    2057
    2158
    22     // handle request parameters for filtering phones
    23     @GetMapping
    24     public List<Phone> getPhones(){
    25         return phoneService.getPhones();
    26     }
    27 
    2859}
Note: See TracChangeset for help on using the changeset viewer.