├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml ├── src ├── main │ ├── java │ │ └── com │ │ │ └── educandoweb │ │ │ └── course │ │ │ ├── CourseApplication.java │ │ │ ├── config │ │ │ └── TestConfig.java │ │ │ ├── entities │ │ │ ├── Category.java │ │ │ ├── Order.java │ │ │ ├── OrderItem.java │ │ │ ├── Payment.java │ │ │ ├── Product.java │ │ │ ├── User.java │ │ │ ├── enums │ │ │ │ └── OrderStatus.java │ │ │ └── pk │ │ │ │ └── OrderItemPK.java │ │ │ ├── repositories │ │ │ ├── CategoryRepository.java │ │ │ ├── OrderItemRepository.java │ │ │ ├── OrderRepository.java │ │ │ ├── ProductRepository.java │ │ │ └── UserRepository.java │ │ │ ├── resources │ │ │ ├── CategoryResource.java │ │ │ ├── OrderResource.java │ │ │ ├── ProductResource.java │ │ │ ├── UserResource.java │ │ │ └── exceptions │ │ │ │ ├── ResourceExceptionHandler.java │ │ │ │ └── StandardError.java │ │ │ └── services │ │ │ ├── CategoryService.java │ │ │ ├── OrderService.java │ │ │ ├── ProductService.java │ │ │ ├── UserService.java │ │ │ └── exceptions │ │ │ ├── DatabaseException.java │ │ │ └── ResourceNotFoundException.java │ └── resources │ │ ├── application-dev.properties │ │ ├── application-prod.properties │ │ ├── application-test.properties │ │ └── application.properties └── test │ └── java │ └── com │ └── educandoweb │ └── course │ └── CourseApplicationTests.java └── system.properties /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | https://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | import java.io.File; 21 | import java.io.FileInputStream; 22 | import java.io.FileOutputStream; 23 | import java.io.IOException; 24 | import java.net.URL; 25 | import java.nio.channels.Channels; 26 | import java.nio.channels.ReadableByteChannel; 27 | import java.util.Properties; 28 | 29 | public class MavenWrapperDownloader { 30 | 31 | /** 32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 33 | */ 34 | private static final String DEFAULT_DOWNLOAD_URL = 35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; 36 | 37 | /** 38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 39 | * use instead of the default one. 40 | */ 41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 42 | ".mvn/wrapper/maven-wrapper.properties"; 43 | 44 | /** 45 | * Path where the maven-wrapper.jar will be saved to. 46 | */ 47 | private static final String MAVEN_WRAPPER_JAR_PATH = 48 | ".mvn/wrapper/maven-wrapper.jar"; 49 | 50 | /** 51 | * Name of the property which should be used to override the default download url for the wrapper. 52 | */ 53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 54 | 55 | public static void main(String args[]) { 56 | System.out.println("- Downloader started"); 57 | File baseDirectory = new File(args[0]); 58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 59 | 60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 61 | // wrapperUrl parameter. 62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 63 | String url = DEFAULT_DOWNLOAD_URL; 64 | if(mavenWrapperPropertyFile.exists()) { 65 | FileInputStream mavenWrapperPropertyFileInputStream = null; 66 | try { 67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 68 | Properties mavenWrapperProperties = new Properties(); 69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 71 | } catch (IOException e) { 72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 73 | } finally { 74 | try { 75 | if(mavenWrapperPropertyFileInputStream != null) { 76 | mavenWrapperPropertyFileInputStream.close(); 77 | } 78 | } catch (IOException e) { 79 | // Ignore ... 80 | } 81 | } 82 | } 83 | System.out.println("- Downloading from: : " + url); 84 | 85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 86 | if(!outputFile.getParentFile().exists()) { 87 | if(!outputFile.getParentFile().mkdirs()) { 88 | System.out.println( 89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 90 | } 91 | } 92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 93 | try { 94 | downloadFileFromURL(url, outputFile); 95 | System.out.println("Done"); 96 | System.exit(0); 97 | } catch (Throwable e) { 98 | System.out.println("- Error downloading"); 99 | e.printStackTrace(); 100 | System.exit(1); 101 | } 102 | } 103 | 104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 105 | URL website = new URL(urlString); 106 | ReadableByteChannel rbc; 107 | rbc = Channels.newChannel(website.openStream()); 108 | FileOutputStream fos = new FileOutputStream(destination); 109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 110 | fos.close(); 111 | rbc.close(); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/acenelio/workshop-springboot2-jpa/4acdad5169c6453e9318d8a760e8880c1e5588f3/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | ########################################################################################## 204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 205 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 206 | ########################################################################################## 207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found .mvn/wrapper/maven-wrapper.jar" 210 | fi 211 | else 212 | if [ "$MVNW_VERBOSE" = true ]; then 213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 214 | fi 215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 216 | while IFS="=" read key value; do 217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 218 | esac 219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Downloading from: $jarUrl" 222 | fi 223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 224 | 225 | if command -v wget > /dev/null; then 226 | if [ "$MVNW_VERBOSE" = true ]; then 227 | echo "Found wget ... using wget" 228 | fi 229 | wget "$jarUrl" -O "$wrapperJarPath" 230 | elif command -v curl > /dev/null; then 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Found curl ... using curl" 233 | fi 234 | curl -o "$wrapperJarPath" "$jarUrl" 235 | else 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Falling back to using Java to download" 238 | fi 239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 240 | if [ -e "$javaClass" ]; then 241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 242 | if [ "$MVNW_VERBOSE" = true ]; then 243 | echo " - Compiling MavenWrapperDownloader.java ..." 244 | fi 245 | # Compiling the Java class 246 | ("$JAVA_HOME/bin/javac" "$javaClass") 247 | fi 248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 249 | # Running the downloader 250 | if [ "$MVNW_VERBOSE" = true ]; then 251 | echo " - Running MavenWrapperDownloader.java ..." 252 | fi 253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 254 | fi 255 | fi 256 | fi 257 | fi 258 | ########################################################################################## 259 | # End of extension 260 | ########################################################################################## 261 | 262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 263 | if [ "$MVNW_VERBOSE" = true ]; then 264 | echo $MAVEN_PROJECTBASEDIR 265 | fi 266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 267 | 268 | # For Cygwin, switch paths to Windows format before running java 269 | if $cygwin; then 270 | [ -n "$M2_HOME" ] && 271 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 272 | [ -n "$JAVA_HOME" ] && 273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 274 | [ -n "$CLASSPATH" ] && 275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 276 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 278 | fi 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 287 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.1.7.RELEASE 10 | 11 | 12 | com.educandoweb 13 | course 14 | 0.0.1-SNAPSHOT 15 | course 16 | Course Spring Boot 17 | 18 | 19 | 11 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-test 31 | test 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-data-jpa 37 | 38 | 39 | 40 | com.h2database 41 | h2 42 | runtime 43 | 44 | 45 | 46 | org.postgresql 47 | postgresql 48 | runtime 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/CourseApplication.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class CourseApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(CourseApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/config/TestConfig.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.config; 2 | 3 | import java.time.Instant; 4 | import java.util.Arrays; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.CommandLineRunner; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.Profile; 10 | 11 | import com.educandoweb.course.entities.Category; 12 | import com.educandoweb.course.entities.Order; 13 | import com.educandoweb.course.entities.OrderItem; 14 | import com.educandoweb.course.entities.Payment; 15 | import com.educandoweb.course.entities.Product; 16 | import com.educandoweb.course.entities.User; 17 | import com.educandoweb.course.entities.enums.OrderStatus; 18 | import com.educandoweb.course.repositories.CategoryRepository; 19 | import com.educandoweb.course.repositories.OrderItemRepository; 20 | import com.educandoweb.course.repositories.OrderRepository; 21 | import com.educandoweb.course.repositories.ProductRepository; 22 | import com.educandoweb.course.repositories.UserRepository; 23 | 24 | @Configuration 25 | @Profile("test") 26 | public class TestConfig implements CommandLineRunner { 27 | 28 | @Autowired 29 | private UserRepository userRepository; 30 | 31 | @Autowired 32 | private OrderRepository orderRepository; 33 | 34 | @Autowired 35 | private CategoryRepository categoryRepository; 36 | 37 | @Autowired 38 | private ProductRepository productRepository; 39 | 40 | @Autowired 41 | private OrderItemRepository orderItemRepository; 42 | 43 | @Override 44 | public void run(String... args) throws Exception { 45 | 46 | Category cat1 = new Category(null, "Electronics"); 47 | Category cat2 = new Category(null, "Books"); 48 | Category cat3 = new Category(null, "Computers"); 49 | 50 | Product p1 = new Product(null, "The Lord of the Rings", "Lorem ipsum dolor sit amet, consectetur.", 90.5, ""); 51 | Product p2 = new Product(null, "Smart TV", "Nulla eu imperdiet purus. Maecenas ante.", 2190.0, ""); 52 | Product p3 = new Product(null, "Macbook Pro", "Nam eleifend maximus tortor, at mollis.", 1250.0, ""); 53 | Product p4 = new Product(null, "PC Gamer", "Donec aliquet odio ac rhoncus cursus.", 1200.0, ""); 54 | Product p5 = new Product(null, "Rails for Dummies", "Cras fringilla convallis sem vel faucibus.", 100.99, ""); 55 | 56 | categoryRepository.saveAll(Arrays.asList(cat1, cat2, cat3)); 57 | productRepository.saveAll(Arrays.asList(p1, p2, p3, p4, p5)); 58 | 59 | p1.getCategories().add(cat2); 60 | p2.getCategories().add(cat1); 61 | p2.getCategories().add(cat3); 62 | p3.getCategories().add(cat3); 63 | p4.getCategories().add(cat3); 64 | p5.getCategories().add(cat2); 65 | 66 | productRepository.saveAll(Arrays.asList(p1, p2, p3, p4, p5)); 67 | 68 | User u1 = new User(null, "Maria Brown", "maria@gmail.com", "988888888", "123456"); 69 | User u2 = new User(null, "Alex Green", "alex@gmail.com", "977777777", "123456"); 70 | 71 | Order o1 = new Order(null, Instant.parse("2019-06-20T19:53:07Z"), OrderStatus.PAID, u1); 72 | Order o2 = new Order(null, Instant.parse("2019-07-21T03:42:10Z"), OrderStatus.WAITING_PAYMENT, u2); 73 | Order o3 = new Order(null, Instant.parse("2019-07-22T15:21:22Z"), OrderStatus.WAITING_PAYMENT, u1); 74 | 75 | userRepository.saveAll(Arrays.asList(u1, u2)); 76 | orderRepository.saveAll(Arrays.asList(o1, o2, o3)); 77 | 78 | OrderItem oi1 = new OrderItem(o1, p1, 2, p1.getPrice()); 79 | OrderItem oi2 = new OrderItem(o1, p3, 1, p3.getPrice()); 80 | OrderItem oi3 = new OrderItem(o2, p3, 2, p3.getPrice()); 81 | OrderItem oi4 = new OrderItem(o3, p5, 2, p5.getPrice()); 82 | 83 | orderItemRepository.saveAll(Arrays.asList(oi1, oi2, oi3, oi4)); 84 | 85 | Payment pay1 = new Payment(null, Instant.parse("2019-06-20T21:53:07Z"), o1); 86 | o1.setPayment(pay1); 87 | 88 | orderRepository.save(o1); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/entities/Category.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.entities; 2 | 3 | import java.io.Serializable; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import javax.persistence.Entity; 8 | import javax.persistence.GeneratedValue; 9 | import javax.persistence.GenerationType; 10 | import javax.persistence.Id; 11 | import javax.persistence.ManyToMany; 12 | import javax.persistence.Table; 13 | 14 | import com.fasterxml.jackson.annotation.JsonIgnore; 15 | 16 | @Entity 17 | @Table(name = "tb_category") 18 | public class Category implements Serializable { 19 | private static final long serialVersionUID = 1L; 20 | 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.IDENTITY) 23 | private Long id; 24 | private String name; 25 | 26 | @JsonIgnore 27 | @ManyToMany(mappedBy = "categories") 28 | private Set products = new HashSet<>(); 29 | 30 | public Category() { 31 | } 32 | 33 | public Category(Long id, String name) { 34 | super(); 35 | this.id = id; 36 | this.name = name; 37 | } 38 | 39 | public Long getId() { 40 | return id; 41 | } 42 | 43 | public void setId(Long id) { 44 | this.id = id; 45 | } 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | 55 | public Set getProducts() { 56 | return products; 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | final int prime = 31; 62 | int result = 1; 63 | result = prime * result + ((id == null) ? 0 : id.hashCode()); 64 | return result; 65 | } 66 | 67 | @Override 68 | public boolean equals(Object obj) { 69 | if (this == obj) 70 | return true; 71 | if (obj == null) 72 | return false; 73 | if (getClass() != obj.getClass()) 74 | return false; 75 | Category other = (Category) obj; 76 | if (id == null) { 77 | if (other.id != null) 78 | return false; 79 | } else if (!id.equals(other.id)) 80 | return false; 81 | return true; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/entities/Order.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.entities; 2 | 3 | import java.io.Serializable; 4 | import java.time.Instant; 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | import javax.persistence.CascadeType; 9 | import javax.persistence.Entity; 10 | import javax.persistence.GeneratedValue; 11 | import javax.persistence.GenerationType; 12 | import javax.persistence.Id; 13 | import javax.persistence.JoinColumn; 14 | import javax.persistence.ManyToOne; 15 | import javax.persistence.OneToMany; 16 | import javax.persistence.OneToOne; 17 | import javax.persistence.Table; 18 | 19 | import com.educandoweb.course.entities.enums.OrderStatus; 20 | import com.fasterxml.jackson.annotation.JsonFormat; 21 | 22 | @Entity 23 | @Table(name = "tb_order") 24 | public class Order implements Serializable { 25 | private static final long serialVersionUID = 1L; 26 | 27 | @Id 28 | @GeneratedValue(strategy = GenerationType.IDENTITY) 29 | private Long id; 30 | 31 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "GMT") 32 | private Instant moment; 33 | 34 | private Integer orderStatus; 35 | 36 | @ManyToOne 37 | @JoinColumn(name = "client_id") 38 | private User client; 39 | 40 | @OneToMany(mappedBy = "id.order") 41 | private Set items = new HashSet<>(); 42 | 43 | @OneToOne(mappedBy = "order", cascade = CascadeType.ALL) 44 | private Payment payment; 45 | 46 | public Order() { 47 | } 48 | 49 | public Order(Long id, Instant moment, OrderStatus orderStatus, User client) { 50 | super(); 51 | this.id = id; 52 | this.moment = moment; 53 | setOrderStatus(orderStatus); 54 | this.client = client; 55 | } 56 | 57 | public Long getId() { 58 | return id; 59 | } 60 | 61 | public void setId(Long id) { 62 | this.id = id; 63 | } 64 | 65 | public Instant getMoment() { 66 | return moment; 67 | } 68 | 69 | public void setMoment(Instant moment) { 70 | this.moment = moment; 71 | } 72 | 73 | public OrderStatus getOrderStatus() { 74 | return OrderStatus.valueOf(orderStatus); 75 | } 76 | 77 | public void setOrderStatus(OrderStatus orderStatus) { 78 | if (orderStatus != null) { 79 | this.orderStatus = orderStatus.getCode(); 80 | } 81 | } 82 | 83 | public User getClient() { 84 | return client; 85 | } 86 | 87 | public void setClient(User client) { 88 | this.client = client; 89 | } 90 | 91 | public Payment getPayment() { 92 | return payment; 93 | } 94 | 95 | public void setPayment(Payment payment) { 96 | this.payment = payment; 97 | } 98 | 99 | public Set getItems() { 100 | return items; 101 | } 102 | 103 | public Double getTotal() { 104 | double sum = 0.0; 105 | for (OrderItem x : items) { 106 | sum += x.getSubTotal(); 107 | } 108 | return sum; 109 | } 110 | 111 | @Override 112 | public int hashCode() { 113 | final int prime = 31; 114 | int result = 1; 115 | result = prime * result + ((id == null) ? 0 : id.hashCode()); 116 | return result; 117 | } 118 | 119 | @Override 120 | public boolean equals(Object obj) { 121 | if (this == obj) 122 | return true; 123 | if (obj == null) 124 | return false; 125 | if (getClass() != obj.getClass()) 126 | return false; 127 | Order other = (Order) obj; 128 | if (id == null) { 129 | if (other.id != null) 130 | return false; 131 | } else if (!id.equals(other.id)) 132 | return false; 133 | return true; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/entities/OrderItem.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.entities; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.EmbeddedId; 6 | import javax.persistence.Entity; 7 | import javax.persistence.Table; 8 | 9 | import com.educandoweb.course.entities.pk.OrderItemPK; 10 | import com.fasterxml.jackson.annotation.JsonIgnore; 11 | 12 | @Entity 13 | @Table(name = "tb_order_item") 14 | public class OrderItem implements Serializable { 15 | private static final long serialVersionUID = 1L; 16 | 17 | @EmbeddedId 18 | private OrderItemPK id = new OrderItemPK(); 19 | 20 | private Integer quantity; 21 | private Double price; 22 | 23 | public OrderItem() { 24 | } 25 | 26 | public OrderItem(Order order, Product product, Integer quantity, Double price) { 27 | super(); 28 | id.setOrder(order); 29 | id.setProduct(product); 30 | this.quantity = quantity; 31 | this.price = price; 32 | } 33 | 34 | @JsonIgnore 35 | public Order getOrder() { 36 | return id.getOrder(); 37 | } 38 | 39 | public void setOrder(Order order) { 40 | id.setOrder(order); 41 | } 42 | 43 | public Product getProduct() { 44 | return id.getProduct(); 45 | } 46 | 47 | public void setProduct(Product product) { 48 | id.setProduct(product); 49 | } 50 | 51 | public Integer getQuantity() { 52 | return quantity; 53 | } 54 | 55 | public void setQuantity(Integer quantity) { 56 | this.quantity = quantity; 57 | } 58 | 59 | public Double getPrice() { 60 | return price; 61 | } 62 | 63 | public void setPrice(Double price) { 64 | this.price = price; 65 | } 66 | 67 | public Double getSubTotal() { 68 | return price * quantity; 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | final int prime = 31; 74 | int result = 1; 75 | result = prime * result + ((id == null) ? 0 : id.hashCode()); 76 | return result; 77 | } 78 | 79 | @Override 80 | public boolean equals(Object obj) { 81 | if (this == obj) 82 | return true; 83 | if (obj == null) 84 | return false; 85 | if (getClass() != obj.getClass()) 86 | return false; 87 | OrderItem other = (OrderItem) obj; 88 | if (id == null) { 89 | if (other.id != null) 90 | return false; 91 | } else if (!id.equals(other.id)) 92 | return false; 93 | return true; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/entities/Payment.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.entities; 2 | 3 | import java.io.Serializable; 4 | import java.time.Instant; 5 | 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | import javax.persistence.MapsId; 11 | import javax.persistence.OneToOne; 12 | import javax.persistence.Table; 13 | 14 | import com.fasterxml.jackson.annotation.JsonIgnore; 15 | 16 | @Entity 17 | @Table(name = "tb_payment") 18 | public class Payment implements Serializable { 19 | private static final long serialVersionUID = 1L; 20 | 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.IDENTITY) 23 | private Long id; 24 | private Instant moment; 25 | 26 | @JsonIgnore 27 | @OneToOne 28 | @MapsId 29 | private Order order; 30 | 31 | public Payment() { 32 | } 33 | 34 | public Payment(Long id, Instant moment, Order order) { 35 | super(); 36 | this.id = id; 37 | this.moment = moment; 38 | this.order = order; 39 | } 40 | 41 | public Long getId() { 42 | return id; 43 | } 44 | 45 | public void setId(Long id) { 46 | this.id = id; 47 | } 48 | 49 | public Instant getMoment() { 50 | return moment; 51 | } 52 | 53 | public void setMoment(Instant moment) { 54 | this.moment = moment; 55 | } 56 | 57 | public Order getOrder() { 58 | return order; 59 | } 60 | 61 | public void setOrder(Order order) { 62 | this.order = order; 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | final int prime = 31; 68 | int result = 1; 69 | result = prime * result + ((id == null) ? 0 : id.hashCode()); 70 | return result; 71 | } 72 | 73 | @Override 74 | public boolean equals(Object obj) { 75 | if (this == obj) 76 | return true; 77 | if (obj == null) 78 | return false; 79 | if (getClass() != obj.getClass()) 80 | return false; 81 | Payment other = (Payment) obj; 82 | if (id == null) { 83 | if (other.id != null) 84 | return false; 85 | } else if (!id.equals(other.id)) 86 | return false; 87 | return true; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/entities/Product.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.entities; 2 | 3 | import java.io.Serializable; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import javax.persistence.Entity; 8 | import javax.persistence.GeneratedValue; 9 | import javax.persistence.GenerationType; 10 | import javax.persistence.Id; 11 | import javax.persistence.JoinColumn; 12 | import javax.persistence.JoinTable; 13 | import javax.persistence.ManyToMany; 14 | import javax.persistence.OneToMany; 15 | import javax.persistence.Table; 16 | 17 | import com.fasterxml.jackson.annotation.JsonIgnore; 18 | 19 | @Entity 20 | @Table(name = "tb_product") 21 | public class Product implements Serializable { 22 | private static final long serialVersionUID = 1L; 23 | 24 | @Id 25 | @GeneratedValue(strategy = GenerationType.IDENTITY) 26 | private Long id; 27 | private String name; 28 | private String description; 29 | private Double price; 30 | private String imgUrl; 31 | 32 | @ManyToMany 33 | @JoinTable(name = "tb_product_category", joinColumns = @JoinColumn(name = "product_id"), inverseJoinColumns = @JoinColumn(name = "category_id")) 34 | private Set categories = new HashSet<>(); 35 | 36 | @OneToMany(mappedBy = "id.product") 37 | private Set items = new HashSet<>(); 38 | 39 | public Product() { 40 | } 41 | 42 | public Product(Long id, String name, String description, Double price, String imgUrl) { 43 | super(); 44 | this.id = id; 45 | this.name = name; 46 | this.description = description; 47 | this.price = price; 48 | this.imgUrl = imgUrl; 49 | } 50 | 51 | public Long getId() { 52 | return id; 53 | } 54 | 55 | public void setId(Long id) { 56 | this.id = id; 57 | } 58 | 59 | public String getName() { 60 | return name; 61 | } 62 | 63 | public void setName(String name) { 64 | this.name = name; 65 | } 66 | 67 | public String getDescription() { 68 | return description; 69 | } 70 | 71 | public void setDescription(String description) { 72 | this.description = description; 73 | } 74 | 75 | public Double getPrice() { 76 | return price; 77 | } 78 | 79 | public void setPrice(Double price) { 80 | this.price = price; 81 | } 82 | 83 | public String getImgUrl() { 84 | return imgUrl; 85 | } 86 | 87 | public void setImgUrl(String imgUrl) { 88 | this.imgUrl = imgUrl; 89 | } 90 | 91 | public Set getCategories() { 92 | return categories; 93 | } 94 | 95 | @JsonIgnore 96 | public Set getOrders() { 97 | Set set = new HashSet<>(); 98 | for (OrderItem x : items) { 99 | set.add(x.getOrder()); 100 | } 101 | return set; 102 | } 103 | 104 | @Override 105 | public int hashCode() { 106 | final int prime = 31; 107 | int result = 1; 108 | result = prime * result + ((id == null) ? 0 : id.hashCode()); 109 | return result; 110 | } 111 | 112 | @Override 113 | public boolean equals(Object obj) { 114 | if (this == obj) 115 | return true; 116 | if (obj == null) 117 | return false; 118 | if (getClass() != obj.getClass()) 119 | return false; 120 | Product other = (Product) obj; 121 | if (id == null) { 122 | if (other.id != null) 123 | return false; 124 | } else if (!id.equals(other.id)) 125 | return false; 126 | return true; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/entities/User.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.entities; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import javax.persistence.Entity; 8 | import javax.persistence.GeneratedValue; 9 | import javax.persistence.GenerationType; 10 | import javax.persistence.Id; 11 | import javax.persistence.OneToMany; 12 | import javax.persistence.Table; 13 | 14 | import com.fasterxml.jackson.annotation.JsonIgnore; 15 | 16 | @Entity 17 | @Table(name = "tb_user") 18 | public class User implements Serializable { 19 | private static final long serialVersionUID = 1L; 20 | 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.IDENTITY) 23 | private Long id; 24 | private String name; 25 | private String email; 26 | private String phone; 27 | private String password; 28 | 29 | @JsonIgnore 30 | @OneToMany(mappedBy = "client") 31 | private List orders = new ArrayList<>(); 32 | 33 | public User() { 34 | } 35 | 36 | public User(Long id, String name, String email, String phone, String password) { 37 | super(); 38 | this.id = id; 39 | this.name = name; 40 | this.email = email; 41 | this.phone = phone; 42 | this.password = password; 43 | } 44 | 45 | public Long getId() { 46 | return id; 47 | } 48 | 49 | public void setId(Long id) { 50 | this.id = id; 51 | } 52 | 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | public void setName(String name) { 58 | this.name = name; 59 | } 60 | 61 | public String getEmail() { 62 | return email; 63 | } 64 | 65 | public void setEmail(String email) { 66 | this.email = email; 67 | } 68 | 69 | public String getPhone() { 70 | return phone; 71 | } 72 | 73 | public void setPhone(String phone) { 74 | this.phone = phone; 75 | } 76 | 77 | public String getPassword() { 78 | return password; 79 | } 80 | 81 | public void setPassword(String password) { 82 | this.password = password; 83 | } 84 | 85 | 86 | public List getOrders() { 87 | return orders; 88 | } 89 | 90 | @Override 91 | public int hashCode() { 92 | final int prime = 31; 93 | int result = 1; 94 | result = prime * result + ((id == null) ? 0 : id.hashCode()); 95 | return result; 96 | } 97 | 98 | @Override 99 | public boolean equals(Object obj) { 100 | if (this == obj) 101 | return true; 102 | if (obj == null) 103 | return false; 104 | if (getClass() != obj.getClass()) 105 | return false; 106 | User other = (User) obj; 107 | if (id == null) { 108 | if (other.id != null) 109 | return false; 110 | } else if (!id.equals(other.id)) 111 | return false; 112 | return true; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/entities/enums/OrderStatus.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.entities.enums; 2 | 3 | public enum OrderStatus { 4 | 5 | WAITING_PAYMENT(1), 6 | PAID(2), 7 | SHIPPED(3), 8 | DELIVERED(4), 9 | CANCELED(5); 10 | 11 | private int code; 12 | 13 | private OrderStatus(int code) { 14 | this.code = code; 15 | } 16 | 17 | public int getCode() { 18 | return code; 19 | } 20 | 21 | public static OrderStatus valueOf(int code) { 22 | for (OrderStatus value : OrderStatus.values()) { 23 | if (value.getCode() == code) { 24 | return value; 25 | } 26 | } 27 | throw new IllegalArgumentException("Invalid OrderStatus code"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/entities/pk/OrderItemPK.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.entities.pk; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Embeddable; 6 | import javax.persistence.JoinColumn; 7 | import javax.persistence.ManyToOne; 8 | 9 | import com.educandoweb.course.entities.Order; 10 | import com.educandoweb.course.entities.Product; 11 | 12 | @Embeddable 13 | public class OrderItemPK implements Serializable { 14 | private static final long serialVersionUID = 1L; 15 | 16 | @ManyToOne 17 | @JoinColumn(name = "order_id") 18 | private Order order; 19 | 20 | @ManyToOne 21 | @JoinColumn(name = "product_id") 22 | private Product product; 23 | 24 | public Order getOrder() { 25 | return order; 26 | } 27 | public void setOrder(Order order) { 28 | this.order = order; 29 | } 30 | public Product getProduct() { 31 | return product; 32 | } 33 | public void setProduct(Product product) { 34 | this.product = product; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | final int prime = 31; 40 | int result = 1; 41 | result = prime * result + ((order == null) ? 0 : order.hashCode()); 42 | result = prime * result + ((product == null) ? 0 : product.hashCode()); 43 | return result; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object obj) { 48 | if (this == obj) 49 | return true; 50 | if (obj == null) 51 | return false; 52 | if (getClass() != obj.getClass()) 53 | return false; 54 | OrderItemPK other = (OrderItemPK) obj; 55 | if (order == null) { 56 | if (other.order != null) 57 | return false; 58 | } else if (!order.equals(other.order)) 59 | return false; 60 | if (product == null) { 61 | if (other.product != null) 62 | return false; 63 | } else if (!product.equals(other.product)) 64 | return false; 65 | return true; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/repositories/CategoryRepository.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.repositories; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.educandoweb.course.entities.Category; 6 | 7 | public interface CategoryRepository extends JpaRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/repositories/OrderItemRepository.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.repositories; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.educandoweb.course.entities.OrderItem; 6 | import com.educandoweb.course.entities.pk.OrderItemPK; 7 | 8 | public interface OrderItemRepository extends JpaRepository { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/repositories/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.repositories; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.educandoweb.course.entities.Order; 6 | 7 | public interface OrderRepository extends JpaRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/repositories/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.repositories; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.educandoweb.course.entities.Product; 6 | 7 | public interface ProductRepository extends JpaRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/repositories/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.repositories; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.educandoweb.course.entities.User; 6 | 7 | public interface UserRepository extends JpaRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/resources/CategoryResource.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.resources; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.educandoweb.course.entities.Category; 13 | import com.educandoweb.course.services.CategoryService; 14 | 15 | @RestController 16 | @RequestMapping(value = "/categories") 17 | public class CategoryResource { 18 | 19 | @Autowired 20 | private CategoryService service; 21 | 22 | @GetMapping 23 | public ResponseEntity> findAll() { 24 | List list = service.findAll(); 25 | return ResponseEntity.ok().body(list); 26 | } 27 | 28 | @GetMapping(value = "/{id}") 29 | public ResponseEntity findById(@PathVariable Long id) { 30 | Category obj = service.findById(id); 31 | return ResponseEntity.ok().body(obj); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/resources/OrderResource.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.resources; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.educandoweb.course.entities.Order; 13 | import com.educandoweb.course.services.OrderService; 14 | 15 | @RestController 16 | @RequestMapping(value = "/orders") 17 | public class OrderResource { 18 | 19 | @Autowired 20 | private OrderService service; 21 | 22 | @GetMapping 23 | public ResponseEntity> findAll() { 24 | List list = service.findAll(); 25 | return ResponseEntity.ok().body(list); 26 | } 27 | 28 | @GetMapping(value = "/{id}") 29 | public ResponseEntity findById(@PathVariable Long id) { 30 | Order obj = service.findById(id); 31 | return ResponseEntity.ok().body(obj); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/resources/ProductResource.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.resources; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.educandoweb.course.entities.Product; 13 | import com.educandoweb.course.services.ProductService; 14 | 15 | @RestController 16 | @RequestMapping(value = "/products") 17 | public class ProductResource { 18 | 19 | @Autowired 20 | private ProductService service; 21 | 22 | @GetMapping 23 | public ResponseEntity> findAll() { 24 | List list = service.findAll(); 25 | return ResponseEntity.ok().body(list); 26 | } 27 | 28 | @GetMapping(value = "/{id}") 29 | public ResponseEntity findById(@PathVariable Long id) { 30 | Product obj = service.findById(id); 31 | return ResponseEntity.ok().body(obj); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/resources/UserResource.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.resources; 2 | 3 | import java.net.URI; 4 | import java.util.List; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.DeleteMapping; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | import org.springframework.web.bind.annotation.PutMapping; 13 | import org.springframework.web.bind.annotation.RequestBody; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RestController; 16 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; 17 | 18 | import com.educandoweb.course.entities.User; 19 | import com.educandoweb.course.services.UserService; 20 | 21 | @RestController 22 | @RequestMapping(value = "/users") 23 | public class UserResource { 24 | 25 | @Autowired 26 | private UserService service; 27 | 28 | @GetMapping 29 | public ResponseEntity> findAll() { 30 | List list = service.findAll(); 31 | return ResponseEntity.ok().body(list); 32 | } 33 | 34 | @GetMapping(value = "/{id}") 35 | public ResponseEntity findById(@PathVariable Long id) { 36 | User obj = service.findById(id); 37 | return ResponseEntity.ok().body(obj); 38 | } 39 | 40 | @PostMapping 41 | public ResponseEntity insert(@RequestBody User obj) { 42 | obj = service.insert(obj); 43 | URI uri = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}") 44 | .buildAndExpand(obj.getId()).toUri(); 45 | return ResponseEntity.created(uri).body(obj); 46 | } 47 | 48 | @DeleteMapping(value = "/{id}") 49 | public ResponseEntity delete(@PathVariable Long id) { 50 | service.delete(id); 51 | return ResponseEntity.noContent().build(); 52 | } 53 | 54 | @PutMapping(value = "/{id}") 55 | public ResponseEntity update(@PathVariable Long id, @RequestBody User obj) { 56 | obj = service.update(id, obj); 57 | return ResponseEntity.ok().body(obj); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/resources/exceptions/ResourceExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.resources.exceptions; 2 | 3 | import java.time.Instant; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.ControllerAdvice; 10 | import org.springframework.web.bind.annotation.ExceptionHandler; 11 | 12 | import com.educandoweb.course.services.exceptions.DatabaseException; 13 | import com.educandoweb.course.services.exceptions.ResourceNotFoundException; 14 | 15 | @ControllerAdvice 16 | public class ResourceExceptionHandler { 17 | 18 | @ExceptionHandler(ResourceNotFoundException.class) 19 | public ResponseEntity resourceNotFound(ResourceNotFoundException e, HttpServletRequest request) { 20 | String error = "Resource not found"; 21 | HttpStatus status = HttpStatus.NOT_FOUND; 22 | StandardError err = new StandardError(Instant.now(), status.value(), error, e.getMessage(), request.getRequestURI()); 23 | return ResponseEntity.status(status).body(err); 24 | } 25 | 26 | @ExceptionHandler(DatabaseException.class) 27 | public ResponseEntity database(DatabaseException e, HttpServletRequest request) { 28 | String error = "Database error"; 29 | HttpStatus status = HttpStatus.BAD_REQUEST; 30 | StandardError err = new StandardError(Instant.now(), status.value(), error, e.getMessage(), request.getRequestURI()); 31 | return ResponseEntity.status(status).body(err); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/resources/exceptions/StandardError.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.resources.exceptions; 2 | 3 | import java.io.Serializable; 4 | import java.time.Instant; 5 | 6 | import com.fasterxml.jackson.annotation.JsonFormat; 7 | 8 | public class StandardError implements Serializable { 9 | private static final long serialVersionUID = 1L; 10 | 11 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "GMT") 12 | private Instant timestamp; 13 | private Integer status; 14 | private String error; 15 | private String message; 16 | private String path; 17 | 18 | public StandardError() { 19 | } 20 | 21 | public StandardError(Instant timestamp, Integer status, String error, String message, String path) { 22 | super(); 23 | this.timestamp = timestamp; 24 | this.status = status; 25 | this.error = error; 26 | this.message = message; 27 | this.path = path; 28 | } 29 | 30 | public Instant getTimestamp() { 31 | return timestamp; 32 | } 33 | 34 | public void setTimestamp(Instant timestamp) { 35 | this.timestamp = timestamp; 36 | } 37 | 38 | public Integer getStatus() { 39 | return status; 40 | } 41 | 42 | public void setStatus(Integer status) { 43 | this.status = status; 44 | } 45 | 46 | public String getError() { 47 | return error; 48 | } 49 | 50 | public void setError(String error) { 51 | this.error = error; 52 | } 53 | 54 | public String getMessage() { 55 | return message; 56 | } 57 | 58 | public void setMessage(String message) { 59 | this.message = message; 60 | } 61 | 62 | public String getPath() { 63 | return path; 64 | } 65 | 66 | public void setPath(String path) { 67 | this.path = path; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/services/CategoryService.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.services; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.educandoweb.course.entities.Category; 10 | import com.educandoweb.course.repositories.CategoryRepository; 11 | 12 | @Service 13 | public class CategoryService { 14 | 15 | @Autowired 16 | private CategoryRepository repository; 17 | 18 | public List findAll() { 19 | return repository.findAll(); 20 | } 21 | 22 | public Category findById(Long id) { 23 | Optional obj = repository.findById(id); 24 | return obj.get(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/services/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.services; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.educandoweb.course.entities.Order; 10 | import com.educandoweb.course.repositories.OrderRepository; 11 | 12 | @Service 13 | public class OrderService { 14 | 15 | @Autowired 16 | private OrderRepository repository; 17 | 18 | public List findAll() { 19 | return repository.findAll(); 20 | } 21 | 22 | public Order findById(Long id) { 23 | Optional obj = repository.findById(id); 24 | return obj.get(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/services/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.services; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.educandoweb.course.entities.Product; 10 | import com.educandoweb.course.repositories.ProductRepository; 11 | 12 | @Service 13 | public class ProductService { 14 | 15 | @Autowired 16 | private ProductRepository repository; 17 | 18 | public List findAll() { 19 | return repository.findAll(); 20 | } 21 | 22 | public Product findById(Long id) { 23 | Optional obj = repository.findById(id); 24 | return obj.get(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/services/UserService.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.services; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import javax.persistence.EntityNotFoundException; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.dao.DataIntegrityViolationException; 10 | import org.springframework.dao.EmptyResultDataAccessException; 11 | import org.springframework.stereotype.Service; 12 | 13 | import com.educandoweb.course.entities.User; 14 | import com.educandoweb.course.repositories.UserRepository; 15 | import com.educandoweb.course.services.exceptions.DatabaseException; 16 | import com.educandoweb.course.services.exceptions.ResourceNotFoundException; 17 | 18 | @Service 19 | public class UserService { 20 | 21 | @Autowired 22 | private UserRepository repository; 23 | 24 | public List findAll() { 25 | return repository.findAll(); 26 | } 27 | 28 | public User findById(Long id) { 29 | Optional obj = repository.findById(id); 30 | return obj.orElseThrow(() -> new ResourceNotFoundException(id)); 31 | } 32 | 33 | public User insert(User obj) { 34 | return repository.save(obj); 35 | } 36 | 37 | public void delete(Long id) { 38 | try { 39 | repository.deleteById(id); 40 | } catch (EmptyResultDataAccessException e) { 41 | throw new ResourceNotFoundException(id); 42 | } catch (DataIntegrityViolationException e) { 43 | throw new DatabaseException(e.getMessage()); 44 | } 45 | } 46 | 47 | public User update(Long id, User obj) { 48 | try { 49 | User entity = repository.getOne(id); 50 | updateData(entity, obj); 51 | return repository.save(entity); 52 | } catch (EntityNotFoundException e) { 53 | throw new ResourceNotFoundException(id); 54 | } 55 | } 56 | 57 | private void updateData(User entity, User obj) { 58 | entity.setName(obj.getName()); 59 | entity.setEmail(obj.getEmail()); 60 | entity.setPhone(obj.getPhone()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/services/exceptions/DatabaseException.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.services.exceptions; 2 | 3 | public class DatabaseException extends RuntimeException { 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | public DatabaseException(String msg) { 8 | super(msg); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/educandoweb/course/services/exceptions/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course.services.exceptions; 2 | 3 | public class ResourceNotFoundException extends RuntimeException { 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | public ResourceNotFoundException(Object id) { 8 | super("Resource not found. Id " + id); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:postgresql://localhost:5432/springboot_course 2 | spring.datasource.username=postgres 3 | spring.datasource.password=1234567 4 | 5 | spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true 6 | spring.jpa.hibernate.ddl-auto=update 7 | spring.jpa.show-sql=true 8 | spring.jpa.properties.hibernate.format_sql=true 9 | 10 | jwt.secret=MYJWTSECRET 11 | jwt.expiration=3600000 12 | -------------------------------------------------------------------------------- /src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=${DATABASE_URL} 2 | 3 | spring.jpa.hibernate.ddl-auto=none 4 | spring.jpa.show-sql=false 5 | spring.jpa.properties.hibernate.format_sql=false 6 | 7 | jwt.secret=${JWT_SECRET} 8 | jwt.expiration=${JWT_EXPIRATION} 9 | -------------------------------------------------------------------------------- /src/main/resources/application-test.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:h2:mem:testdb 2 | spring.datasource.username=sa 3 | spring.datasource.password= 4 | 5 | spring.h2.console.enabled=true 6 | spring.h2.console.path=/h2-console 7 | 8 | spring.jpa.show-sql=true 9 | spring.jpa.properties.hibernate.format_sql=true 10 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=prod 2 | 3 | spring.jpa.open-in-view=true 4 | -------------------------------------------------------------------------------- /src/test/java/com/educandoweb/course/CourseApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.educandoweb.course; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CourseApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /system.properties: -------------------------------------------------------------------------------- 1 | java.runtime.version=11 2 | --------------------------------------------------------------------------------