fixed search and add hints
This commit is contained in:
@@ -3,6 +3,10 @@ package com.krylov.refound.controller;
|
||||
import com.krylov.refound.dto.PostRequest;
|
||||
import com.krylov.refound.dto.PostResponse;
|
||||
import com.krylov.refound.dto.StatusUpdateRequest;
|
||||
import com.krylov.refound.enums.ErrorCode;
|
||||
import com.krylov.refound.exception.ApiException;
|
||||
import com.krylov.refound.search.PostFeedFilter;
|
||||
import com.krylov.refound.search.SearchSuggestService;
|
||||
import com.krylov.refound.service.PostService;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -11,6 +15,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -32,6 +37,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
public class PostController {
|
||||
|
||||
private final PostService service;
|
||||
private final SearchSuggestService searchSuggestService;
|
||||
|
||||
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public PostRequest create(@ModelAttribute PostRequest request, @RequestParam(value = "images", required = false) List<MultipartFile> images) {
|
||||
@@ -40,9 +46,26 @@ public class PostController {
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Page<PostResponse> getFeed(@RequestParam(required = false) String search, @PageableDefault(size = 20, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) {
|
||||
log.info("get all feed");
|
||||
return service.getFeed(search, pageable);
|
||||
public Page<PostResponse> getFeed(@RequestParam(required = false) String search,
|
||||
@RequestParam(required = false) String type,
|
||||
@RequestParam(name = "category", required = false) List<String> categories,
|
||||
@RequestParam(name = "city", required = false) List<String> cities,
|
||||
@PageableDefault(size = 20, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) {
|
||||
log.info("get feed: search='{}', type={}, categories={}, cities={}", search, type, categories, cities);
|
||||
PostFeedFilter filter;
|
||||
try {
|
||||
filter = PostFeedFilter.of(type, categories, cities);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ApiException(ErrorCode.VALIDATION_ERROR, "Некорректный фильтр ленты: " + e.getMessage(),
|
||||
HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return service.getFeed(search, filter, pageable);
|
||||
}
|
||||
|
||||
/** Подсказки для последнего слова строки поиска: «потерян барс» → [барсетка, барсик]. */
|
||||
@GetMapping("/search/suggest")
|
||||
public List<String> suggest(@RequestParam(name = "q", defaultValue = "") String query) {
|
||||
return searchSuggestService.suggest(query);
|
||||
}
|
||||
|
||||
@GetMapping("/{id:\\d+}")
|
||||
|
||||
Reference in New Issue
Block a user