diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1518830 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: java +jdk: oraclejdk8 +before_install: + - cd Back-end + - chmod +x mvnw \ No newline at end of file diff --git a/Back-end/.gitignore b/Back-end/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/Back-end/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/Back-end/.mvn/wrapper/maven-wrapper.jar b/Back-end/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..9cc84ea Binary files /dev/null and b/Back-end/.mvn/wrapper/maven-wrapper.jar differ diff --git a/Back-end/.mvn/wrapper/maven-wrapper.properties b/Back-end/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..b573bb5 --- /dev/null +++ b/Back-end/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip diff --git a/Back-end/mvnw b/Back-end/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/Back-end/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/Back-end/mvnw.cmd b/Back-end/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/Back-end/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/Back-end/pom.xml b/Back-end/pom.xml new file mode 100644 index 0000000..3bcfcdf --- /dev/null +++ b/Back-end/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + casafacilimoveis.com + casafacilimoveis + 0.0.1-SNAPSHOT + jar + + + + Casa Fácil Imóveis + Projeto do Casa Fácil Imóveis Campo Grande + + + org.springframework.boot + spring-boot-starter-parent + 2.0.4.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-security + + + + org.springframework.boot + spring-boot-starter-mail + + + + org.springframework.boot + spring-boot-starter-web + + + + org.flywaydb + flyway-core + + + + org.springframework.boot + spring-boot-devtools + runtime + + + + org.postgresql + postgresql + 9.4-1201-jdbc41 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + io.springfox + springfox-swagger2 + 2.6.1 + + + io.springfox + springfox-swagger-ui + 2.6.1 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/Back-end/src/main/java/com/casafacilimoveis/CasaFacilImoveisApplication.java b/Back-end/src/main/java/com/casafacilimoveis/CasaFacilImoveisApplication.java new file mode 100644 index 0000000..99b5a7a --- /dev/null +++ b/Back-end/src/main/java/com/casafacilimoveis/CasaFacilImoveisApplication.java @@ -0,0 +1,27 @@ +package com.casafacilimoveis; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +/** + * The type Casa facil imoveis application. + */ +@SpringBootApplication +public class CasaFacilImoveisApplication extends SpringBootServletInitializer { + + /** + * The entry point of application. + * + * @param args the input arguments + */ + public static void main(String[] args) { + SpringApplication.run(CasaFacilImoveisApplication.class, args); + } + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { + return builder.sources(CasaFacilImoveisApplication.class); + } +} diff --git a/Back-end/src/main/java/com/casafacilimoveis/configuracao/JpaConfiguration.java b/Back-end/src/main/java/com/casafacilimoveis/configuracao/JpaConfiguration.java new file mode 100644 index 0000000..3a3a396 --- /dev/null +++ b/Back-end/src/main/java/com/casafacilimoveis/configuracao/JpaConfiguration.java @@ -0,0 +1,82 @@ +package com.casafacilimoveis.configuracao; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; +import java.util.Properties; + +/** + * Created by @author Wender Galan on 28/02/2018. + */ +@EnableJpaRepositories(basePackages = "com.casafacilimoveis.repository.*") +@EnableTransactionManagement +@Configuration +public class JpaConfiguration { + + @Autowired + private Environment environment; + + /** + * Data source data source. + * + * @return the data source + */ + @Bean + public DataSource dataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(environment.getProperty("db.driver")); + dataSource.setUrl(environment.getProperty("db.url")); + dataSource.setUsername(environment.getProperty("db.usuario")); + dataSource.setPassword(environment.getProperty("db.senha")); + + return dataSource; + } + + /** + * Entity manager factory local container entity manager factory bean. + * + * @return the local container entity manager factory bean + */ + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + vendorAdapter.setGenerateDdl(true); + + LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); + factory.setJpaVendorAdapter(vendorAdapter); + factory.setPackagesToScan("com.casafacilimoveis.model"); + factory.setDataSource(dataSource()); + + Properties props = new Properties(); + props.setProperty("hibernate.dialect", environment.getProperty("hibernate.dialect")); + props.setProperty("hibernate.show_sql", environment.getProperty("hibernate.show_sql")); + props.setProperty("hibernate.format_sql", environment.getProperty("hibernate.format_sql")); + props.setProperty("hibernate.hbm2ddl.auto", environment.getProperty("hibernate.hbm2ddl.auto")); + //Remove o erro de conflito de plugins + props.setProperty("hibernate.temp.use_jdbc_metadata_defaults", environment.getProperty("hibernate.temp.use_jdbc_metadata_defaults")); + factory.setJpaProperties(props); + + return factory; + } + + /** + * Transaction manager jpa transaction manager. + * + * @param emf the emf + * @return the jpa transaction manager + */ + @Bean + public JpaTransactionManager transactionManager(EntityManagerFactory emf) { + return new JpaTransactionManager(emf); + } +} diff --git a/Back-end/src/main/java/com/casafacilimoveis/configuracao/SecurityConfiguration.java b/Back-end/src/main/java/com/casafacilimoveis/configuracao/SecurityConfiguration.java new file mode 100644 index 0000000..52a582e --- /dev/null +++ b/Back-end/src/main/java/com/casafacilimoveis/configuracao/SecurityConfiguration.java @@ -0,0 +1,22 @@ +package com.casafacilimoveis.configuracao; + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +/** + * The type Security configuration. + * @author Wender Galan + * Created on: 10/08/2018 + */ +@Configuration +public class SecurityConfiguration extends WebSecurityConfigurerAdapter { + + /** + * O método configura a segunraça do projeto para que todas as URL possam ser acessadas sem a necessidade de TOKEN + * */ + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests().antMatchers("/").permitAll(); + } +} diff --git a/Back-end/src/main/java/com/casafacilimoveis/configuracao/SwaggerConfiguration.java b/Back-end/src/main/java/com/casafacilimoveis/configuracao/SwaggerConfiguration.java new file mode 100644 index 0000000..d42bd55 --- /dev/null +++ b/Back-end/src/main/java/com/casafacilimoveis/configuracao/SwaggerConfiguration.java @@ -0,0 +1,47 @@ +package com.casafacilimoveis.configuracao; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +/** + * The type Swagger configuration. + * @author Wender Galan + * Created on: 10/08/2018 + */ +@Configuration +@EnableSwagger2 +public class SwaggerConfiguration { + + /** + * Confiura o swagger para poder ter a visualização em HTML + * + * @return the docket + */ + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2).select() + //Passar o package de onde estão os controller - irá fazer a busca dos controller + .apis(RequestHandlerSelectors.basePackage("com.casafacilimoveis")) + .paths(PathSelectors.any()).build() + .apiInfo(apiInfo()); + } + + private ApiInfo apiInfo() { + //Preenche as informações de contato do dev + Contact contact = new Contact("Wender Galan", "http://wendergalan.com", "contato@wendergalan.com"); + + return new ApiInfoBuilder().title("Casa Fácil Imóveis API") + .description("Documentação da API de acesso aos endpoints da aplicação Casa Fácil Imóveis.") + .contact(contact) + .version("1.0") + .build(); + } +} diff --git a/Back-end/src/main/java/com/casafacilimoveis/controller/EmailController.java b/Back-end/src/main/java/com/casafacilimoveis/controller/EmailController.java new file mode 100644 index 0000000..c5eb15a --- /dev/null +++ b/Back-end/src/main/java/com/casafacilimoveis/controller/EmailController.java @@ -0,0 +1,52 @@ +package com.casafacilimoveis.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mail.MailParseException; +import org.springframework.mail.SimpleMailMessage; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +/** + * The type Email controller. + * + * O email que faz o envio de e-mail tem as seguintes configurações: + * + * Usuario: casafacilimoveisconfirmation@gmail.com + * Senha: l3e8r5h6g2 + */ +@RestController +@RequestMapping("/email") +public class EmailController { + + @Autowired + private JavaMailSender mailSender; + + + /** + * CONFIGURAR O ENVIO DE EMAIL AINDA + * + * @return the string + */ + @RequestMapping(path = "/email-send", method = RequestMethod.GET) + public String sendEmail() { + SimpleMailMessage message = new SimpleMailMessage(); + + message.setText("Aqui vai o corpo da mensagem"); + message.setSubject("Aqui vai o titulo do email"); + message.setTo("wendergalan2014@hotmail.com"); + + try { + mailSender.send(message); + return "Email enviado com sucesso!"; + } catch (Exception e) { + e.printStackTrace(); + if (e instanceof MailParseException) { + return "O e-mail é inválido!"; + } + return "Erro ao envia o email!"; + } + + } +} diff --git a/Back-end/src/main/java/com/casafacilimoveis/controller/ServidorController.java b/Back-end/src/main/java/com/casafacilimoveis/controller/ServidorController.java new file mode 100644 index 0000000..4d594c6 --- /dev/null +++ b/Back-end/src/main/java/com/casafacilimoveis/controller/ServidorController.java @@ -0,0 +1,25 @@ +package com.casafacilimoveis.controller; + +import org.springframework.web.bind.annotation.*; + +/** + * The type Servidor controller. + */ +@CrossOrigin +@RestController +@RequestMapping("/servidor") +public class ServidorController { + + + /** + * PODE APAGAR ESTA CLASSE, É APENAS PARA TESTES + * + * @param nome the nome + * @return the string + */ + @GetMapping("/salvar") + public String salvar(@RequestParam("nome") String nome) { + + return "Deu tudo certo " + nome; + } +} diff --git a/Back-end/src/main/java/com/casafacilimoveis/util/SenhaUtils.java b/Back-end/src/main/java/com/casafacilimoveis/util/SenhaUtils.java new file mode 100644 index 0000000..a92d4f4 --- /dev/null +++ b/Back-end/src/main/java/com/casafacilimoveis/util/SenhaUtils.java @@ -0,0 +1,43 @@ +package com.casafacilimoveis.util; + +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +/** + * The type Senha utils. + * @author Wender Galan + * Em 09/08/2018 + * + * Exemplo de utilização: + * String senhaEncoded = SenhaUtils.gerarBCrypt("senhaDoUsuario"); + * boolean senhaValida = SenhaUtils.senhaValida("senhaDoUsuario", senhaEncoded); + * + */ +public class SenhaUtils { + + /** + * Gera um hash utilizando o Bcrypt + * + * @param senha the senha + * @return the string + */ + public static String gerarBCrypt(String senha){ + if (senha == null){ + return senha; + } + + BCryptPasswordEncoder bCryptEncoder = new BCryptPasswordEncoder(); + return bCryptEncoder.encode(senha); + } + + /** + * Verifica se a senha é válida + * + * @param senha the senha + * @param senhaEncoded the senha encoded + * @return the boolean + */ + public static boolean senhaValida(String senha, String senhaEncoded){ + BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); + return bCryptPasswordEncoder.matches(senha, senhaEncoded); + } +} diff --git a/Back-end/src/main/resources/application.properties b/Back-end/src/main/resources/application.properties new file mode 100644 index 0000000..29dab3e --- /dev/null +++ b/Back-end/src/main/resources/application.properties @@ -0,0 +1,42 @@ +#Porta do servidor +server.port=9090 + +#Database configuração +#Banco de Dados Local +#db.driver=org.postgresql.Driver +#db.url=jdbc:postgresql://localhost:5432/DBTeste +#db.usuario=postgres +#db.senha=admin + +#Banco de Dados do Heroku +db.driver=org.postgresql.Driver +db.url=jdbc:postgresql://ec2-54-225-76-201.compute-1.amazonaws.com:5432/d6lhr24e7nudg7?sslmode=require +db.usuario=zxebwestoynydb +db.senha=d34c0eb85f03b41d9560aa2b1655c6bbcb30a9dea0a8fdd9985ab06be5016a73 + +#Hibernate Configuração +hibernate.dialect=org.hibernate.dialect.PostgreSQL82Dialect +hibernate.hbm2ddl.auto=none +hibernate.show_sql=true +hibernate.format_sql=true +hibernate.temp.use_jdbc_metadata_defaults = false + +#Flyway +spring.jpa.hibernate.ddl-auto=none + +#Erro durante a execução, estas duas linhas resolviam, problema da própria API +#spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false +#spring.jpa.hibernate.jdbc.lob.non_contextual_creation=true +#spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect + +#Configurações de EMAIL +#Tem que liberar a conta para acesso de aplicativos com menor segurança +spring.mail.host=smtp.gmail.com +spring.mail.port=465 +spring.mail.username=casafacilimoveisconfirmation@gmail.com +spring.mail.password=l3e8r5h6g2 +spring.mail.properties.mail.smtp.auth=true +spring.mail.properties.mail.smtp.starttls.enable=true +spring.mail.properties.mail.smtp.starttls.required=true +spring.mail.properties.mail.smtp.ssl.enable=true +spring.mail.test-connection=true \ No newline at end of file diff --git a/Back-end/src/main/resources/db/migration/postgres/V1__tabelas.sql b/Back-end/src/main/resources/db/migration/postgres/V1__tabelas.sql new file mode 100644 index 0000000..9186a13 --- /dev/null +++ b/Back-end/src/main/resources/db/migration/postgres/V1__tabelas.sql @@ -0,0 +1,11 @@ +--PRIMEIRA VERSÃO DO BANCO DE DADOS +CREATE TABLE public.usuarios ( + id INTEGER NOT NULL, + nome TEXT NOT NULL, + login VARCHAR(500) NOT NULL, + senha VARCHAR(1000), + PRIMARY KEY(id) +) +WITH (oids = false); + +INSERT INTO public.usuarios (id, nome, login, senha) VALUES (1, 'Jose Teste', 'josesinho', 'senha'); \ No newline at end of file diff --git a/Back-end/src/main/resources/db/migration/postgres/information.txt b/Back-end/src/main/resources/db/migration/postgres/information.txt new file mode 100644 index 0000000..a93a944 --- /dev/null +++ b/Back-end/src/main/resources/db/migration/postgres/information.txt @@ -0,0 +1,7 @@ +Dentro destas pastas ficam localizados os arquivos de migração do banco de dados, +sendo que está sendo gerenciado pelo Flyway que controla a versão do banco e toda vez +que não contiver as tabelas do SQL ele irá criar para fazer a manutenção. + +O banco de dados está hospedado no heroku cli. + +A primeira versão de SQL so banco está nesta mesma pasta com o nome V1__tabelas.sql \ No newline at end of file diff --git a/Back-end/src/test/java/com/casafacilimoveis/CasaFacilImoveisApplicationTests.java b/Back-end/src/test/java/com/casafacilimoveis/CasaFacilImoveisApplicationTests.java new file mode 100644 index 0000000..cca83ac --- /dev/null +++ b/Back-end/src/test/java/com/casafacilimoveis/CasaFacilImoveisApplicationTests.java @@ -0,0 +1,16 @@ +package com.casafacilimoveis; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class CasaFacilImoveisApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/Database/Credenciais Database.txt b/Database/Credenciais Database.txt new file mode 100644 index 0000000..401e90b --- /dev/null +++ b/Database/Credenciais Database.txt @@ -0,0 +1,8 @@ +Host: ec2-54-225-76-201.compute-1.amazonaws.com +Database: d6lhr24e7nudg7 +User: zxebwestoynydb +Port: 5432 +Password: d34c0eb85f03b41d9560aa2b1655c6bbcb30a9dea0a8fdd9985ab06be5016a73 +URI: postgres://zxebwestoynydb:d34c0eb85f03b41d9560aa2b1655c6bbcb30a9dea0a8fdd9985ab06be5016a73@ec2-54-225-76-201.compute-1.amazonaws.com:5432/d6lhr24e7nudg7 +Heroku CLI: heroku pg:psql postgresql-flat-79732 --app casa-facil-imoveis +URL: jdbc:postgresql://ec2-54-225-76-201.compute-1.amazonaws.com:5432/d6lhr24e7nudg7?sslmode=require \ No newline at end of file diff --git a/LICENSE b/LICENSE index 261eeb9..427417b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,4 @@ + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -178,7 +179,7 @@ APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" + boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a @@ -186,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index fab45b4..715de7b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,36 @@ -# casa-facil-imoveis +# Casa Fácil Imóveis + +[![Build Status](https://travis-ci.org/WenderGalan/casa-facil-imoveis.svg?branch=master)](https://travis-ci.org/WenderGalan/casa-facil-imoveis) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![GitHub contributors](https://img.shields.io/github/contributors/Naereen/StrapDown.js.svg)](https://GitHub.com/Naereen/StrapDown.js/graphs/contributors/) + O projeto consiste em construir uma aplicação de compra/venda de imóveis parecido com alguns sites já existentes. + +O projeto está divido da seguinte maneira, o front-end foi desenvolvido pelo [Matheus Pimentel](https://github.com/MatheusPimentel) e o back-end por [Wender Galan](https://github.com/WenderGalan). + +## Tecnologias Utilizadas: + + - ### Back-end: [Spring boot](https://spring.io/projects/spring-boot) (dependências): + - JPA Data: Gerenciamento das entidades da aplicação + - Spring Security: Segurança dos web-services (Foi usado apenas para criptografia de senhas) + - Spring Email: Usado para o envio de e-mails dentro da aplicação + - Spring Web + - Spring DevTools + - [FlyWay](https://flywaydb.org/): Faz o gerenciamento de versões do banco de dados. + - Postgres + - Spring test (Teste de unidade) + - [Swagger](https://swagger.io/): Faz o gerenciamento de todas as requisões (controllers) de dentro da aplicação facilitando a visualização das mesmas. + +- ### Front-end: [Vue JS](https://vuejs.org/) (dependências): + - [Bootstrap-Vue](https://bootstrap-vue.js.org/docs/): Usado para auxiliar na criação de componentes responsivos. + - [Axios](https://github.com/axios/axios): Faz as requisições http com o back-end. + - [Vue-Router](https://router.vuejs.org/): Ferramenta do Vue usada para fazer as rotas de usuário. + - [ESLint](https://eslint.org/): Ferramenta para manter os padrões de código do JavaScript. + - [Vuex](https://vuex.vuejs.org/): Ferramenta do Vue para fazer sessão e armazenar informações do usuário + +- ### Database: [Postgres](https://www.postgresql.org/) + - Observações: A aplicação está com o banco de dados em deploy no Heroku, a principio da para deixar lá para poder utilizar a API sem necessidade de banco local, mas devido não ter custos o serviço é um pouco lento. + +- ### Integração contínua: [Travis CI](https://travis-ci.org/) + +- ### Links para teste da aplicação: + + [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://casa-facil-imoveis.herokuapp.com/)