diff --git a/backend/pom.xml b/backend/pom.xml
index aee70d5..e177883 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -36,6 +36,18 @@
spring-boot-starter-test
test
+
+
+ org.hibernate.validator
+ hibernate-validator
+ 7.0.2.Final
+
+
+
+ javax.validation
+ validation-api
+ 2.0.1.Final
+
diff --git a/backend/src/main/java/com/senac/gestaocurso/enterprise/exception/BusinessException.java b/backend/src/main/java/com/senac/gestaocurso/enterprise/exception/BusinessException.java
new file mode 100644
index 0000000..675841b
--- /dev/null
+++ b/backend/src/main/java/com/senac/gestaocurso/enterprise/exception/BusinessException.java
@@ -0,0 +1,15 @@
+package com.senac.gestaocurso.enterprise.exception;
+
+
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+
+
+@ResponseStatus(HttpStatus.CONFLICT)
+public class BusinessException extends RuntimeException {
+ public BusinessException(String msg) {
+ super(msg);
+ }
+}
\ No newline at end of file
diff --git a/backend/src/main/java/com/senac/gestaocurso/enterprise/exception/ValidationException.java b/backend/src/main/java/com/senac/gestaocurso/enterprise/exception/ValidationException.java
new file mode 100644
index 0000000..fe407dc
--- /dev/null
+++ b/backend/src/main/java/com/senac/gestaocurso/enterprise/exception/ValidationException.java
@@ -0,0 +1,15 @@
+package com.senac.gestaocurso.enterprise.exception;
+
+
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+
+
+@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
+public class ValidationException extends RuntimeException {
+ public ValidationException(String msg) {
+ super(msg);
+ }
+}
\ No newline at end of file
diff --git a/backend/src/main/java/com/senac/gestaocurso/health/HealthCheckController.java b/backend/src/main/java/com/senac/gestaocurso/health/HealthCheckController.java
new file mode 100644
index 0000000..2da8fe7
--- /dev/null
+++ b/backend/src/main/java/com/senac/gestaocurso/health/HealthCheckController.java
@@ -0,0 +1,16 @@
+package com.senac.gestaocurso.health;
+
+
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+
+@RestController
+public class HealthCheckController {
+ @GetMapping("/health")
+ public String healthCheck() {
+ return "Aplicação está rodando";
+ }
+}
\ No newline at end of file
diff --git a/backend/src/main/java/com/senac/gestaocurso/models/Avaliacao.java b/backend/src/main/java/com/senac/gestaocurso/models/Avaliacao.java
index 6fb9832..78202f2 100644
--- a/backend/src/main/java/com/senac/gestaocurso/models/Avaliacao.java
+++ b/backend/src/main/java/com/senac/gestaocurso/models/Avaliacao.java
@@ -3,7 +3,8 @@
import jakarta.persistence.*;
-
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
import java.time.LocalDate;
@@ -22,6 +23,8 @@ public class Avaliacao extends EntityID {
private String nome;
@Column
+ @Min(value = 0, message = "A nota deve ser no mínimo 0")
+ @Max(value = 10, message = "A nota deve ser no máximo 10")
private Integer nota;
@Column
diff --git a/backend/src/main/java/com/senac/gestaocurso/models/Funcionario.java b/backend/src/main/java/com/senac/gestaocurso/models/Funcionario.java
index e1bf8e6..255ea21 100644
--- a/backend/src/main/java/com/senac/gestaocurso/models/Funcionario.java
+++ b/backend/src/main/java/com/senac/gestaocurso/models/Funcionario.java
@@ -2,6 +2,10 @@
+import jakarta.persistence.*;
+import org.hibernate.validator.constraints.br.CPF;
+import org.hibernate.validator.constraints.br.TituloEleitoral;
+import javax.validation.constraints.Email;
import com.senac.gestaocurso.enums.*;
import jakarta.persistence.*;
import java.time.LocalDate;
@@ -17,6 +21,7 @@ public class Funcionario extends EntityID {
private String nome;
@Column
+ @CPF(message = "Informe um CPF válido")
private String cpf;
@Column
@@ -44,6 +49,7 @@ public class Funcionario extends EntityID {
private EstadoCivil estadoCivil;
@Column
+ @TituloEleitoral(message = "Informe um título de eleitor válido")
private String tituloEleitor;
@Column
@@ -59,6 +65,7 @@ public class Funcionario extends EntityID {
private String registroProfissional;
@Column
+ @Email(message = "Informe um e-mail válido")
private String email;
@Column
diff --git a/backend/src/main/java/com/senac/gestaocurso/models/Inscricao.java b/backend/src/main/java/com/senac/gestaocurso/models/Inscricao.java
index 36fed70..73b02ed 100644
--- a/backend/src/main/java/com/senac/gestaocurso/models/Inscricao.java
+++ b/backend/src/main/java/com/senac/gestaocurso/models/Inscricao.java
@@ -29,6 +29,7 @@ public class Inscricao extends EntityID {
@JoinColumn(name = "turma_id")
private Turma turma;
+
public Turma getTurma() {
return turma;
}
@@ -42,6 +43,13 @@ public Inscricao() {
}
+ public Turma getTurma() {
+ return turma;
+ }
+
+ public void setTurma(Turma turma) {
+ this.turma = turma;
+ }
public Funcionario getInscrito() {
return inscrito;
diff --git a/backend/src/main/java/com/senac/gestaocurso/models/Turma.java b/backend/src/main/java/com/senac/gestaocurso/models/Turma.java
index 9592e37..4cf50c3 100644
--- a/backend/src/main/java/com/senac/gestaocurso/models/Turma.java
+++ b/backend/src/main/java/com/senac/gestaocurso/models/Turma.java
@@ -31,6 +31,8 @@ public class Turma extends EntityID {
@OneToMany(mappedBy = "turma", cascade = CascadeType.ALL, orphanRemoval = true)
private List inscritos = new ArrayList<>();
+ @Column
+ private Integer limiteQtdInscricao;
public Turma() {
@@ -86,15 +88,26 @@ public void setCurso(Curso curso) {
this.curso = curso;
}
+ public Integer getLimiteQtdInscricao() {
+ return limiteQtdInscricao;
+ }
+
+ public void setLimiteQtdInscricao(Integer limiteQtdInscricao) {
+ this.limiteQtdInscricao = limiteQtdInscricao;
+ }
+
@Override
public String toString() {
return "Turma{" +
- "nomeTurma='" + nome + '\'' +
- ", inscritos=" + inscritos +
+ "curso=" + curso +
+ ", nome='" + nome + '\'' +
", dataInicio=" + dataInicio +
", dataFinal=" + dataFinal +
+ ", descricao='" + descricao + '\'' +
+ ", inscritos=" + inscritos +
+ ", limiteQtdInscricao=" + limiteQtdInscricao +
'}';
}
}
\ No newline at end of file
diff --git a/backend/src/main/java/com/senac/gestaocurso/repository/FuncionarioRepository.java b/backend/src/main/java/com/senac/gestaocurso/repository/FuncionarioRepository.java
index 85ee356..2fa1d6b 100644
--- a/backend/src/main/java/com/senac/gestaocurso/repository/FuncionarioRepository.java
+++ b/backend/src/main/java/com/senac/gestaocurso/repository/FuncionarioRepository.java
@@ -4,6 +4,9 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
+import java.util.Optional;
+
@Repository
public interface FuncionarioRepository extends JpaRepository {
+ Optional findByCpf(String cpf);
}
diff --git a/backend/src/main/java/com/senac/gestaocurso/repository/InscricaoRepository.java b/backend/src/main/java/com/senac/gestaocurso/repository/InscricaoRepository.java
index c3b211c..9b0ba39 100644
--- a/backend/src/main/java/com/senac/gestaocurso/repository/InscricaoRepository.java
+++ b/backend/src/main/java/com/senac/gestaocurso/repository/InscricaoRepository.java
@@ -1,9 +1,17 @@
package com.senac.gestaocurso.repository;
+
+
import com.senac.gestaocurso.models.Inscricao;
+import com.senac.gestaocurso.models.Turma;
import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Service;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+
-@Service
+@Repository
public interface InscricaoRepository extends JpaRepository {
-}
+ List findAllByTurma(Turma turma);
+}
\ No newline at end of file
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/AbstractController.java b/backend/src/main/java/com/senac/gestaocurso/resource/AbstractController.java
new file mode 100644
index 0000000..a09d042
--- /dev/null
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/AbstractController.java
@@ -0,0 +1,55 @@
+package com.senac.gestaocurso.resource;
+
+
+
+import com.senac.gestaocurso.enterprise.exception.BusinessException;
+import com.senac.gestaocurso.enterprise.exception.ValidationException;
+import org.springframework.http.HttpStatus;
+import org.springframework.validation.FieldError;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+
+
+abstract public class AbstractController {
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
+ @ExceptionHandler(MethodArgumentNotValidException.class)
+ public Map handleValidationExceptions(MethodArgumentNotValidException ex) {
+ Map errors = new HashMap<>();
+ List collect = ex.getBindingResult()
+ .getAllErrors().stream()
+ .map(p -> ((FieldError) p).getField() + " "
+ + p.getDefaultMessage())
+ .collect(Collectors.toList());
+ errors.put("erro", collect.toString());
+
+ return errors;
+ }
+
+
+
+ @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
+ @ExceptionHandler(ValidationException.class)
+ public Map handleValidationExceptions(ValidationException ex) {
+ Map errors = new HashMap<>();
+ errors.put("erro", ex.getMessage());
+
+ return errors;
+ }
+
+
+
+ @ResponseStatus(HttpStatus.CONFLICT)
+ @ExceptionHandler(BusinessException.class)
+ public Map handleBusinessExceptions(ValidationException ex) {
+ Map errors = new HashMap<>();
+ errors.put("erro", ex.getMessage());
+
+ return errors;
+ }
+}
\ No newline at end of file
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/AulaController.java b/backend/src/main/java/com/senac/gestaocurso/resource/AulaController.java
index e4bce42..68d56ae 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/AulaController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/AulaController.java
@@ -14,7 +14,7 @@
@RestController
@RequestMapping("/api/aulas")
-public class AulaController {
+public class AulaController extends AbstractController {
@Autowired
private AulaService aulaService;
@@ -26,8 +26,7 @@ public ResponseEntity salvar(@RequestBody Aula aulas){
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page aulas = aulaService.buscaTodos(pageable);
return ResponseEntity.ok(aulas);
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/AvaliacaoController.java b/backend/src/main/java/com/senac/gestaocurso/resource/AvaliacaoController.java
index 740db17..72e673c 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/AvaliacaoController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/AvaliacaoController.java
@@ -15,38 +15,38 @@
@RestController
@RequestMapping("/api/avaliacao")
-public class AvaliacaoController {
- public class FuncionarioController {
- @Autowired
- private AvaliacaoService avaliacaoService;
-
- @PostMapping()
- public ResponseEntity salvar(@RequestBody Avaliacao avaliacoes) {
- Avaliacao save = avaliacaoService.salvar(avaliacoes);
- return ResponseEntity.created(URI.create("/api/avaliacao" + avaliacoes.getId())).body(save);
- }
-
-
- @GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
- Pageable pageable = PageRequest.of(page, size);
- Page avaliacoes = avaliacaoService.buscaTodos(pageable);
- return ResponseEntity.ok(avaliacoes);
- }
-
- @GetMapping("/{id}")
- public ResponseEntity findById(@PathVariable("id") Long id) {
- Avaliacao avaliacao = avaliacaoService.buscaPorId(id);
- return ResponseEntity.ok().body(avaliacao);
- }
-
-
- @DeleteMapping("{id}")
- public ResponseEntity remove(@PathVariable("id") Long id) {
- avaliacaoService.remover(id);
- return ResponseEntity.noContent().build();
- }
+public class AvaliacaoController extends AbstractController {
+ @Autowired
+ private AvaliacaoService avaliacaoService;
+
+
+
+ @PostMapping()
+ public ResponseEntity salvar(@RequestBody Avaliacao avaliacoes) {
+ Avaliacao save = avaliacaoService.salvar(avaliacoes);
+ return ResponseEntity.created(URI.create("/api/avaliacao" + avaliacoes.getId())).body(save);
+ }
+
+
+ @GetMapping
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
+ Pageable pageable = PageRequest.of(page, size);
+ Page avaliacoes = avaliacaoService.buscaTodos(pageable);
+ return ResponseEntity.ok(avaliacoes);
+ }
+
+ @GetMapping("/{id}")
+ public ResponseEntity findById(@PathVariable("id") Long id) {
+ Avaliacao avaliacao = avaliacaoService.buscaPorId(id);
+ return ResponseEntity.ok().body(avaliacao);
+ }
+
+
+ @DeleteMapping("{id}")
+ public ResponseEntity remove(@PathVariable("id") Long id) {
+ avaliacaoService.remover(id);
+ return ResponseEntity.noContent().build();
+ }
/**
* Reparar classe Avaliacao para alterar o service, mapeamento esta certo
@@ -56,5 +56,4 @@ public ResponseEntity update(@PathVariable("id") Long id, @RequestBody Avaliacao
Avaliacao avaliacao = avaliacaoService.alterar(id, entity);
*/
}
- }
-
+ }
\ No newline at end of file
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/CargoController.java b/backend/src/main/java/com/senac/gestaocurso/resource/CargoController.java
index d18a9d6..d237e54 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/CargoController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/CargoController.java
@@ -1,6 +1,7 @@
package com.senac.gestaocurso.resource;
+
import com.senac.gestaocurso.models.Cargo;
import com.senac.gestaocurso.service.CargoService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -12,10 +13,11 @@
import java.net.URI;
import java.util.List;
+
+
@RestController
@RequestMapping("/api/cargos")
-
-public class CargoController {
+public class CargoController extends AbstractController {
@Autowired
private CargoService cargoService;
@@ -26,8 +28,7 @@ public ResponseEntity salvar(@RequestBody Cargo cargo){
}
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page cargos = cargoService.buscaTodos(pageable);
return ResponseEntity.ok(cargos);
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/CertificacoesController.java b/backend/src/main/java/com/senac/gestaocurso/resource/CertificacoesController.java
index e8b44ea..ad6f983 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/CertificacoesController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/CertificacoesController.java
@@ -13,8 +13,7 @@
@RestController
@RequestMapping("/api/certificacoes")
-public class CertificacoesController {
-
+public class CertificacoesController extends AbstractController {
@Autowired
private CertificacoesService certificacoesService;
@@ -25,8 +24,7 @@ public ResponseEntity salvar(@RequestBody Certificacoes certificacoes){
}
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page certificacoes = certificacoesService.buscaTodos(pageable);
return ResponseEntity.ok(certificacoes);
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/CursoController.java b/backend/src/main/java/com/senac/gestaocurso/resource/CursoController.java
index 6880283..0514db5 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/CursoController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/CursoController.java
@@ -15,7 +15,7 @@
@RestController
@RequestMapping("/api/cursos")
-public class CursoController {
+public class CursoController extends AbstractController {
@Autowired
private CursoService cursoService;
@@ -26,8 +26,7 @@ public ResponseEntity salvar(@RequestBody Curso curso){
}
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page cursos = cursoService.buscaTodos(pageable);
return ResponseEntity.ok(cursos);
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/DadosBancariosController.java b/backend/src/main/java/com/senac/gestaocurso/resource/DadosBancariosController.java
index c0895bb..a126568 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/DadosBancariosController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/DadosBancariosController.java
@@ -14,7 +14,7 @@
import java.util.List;
@RestController
@RequestMapping("api/dadosbancarios")
-public class DadosBancariosController {
+public class DadosBancariosController extends AbstractController {
@Autowired
private DadosBancariosService dadosBancariosService;
@@ -25,8 +25,7 @@ public ResponseEntity salvar(@RequestBody DadosBancarios dadosBancarios){
}
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page dadosBancarios = dadosBancariosService.buscaTodos(pageable);
return ResponseEntity.ok(dadosBancarios);
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/DependentesController.java b/backend/src/main/java/com/senac/gestaocurso/resource/DependentesController.java
index c35a0bd..2663bf3 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/DependentesController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/DependentesController.java
@@ -14,7 +14,7 @@
@RestController
@RequestMapping("api/dependentes")
-public class DependentesController {
+public class DependentesController extends AbstractController {
@Autowired
private DependentesService dependentesService;
@@ -25,8 +25,7 @@ public ResponseEntity salvar(@RequestBody Dependentes dependentes){
}
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page dependentes = dependentesService.buscaTodos(pageable);
return ResponseEntity.ok(dependentes);
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/ExpAnteriorController.java b/backend/src/main/java/com/senac/gestaocurso/resource/ExpAnteriorController.java
index f86417d..3eff685 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/ExpAnteriorController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/ExpAnteriorController.java
@@ -15,7 +15,7 @@
@RestController
@RequestMapping("/api/experiencias")
-public class ExpAnteriorController {
+public class ExpAnteriorController extends AbstractController {
@Autowired
private ExpAnteriorService expAnteriorService;
@@ -26,8 +26,7 @@ public ResponseEntity salvar(@RequestBody ExpAnterior expAnterior) {
}
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page expAnteriors = expAnteriorService.buscaTodos(pageable);
return ResponseEntity.ok(expAnteriors);
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/FiliacaoController.java b/backend/src/main/java/com/senac/gestaocurso/resource/FiliacaoController.java
index 74aa1fd..012d137 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/FiliacaoController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/FiliacaoController.java
@@ -13,7 +13,7 @@
import java.util.List;
@RestController
@RequestMapping("api/filiacao")
-public class FiliacaoController {
+public class FiliacaoController extends AbstractController {
@Autowired
private FiliacaoService filiacaoService;
@@ -24,8 +24,7 @@ public ResponseEntity salvar(@RequestBody Filiacao filiacao){
}
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page filiacao = filiacaoService.buscaTodos(pageable);
return ResponseEntity.ok(filiacao);
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/FrequenciaController.java b/backend/src/main/java/com/senac/gestaocurso/resource/FrequenciaController.java
index a1aca85..ba3b891 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/FrequenciaController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/FrequenciaController.java
@@ -13,7 +13,7 @@
import java.util.List;
@RestController
@RequestMapping("api/frequencia")
-public class FrequenciaController {
+public class FrequenciaController extends AbstractController {
@Autowired
private FrequenciaService frequenciaService;
@@ -23,8 +23,7 @@ public ResponseEntity salvar(@RequestBody Frequencia frequencia){
return ResponseEntity.created(URI.create("/api/frequencia" + frequencia.getId())).body(save);
}
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page frequencias = frequenciaService.buscaTodos(pageable);
return ResponseEntity.ok(frequencias);
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/FuncionarioController.java b/backend/src/main/java/com/senac/gestaocurso/resource/FuncionarioController.java
index ad4d3d3..8dc57c9 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/FuncionarioController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/FuncionarioController.java
@@ -1,38 +1,44 @@
package com.senac.gestaocurso.resource;
+
import com.senac.gestaocurso.models.Funcionario;
import com.senac.gestaocurso.service.FuncionarioService;
+import jakarta.validation.Valid;
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;
-import java.util.List;
+
+
+
@RestController
@RequestMapping("/api/funcionario")
-
-public class FuncionarioController {
+public class FuncionarioController extends AbstractController {
@Autowired
private FuncionarioService funcionarioService;
+
+
@PostMapping()
- public ResponseEntity salvar(@RequestBody Funcionario funcionario){
+ public ResponseEntity salvar(@Valid @RequestBody Funcionario funcionario){
Funcionario save = funcionarioService.salvar(funcionario);
return ResponseEntity.created(URI.create("/api/funcionario" + funcionario.getId())).body(save);
}
+
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "3") int size) {
Pageable pageable = PageRequest.of(page, size);
Page funcionarios = funcionarioService.buscaTodos(pageable);
return ResponseEntity.ok(funcionarios);
}
+
+
@GetMapping("/{id}")
public ResponseEntity findById(@PathVariable("id") Long id){
Funcionario funcionario = funcionarioService.buscaPorId(id);
@@ -47,12 +53,11 @@ public ResponseEntity remove(@PathVariable("id") Long id){
return ResponseEntity.noContent().build();
}
+
+
@PutMapping("{id}")
public ResponseEntity update(@PathVariable("id") Long id, @RequestBody Funcionario entity){
Funcionario alterado = funcionarioService.alterar(id, entity);
return ResponseEntity.ok().body(alterado);
}
-}
-
-
-
+}
\ No newline at end of file
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/InscricaoController.java b/backend/src/main/java/com/senac/gestaocurso/resource/InscricaoController.java
index 7f56290..fc8adfd 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/InscricaoController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/InscricaoController.java
@@ -1,5 +1,8 @@
package com.senac.gestaocurso.resource;
+
+
+import com.senac.gestaocurso.models.Inscricao;
import com.senac.gestaocurso.models.Funcionario;
import com.senac.gestaocurso.models.Inscricao;
import com.senac.gestaocurso.service.FuncionarioService;
@@ -10,45 +13,53 @@
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
-
import java.net.URI;
-import java.util.List;
+
+
+
@RestController
@RequestMapping("api/inscricao")
-public class InscricaoController {
+public class InscricaoController extends AbstractController {
@Autowired
private InscricaoService inscricaoService;
+
+
@PostMapping()
public ResponseEntity salvar(@RequestBody Inscricao inscricao){
Inscricao save = inscricaoService.salvar(inscricao);
return ResponseEntity.created(URI.create("/api/inscricao" + inscricao.getId())).body(save);
}
+
+
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page inscricao = inscricaoService.buscaTodos(pageable);
return ResponseEntity.ok(inscricao);
}
+
+
@GetMapping("/{id}")
public ResponseEntity findById(@PathVariable("id") Long id){
Inscricao inscricao = inscricaoService.buscaPorId(id);
return ResponseEntity.ok().body(inscricao);
}
+
+
@DeleteMapping("{id}")
public ResponseEntity remove(@PathVariable("id") Long id){
inscricaoService.remover(id);
return ResponseEntity.noContent().build();
}
+
+
+
@PutMapping("{id}")
public ResponseEntity update(@PathVariable("id") Long id, @RequestBody Inscricao entity){
Inscricao inscricao = inscricaoService.alterar(id, entity);
return ResponseEntity.ok().body(inscricao);
}
-}
-
-
-
+}
\ No newline at end of file
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/MateriaController.java b/backend/src/main/java/com/senac/gestaocurso/resource/MateriaController.java
index 192be50..d8c9001 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/MateriaController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/MateriaController.java
@@ -14,7 +14,7 @@
@RestController
@RequestMapping("api/materia")
-public class MateriaController {
+public class MateriaController extends AbstractController {
@Autowired
private MateriaService materiaService;
@@ -25,8 +25,7 @@ public ResponseEntity salvar(@RequestBody Materia materia){
}
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page materias = materiaService.buscaTodos(pageable);
return ResponseEntity.ok(materias);
diff --git a/backend/src/main/java/com/senac/gestaocurso/resource/TurmaController.java b/backend/src/main/java/com/senac/gestaocurso/resource/TurmaController.java
index 09fa6b4..263f3d7 100644
--- a/backend/src/main/java/com/senac/gestaocurso/resource/TurmaController.java
+++ b/backend/src/main/java/com/senac/gestaocurso/resource/TurmaController.java
@@ -14,8 +14,7 @@
import java.util.List;
@RestController
@RequestMapping("api/turma")
-public class TurmaController {
-
+public class TurmaController extends AbstractController {
@Autowired
private TurmaService turmaService;
@@ -26,8 +25,7 @@ public ResponseEntity salvar(@RequestBody Turma turma){
}
@GetMapping
- public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page,
- @RequestParam(defaultValue = "0") int size) {
+ public ResponseEntity findAll(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
Pageable pageable = PageRequest.of(page, size);
Page funcionarios = turmaService.buscaTodos(pageable);
return ResponseEntity.ok(funcionarios);
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 e9e08c6..6128582 100644
--- a/backend/src/main/java/com/senac/gestaocurso/service/AvaliacaoService.java
+++ b/backend/src/main/java/com/senac/gestaocurso/service/AvaliacaoService.java
@@ -7,22 +7,33 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
-
-import java.util.List;
import java.util.Optional;
+
+
@Service
public class AvaliacaoService {
-
@Autowired
private AvaliacaoRepository avaliacaoRepository;
- public Avaliacao salvar(Avaliacao entity) {return avaliacaoRepository.save(entity);}
+
+
+
+ public Avaliacao salvar(Avaliacao entity) {
+ return avaliacaoRepository.save(entity);
+ }
+
+
+
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()) {
@@ -32,12 +43,19 @@ public Avaliacao alterar(Long id, Avaliacao alterado) {
avaliacao.setMateria(alterado.getMateria());
avaliacao.setNome(alterado.getNome());
avaliacao.setNota(avaliacao.getNota());
+
return avaliacaoRepository.save(avaliacao);
}
return null;
}
+
+
+
public void remover(Long id) {avaliacaoRepository.deleteById(id);
}
-
-}
+
+
+ public void remover(Long id) {avaliacaoRepository.deleteById(id);
+ }
+}
\ No newline at end of file
diff --git a/backend/src/main/java/com/senac/gestaocurso/service/FuncionarioService.java b/backend/src/main/java/com/senac/gestaocurso/service/FuncionarioService.java
index cdb47ad..892ab27 100644
--- a/backend/src/main/java/com/senac/gestaocurso/service/FuncionarioService.java
+++ b/backend/src/main/java/com/senac/gestaocurso/service/FuncionarioService.java
@@ -1,31 +1,51 @@
package com.senac.gestaocurso.service;
+
+
+import com.senac.gestaocurso.enterprise.exception.BusinessException;
import com.senac.gestaocurso.models.Funcionario;
import com.senac.gestaocurso.repository.FuncionarioRepository;
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;
import java.util.Optional;
+
+
@Service
public class FuncionarioService {
-
@Autowired
private FuncionarioRepository funcionarioRepository;
-
+
+
+
public Funcionario salvar(Funcionario entity) {
+ if (funcionarioRepository.findByCpf(entity.getCpf()).isPresent()) { // CPF já cadastrado
+ throw new BusinessException("CPF já cadastrado");
+ }
+
return funcionarioRepository.save(entity);
}
+
+
public Page buscaTodos(Pageable pageable) {
return funcionarioRepository.findAll(pageable);
}
+
+
+
+ public Page buscaTodos(Pageable pageable) {
+ return funcionarioRepository.findAll(pageable);
+ }
+
public Funcionario buscaPorId(Long id) {
return funcionarioRepository.findById(id).orElse(null);
}
+
+
+
public Funcionario alterar(Long id, Funcionario alterado) {
Optional encontrado = funcionarioRepository.findById(id);
if ((encontrado.isPresent())) {
@@ -76,7 +96,10 @@ public Funcionario alterar(Long id, Funcionario alterado) {
}
return null;
}
- public void remover(Long id) {funcionarioRepository.deleteById(id);
- }
-}
+
+
+ public void remover(Long id) {
+ funcionarioRepository.deleteById(id);
+ }
+}
\ No newline at end of file
diff --git a/backend/src/main/java/com/senac/gestaocurso/service/InscricaoService.java b/backend/src/main/java/com/senac/gestaocurso/service/InscricaoService.java
index 89d3a13..549e953 100644
--- a/backend/src/main/java/com/senac/gestaocurso/service/InscricaoService.java
+++ b/backend/src/main/java/com/senac/gestaocurso/service/InscricaoService.java
@@ -1,28 +1,54 @@
package com.senac.gestaocurso.service;
+
+import com.senac.gestaocurso.enterprise.exception.BusinessException;
import com.senac.gestaocurso.models.Inscricao;
+import com.senac.gestaocurso.models.Turma;
import com.senac.gestaocurso.repository.InscricaoRepository;
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;
import java.util.Optional;
+
+
+
@Service
public class InscricaoService {
-
@Autowired
private InscricaoRepository inscricaoRepository;
+
+
+
+ private Boolean verificarLimiteInscricoes(Turma turma) {
+ List qtdInscritosTurma = inscricaoRepository.findAllByTurma(turma);
+
+ return qtdInscritosTurma.size() > turma.getLimiteQtdInscricao();
+ }
+
+
+
public Inscricao salvar(Inscricao entity) {
+ if (!verificarLimiteInscricoes(entity.getTurma())) {
+ throw new BusinessException("Limite de inscrições atingido");
+ }
+
return inscricaoRepository.save(entity);
}
+
+
+
public Page buscaTodos(Pageable pageable) {
return inscricaoRepository.findAll(pageable);
}
+
public Inscricao buscaPorId(Long id) {
return inscricaoRepository.findById(id).orElse(null);
}
+
+
+
public Inscricao alterar(Long id, Inscricao alterado) {
Optional encontrado = inscricaoRepository.findById(id);
if ((encontrado.isPresent())) {
@@ -31,10 +57,20 @@ public Inscricao alterar(Long id, Inscricao alterado) {
inscricao.setStatus(alterado.getStatus());
inscricao.setInscrito(alterado.getInscrito());
inscricao.setValor(alterado.getValor());
+
+ if (!verificarLimiteInscricoes(inscricao.getTurma())) {
+ throw new BusinessException("Limite de inscrições atingido");
+ }
+
return inscricaoRepository.save(inscricao);
}
+
return null;
}
- public void remover(Long id) {inscricaoRepository.deleteById(id);
+
+
+
+ public void remover(Long id) {
+ inscricaoRepository.deleteById(id);
}
}
\ No newline at end of file
diff --git a/backend/src/main/java/com/senac/gestaocurso/service/TurmaService.java b/backend/src/main/java/com/senac/gestaocurso/service/TurmaService.java
index 13e03fb..9448c89 100644
--- a/backend/src/main/java/com/senac/gestaocurso/service/TurmaService.java
+++ b/backend/src/main/java/com/senac/gestaocurso/service/TurmaService.java
@@ -9,19 +9,32 @@
import java.util.List;
import java.util.Optional;
+
+
+
@Service
public class TurmaService {
@Autowired
private TurmaRepository turmaRepository;
+
+
+
public Turma salvar(Turma entity) {
return turmaRepository.save(entity);
}
+
+
+
public Page buscaTodos(Pageable pageable) {
return turmaRepository.findAll(pageable);
}
+
public Turma buscaPorId(Long id) {
return turmaRepository.findById(id).orElse(null);
}
+
+
+
public Turma alterar(Long id, Turma alterado) {
Optional encontrado = turmaRepository.findById(id);
if ((encontrado.isPresent())) {
@@ -32,11 +45,15 @@ public Turma alterar(Long id, Turma alterado) {
turma.setInscritos(alterado.getInscritos());
turma.setDataInicio(alterado.getDataInicio());
turma.setDataFinal(alterado.getDataFinal());
+ turma.setLimiteQtdInscricao(alterado.getLimiteQtdInscricao());
+
return turmaRepository.save(turma);
}
return null;
}
+
+
+
public void remover(Long id) {turmaRepository.deleteById(id);
}
-}
-
+}
\ No newline at end of file
diff --git a/database/schema.sql b/database/schema.sql
new file mode 100644
index 0000000..7a2f9d5
--- /dev/null
+++ b/database/schema.sql
@@ -0,0 +1 @@
+create database gestao_cursos;
\ No newline at end of file