Skip to content

Commit

Permalink
Serviços separados em módulo independente
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepenteado committed Sep 30, 2023
1 parent 94ba530 commit 852b686
Show file tree
Hide file tree
Showing 30 changed files with 149 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .docker/postgresql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
volumes:
- apsso-test-pgdata:/var/lib/postgresql/data
ports:
- 54320:5432
- 5433:5432

volumes:
apsso-pgdata:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
POSTGRES_USER: apsso-dbuser
POSTGRES_PASSWORD: apsso-dbpasswd
ports:
- 54320:5432
- 5433:5432

steps:

Expand Down Expand Up @@ -70,4 +70,4 @@ jobs:
- name: Push da imagem docker do backend do módulo administrativo
run: |
docker push ghcr.io/andrepenteado/apsso/apsso-backend:latest
docker push ghcr.io/andrepenteado/apsso/apsso-backend:${{ env.VERSAO }}
docker push ghcr.io/andrepenteado/apsso/apsso-backend:${{ env.VERSAO }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ nbactions.xml
/frontend/node_modules/
/frontend/.angular/
/frontend/frontend.iml
/services/target/
2 changes: 1 addition & 1 deletion .run/apsso-debug.run.xml → .run/APsso Debug.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="apsso-debug" type="Remote">
<configuration default="false" name="APsso Debug" type="Remote">
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
<option name="SHMEM_ADDRESS" />
Expand Down
2 changes: 1 addition & 1 deletion .run/Backend UP.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Backend UP" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
<option name="ALTERNATIVE_JRE_PATH" value="corretto-21" />
<option name="ALTERNATIVE_JRE_PATH" value="Amazon Corretto JDK 21" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<module name="backend" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.github.andrepenteado.apsso.backend.ApssoBackendApplication" />
Expand Down
7 changes: 6 additions & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>com.github.andrepenteado.sso</groupId>
<artifactId>services</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Testes -->
<dependency>
Expand Down Expand Up @@ -64,4 +69,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,26 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.validation.BindingResult;
import org.springframework.web.cors.CorsConfiguration;

@SpringBootApplication
@SpringBootApplication(scanBasePackages = "com.github.andrepenteado.apsso")
@EntityScan(basePackages = "com.github.andrepenteado.apsso")
@EnableJpaRepositories(basePackages = "com.github.andrepenteado.apsso")
public class ApssoBackendApplication {

public static void main(String[] args) {
SpringApplication.run(ApssoBackendApplication.class, args);
}

public static String validateModel(BindingResult validacao) {
String result = null;
if (validacao.hasErrors()) {
final StringBuilder errosFinal = new StringBuilder();
validacao.getFieldErrors().forEach(msg -> {
errosFinal.append(msg.getDefaultMessage());
});
result = errosFinal.toString();
}
return result;
}

@Bean
@Profile("!test")
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.andrepenteado.apsso.backend.resources;

import com.github.andrepenteado.apsso.backend.models.PerfilSistema;
import com.github.andrepenteado.apsso.backend.models.Sistema;
import com.github.andrepenteado.apsso.backend.services.PerfilSistemaService;
import com.github.andrepenteado.apsso.backend.services.SistemaService;
import com.github.andrepenteado.apsso.services.PerfilSistemaService;
import com.github.andrepenteado.apsso.services.SistemaService;
import com.github.andrepenteado.apsso.services.models.PerfilSistema;
import com.github.andrepenteado.apsso.services.models.Sistema;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.andrepenteado.apsso.backend.resources;

import com.github.andrepenteado.apsso.backend.models.Usuario;
import com.github.andrepenteado.apsso.backend.services.UsuarioService;
import com.github.andrepenteado.apsso.services.UsuarioService;
import com.github.andrepenteado.apsso.services.models.Usuario;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.andrepenteado.apsso.backend.models.PerfilSistema;
import com.github.andrepenteado.apsso.backend.models.Sistema;
import com.github.andrepenteado.apsso.services.models.PerfilSistema;
import com.github.andrepenteado.apsso.services.models.Sistema;
import com.github.springtestdbunit.DbUnitTestExecutionListener;
import com.github.springtestdbunit.annotation.DatabaseSetup;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -182,4 +182,4 @@ void testExcluirPerfil() throws Exception {
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());*/
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.andrepenteado.apsso.backend.models.PerfilSistema;
import com.github.andrepenteado.apsso.backend.models.Sistema;
import com.github.andrepenteado.apsso.backend.models.Usuario;
import com.github.andrepenteado.apsso.services.models.PerfilSistema;
import com.github.andrepenteado.apsso.services.models.Sistema;
import com.github.andrepenteado.apsso.services.models.Usuario;
import com.github.springtestdbunit.DbUnitTestExecutionListener;
import com.github.springtestdbunit.annotation.DatabaseSetup;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -175,4 +175,4 @@ void testExcluir() throws Exception {
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());*/
}
}
}
2 changes: 1 addition & 1 deletion backend/src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spring:

