-
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.
- Loading branch information
Showing
17 changed files
with
390 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,55 @@ | ||
# Compiled class file | ||
target/ | ||
release/ | ||
dependency-reduced-pom.xml | ||
.mvn/wrapper/ | ||
|
||
*.class | ||
*.jar | ||
*.war | ||
*.ear | ||
*.log | ||
|
||
.classpath | ||
.project | ||
.settings/ | ||
|
||
.idea/ | ||
|
||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
*.class | ||
|
||
# Log file | ||
logs/ | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
log/ | ||
target/ | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
*.idea/ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
.gradle/ | ||
build/ | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
replay_pid* | ||
nbproject/private/ | ||
build/ | ||
|
||
.vscode/ | ||
|
||
nb-configuration.xml | ||
|
||
.cache/ | ||
.cproject | ||
.settings/ | ||
.tmproj | ||
*.log | ||
*.tmp | ||
*.bak | ||
*.swp | ||
Thumbs.db | ||
Desktop.ini | ||
.DS_Store |
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,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>br.com.grupo63.techchallenge</groupId> | ||
<artifactId>service-common</artifactId> | ||
<packaging>jar</packaging> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>17</source> | ||
<target>17</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<version>1.0</version> | ||
<url>http://maven.apache.org</url> | ||
<name>service-common</name> | ||
<description>FIAP SOAT1 2023 - Group 63 - Common files</description> | ||
<properties> | ||
<java.version>17</java.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.24</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<version>3.2.1</version> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.session</groupId> | ||
<version>3.2.1</version> | ||
<artifactId>spring-session-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<version>3.2.1</version> | ||
<artifactId>spring-boot-starter-validation</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<version>3.2.1</version> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-devtools</artifactId> | ||
<version>3.2.1</version> | ||
<scope>runtime</scope> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<version>3.2.1</version> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springdoc</groupId> | ||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> | ||
<version>2.1.0</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
61 changes: 61 additions & 0 deletions
61
src/main/java/br/com/grupo63/techchallenge/common/api/controller/AbstractAPIController.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,61 @@ | ||
package br.com.grupo63.techchallenge.common.api.controller; | ||
|
||
import br.com.grupo63.techchallenge.common.api.controller.dto.DefaultResponseDTO; | ||
import br.com.grupo63.techchallenge.common.exception.GenericException; | ||
import br.com.grupo63.techchallenge.common.exception.NotFoundException; | ||
import br.com.grupo63.techchallenge.common.exception.ValidationException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.MessageSource; | ||
import org.springframework.context.i18n.LocaleContextHolder; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.ObjectError; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public abstract class AbstractAPIController { | ||
|
||
@Autowired | ||
private MessageSource messageSource; | ||
|
||
@ExceptionHandler | ||
public ResponseEntity<DefaultResponseDTO> handleException(Exception exception) { | ||
exception.printStackTrace(); | ||
DefaultResponseDTO responseDTO = new DefaultResponseDTO( | ||
messageSource.getMessage("default.title.unknownError", null, LocaleContextHolder.getLocale()), | ||
messageSource.getMessage("default.title.unknownError.description", null, LocaleContextHolder.getLocale())); | ||
|
||
if (exception instanceof ValidationException validationException) { | ||
responseDTO.setTitle(messageSource.getMessage(validationException.getName(), null, LocaleContextHolder.getLocale())); | ||
responseDTO.setDescription(messageSource.getMessage(validationException.getDescription(), null, LocaleContextHolder.getLocale())); | ||
|
||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseDTO); | ||
} else if (exception instanceof MethodArgumentNotValidException methodArgumentNotValidException) { | ||
responseDTO.setTitle(messageSource.getMessage("default.title.validationError", null, LocaleContextHolder.getLocale())); | ||
responseDTO.setDescription( | ||
methodArgumentNotValidException | ||
.getBindingResult().getAllErrors() | ||
.stream().map(ObjectError::getDefaultMessage) | ||
.filter(Objects::nonNull) | ||
.map(message -> messageSource.getMessage(message, null, LocaleContextHolder.getLocale())) | ||
.collect(Collectors.joining("; "))); | ||
|
||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(responseDTO); | ||
} else if (exception instanceof NotFoundException) { | ||
responseDTO.setTitle(messageSource.getMessage("default.title.notFoundError", null, LocaleContextHolder.getLocale())); | ||
responseDTO.setDescription(messageSource.getMessage("default.title.notFoundError.description", null, LocaleContextHolder.getLocale())); | ||
|
||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(responseDTO); | ||
} else if (exception instanceof GenericException genericException) { | ||
responseDTO.setTitle(genericException.getName()); | ||
responseDTO.setDescription(genericException.getDescription()); | ||
|
||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseDTO); | ||
} | ||
|
||
return ResponseEntity.internalServerError().body(responseDTO); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/br/com/grupo63/techchallenge/common/api/controller/dto/DefaultResponseDTO.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 br.com.grupo63.techchallenge.common.api.controller.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
|
||
public class DefaultResponseDTO { | ||
private String title; | ||
private String description; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/br/com/grupo63/techchallenge/common/controller/dto/AbstractControllerDTO.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,14 @@ | ||
package br.com.grupo63.techchallenge.common.controller.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public abstract class AbstractControllerDTO { | ||
|
||
@Schema(defaultValue = "1") | ||
protected Long id; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/br/com/grupo63/techchallenge/common/domain/Entity.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,29 @@ | ||
package br.com.grupo63.techchallenge.common.domain; | ||
|
||
import br.com.grupo63.techchallenge.common.domain.validation.group.Update; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.io.Serializable; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
public abstract class Entity implements Serializable { | ||
|
||
@NotNull(message = "order.create.idNotNull", groups = {Update.class}) | ||
@Min(value = 1, message = "order.create.idNotNull", groups = {Update.class}) | ||
protected Long id; | ||
|
||
protected boolean deleted = false; | ||
|
||
public void delete() { | ||
this.deleted = true; | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/br/com/grupo63/techchallenge/common/domain/validation/group/Create.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,4 @@ | ||
package br.com.grupo63.techchallenge.common.domain.validation.group; | ||
|
||
public interface Create { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/br/com/grupo63/techchallenge/common/domain/validation/group/Delete.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,4 @@ | ||
package br.com.grupo63.techchallenge.common.domain.validation.group; | ||
|
||
public interface Delete { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/br/com/grupo63/techchallenge/common/domain/validation/group/Read.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,4 @@ | ||
package br.com.grupo63.techchallenge.common.domain.validation.group; | ||
|
||
public interface Read { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/br/com/grupo63/techchallenge/common/domain/validation/group/Update.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,4 @@ | ||
package br.com.grupo63.techchallenge.common.domain.validation.group; | ||
|
||
public interface Update { | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/br/com/grupo63/techchallenge/common/exception/GenericException.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 br.com.grupo63.techchallenge.common.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class GenericException extends Exception { | ||
private String name; | ||
private String description; | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/br/com/grupo63/techchallenge/common/exception/NotFoundException.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,4 @@ | ||
package br.com.grupo63.techchallenge.common.exception; | ||
|
||
public class NotFoundException extends GenericException { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/br/com/grupo63/techchallenge/common/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,9 @@ | ||
package br.com.grupo63.techchallenge.common.exception; | ||
|
||
|
||
public class ValidationException extends GenericException { | ||
|
||
public ValidationException(String name, String description) { | ||
super(name, description); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/br/com/grupo63/techchallenge/common/gateway/IPersistenceEntityGateway.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,14 @@ | ||
package br.com.grupo63.techchallenge.common.gateway; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface IPersistenceEntityGateway<T> { | ||
|
||
List<T> findByDeletedFalse(); | ||
|
||
T saveAndFlush(T entity); | ||
|
||
Optional<T> findByIdAndDeletedFalse(Long id); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/br/com/grupo63/techchallenge/common/gateway/repository/IJpaRepository.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,12 @@ | ||
package br.com.grupo63.techchallenge.common.gateway.repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface IJpaRepository<E> { | ||
|
||
Optional<E> findByIdAndDeletedFalse(Long id); | ||
|
||
List<E> findByDeletedFalse(); | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...java/br/com/grupo63/techchallenge/common/gateway/repository/entity/PersistenceEntity.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,50 @@ | ||
package br.com.grupo63.techchallenge.common.gateway.repository.entity; | ||
|
||
import br.com.grupo63.techchallenge.common.domain.Entity; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.io.Serial; | ||
import java.io.Serializable; | ||
import java.time.LocalDateTime; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
|
||
@MappedSuperclass | ||
@EntityListeners({AuditingEntityListener.class}) | ||
public abstract class PersistenceEntity implements Serializable { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Id | ||
@Access(AccessType.FIELD) | ||
@Column(name = "id", nullable = false, unique = true) | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
protected Long id; | ||
|
||
@Basic | ||
@Column(name = "deleted", nullable = false) | ||
protected boolean deleted = false; | ||
|
||
@Column(name = "creation_date", nullable = false) | ||
@LastModifiedDate | ||
private LocalDateTime creationDate; | ||
|
||
@Column(name = "last_update_date", nullable = false) | ||
@LastModifiedDate | ||
private LocalDateTime lastUpdateDate; | ||
|
||
public PersistenceEntity(Entity entity) { | ||
this.id = entity.getId(); | ||
this.deleted = entity.isDeleted(); | ||
} | ||
} |
Oops, something went wrong.