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

Commit

Permalink
feat: implementando função de paginação
Browse files Browse the repository at this point in the history
  • Loading branch information
JuannCarloss committed Mar 20, 2024
1 parent 632e932 commit 5cd3128
Show file tree
Hide file tree
Showing 22 changed files with 170 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.senac.gestaocurso.models.Certificacoes;
import com.senac.gestaocurso.service.CertificacoesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.net.URI;
Expand All @@ -18,12 +21,14 @@ public class CertificacoesController {
@PostMapping()
public ResponseEntity salvar(@RequestBody Certificacoes certificacoes){
Certificacoes save = certificacoesService.salvar(certificacoes);
return ResponseEntity.created(URI.create("/funcionario/salvar" + certificacoes.getId())).body(save);
return ResponseEntity.created(URI.create("/api/certificacoes" + certificacoes.getId())).body(save);
}

@GetMapping
public ResponseEntity findAll() {
List<Certificacoes> certificacoes = certificacoesService.buscaTodos();
public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "0") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<Certificacoes> certificacoes = certificacoesService.buscaTodos(pageable);
return ResponseEntity.ok(certificacoes);
}
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.senac.gestaocurso.models.Curso;
import com.senac.gestaocurso.service.CursoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -19,12 +22,14 @@ public class CursoController {
@PostMapping()
public ResponseEntity salvar(@RequestBody Curso curso){
Curso save = cursoService.salvar(curso);
return ResponseEntity.created(URI.create("/cursos/salvar" + curso.getId())).body(save);
return ResponseEntity.created(URI.create("/api/cursos" + curso.getId())).body(save);
}

@GetMapping
public ResponseEntity findAll() {
List<Curso> cursos = cursoService.buscaTodos();
public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "0") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<Curso> cursos = cursoService.buscaTodos(pageable);
return ResponseEntity.ok(cursos);
}
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.senac.gestaocurso.models.DadosBancarios;
import com.senac.gestaocurso.service.DadosBancariosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -18,12 +21,14 @@ public class DadosBancariosController {
@PostMapping()
public ResponseEntity salvar(@RequestBody DadosBancarios dadosBancarios){
DadosBancarios save = dadosBancariosService.salvar(dadosBancarios);
return ResponseEntity.created(URI.create("/dadosbancarios/salvar" + dadosBancarios.getId())).body(save);
return ResponseEntity.created(URI.create("/api/dadosbancarios" + dadosBancarios.getId())).body(save);
}

@GetMapping
public ResponseEntity findAll() {
List<DadosBancarios> dadosBancarios = dadosBancariosService.buscaTodos();
public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "0") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<DadosBancarios> dadosBancarios = dadosBancariosService.buscaTodos(pageable);
return ResponseEntity.ok(dadosBancarios);
}
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.senac.gestaocurso.models.Dependentes;
import com.senac.gestaocurso.service.DependentesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.net.URI;
Expand All @@ -18,12 +21,14 @@ public class DependentesController {
@PostMapping()
public ResponseEntity salvar(@RequestBody Dependentes dependentes){
Dependentes save = dependentesService.salvar(dependentes);
return ResponseEntity.created(URI.create("/dependentes/salvar" + dependentes.getId())).body(save);
return ResponseEntity.created(URI.create("/api/dependentes" + dependentes.getId())).body(save);
}

@GetMapping
public ResponseEntity findAll() {
List<Dependentes> dependentes = dependentesService.buscaTodos();
public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "0") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<Dependentes> dependentes = dependentesService.buscaTodos(pageable);
return ResponseEntity.ok(dependentes);
}
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.senac.gestaocurso.models.ExpAnterior;
import com.senac.gestaocurso.service.ExpAnteriorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.net.URI;
Expand All @@ -19,12 +22,14 @@ public class ExpAnteriorController {
@PostMapping()
public ResponseEntity salvar(@RequestBody ExpAnterior expAnterior) {
ExpAnterior save = expAnteriorService.salvar(expAnterior);
return ResponseEntity.created(URI.create("/funcionario/salvar" + expAnterior.getId())).body(save);
return ResponseEntity.created(URI.create("/api/experiencias" + expAnterior.getId())).body(save);
}

@GetMapping
public ResponseEntity findAll() {
List<ExpAnterior> expAnteriors = expAnteriorService.buscaTodos();
public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "0") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<ExpAnterior> expAnteriors = expAnteriorService.buscaTodos(pageable);
return ResponseEntity.ok(expAnteriors);
}
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.senac.gestaocurso.models.Filiacao;
import com.senac.gestaocurso.service.FiliacaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -17,12 +20,14 @@ public class FiliacaoController {
@PostMapping()
public ResponseEntity salvar(@RequestBody Filiacao filiacao){
Filiacao save = filiacaoService.salvar(filiacao);
return ResponseEntity.created(URI.create("/filiacao/salvar" + filiacao.getId())).body(save);
return ResponseEntity.created(URI.create("/api/filiacao" + filiacao.getId())).body(save);
}

@GetMapping
public ResponseEntity findAll() {
List<Filiacao> filiacao = filiacaoService.buscaTodos();
public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "0") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<Filiacao> filiacao = filiacaoService.buscaTodos(pageable);
return ResponseEntity.ok(filiacao);
}
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.senac.gestaocurso.models.Frequencia;
import com.senac.gestaocurso.service.FrequenciaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -17,11 +20,13 @@ public class FrequenciaController {
@PostMapping()
public ResponseEntity salvar(@RequestBody Frequencia frequencia){
Frequencia save = frequenciaService.salvar(frequencia);
return ResponseEntity.created(URI.create("/frequencia/salvar" + frequencia.getId())).body(save);
return ResponseEntity.created(URI.create("/api/frequencia" + frequencia.getId())).body(save);
}
@GetMapping
public ResponseEntity findAll() {
List<Frequencia> frequencias = frequenciaService.buscaTodos();
public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "0") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<Frequencia> frequencias = frequenciaService.buscaTodos(pageable);
return ResponseEntity.ok(frequencias);
}
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.senac.gestaocurso.models.Funcionario;
import com.senac.gestaocurso.service.FuncionarioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -24,8 +27,10 @@ public ResponseEntity salvar(@RequestBody Funcionario funcionario){


@GetMapping
public ResponseEntity findAll() {
List<Funcionario> funcionarios = funcionarioService.buscaTodos();
public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "0") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<Funcionario> funcionarios = funcionarioService.buscaTodos(pageable);
return ResponseEntity.ok(funcionarios);
}
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.senac.gestaocurso.service.FuncionarioService;
import com.senac.gestaocurso.service.InscricaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -19,12 +22,14 @@ public class InscricaoController {
@PostMapping()
public ResponseEntity salvar(@RequestBody Inscricao inscricao){
Inscricao save = inscricaoService.salvar(inscricao);
return ResponseEntity.created(URI.create("/inscricao/salvar" + inscricao.getId())).body(save);
return ResponseEntity.created(URI.create("/api/inscricao" + inscricao.getId())).body(save);
}

@GetMapping
public ResponseEntity findAll() {
List<Inscricao> inscricao = inscricaoService.buscaTodos();
public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "0") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<Inscricao> inscricao = inscricaoService.buscaTodos(pageable);
return ResponseEntity.ok(inscricao);
}
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.senac.gestaocurso.models.Materia;
import com.senac.gestaocurso.service.MateriaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -18,12 +21,14 @@ public class MateriaController {
@PostMapping()
public ResponseEntity salvar(@RequestBody Materia materia){
Materia save = materiaService.salvar(materia);
return ResponseEntity.created(URI.create("/materia/salvar" + materia.getId())).body(save);
return ResponseEntity.created(URI.create("/api/materia" + materia.getId())).body(save);
}

@GetMapping
public ResponseEntity findAll() {
List<Materia> materias = materiaService.buscaTodos();
public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "0") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<Materia> materias = materiaService.buscaTodos(pageable);
return ResponseEntity.ok(materias);
}
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.senac.gestaocurso.models.Turma;
import com.senac.gestaocurso.service.TurmaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -19,12 +22,14 @@ public class TurmaController {
@PostMapping()
public ResponseEntity salvar(@RequestBody Turma turma){
Turma save = turmaService.salvar(turma);
return ResponseEntity.created(URI.create("/turma/salvar" + turma.getId())).body(save);
return ResponseEntity.created(URI.create("/api/turma" + turma.getId())).body(save);
}

@GetMapping
public ResponseEntity findAll() {
List<Turma> funcionarios = turmaService.buscaTodos();
public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "0") int size) {
Pageable pageable = PageRequest.of(page, size);
Page<Turma> funcionarios = turmaService.buscaTodos(pageable);
return ResponseEntity.ok(funcionarios);
}
@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.senac.gestaocurso.models.Certificacoes;
import com.senac.gestaocurso.repository.CertifcacoesRepository;
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,10 +17,12 @@
public class CertificacoesService {
@Autowired
private CertifcacoesRepository certifcacoesRepository;
public Certificacoes salvar(Certificacoes entity) {return certifcacoesRepository.save(entity);}
public Certificacoes salvar(Certificacoes entity) {
return certifcacoesRepository.save(entity);
}

public List<Certificacoes> buscaTodos() {
return certifcacoesRepository.findAll();
public Page<Certificacoes> buscaTodos(Pageable pageable) {
return certifcacoesRepository.findAll(pageable);
}
public Certificacoes buscaPorId(Long id) {
return certifcacoesRepository.findById(id).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.senac.gestaocurso.models.Curso;
import com.senac.gestaocurso.repository.CursoRepository;
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 @@ -12,9 +14,11 @@
public class CursoService {
@Autowired
private CursoRepository cursoRepository;
public Curso salvar(Curso entity) {return cursoRepository.save(entity);}
public List<Curso> buscaTodos() {
return cursoRepository.findAll();
public Curso salvar(Curso entity) {
return cursoRepository.save(entity);
}
public Page<Curso> buscaTodos(Pageable pageable) {
return cursoRepository.findAll(pageable);
}
public Curso buscaPorId(Long id) {
return cursoRepository.findById(id).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.senac.gestaocurso.models.DadosBancarios;
import com.senac.gestaocurso.repository.DadosBancariosRepository;
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 @@ -13,9 +15,11 @@
public class DadosBancariosService {
@Autowired
private DadosBancariosRepository dadosBancariosRepository;
public DadosBancarios salvar(DadosBancarios entity) {return dadosBancariosRepository.save(entity);}
public List<DadosBancarios> buscaTodos() {
return dadosBancariosRepository.findAll();
public DadosBancarios salvar(DadosBancarios entity) {
return dadosBancariosRepository.save(entity);
}
public Page<DadosBancarios> buscaTodos(Pageable pageable) {
return dadosBancariosRepository.findAll(pageable);
}
public DadosBancarios buscaPorId(Long id) {
return dadosBancariosRepository.findById(id).orElse(null);
Expand Down
Loading

0 comments on commit 5cd3128

Please sign in to comment.