datasource:
url: jdbc:postgresql://localhost:54320/apsso-dbname?autoReconnect=true
url: jdbc:postgresql://localhost:5433/apsso-dbname?autoReconnect=true
username: apsso-dbuser
password: apsso-dbpasswd
driver-class-name: org.postgresql.Driver
Expand Down
7 changes: 6 additions & 1 deletion login/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<artifactId>jakarta.servlet.jsp.jstl</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.github.andrepenteado.sso</groupId>
<artifactId>services</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand All @@ -42,4 +47,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@SpringBootApplication(scanBasePackages = "com.github.andrepenteado.apsso")
@EntityScan(basePackages = "com.github.andrepenteado.apsso")
@EnableJpaRepositories(basePackages = "com.github.andrepenteado.apsso")
public class ApssoLoginApplication extends SpringBootServletInitializer {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.github.andrepenteado.apsso.backend.resources;
package com.github.andrepenteado.apsso.login.resources;

import com.github.andrepenteado.apsso.backend.models.Usuario;
import com.github.andrepenteado.apsso.backend.services.UsuarioService;
import com.github.andrepenteado.apsso.services.UsuarioService;
import com.github.andrepenteado.apsso.services.models.Usuario;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
</properties>

<modules>
<module>services</module>
<module>login</module>
<module>backend</module>
</modules>
Expand All @@ -50,6 +51,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down
40 changes: 40 additions & 0 deletions services/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<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>com.github.andrepenteado.sso</groupId>
<artifactId>services</artifactId>
<packaging>jar</packaging>

<name>Biblioteca de Serviços</name>
<description>Biblioteca compartilhada de serviços dos módulos</description>

<organization>
<name>APcode</name>
<url>http://www.apcode.com.br</url>
</organization>

<developers>
<developer>
<name>André Penteado</name>
<email>andre.penteado@apcode.com.br</email>
<organization>APcode</organization>
</developer>
</developers>

<parent>
<groupId>com.github.andrepenteado</groupId>
<artifactId>apsso</artifactId>
<version>2.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.andrepenteado.apsso.backend.services;
package com.github.andrepenteado.apsso.services;

import com.github.andrepenteado.apsso.backend.models.PerfilSistema;
import com.github.andrepenteado.apsso.services.models.PerfilSistema;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.andrepenteado.apsso.backend.services;
package com.github.andrepenteado.apsso.services;

import com.github.andrepenteado.apsso.backend.models.Sistema;
import com.github.andrepenteado.apsso.services.models.Sistema;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.andrepenteado.apsso.backend.services;
package com.github.andrepenteado.apsso.services;

import com.github.andrepenteado.apsso.backend.models.Usuario;
import com.github.andrepenteado.apsso.services.models.Usuario;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.github.andrepenteado.apsso.services;

import org.springframework.validation.BindingResult;

public class Util {

public static String validateModel(BindingResult validacao) {
String result = null;
if (validacao.hasErrors()) {
final StringBuilder errosFinal = new StringBuilder();
validacao.getFieldErrors().forEach(msg -> {
errosFinal.append(msg.getDefaultMessage());
});
result = errosFinal.toString();
}
return result;
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.andrepenteado.apsso.backend.services.impl;
package com.github.andrepenteado.apsso.services.impl;

import com.github.andrepenteado.apsso.backend.ApssoBackendApplication;
import com.github.andrepenteado.apsso.backend.models.PerfilSistema;
import com.github.andrepenteado.apsso.backend.repositories.PerfilSistemaRepository;
import com.github.andrepenteado.apsso.backend.services.PerfilSistemaService;
import com.github.andrepenteado.apsso.services.repositories.PerfilSistemaRepository;
import com.github.andrepenteado.apsso.services.Util;
import com.github.andrepenteado.apsso.services.models.PerfilSistema;
import com.github.andrepenteado.apsso.services.PerfilSistemaService;
import lombok.RequiredArgsConstructor;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -31,7 +31,7 @@ public List<PerfilSistema> listarPorSistema(String idSistema) {

@Override
public PerfilSistema incluir(PerfilSistema perfilSistema, BindingResult validacao) {
String erros = ApssoBackendApplication.validateModel(validacao);
String erros = Util.validateModel(validacao);
if (erros != null)
throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, erros);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.andrepenteado.apsso.backend.services.impl;
package com.github.andrepenteado.apsso.services.impl;

import com.github.andrepenteado.apsso.backend.ApssoBackendApplication;
import com.github.andrepenteado.apsso.backend.models.Sistema;
import com.github.andrepenteado.apsso.backend.repositories.SistemaRepository;
import com.github.andrepenteado.apsso.backend.services.SistemaService;
import com.github.andrepenteado.apsso.services.repositories.SistemaRepository;
import com.github.andrepenteado.apsso.services.Util;
import com.github.andrepenteado.apsso.services.models.Sistema;
import com.github.andrepenteado.apsso.services.SistemaService;
import lombok.RequiredArgsConstructor;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -34,7 +34,7 @@ public Optional<Sistema> buscar(String id) {

@Override
public Sistema incluirOuAlterar(Sistema sistema, BindingResult validacao) {
String erros = ApssoBackendApplication.validateModel(validacao);
String erros = Util.validateModel(validacao);
if (erros != null)
throw new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, erros);

Expand Down
Loading

0 comments on commit 852b686

Please sign in to comment.