|
22 | 22 | import org.springframework.beans.propertyeditors.StringTrimmerEditor;
|
23 | 23 | import org.springframework.http.HttpStatus;
|
24 | 24 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
| 25 | +import org.springframework.security.core.context.SecurityContextHolder; |
25 | 26 | import org.springframework.stereotype.Controller;
|
26 | 27 | import org.springframework.ui.Model;
|
27 | 28 | import org.springframework.validation.BindingResult;
|
|
72 | 73 | import java.util.Locale;
|
73 | 74 | import java.util.Map;
|
74 | 75 | import java.util.Objects;
|
| 76 | +import java.util.stream.Collectors; |
75 | 77 |
|
76 | 78 | import static ru.mystamps.web.common.ControllerUtils.redirectTo;
|
77 | 79 |
|
@@ -470,10 +472,12 @@ public String processAskForm(
|
470 | 472 | public String searchSeriesByCatalog(
|
471 | 473 | @RequestParam(name = "catalogNumber", defaultValue = "") String catalogNumber,
|
472 | 474 | @RequestParam(name = "catalogName", defaultValue = "") String catalogName,
|
| 475 | + @RequestParam(name = "inCollection", defaultValue = "false") Boolean inCollection, |
| 476 | + @CurrentUser Integer currentUserId, |
473 | 477 | Model model,
|
474 | 478 | Locale userLocale,
|
475 | 479 | RedirectAttributes redirectAttributes) {
|
476 |
| - |
| 480 | + |
477 | 481 | if (StringUtils.isBlank(catalogNumber)) {
|
478 | 482 | redirectAttributes.addFlashAttribute("numberIsEmpty", true);
|
479 | 483 | return "redirect:" + SiteUrl.INDEX_PAGE;
|
@@ -504,6 +508,18 @@ public String searchSeriesByCatalog(
|
504 | 508 | series = Collections.emptyList();
|
505 | 509 | break;
|
506 | 510 | }
|
| 511 | + |
| 512 | + if (Features.SEARCH_IN_COLLECTION.isActive() |
| 513 | + && inCollection |
| 514 | + && SecurityContextHolder.getContext().getAuthentication().isAuthenticated()) { |
| 515 | + series = series |
| 516 | + .stream() |
| 517 | + .filter( |
| 518 | + e->collectionService.isSeriesInCollection(currentUserId, e.getId()) |
| 519 | + ) |
| 520 | + .collect(Collectors.toList()); |
| 521 | + } |
| 522 | + |
507 | 523 | model.addAttribute("searchResults", series);
|
508 | 524 |
|
509 | 525 | return "series/search_result";
|
|
0 commit comments