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

Edited registration and login services

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  
    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}
  • phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneOfferController.java

    rdbd4834 rf25d07e  
    11package finki.it.phoneluxbackend.controllers;
    22
     3import finki.it.phoneluxbackend.entities.Phone;
    34import finki.it.phoneluxbackend.entities.PhoneOffer;
    45import finki.it.phoneluxbackend.services.PhoneOfferService;
     6import finki.it.phoneluxbackend.services.PhoneService;
     7import lombok.AllArgsConstructor;
    58import org.springframework.beans.factory.annotation.Autowired;
    69import org.springframework.web.bind.annotation.GetMapping;
     
    1215
    1316@RestController
    14 @RequestMapping(path = "/phone/{phoneId}")
     17@AllArgsConstructor
     18@RequestMapping(path = "/phones/offers/{phoneId}")
    1519public class PhoneOfferController {
    1620    private final PhoneOfferService phoneOfferService;
    17 
    18     @Autowired
    19     public PhoneOfferController(PhoneOfferService phoneOfferService) {
    20         this.phoneOfferService = phoneOfferService;
    21     }
     21    private final PhoneService phoneService;
    2222
    2323    @GetMapping
     
    2525        return phoneOfferService.getPhoneOffersForPhone(phoneId);
    2626    }
     27
    2728}
  • phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/RegistrationController.java

    rdbd4834 rf25d07e  
    44import finki.it.phoneluxbackend.services.RegistrationService;
    55import lombok.AllArgsConstructor;
     6import org.springframework.http.ResponseEntity;
    67import org.springframework.web.bind.annotation.*;
    78
     
    1314
    1415    @PostMapping
    15     public String RegisterRequest(@RequestBody RegistrationRequest request)
     16    public ResponseEntity<Object> RegisterRequest(@RequestBody RegistrationRequest request)
    1617    {
    1718        return registrationService.register(request);
Note: See TracChangeset for help on using the changeset viewer.