From 9d4784a3e96f1dcd02f4339443bbb0e015b7d1cc Mon Sep 17 00:00:00 2001 From: JuannCarloss Date: Tue, 19 Mar 2024 22:53:27 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20implementando=20metodo=20de=20alterar?= =?UTF-8?q?=20avaliacao=20e=20metodo=20de=20pagina=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gestaocurso/service/AvaliacaoService.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/com/senac/gestaocurso/service/AvaliacaoService.java b/backend/src/main/java/com/senac/gestaocurso/service/AvaliacaoService.java index ce3271e..e9e08c6 100644 --- a/backend/src/main/java/com/senac/gestaocurso/service/AvaliacaoService.java +++ b/backend/src/main/java/com/senac/gestaocurso/service/AvaliacaoService.java @@ -4,6 +4,8 @@ import com.senac.gestaocurso.models.Avaliacao; import com.senac.gestaocurso.repository.AvaliacaoRepository; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import java.util.List; @@ -15,20 +17,22 @@ public class AvaliacaoService { @Autowired private AvaliacaoRepository avaliacaoRepository; public Avaliacao salvar(Avaliacao entity) {return avaliacaoRepository.save(entity);} - public List buscaTodos() { - return avaliacaoRepository.findAll(); + public Page buscaTodos(Pageable pageable) { + return avaliacaoRepository.findAll(pageable); } public Avaliacao buscaPorId(Long id) { return avaliacaoRepository.findById(id).orElse(null); } public Avaliacao alterar(Long id, Avaliacao alterado) { Optional encontrado = avaliacaoRepository.findById(id); - if ((encontrado.isPresent())) { - - /** - * Classe precisa ser re-analisada - * */ - + if (encontrado.isPresent()) { + var avaliacao = encontrado.get(); + avaliacao.setAluno(alterado.getAluno()); + avaliacao.setData(alterado.getData()); + avaliacao.setMateria(alterado.getMateria()); + avaliacao.setNome(alterado.getNome()); + avaliacao.setNota(avaliacao.getNota()); + return avaliacaoRepository.save(avaliacao); } return null; }