This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from lucas0headshot/lucas
Implementar RNs e validações nas Classes
- Loading branch information
Showing
30 changed files
with
368 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/com/senac/gestaocurso/enterprise/exception/BusinessException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/com/senac/gestaocurso/enterprise/exception/ValidationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
backend/src/main/java/com/senac/gestaocurso/health/HealthCheckController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 11 additions & 3 deletions
14
backend/src/main/java/com/senac/gestaocurso/repository/InscricaoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Inscricao, Long> { | ||
} | ||
List<Inscricao> findAllByTurma(Turma turma); | ||
} |
55 changes: 55 additions & 0 deletions
55
backend/src/main/java/com/senac/gestaocurso/resource/AbstractController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, String> handleValidationExceptions(MethodArgumentNotValidException ex) { | ||
Map<String, String> errors = new HashMap<>(); | ||
List<String> 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<String, String> handleValidationExceptions(ValidationException ex) { | ||
Map<String, String> errors = new HashMap<>(); | ||
errors.put("erro", ex.getMessage()); | ||
|
||
return errors; | ||
} | ||
|
||
|
||
|
||
@ResponseStatus(HttpStatus.CONFLICT) | ||
@ExceptionHandler(BusinessException.class) | ||
public Map<String, String> handleBusinessExceptions(ValidationException ex) { | ||
Map<String, String> errors = new HashMap<>(); | ||
errors.put("erro", ex.getMessage()); | ||
|
||
return errors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.