diff --git a/backend/src/main/java/com/senac/gestaocurso/repository/AulaRepository.java b/backend/src/main/java/com/senac/gestaocurso/repository/AulaRepository.java index 30c4949..810fb70 100644 --- a/backend/src/main/java/com/senac/gestaocurso/repository/AulaRepository.java +++ b/backend/src/main/java/com/senac/gestaocurso/repository/AulaRepository.java @@ -5,6 +5,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.time.LocalDate; + @Repository public interface AulaRepository extends JpaRepository, CustomQuerydslPredicateExecutor { + + Aula findByMateria(Long idMateria); + Aula findByDia(LocalDate dia); + Aula findByProfessor(Long idProfessor); } diff --git a/backend/src/main/java/com/senac/gestaocurso/service/AulaService.java b/backend/src/main/java/com/senac/gestaocurso/service/AulaService.java index 6bd069c..b8181a8 100644 --- a/backend/src/main/java/com/senac/gestaocurso/service/AulaService.java +++ b/backend/src/main/java/com/senac/gestaocurso/service/AulaService.java @@ -2,6 +2,7 @@ import com.senac.gestaocurso.models.domain.Aula; import com.senac.gestaocurso.repository.AulaRepository; +import com.senac.gestaocurso.strategy.NovaValidacaoAulaStrategy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -13,14 +14,24 @@ public class AulaService { @Autowired private AulaRepository aulaRepository; - public Aula salvar(Aula entity) {return aulaRepository.save(entity);} - public Page buscaTodos(Pageable pageable) { + + @Autowired + private List novaValidacaoAulaStrategies; + + public Aula salvar(Aula entity){ + novaValidacaoAulaStrategies.forEach(validar -> validar.validar(entity)); + return aulaRepository.save(entity); + } + + public Page buscaTodos(Pageable pageable){ return aulaRepository.findAll(pageable); } - public Aula buscaPorId(Long id) { + + public Aula buscaPorId(Long id){ return aulaRepository.findById(id).orElse(null); } - public Aula alterar(Long id, Aula alterado) { + + public Aula alterar(Long id, Aula alterado){ Optional encontrado = aulaRepository.findById(id); if ((encontrado.isPresent())) { Aula aula = encontrado.get(); @@ -28,8 +39,10 @@ public Aula alterar(Long id, Aula alterado) { aula.setDia(alterado.getDia()); return aulaRepository.save(aula); } + return null; } + public void remover(Long id) {aulaRepository.deleteById(id); } } diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/NovaValidacaoAulaStrategy.java b/backend/src/main/java/com/senac/gestaocurso/strategy/NovaValidacaoAulaStrategy.java new file mode 100644 index 0000000..9f42320 --- /dev/null +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/NovaValidacaoAulaStrategy.java @@ -0,0 +1,8 @@ +package com.senac.gestaocurso.strategy; + +import com.senac.gestaocurso.models.Aula; + +public interface NovaValidacaoAulaStrategy { + + void validar(Aula aula); +} diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/aulaValidacaoImp/ValidarMateriaDoProfessorPorDia.java b/backend/src/main/java/com/senac/gestaocurso/strategy/aulaValidacaoImp/ValidarMateriaDoProfessorPorDia.java new file mode 100644 index 0000000..af1af5a --- /dev/null +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/aulaValidacaoImp/ValidarMateriaDoProfessorPorDia.java @@ -0,0 +1,27 @@ +package com.senac.gestaocurso.strategy.aulaValidacaoImp; + +import com.senac.gestaocurso.enterprise.ValidationException; +import com.senac.gestaocurso.models.Aula; +import com.senac.gestaocurso.repository.AulaRepository; +import com.senac.gestaocurso.strategy.NovaValidacaoAulaStrategy; +import org.springframework.beans.factory.annotation.Autowired; + +import java.time.LocalDate; + +public class ValidarMateriaDoProfessorPorDia implements NovaValidacaoAulaStrategy { + + @Autowired + private AulaRepository repository; + + @Override + public void validar(Aula aula) { + if (validaMateriaPorDia(aula.getDia(), aula.getProfessor().getId())){ + throw new ValidationException("Esse professor já está com aula neste dia"); + } + } + + private boolean validaMateriaPorDia(LocalDate dia, Long idProfessor){ + return repository.findByDia(dia) != null && + repository.findByProfessor(idProfessor) != null; + } +} diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarListaCertificacoes.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ImplementaListaCertificacao.java similarity index 65% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarListaCertificacoes.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ImplementaListaCertificacao.java index c7f35e8..56a735c 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarListaCertificacoes.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ImplementaListaCertificacao.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.models.domain.Certificacao; import com.senac.gestaocurso.models.Funcionario; @@ -9,11 +9,11 @@ import java.util.stream.Collectors; @Component -public class ValidarListaCertificacoes implements ValidarImplementacaoListasStrategy { +public class ImplementaListaCertificacao implements ValidarImplementacaoListasStrategy { @Override public void lista(Funcionario funcionario) { - if (!funcionario.getCertificacoes().isEmpty()) { - List certificacaoList = funcionario.getCertificacoes() + if (validaLista(funcionario)) { + List certificacoesList = funcionario.getCertificacoes() .stream() .map(certificacoesIn -> new Certificacao( certificacoesIn.getNome(), @@ -25,4 +25,10 @@ public void lista(Funcionario funcionario) { funcionario.setCertificacoes(certificacaoList); } } + + private Boolean validaLista(Funcionario funcionario){ + if (!funcionario.getCertificacoes().isEmpty()) return true; + + return false; + } } diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarListaDadosBancarios.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ImplementaListaDadoBancario.java similarity index 66% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarListaDadosBancarios.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ImplementaListaDadoBancario.java index 4b154a7..f2490a3 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarListaDadosBancarios.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ImplementaListaDadoBancario.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.models.DadosBancario; import com.senac.gestaocurso.models.Funcionario; @@ -9,11 +9,11 @@ import java.util.stream.Collectors; @Component -public class ValidarListaDadosBancarios implements ValidarImplementacaoListasStrategy { +public class ImplementaListaDadoBancario implements ValidarImplementacaoListasStrategy { @Override public void lista(Funcionario funcionario) { - if (!funcionario.getDadosBancarios().isEmpty()) { - List dadosBancarioList = funcionario.getDadosBancarios() + if (validaLista(funcionario)) { + List dadosBancariosList = funcionario.getDadosBancarios() .stream() .map(dadosBancariosIn -> new DadosBancario( dadosBancariosIn.getBanco(), @@ -26,4 +26,10 @@ public void lista(Funcionario funcionario) { funcionario.setDadosBancarios(dadosBancarioList); } } + + private boolean validaLista(Funcionario funcionario){ + if (!funcionario.getDadosBancarios().isEmpty()) return true; + + return false; + } } diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarListaDependentes.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ImplementaListaDependente.java similarity index 64% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarListaDependentes.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ImplementaListaDependente.java index 0fe4344..7e35893 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarListaDependentes.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ImplementaListaDependente.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.models.Dependente; import com.senac.gestaocurso.models.Funcionario; @@ -9,13 +9,13 @@ import java.util.stream.Collectors; @Component -public class ValidarListaDependentes implements ValidarImplementacaoListasStrategy { +public class ImplementaListaDependente implements ValidarImplementacaoListasStrategy { @Override public void lista(Funcionario funcionario) { - if (!funcionario.getDependentes().isEmpty()){ - List dependenteList = funcionario.getDependentes() + if (validaLista(funcionario)){ + List dependentesList = funcionario.getDependentes() .stream() .map(dependentesIn -> new Dependente( dependentesIn.getNome(), @@ -27,4 +27,10 @@ public void lista(Funcionario funcionario) { funcionario.setDependentes(dependenteList); } } + + private boolean validaLista(Funcionario funcionario){ + if (!funcionario.getDependentes().isEmpty()) return true; + + return false; + } } diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarListaExpAnterior.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ImplementaListaExperienciaAnterior.java similarity index 66% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarListaExpAnterior.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ImplementaListaExperienciaAnterior.java index c9d3e6b..50edad2 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarListaExpAnterior.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ImplementaListaExperienciaAnterior.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.models.ExperienciaAnterior; import com.senac.gestaocurso.models.Funcionario; @@ -9,11 +9,11 @@ import java.util.stream.Collectors; @Component -public class ValidarListaExpAnterior implements ValidarImplementacaoListasStrategy { +public class ImplementaListaExperienciaAnterior implements ValidarImplementacaoListasStrategy { @Override public void lista(Funcionario funcionario) { - if (!funcionario.getExpAnterior().isEmpty()) { - List experienciaAnteriorList = funcionario.getExpAnterior() + if (validaLista(funcionario)) { + List expAnteriorList = funcionario.getExpAnterior() .stream() .map(expAnteriorIn -> new ExperienciaAnterior( expAnteriorIn.getDescricao(), @@ -26,4 +26,10 @@ public void lista(Funcionario funcionario) { funcionario.setExpAnterior(experienciaAnteriorList); } } + + private boolean validaLista(Funcionario funcionario){ + if (!funcionario.getExpAnterior().isEmpty()) return true; + + return false; + } } diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarCnh.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarCnh.java similarity index 92% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarCnh.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarCnh.java index 9231f7c..8578c46 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarCnh.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarCnh.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.enterprise.ValidationException; import com.senac.gestaocurso.models.Funcionario; diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarCpf.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarCpf.java similarity index 92% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarCpf.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarCpf.java index a9c93ba..69922b4 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarCpf.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarCpf.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.enterprise.ValidationException; import com.senac.gestaocurso.models.Funcionario; diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarCtbs.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarCtbs.java similarity index 92% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarCtbs.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarCtbs.java index 42c7b24..c55c962 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarCtbs.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarCtbs.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.enterprise.ValidationException; import com.senac.gestaocurso.models.Funcionario; diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarEmail.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarEmail.java similarity index 92% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarEmail.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarEmail.java index 9e3db94..b59cdd7 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarEmail.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarEmail.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.enterprise.ValidationException; import com.senac.gestaocurso.models.Funcionario; diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarMatricula.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarMatricula.java similarity index 92% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarMatricula.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarMatricula.java index 272bc63..4debdf0 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarMatricula.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarMatricula.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.enterprise.ValidationException; import com.senac.gestaocurso.models.Funcionario; diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarPisPasep.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarPisPasep.java similarity index 92% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarPisPasep.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarPisPasep.java index 1dda63b..91ce61a 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarPisPasep.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarPisPasep.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.enterprise.ValidationException; import com.senac.gestaocurso.models.Funcionario; diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValdiarReservista.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarReservista.java similarity index 86% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValdiarReservista.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarReservista.java index 478e329..a13a01e 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValdiarReservista.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarReservista.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.enterprise.ValidationException; import com.senac.gestaocurso.models.Funcionario; @@ -8,7 +8,7 @@ import org.springframework.stereotype.Component; @Component -public class ValdiarReservista implements NovaValidacaoFuncionarioStrategy { +public class ValidarReservista implements NovaValidacaoFuncionarioStrategy { @Autowired private FuncionarioRepository repository; diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarRg.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarRg.java similarity index 92% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarRg.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarRg.java index 197e88a..bbfbf95 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarRg.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarRg.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.enterprise.ValidationException; import com.senac.gestaocurso.models.Funcionario; diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarTelefone.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarTelefone.java similarity index 92% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarTelefone.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarTelefone.java index 7b866f7..764e748 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarTelefone.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarTelefone.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.enterprise.ValidationException; import com.senac.gestaocurso.models.Funcionario; diff --git a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarTituloEleitor.java b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarTituloEleitor.java similarity index 93% rename from backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarTituloEleitor.java rename to backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarTituloEleitor.java index 80869ca..2852a27 100644 --- a/backend/src/main/java/com/senac/gestaocurso/strategy/impl/ValidarTituloEleitor.java +++ b/backend/src/main/java/com/senac/gestaocurso/strategy/funcionarioValidacaoImp/ValidarTituloEleitor.java @@ -1,4 +1,4 @@ -package com.senac.gestaocurso.strategy.impl; +package com.senac.gestaocurso.strategy.funcionarioValidacaoImp; import com.senac.gestaocurso.enterprise.ValidationException; import com.senac.gestaocurso.models.Funcionario;