fullSearch (Query method)
Repository
@Query("{ $and: [ { date: {$gte: ?1} }, { date: { $lte: ?2} } , { $or: [ { 'title': { $regex: ?0, $options: 'i' } }, { 'body': { $regex: ?0, $options: 'i' } }, { 'comments.text': { $regex: ?0, $options: 'i' } } ] } ] }")
Flux<Post> fullSearch(String text, Instant minDate, Instant maxDate);Service
public List<PostDTO> fullSearch(String text, Instant minDate, Instant maxDate) {
maxDate = maxDate.plusSeconds(86400); // 24 * 60 * 60
List<PostDTO> result = repository.fullSearch(text, minDate, maxDate).stream().map(x -> new PostDTO(x)).toList();
return result;
}public Flux<PostDTO> fullSearch(String text, Instant minDate, Instant maxDate) {
maxDate = maxDate.plusSeconds(86400); // 24 * 60 * 60
return repository.fullSearch(text, minDate, maxDate)
.map(PostDTO::new)
.switchIfEmpty(Mono.error(new ResourceNotFoundException("Recurso não encontrado")));
}Controller
Atualizado