Skip to content
Snippets Groups Projects
Commit ffb47701 authored by John Watkins's avatar John Watkins
Browse files

Added filter of shops that people have stamps or have starred

parent 50506d2d
No related branches found
No related tags found
1 merge request!114LoggingService service class, new method to add a log to the "Logs" table when...
......@@ -4,6 +4,9 @@ import com.example.clientproject.data.shops.Shops;
import com.example.clientproject.data.shops.ShopsRepo;
import com.example.clientproject.data.tags.Tags;
import com.example.clientproject.data.tags.TagsRepo;
import com.example.clientproject.data.users.Users;
import com.example.clientproject.service.Utils.JWTUtils;
import com.example.clientproject.services.DashboardStampLoader;
import com.example.clientproject.services.RecommendationGenerator;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -26,6 +29,12 @@ public class ShopSearch {
@Autowired
RecommendationGenerator recommendationGenerator;
@Autowired
DashboardStampLoader stampLoader;
@Autowired
JWTUtils jwtUtils;
@GetMapping("/shop/search")
public String searchShops(@RequestParam(value = "q", required = false) String query,
@RequestParam(value = "p", required = false) Integer page,
......@@ -36,6 +45,26 @@ public class ShopSearch {
//Get all the active shops
List<Shops> allShops = shopsRepo.findActiveShops();
Optional<Users> user = jwtUtils.getLoggedInUserRow(session);
if(user.isPresent()){
Map<String,Object> userInfo = stampLoader.getData((int) user.get().getUserId());
//Filter off shops that the user has stamps in
List<Shops> purchased = (List<Shops>)userInfo.get("purchased");
allShops = allShops
.stream()
.filter(s -> !purchased.contains(s))
.collect(Collectors.toList());
//Filter off shops the user has favourited
List<Shops> favourited = (List<Shops>)userInfo.get("favourited");
allShops = allShops
.stream()
.filter(s -> !favourited.contains(s))
.collect(Collectors.toList());
}
//Filter the shops using the query provided
if(query != null){
allShops = allShops
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment