Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
feat: implementando metodo de alterar avaliacao e metodo de paginação
Browse files Browse the repository at this point in the history
  • Loading branch information
JuannCarloss committed Mar 20, 2024
1 parent 1056455 commit 9d4784a
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,20 +17,22 @@ public class AvaliacaoService {
@Autowired
private AvaliacaoRepository avaliacaoRepository;
public Avaliacao salvar(Avaliacao entity) {return avaliacaoRepository.save(entity);}
public List<Avaliacao> buscaTodos() {
return avaliacaoRepository.findAll();
public Page<Avaliacao> 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<Avaliacao> 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;
}
Expand Down

0 comments on commit 9d4784a

Please sign in to comment.