Skip to content

Commit

Permalink
possibilitando filtro de topico por nome do curso relacionado
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemayko committed May 10, 2021
1 parent 2fc819d commit f0c6c54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import br.com.alura.forum.controller.dto.TopicoDTO;
import br.com.alura.forum.controller.repository.TopicoRepository;
import br.com.alura.forum.modelo.Curso;
import br.com.alura.forum.modelo.Topico;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
Expand All @@ -20,7 +17,10 @@ public TopicoController(TopicoRepository repo) {
}

@GetMapping("/topicos")
public List<TopicoDTO> listaTopicos(){
return TopicoDTO.converter(repo.findAll());
public List<TopicoDTO> listaTopicos(String nomeCurso){
if(nomeCurso != null){
return TopicoDTO.converter(repo.findByCurso_nomeContainingIgnoreCase(nomeCurso));
}
return TopicoDTO.converter(repo.findAll());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import br.com.alura.forum.modelo.Topico;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface TopicoRepository extends JpaRepository<Topico, Long> {

public List<Topico> findByCurso_nomeContainingIgnoreCase(String nome);
}

0 comments on commit f0c6c54

Please sign in to comment.