Changeset e5b84dc for phonelux-backend/src/main/java/finki/it
- Timestamp:
- 09/11/22 18:03:58 (2 years ago)
- Branches:
- master
- Children:
- 775e15e
- Parents:
- 527b93f
- Location:
- phonelux-backend/src/main/java/finki/it/phoneluxbackend
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneController.java
r527b93f re5b84dc 22 22 // handle request parameters for filtering phones 23 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()); 24 public List<Phone> getPhones(@RequestParam(name = "shops", required = false) String shops, 25 @RequestParam(name = "brands", required = false) String brands, 26 @RequestParam(name = "sortBy", required = false) String sortBy, 27 @RequestParam(name = "priceRange", required = false) String priceRange, 28 @RequestParam(name = "searchValue", required = false) String searchValue){ 29 30 return phoneService.getPhones(shops,brands,sortBy,priceRange,searchValue); 28 31 } 29 32 -
phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneOfferController.java
r527b93f re5b84dc 16 16 @RestController 17 17 @AllArgsConstructor 18 @RequestMapping(path = "/phones/offers/{phoneId}")19 18 public class PhoneOfferController { 20 19 private final PhoneOfferService phoneOfferService; 21 20 private final PhoneService phoneService; 22 21 23 @GetMapping 22 @GetMapping(path = "/phones/offers/{phoneId}") 24 23 public List<PhoneOffer> getOffersForPhone(@PathVariable("phoneId") Long phoneId){ 25 24 return phoneOfferService.getPhoneOffersForPhone(phoneId); 26 25 } 27 26 27 @GetMapping(path = "/phoneoffer/{offerId}") 28 public PhoneOffer getPhoneOffer(@PathVariable("offerId") Long offerId){ 29 return phoneOfferService.getPhoneOffer(offerId); 30 } 31 28 32 } -
phonelux-backend/src/main/java/finki/it/phoneluxbackend/security/CustomAuthenticationFilter.java
r527b93f re5b84dc 33 33 @Override 34 34 public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { 35 String email = request.getParameter("email"); // mozda ke treba da se smeni vo username35 String email = request.getParameter("email"); 36 36 String password = request.getParameter("password"); 37 37 UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(email,password); … … 46 46 String access_token = JWT.create() 47 47 .withSubject(user.getEmail()) 48 .withExpiresAt(new Date(System.currentTimeMillis() + 10 * 60 * 1000 ))48 .withExpiresAt(new Date(System.currentTimeMillis() + 10 * 60 * 100000)) // approx. 16.5 hours 49 49 .withIssuer(request.getRequestURL().toString()) 50 50 .withClaim("role", user.getAuthorities().stream() -
phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneOfferService.java
r527b93f re5b84dc 30 30 } 31 31 32 public PhoneOffer getPhoneOffer(Long offerId){ 33 boolean exists = phoneOfferRepository.existsById(offerId); 34 35 if(!exists) 36 throw new IllegalStateException("Phone offer with id "+offerId+" does not exist"); 37 38 return phoneOfferRepository.findById(offerId).get(); 39 } 40 41 32 42 public List<String> getShops() { 33 43 return phoneOfferRepository.findAll().stream() -
phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneService.java
r527b93f re5b84dc 10 10 import java.util.Comparator; 11 11 import java.util.List; 12 import java.util.Objects; 12 13 import java.util.stream.Collectors; 13 14 … … 22 23 23 24 // TODO: insert logic to filter 24 public List<Phone> getPhones(){ 25 return phoneRepository.findAll(); 25 public List<Phone> getPhones(String shops, String brands, String sortBy, String priceRange, String searchValue){ 26 List<Phone> phones = phoneRepository.findAll(); 27 28 29 if(brands != null) 30 { 31 phones = phones.stream() 32 .filter(phone -> brands.contains(phone.getBrand())).collect(Collectors.toList()); 33 } 34 35 if(shops != null) 36 { 37 phones = phones.stream() 38 .filter(phone -> phone.getPhoneOffers().stream().anyMatch(offer -> shops.contains(offer.getOffer_shop()))) 39 .collect(Collectors.toList()); 40 } 41 42 if(priceRange != null) 43 { 44 int lowestPrice = Integer.parseInt(priceRange.split("-")[0]); 45 int highestPrice = Integer.parseInt(priceRange.split("-")[1]); 46 phones = phones.stream() 47 .filter(phone -> phone.getLowestPrice() >= lowestPrice && phone.getLowestPrice() <= highestPrice) 48 .collect(Collectors.toList()); 49 } 50 51 if(searchValue != null && !Objects.equals(searchValue.stripIndent(), "")){ 52 phones = phones.stream() 53 .filter(phone -> phone.getBrand().toLowerCase().contains(searchValue.stripIndent().toLowerCase()) 54 || phone.getModel().toLowerCase().contains(searchValue.stripIndent().toLowerCase())) 55 .collect(Collectors.toList()); 56 } 57 58 phones = phones.stream().sorted(Comparator.comparing(Phone::getTotal_offers).reversed()) 59 .collect(Collectors.toList()); 60 if(sortBy != null) 61 { 62 if(sortBy.equals("ascending")) { 63 phones = phones.stream() 64 .sorted(Comparator.comparing(Phone::getLowestPrice)) 65 .collect(Collectors.toList()); 66 } 67 68 if(sortBy.equals("descending")) { 69 phones = phones.stream() 70 .sorted(Comparator.comparing(Phone::getLowestPrice).reversed()) 71 .collect(Collectors.toList()); 72 } 73 } 74 75 return phones; 26 76 } 27 77 -
phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/UserService.java
r527b93f re5b84dc 40 40 User userToRegister = userRepository.findByEmail(user.getEmail()).get(); 41 41 if(userToRegister.getEnabled()) { 42 return ResponseEntity.badRequest().body("Error: Email "+user.getEmail()+" already taken!");42 return ResponseEntity.badRequest().body("Error:Е-маил адресата е веќе зафатена!"); 43 43 } 44 44 else { 45 return ResponseEntity.badRequest().body("E mail "+user.getEmail()+" not activated!" );45 return ResponseEntity.badRequest().body("Error:Профилот не е активиран. Потврдете на вашата е-маил адреса!" ); 46 46 } 47 47 }
Note:
See TracChangeset
for help on using the changeset viewer.