fullSearch (Query method)

Repository

Tudo permanece o mesmo, só trocamos o retorno.

@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

Antes

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;
}

Depois

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

Antes

@GetMapping(value = "/fullsearch")
public ResponseEntity<List<PostDTO>> fullSearch(
			@RequestParam(value = "text", defaultValue = "") String text,
			@RequestParam(value = "minDate", defaultValue = "") String minDate,
			@RequestParam(value = "maxDate", defaultValue = "") String maxDate) throws UnsupportedEncodingException, ParseException {
		
    text = URL.decodeParam(text);
    Instant min = URL.convertDate(minDate, Instant.EPOCH);
    Instant max = URL.convertDate(maxDate, Instant.now());
		
    List<PostDTO> list = service.fullSearch(text, min, max);
    return ResponseEntity.ok(list);
}

Depois

@GetMapping(value = "/fullsearch")
public Flux<PostDTO> fullSearch(
			@RequestParam(value = "text", defaultValue = "") String text,
			@RequestParam(value = "minDate", defaultValue = "") String minDate,
			@RequestParam(value = "maxDate", defaultValue = "") String maxDate) throws UnsupportedEncodingException, ParseException {
		
    text = URL.decodeParam(text);
    Instant min = URL.convertDate(minDate, Instant.EPOCH);
    Instant max = URL.convertDate(maxDate, Instant.now());
		
    return service.fullSearch(text, min, max);
}

Atualizado