Changeset 34950c6
- Timestamp:
- 09/22/22 03:14:04 (2 years ago)
- Branches:
- master
- Children:
- 436e0da
- Parents:
- d66b8eb
- Location:
- phonelux-backend/src/main/java/finki/it/phoneluxbackend
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
phonelux-backend/src/main/java/finki/it/phoneluxbackend/controllers/PhoneController.java
rd66b8eb r34950c6 24 24 @RequestParam(name = "sortBy", required = false) String sortBy, 25 25 @RequestParam(name = "priceRange", required = false) String priceRange, 26 @RequestParam(name = "searchValue", required = false) String searchValue){ 26 @RequestParam(name = "searchValue", required = false) String searchValue, 27 @RequestParam(name = "ram", required = false) String ram, 28 @RequestParam(name = "rom", required = false) String rom, 29 @RequestParam(name = "frontcamera", required = false) String frontcamera, 30 @RequestParam(name = "backcamera", required = false) String backcamera, 31 @RequestParam(name = "chipset", required = false) String chipset, 32 @RequestParam(name = "cpu", required = false) String cpu, 33 @RequestParam(name = "operatingsystem", required = false) String operatingsystem, 34 @RequestParam(name = "color", required = false) String color, 35 @RequestParam(name = "battery", required = false) String battery){ 27 36 28 return phoneService.getPhones(shops,brands,sortBy,priceRange,searchValue); 37 return phoneService.getPhones(shops,brands,sortBy,priceRange,searchValue, 38 ram, rom, frontcamera, backcamera, chipset, cpu, operatingsystem, color, battery); 29 39 } 30 40 -
phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneOfferService.java
rd66b8eb r34950c6 231 231 .map(cpu -> cpu.split("\n")[0].stripIndent().replaceAll("\n","")) 232 232 .filter(cpu -> !cpu.contains("Snapdragon") && !cpu.contains("Exynos")) 233 .filter(cpu -> Character.isAlphabetic(cpu.charAt(0))) 233 234 .distinct() 234 235 .sorted() … … 252 253 List<PhoneOffer> offers = phoneOfferRepository.findAll(); 253 254 254 returnoffers.stream()255 List<String> cameras = offers.stream() 255 256 .map(PhoneOffer::getBack_camera) 256 257 .filter(camera -> camera != null && !camera.equals("") && !camera.equals("/")) 257 258 .map(camera -> camera.split("[\n,]")[0].replaceAll("\t","")) 258 .distinct() 259 .sorted() 260 .collect(Collectors.toList()); 259 .flatMap(camera -> Arrays.stream(camera.split("[+/]"))) 260 .map(camera -> camera.replaceAll("MP","").stripIndent()) 261 .distinct() 262 .sorted() 263 .collect(Collectors.toList()); 264 265 cameras.stream() 266 .forEach(camera -> { 267 if(Character.isDigit(camera.charAt(0))) 268 cameras.set(cameras.indexOf(camera), camera+"MP"); 269 270 }); 271 272 return cameras; 261 273 } 262 274 … … 267 279 .map(PhoneOffer::getBattery) 268 280 .filter(battery -> battery != null && !battery.equals("") && !battery.equals("/")) 269 .map(battery -> battery.split(",")[0].stripIndent()) 281 .map(battery -> battery.split(",")[0] 282 .split("\n")[0] 283 .replaceAll("'","") 284 .replaceAll("\t"," ") 285 .stripIndent()) 286 .map(battery -> battery.replaceAll("battery", "").stripIndent()) 270 287 .distinct() 271 288 .sorted(Comparator.reverseOrder()) -
phonelux-backend/src/main/java/finki/it/phoneluxbackend/services/PhoneService.java
rd66b8eb r34950c6 8 8 import org.springframework.stereotype.Service; 9 9 10 import java.util.Arrays; 10 11 import java.util.Comparator; 11 12 import java.util.List; … … 23 24 24 25 // TODO: insert logic to filter 25 public List<Phone> getPhones(String shops, String brands, String sortBy, String priceRange, String searchValue){ 26 public List<Phone> getPhones(String shops, String brands, String sortBy, String priceRange, String searchValue, 27 String ram, String rom, String frontcamera, String backcamera, String chipset, 28 String cpu, String operatingsystem, String color, String battery){ 26 29 List<Phone> phones = phoneRepository.findAll(); 27 30 … … 55 58 .collect(Collectors.toList()); 56 59 } 60 61 62 // specifications filters 63 64 if(ram != null){ 65 String [] memories = ram.split(","); 66 phones = phones.stream() 67 .filter(phone -> Arrays.stream(memories).anyMatch(memory -> phone.getPhoneOffers().stream() 68 .filter(offer -> offer.getRam_memory() != null) 69 .anyMatch(offer -> hasSpecification(offer.getRam_memory(),memory)) 70 ) 71 ) 72 .collect(Collectors.toList()); 73 } 74 75 if(rom != null){ 76 String [] memories = rom.split(","); 77 phones = phones.stream() 78 .filter(phone -> Arrays.stream(memories).anyMatch(memory -> phone.getPhoneOffers().stream() 79 .filter(offer -> offer.getRom_memory() != null) 80 .anyMatch(offer -> hasSpecification(offer.getRom_memory(),memory)))) 81 .collect(Collectors.toList()); 82 } 83 84 if(frontcamera != null){ 85 String [] cameras = frontcamera.split(","); 86 phones = phones.stream() 87 .filter(phone -> Arrays.stream(cameras).anyMatch(camera -> phone.getPhoneOffers().stream() 88 .filter(offer -> offer.getFront_camera() != null) 89 .anyMatch(offer -> hasSpecification(offer.getFront_camera(),camera) 90 ) 91 ) 92 ) 93 .collect(Collectors.toList()); 94 } 95 96 if(backcamera != null){ 97 String [] cameras = backcamera.split(","); 98 phones = phones.stream() 99 .filter(phone -> Arrays.stream(cameras).anyMatch(camera -> phone.getPhoneOffers().stream() 100 .filter(offer -> offer.getBack_camera() != null) 101 .anyMatch(offer -> hasSpecification(offer.getBack_camera(),camera)))) 102 .collect(Collectors.toList()); 103 } 104 105 if(chipset != null) 106 { 107 String [] chipsets = chipset.split(","); 108 phones = phones.stream() 109 .filter(phone -> Arrays.stream(chipsets).anyMatch(chip -> phone.getPhoneOffers().stream() 110 .filter(offer -> offer.getChipset() != null) 111 .anyMatch(offer -> offer.getChipset().contains(chip)))) 112 .collect(Collectors.toList()); 113 } 114 115 if(cpu != null) 116 { 117 String [] cpus = cpu.split(","); 118 phones = phones.stream() 119 .filter(phone -> Arrays.stream(cpus).anyMatch(processor -> phone.getPhoneOffers().stream() 120 .filter(offer -> offer.getCpu() != null) 121 .anyMatch(offer -> offer.getCpu().contains(processor)))) 122 .collect(Collectors.toList()); 123 } 124 125 if(operatingsystem != null) 126 { 127 String [] operatingSystems = operatingsystem.split(","); 128 phones = phones.stream() 129 .filter(phone -> Arrays.stream(operatingSystems).anyMatch(os -> phone.getPhoneOffers().stream() 130 .filter(offer -> offer.getOperating_system() != null) 131 .anyMatch(offer -> offer.getOperating_system().contains(os)))) 132 .collect(Collectors.toList()); 133 } 134 135 if(color != null) 136 { 137 String [] colors = color.split(","); 138 phones = phones.stream() 139 .filter(phone -> Arrays.stream(colors).anyMatch(c -> phone.getPhoneOffers().stream() 140 .filter(offer -> offer.getColor() != null) 141 .anyMatch(offer -> offer.getColor().contains(c)))) 142 .collect(Collectors.toList()); 143 } 144 145 if(battery != null) 146 { 147 String [] batteries = battery.split(","); 148 phones = phones.stream() 149 .filter(phone -> Arrays.stream(batteries).anyMatch(b -> phone.getPhoneOffers().stream() 150 .filter(offer -> offer.getBattery() != null) 151 .anyMatch(offer -> offer.getBattery().contains(b)))) 152 .collect(Collectors.toList()); 153 } 154 57 155 58 156 phones = phones.stream().sorted(Comparator.comparing(Phone::getTotal_offers).reversed()) … … 74 172 75 173 return phones; 174 } 175 176 public boolean hasSpecification(String specification, String filter){ 177 if(specification.contains(filter)) 178 { 179 if(specification.indexOf(filter)-1 < 0) { 180 return true; 181 } 182 183 if(!Character.isDigit(specification 184 .charAt(specification.indexOf(filter)-1))) { 185 return true; 186 } 187 } 188 189 if(specification.contains(filter.split("GB")[0]+" GB")) 190 { 191 if(specification.indexOf(filter.split("GB")[0]+" GB")-1 < 0) { 192 return true; 193 } 194 195 if(!Character.isDigit(specification 196 .charAt(specification.indexOf(filter.split("GB")[0]+" GB")-1))) { 197 return true; 198 } 199 } 200 201 if(specification.contains(filter.split("MP")[0]+" MP")) 202 { 203 if(specification.indexOf(filter.split("MP")[0]+" MP")-1 < 0) { 204 return true; 205 } 206 207 if(!Character.isDigit(specification 208 .charAt(specification.indexOf(filter.split("MP")[0]+" MP")-1))) { 209 return true; 210 } 211 } 212 213 if(specification.contains(filter.split("MB")[0]+" MB")) 214 { 215 if(specification.indexOf(filter.split("MB")[0]+" MB")-1 < 0) { 216 return true; 217 } 218 219 if(!Character.isDigit(specification 220 .charAt(specification.indexOf(filter.split("MB")[0]+" MB")-1))) { 221 return true; 222 } 223 } 224 225 return false; 76 226 } 77 227
Note:
See TracChangeset
for help on using the changeset viewer.