diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1ef07b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### Docker ### +.data/ + +### VS Code ### +.vscode/ diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..cb28b0e Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..462686e --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..66df285 --- /dev/null +++ b/mvnw @@ -0,0 +1,308 @@ +#!/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 +# +# https://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.2.0 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# 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 /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + 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 + JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=$(java-config --jre-home) + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=$(cygpath --unix "$JAVA_HOME") + [ -n "$CLASSPATH" ] && + CLASSPATH=$(cygpath --path --unix "$CLASSPATH") +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && + JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)" +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="$(\unset -f command 2>/dev/null; \command -v 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 + +# 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/.." || exit 1; pwd) + fi + # end of workaround + done + printf '%s' "$(cd "$basedir" || exit 1; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + # Remove \r in case we run on Windows within Git Bash + # and check out the repository with auto CRLF management + # enabled. Otherwise, we may read lines that are delimited with + # \r\n and produce $'-Xarg\r' rather than -Xarg due to word + # splitting rules. + tr -s '\r\n' ' ' < "$1" + fi +} + +log() { + if [ "$MVNW_VERBOSE" = true ]; then + printf '%s\n' "$1" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname "$0")") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +log "$MAVEN_PROJECTBASEDIR" + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" +if [ -r "$wrapperJarPath" ]; then + log "Found $wrapperJarPath" +else + log "Couldn't find $wrapperJarPath, downloading it ..." + + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + fi + while IFS="=" read -r key value; do + # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) + safeValue=$(echo "$value" | tr -d '\r') + case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; + esac + done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" + log "Downloading from: $wrapperUrl" + + if $cygwin; then + wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") + fi + + if command -v wget > /dev/null; then + log "Found wget ... using wget" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + log "Found curl ... using curl" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + fi + else + log "Falling back to using Java to download" + javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=$(cygpath --path --windows "$javaSource") + javaClass=$(cygpath --path --windows "$javaClass") + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + log " - Compiling MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + log " - Running MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +# If specified, validate the SHA-256 sum of the Maven wrapper jar file +wrapperSha256Sum="" +while IFS="=" read -r key value; do + case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; + esac +done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" +if [ -n "$wrapperSha256Sum" ]; then + wrapperSha256Result=false + if command -v sha256sum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + elif command -v shasum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." + echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." + exit 1 + fi + if [ $wrapperSha256Result = false ]; then + echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 + echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 + echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 + exit 1 + fi +fi + +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 "$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 + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +# shellcheck disable=SC2086 # safe args +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..95ba6f5 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,205 @@ +@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 https://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 Apache Maven Wrapper startup batch script, version 3.2.0 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@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 keystroke 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 set title of command window +title %0 +@REM enable echoing by 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 "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\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 + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%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 "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\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% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..60f176f --- /dev/null +++ b/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.0.6 + + + com.gabriel_torelo + game_list + 0.0.1-SNAPSHOT + game_list + Demo project for Spring Boot + + 17 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-web + + + + com.h2database + h2 + runtime + + + + org.postgresql + postgresql + runtime + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 3.1.0 + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/src/main/java/com/gabriel_torelo/game_list/GameListApplication.java b/src/main/java/com/gabriel_torelo/game_list/GameListApplication.java new file mode 100644 index 0000000..53204e9 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/GameListApplication.java @@ -0,0 +1,13 @@ +package com.gabriel_torelo.game_list; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class GameListApplication { + + public static void main(String[] args) { + SpringApplication.run(GameListApplication.class, args); + } + +} diff --git a/src/main/java/com/gabriel_torelo/game_list/config/WebConfig.java b/src/main/java/com/gabriel_torelo/game_list/config/WebConfig.java new file mode 100644 index 0000000..9f77387 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/config/WebConfig.java @@ -0,0 +1,25 @@ +package com.gabriel_torelo.game_list.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig { + + @Value("${cors.origins}") + private String corsOrigins; + + @Bean + public WebMvcConfigurer corsConfigurer() { + return new WebMvcConfigurer() { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**").allowedMethods("*").allowedOrigins(corsOrigins); + } + }; + } + +} diff --git a/src/main/java/com/gabriel_torelo/game_list/controllers/GameController.java b/src/main/java/com/gabriel_torelo/game_list/controllers/GameController.java new file mode 100644 index 0000000..b789e7d --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/controllers/GameController.java @@ -0,0 +1,35 @@ +package com.gabriel_torelo.game_list.controllers; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.gabriel_torelo.game_list.dto.GameLongDTO; +import com.gabriel_torelo.game_list.dto.GameMinDTO; +import com.gabriel_torelo.game_list.dto.GameShortDTO; +import com.gabriel_torelo.game_list.services.GameService; + +@RestController +@RequestMapping(value = "/games") +public class GameController { + + @Autowired + private GameService gameService; + + @GetMapping + public List readAll() { + return gameService.readAll(); + } + + @GetMapping(value = "/{id}") + public GameShortDTO readID(@PathVariable Long id) { + return gameService.readID(id); + } + + @GetMapping(value = "/{id}/more_about") + public GameLongDTO readMoreID(@PathVariable Long id) { + return gameService.readMoreID(id); + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/controllers/GameListController.java b/src/main/java/com/gabriel_torelo/game_list/controllers/GameListController.java new file mode 100644 index 0000000..c23d443 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/controllers/GameListController.java @@ -0,0 +1,46 @@ +package com.gabriel_torelo.game_list.controllers; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.gabriel_torelo.game_list.dto.ChangePositionDTO; +import com.gabriel_torelo.game_list.dto.GameListDTO; +import com.gabriel_torelo.game_list.dto.GameMinDTO; +import com.gabriel_torelo.game_list.services.GameListService; +import com.gabriel_torelo.game_list.services.GameService; + +@RestController +@RequestMapping(value = "/lists") +public class GameListController { + + @Autowired + private GameListService gameListService; + + @Autowired + private GameService gameService; + + @GetMapping + public List readAll() { + return gameListService.readAll(); + } + + @GetMapping(value = "/{id}") + public GameListDTO readID(@PathVariable Long id) { + return gameListService.readID(id); + } + + @GetMapping(value = "/{id}/games") + public List readListID(@PathVariable Long id) { + return gameService.readListID(id); + } + + @PostMapping(value = "/{id}/change") + public void moveGame(@PathVariable Long id, @RequestBody ChangePositionDTO reqBody) { + gameListService.moveGame(id, reqBody.getCurrentIndex(), reqBody.getNewIndex()); + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/dto/ChangePositionDTO.java b/src/main/java/com/gabriel_torelo/game_list/dto/ChangePositionDTO.java new file mode 100644 index 0000000..321642b --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/dto/ChangePositionDTO.java @@ -0,0 +1,22 @@ +package com.gabriel_torelo.game_list.dto; + +public class ChangePositionDTO { + private Integer currentIndex; + private Integer newIndex; + + public Integer getCurrentIndex() { + return currentIndex; + } + + public void setCurrentIndex(Integer currentIndex) { + this.currentIndex = currentIndex; + } + + public Integer getNewIndex() { + return newIndex; + } + + public void setNewIndex(Integer newIndex) { + this.newIndex = newIndex; + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/dto/GameListDTO.java b/src/main/java/com/gabriel_torelo/game_list/dto/GameListDTO.java new file mode 100644 index 0000000..0413a7c --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/dto/GameListDTO.java @@ -0,0 +1,32 @@ +package com.gabriel_torelo.game_list.dto; + +import org.springframework.beans.BeanUtils; +import com.gabriel_torelo.game_list.entities.GameList; + +public class GameListDTO { + private Long id; + private String name; + + public GameListDTO() { + } + + public GameListDTO(GameList entity) { + BeanUtils.copyProperties(entity, this); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/dto/GameLongDTO.java b/src/main/java/com/gabriel_torelo/game_list/dto/GameLongDTO.java new file mode 100644 index 0000000..bc8c94d --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/dto/GameLongDTO.java @@ -0,0 +1,86 @@ +package com.gabriel_torelo.game_list.dto; + +import org.springframework.beans.BeanUtils; +import com.gabriel_torelo.game_list.entities.Game; + +public class GameLongDTO { + private Long id; + private String title; + private Integer year; + private String gender; + private String platforms; + private Double score; + private String imgUrl; + private String longDescription; + + public GameLongDTO() { + } + + public GameLongDTO(Game entity) { + BeanUtils.copyProperties(entity, this); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Integer getYear() { + return year; + } + + public void setYear(Integer year) { + this.year = year; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getPlatforms() { + return platforms; + } + + public void setPlatforms(String platforms) { + this.platforms = platforms; + } + + public Double getScore() { + return score; + } + + public void setScore(Double score) { + this.score = score; + } + + public String getImgUrl() { + return imgUrl; + } + + public void setImgUrl(String imgUrl) { + this.imgUrl = imgUrl; + } + + public String getLongDescription() { + return longDescription; + } + + public void setLongDescription(String longDescription) { + this.longDescription = longDescription; + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/dto/GameMinDTO.java b/src/main/java/com/gabriel_torelo/game_list/dto/GameMinDTO.java new file mode 100644 index 0000000..832e1b0 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/dto/GameMinDTO.java @@ -0,0 +1,70 @@ +package com.gabriel_torelo.game_list.dto; + +import com.gabriel_torelo.game_list.entities.Game; +import com.gabriel_torelo.game_list.projections.GameMinProjection; + +public class GameMinDTO { + private Long id; + private String title; + private Double score; + private String imgUrl; + private Integer position; + + public GameMinDTO() { + } + + public GameMinDTO(Game entity) { + id = entity.getId(); + title = entity.getTitle(); + score = entity.getScore(); + imgUrl = entity.getImgUrl(); + } + + public GameMinDTO(GameMinProjection projection) { + id = projection.getId(); + title = projection.getTitle(); + score = projection.getScore(); + imgUrl = projection.getImgUrl(); + position = projection.getPosition(); + } + + public Long getId() { + return id; + } + + public String getTitle() { + return title; + } + + public Double getScore() { + return score; + } + + public String getImgUrl() { + return imgUrl; + } + + public void setId(Long id) { + this.id = id; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setScore(Double score) { + this.score = score; + } + + public void setImgUrl(String imgUrl) { + this.imgUrl = imgUrl; + } + + public Integer getPosition() { + return position; + } + + public void setPosition(Integer position) { + this.position = position; + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/dto/GameShortDTO.java b/src/main/java/com/gabriel_torelo/game_list/dto/GameShortDTO.java new file mode 100644 index 0000000..bb70501 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/dto/GameShortDTO.java @@ -0,0 +1,39 @@ +package com.gabriel_torelo.game_list.dto; + +import com.gabriel_torelo.game_list.entities.Game; + +public class GameShortDTO { + private GameMinDTO gameMinDTO = new GameMinDTO(); + private String shortDescription; + + public GameShortDTO() { + } + + public GameShortDTO(Game entity) { + gameMinDTO.setId(entity.getId()); + gameMinDTO.setTitle(entity.getTitle()); + gameMinDTO.setScore(entity.getScore()); + gameMinDTO.setImgUrl(entity.getImgUrl()); + shortDescription = entity.getShortDescription(); + } + + public Long getId() { + return gameMinDTO.getId(); + } + + public String getTitle() { + return gameMinDTO.getTitle(); + } + + public Double getScore() { + return gameMinDTO.getScore(); + } + + public String getImgUrl() { + return gameMinDTO.getImgUrl(); + } + + public String getShortDescription() { + return shortDescription; + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/entities/Belonging.java b/src/main/java/com/gabriel_torelo/game_list/entities/Belonging.java new file mode 100644 index 0000000..581ea33 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/entities/Belonging.java @@ -0,0 +1,64 @@ +package com.gabriel_torelo.game_list.entities; + +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + +@Entity +@Table(name = "tb_belonging") +public class Belonging { + + @EmbeddedId + private BelongingPK id = new BelongingPK(); + private Integer position; + + public Belonging() { + } + + public Belonging(Game game, GameList list, Integer position) { + id.setGame(game); + id.setGameList(list); + this.position = position; + } + + public BelongingPK getId() { + return id; + } + + public void setId(BelongingPK id) { + this.id = id; + } + + public Integer getPosition() { + return position; + } + + public void setPosition(Integer position) { + this.position = position; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Belonging other = (Belonging) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/entities/BelongingPK.java b/src/main/java/com/gabriel_torelo/game_list/entities/BelongingPK.java new file mode 100644 index 0000000..d261a86 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/entities/BelongingPK.java @@ -0,0 +1,72 @@ +package com.gabriel_torelo.game_list.entities; + +import jakarta.persistence.Embeddable; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; + +@Embeddable +public class BelongingPK { + + @ManyToOne + @JoinColumn(name = "game_id") + private Game game; + + @ManyToOne + @JoinColumn(name = "list_id") + private GameList list; + + public BelongingPK(){ + } + + public BelongingPK(Game game, GameList gameList) { + this.game = game; + this.list = gameList; + } + + public Game getGame() { + return game; + } + + public void setGame(Game game) { + this.game = game; + } + + public GameList getGameList() { + return list; + } + + public void setGameList(GameList gameList) { + this.list = gameList; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((game == null) ? 0 : game.hashCode()); + result = prime * result + ((list == null) ? 0 : list.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BelongingPK other = (BelongingPK) obj; + if (game == null) { + if (other.game != null) + return false; + } else if (!game.equals(other.game)) + return false; + if (list == null) { + if (other.list != null) + return false; + } else if (!list.equals(other.list)) + return false; + return true; + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/entities/Game.java b/src/main/java/com/gabriel_torelo/game_list/entities/Game.java new file mode 100644 index 0000000..283da46 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/entities/Game.java @@ -0,0 +1,142 @@ +package com.gabriel_torelo.game_list.entities; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +@Entity +@Table(name = "tb_game") +public class Game { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String title; + + @Column(name = "game_year") + private Integer year; + private String gender; + private String platforms; + private Double score; + private String imgUrl; + private String shortDescription; + + @Column(columnDefinition = "TEXT") + private String longDescription; + + public Game() { + } + + public Game(Long id, String title, Integer year, String gender, String platforms, Double score, String imgUrl, + String shortDescription, String longDescription) { + this.id = id; + this.title = title; + this.year = year; + this.gender = gender; + this.platforms = platforms; + this.score = score; + this.imgUrl = imgUrl; + this.shortDescription = shortDescription; + this.longDescription = longDescription; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Integer getYear() { + return year; + } + + public void setYear(Integer year) { + this.year = year; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getPlatforms() { + return platforms; + } + + public void setPlatforms(String platforms) { + this.platforms = platforms; + } + + public Double getScore() { + return score; + } + + public void setScore(Double score) { + this.score = score; + } + + public String getImgUrl() { + return imgUrl; + } + + public void setImgUrl(String imgUrl) { + this.imgUrl = imgUrl; + } + + public String getShortDescription() { + return shortDescription; + } + + public void setShortDescription(String shortDescription) { + this.shortDescription = shortDescription; + } + + public String getLongDescription() { + return longDescription; + } + + public void setLongDescription(String longDescription) { + this.longDescription = longDescription; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Game other = (Game) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/entities/GameList.java b/src/main/java/com/gabriel_torelo/game_list/entities/GameList.java new file mode 100644 index 0000000..a12c21b --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/entities/GameList.java @@ -0,0 +1,66 @@ +package com.gabriel_torelo.game_list.entities; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; + +@Entity +@Table(name = "tb_game_list") +public class GameList { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + + public GameList() { + } + + public GameList(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + GameList other = (GameList) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/projections/GameMinProjection.java b/src/main/java/com/gabriel_torelo/game_list/projections/GameMinProjection.java new file mode 100644 index 0000000..f5c2071 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/projections/GameMinProjection.java @@ -0,0 +1,9 @@ +package com.gabriel_torelo.game_list.projections; + +public interface GameMinProjection { + Long getId(); + String getTitle(); + Double getScore(); + String getImgUrl(); + Integer getPosition(); +} diff --git a/src/main/java/com/gabriel_torelo/game_list/repositories/GameListRepository.java b/src/main/java/com/gabriel_torelo/game_list/repositories/GameListRepository.java new file mode 100644 index 0000000..5d61216 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/repositories/GameListRepository.java @@ -0,0 +1,18 @@ +package com.gabriel_torelo.game_list.repositories; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import com.gabriel_torelo.game_list.entities.GameList; + +public interface GameListRepository extends JpaRepository { + + @Modifying + @Query(nativeQuery = true, value = """ + UPDATE tb_belonging + SET position = :newIndex + WHERE list_id = :listID + AND game_id = :gameID + """) + void moveGameInList(Long listID, Long gameID, Integer newIndex); +} diff --git a/src/main/java/com/gabriel_torelo/game_list/repositories/GameRepository.java b/src/main/java/com/gabriel_torelo/game_list/repositories/GameRepository.java new file mode 100644 index 0000000..bebd45c --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/repositories/GameRepository.java @@ -0,0 +1,19 @@ +package com.gabriel_torelo.game_list.repositories; + +import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import com.gabriel_torelo.game_list.entities.Game; +import com.gabriel_torelo.game_list.projections.GameMinProjection; + +public interface GameRepository extends JpaRepository { + + @Query(nativeQuery = true, value = """ + SELECT tb_game.id, tb_game.title, tb_game.score, tb_game.img_url AS imgUrl, tb_belonging.position + FROM tb_game + INNER JOIN tb_belonging ON tb_game.id = tb_belonging.game_id + WHERE tb_belonging.list_id = :listId + ORDER BY tb_belonging.position + """) + List readListID(Long listId); +} diff --git a/src/main/java/com/gabriel_torelo/game_list/services/GameListService.java b/src/main/java/com/gabriel_torelo/game_list/services/GameListService.java new file mode 100644 index 0000000..3635d76 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/services/GameListService.java @@ -0,0 +1,50 @@ +package com.gabriel_torelo.game_list.services; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.gabriel_torelo.game_list.dto.GameListDTO; +import com.gabriel_torelo.game_list.entities.GameList; +import com.gabriel_torelo.game_list.projections.GameMinProjection; +import com.gabriel_torelo.game_list.repositories.GameListRepository; +import com.gabriel_torelo.game_list.repositories.GameRepository; + +@Service +public class GameListService { + + @Autowired + private GameListRepository gamelistRepository; + + @Autowired + private GameRepository gameRepository; + + @Transactional(readOnly = true) + public List readAll() { + List rGameLists = gamelistRepository.findAll(); + + return rGameLists.stream().map(gameListEntity -> new GameListDTO(gameListEntity)).toList(); + } + + @Transactional(readOnly = true) + public GameListDTO readID(Long id) { + GameList rGameList = gamelistRepository.findById(id).get(); + + return new GameListDTO(rGameList); + } + + @Transactional + public void moveGame(Long listID, int currentIndex, int newIndex) { + List rGameListProj = gameRepository.readListID(listID); + GameMinProjection rGameRemvd = rGameListProj.remove(currentIndex); + + rGameListProj.add(newIndex, rGameRemvd); + + int startRange = currentIndex < newIndex ? currentIndex : newIndex; + int endRange = currentIndex > newIndex ? currentIndex : newIndex; + + for (int i = startRange; i <= endRange; i++) { + gamelistRepository.moveGameInList(listID, rGameListProj.get(i).getId(), i); + } + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/services/GameService.java b/src/main/java/com/gabriel_torelo/game_list/services/GameService.java new file mode 100644 index 0000000..0f09237 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/services/GameService.java @@ -0,0 +1,47 @@ +package com.gabriel_torelo.game_list.services; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.gabriel_torelo.game_list.dto.GameLongDTO; +import com.gabriel_torelo.game_list.dto.GameMinDTO; +import com.gabriel_torelo.game_list.dto.GameShortDTO; +import com.gabriel_torelo.game_list.entities.Game; +import com.gabriel_torelo.game_list.projections.GameMinProjection; +import com.gabriel_torelo.game_list.repositories.GameRepository; + +@Service +public class GameService { + + @Autowired + private GameRepository gameRepository; + + @Transactional(readOnly = true) + public List readAll() { + List rGames = gameRepository.findAll(); + + return rGames.stream().map(gameEntity -> new GameMinDTO(gameEntity)).toList(); + } + + @Transactional(readOnly = true) + public GameShortDTO readID(Long id) { + Game rGame = gameRepository.findById(id).get(); + + return new GameShortDTO(rGame); + } + + @Transactional(readOnly = true) + public GameLongDTO readMoreID(Long id) { + Game rGame = gameRepository.findById(id).get(); + + return new GameLongDTO(rGame); + } + + @Transactional(readOnly = true) + public List readListID(Long id) { + List rGameProj = gameRepository.readListID(id); + + return rGameProj.stream().map(gameProject -> new GameMinDTO(gameProject)).toList(); + } +} diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties new file mode 100644 index 0000000..674fe46 --- /dev/null +++ b/src/main/resources/application-dev.properties @@ -0,0 +1,13 @@ +# Cria script que gera todas as Tabelas/Colunas no BD +#spring.jpa.properties.jakarta.persistence.schema-generation.create-source=metadata +#spring.jpa.properties.jakarta.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.jakarta.persistence.schema-generation.scripts.create-target=create.sql +#spring.jpa.properties.hibernate.hbm2ddl.delimiter=; + +spring.datasource.url=jdbc:postgresql://localhost:5433/gameList +spring.datasource.username=postgres +spring.datasource.password=1234567 + +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true +spring.jpa.hibernate.ddl-auto=none diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties new file mode 100644 index 0000000..d1beb75 --- /dev/null +++ b/src/main/resources/application-prod.properties @@ -0,0 +1,7 @@ +spring.datasource.url=${DB_URL} +spring.datasource.username=${DB_USERNAME} +spring.datasource.password=${DB_PASSWORD} + +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true +spring.jpa.hibernate.ddl-auto=none diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties new file mode 100644 index 0000000..9e61b4b --- /dev/null +++ b/src/main/resources/application-test.properties @@ -0,0 +1,12 @@ +# H2 Connection +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.username=sa +spring.datasource.password= + +# H2 Client +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console + +# Show SQL +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..e560631 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,4 @@ +spring.profiles.active=${APP_PROFILE:test} +spring.jpa.open-in-view=false + +cors.origins=${CORS_ORIGINS:http://localhost:5173,http://localhost:3000} diff --git a/src/main/resources/import.sql b/src/main/resources/import.sql new file mode 100644 index 0000000..6e5d4aa --- /dev/null +++ b/src/main/resources/import.sql @@ -0,0 +1,31 @@ +INSERT INTO tb_game_list (name) VALUES ('Todos os Jogos'); +INSERT INTO tb_game_list (name) VALUES ('Meus Favoritos'); + +INSERT INTO tb_game (title, score, game_year, gender, platforms, img_url, short_description, long_description) VALUES ('Street Fighter 6', 4.6, 2023, 'Role-playing (RPG) e Tiro', 'PlayStation 4|5,Xbox Series S|X, Arcade e Windows', 'https://image.api.playstation.com/vulcan/ap/rnd/202211/1407/XFU0aPBvtm3W2od1ZvhByAOv.png', '[Wikipedia] - Street Fighter 6 é um jogo de luta desenvolvido e publicado pela Capcom. Anunciado em fevereiro de 2022, é o sétimo título principal da franquia Street Fighter.', '[Wikipedia] - Desenvolvido no RE Engine, o Street Fighter 6 oferece suporte para reprodução entre plataformas e código de rede de reversão. Oferece três modos de jogo abrangentes e três opções de controle. O jogo também apresenta um sistema de comentários em tempo real, proporcionando uma sensação de estilo de torneio e a opção de torcer pelo jogador.'); +INSERT INTO tb_game (title, score, game_year, gender, platforms, img_url, short_description, long_description) VALUES ('Red Dead Redemption 2', 4.3, 2018, 'Role-playing (RPG) e Aventura', 'PlayStation 4, Xbox One, Google Stadia e Windows', 'https://image.api.playstation.com/cdn/UP1004/CUSA03041_00/Hpl5MtwQgOVF9vJqlfui6SDB5Jl4oBSq.png', '[Wikipedia] - Red Dead Redemption 2 é um jogo de ação e aventura desenvolvido e publicado pela Rockstar Games. O jogo é a terceira entrada na série Red Dead.', '[Wikipedia] - A história se passa em uma representação fictícia dos Estados Unidos em 1899 e segue as façanhas de Arthur Morgan, um fora da lei e membro da gangue Van der Linde, que deve lidar com o declínio do Velho Oeste enquanto tenta sobreviver contra as forças do governo, gangues rivais e outros adversários. O jogo é apresentado por meio de perspectivas de primeira e terceira pessoa, e o jogador pode vagar livremente em seu mundo aberto interativo.'); +INSERT INTO tb_game (title, score, game_year, gender, platforms, img_url, short_description, long_description) VALUES ('The Witcher 3: Wild Hunt', 4.6, 2014, 'Role-playing (RPG) e Aventura', 'PlayStation 4|5, Nintendo Switch, Xbox One, Xbox Series X|S e Windows', 'https://image.api.playstation.com/vulcan/ap/rnd/202211/0711/kh4MUIuMmHlktOHar3lVl6rY.png', '[Wikipedia] - The Witcher 3: Wild Hunt é um RPG de ação desenvolvido e publicado pela CD Projekt. É a sequência do jogo de 2011 The Witcher 2: Assassins of Kings e o terceiro jogo da série de videogames The Witcher.', '[Wikipedia] - O jogo se passa em um mundo de fantasia fictício baseado na mitologia eslava. Os jogadores controlam Geralt of Rivia, um matador de monstros de aluguel conhecido como Witcher, e procuram por sua filha adotiva, que está fugindo da Wild Hunt sobrenatural. Os jogadores lutam contra os muitos perigos do jogo com armas e magia, interagem com personagens e completam missões.'); +INSERT INTO tb_game (title, score, game_year, gender, platforms, img_url, short_description, long_description) VALUES ('Resident Evil 4', 4.0, 2023, 'Terror, Sobrevivência, Ação e Aventura', 'PlayStation 4|5, Xbox Series X|S e Steam', 'https://image.api.playstation.com/vulcan/ap/rnd/202210/0706/EVWyZD63pahuh95eKloFaJuC.png', '[Wikipedia] - Resident Evil 4 é um jogo eletrônico de survival horror e tiro em terceira pessoa desenvolvido e publicado pela Capcom é o sexto jogo principal da franquia Resident Evil.', '[Wikipedia] - A história segue o agente especial Leon S. Kennedy, que é enviado em uma missão para resgatar a filha do presidente dos Estados Unidos, Ashley Graham, que foi sequestrada por um culto religioso em uma parte rural da Espanha. Leon luta contra hordas de inimigos infectados por um parasita controlador de mentes e se reúne com a espiã Ada Wong.'); +INSERT INTO tb_game (title, score, game_year, gender, platforms, img_url, short_description, long_description) VALUES ('Final Fantasy XVI', 4.4, 2023, 'Role-playing (RPG), Luta e Aventura', 'PlayStation 5', 'https://image.api.playstation.com/vulcan/ap/rnd/202210/2407/T7XXHmYlFA3sUGYGp8KT3jbU.png', '[Wikipedia] - Final Fantasy XVI é um jogo eletrônico de RPG de ação desenvolvido e publicado pela Square Enix, é o décimo sexto título principal da série Final Fantasy.', '[Wikipedia] - Final Fantasy XVI se passa no mundo ficcional de Valisthea, onde a população vive com conforto graças a enormes montanhas de cristal chamadas de Cristais-Máter. O mundo é controlado por seis países: o Grão-Ducado de Rosaria, o Sacro Império de Sanbreque, o Reino de Waloed, a República de Dhalmekia, o Reino de Ferro e o Domínio Cristalino. Um importante aspecto do mundo são os Eikons, monstros convocáveis controlados ou manifestados por humanos chamados de Dominante.'); +INSERT INTO tb_game (title, score, game_year, gender, platforms, img_url, short_description, long_description) VALUES ('Assassin''s Creed Mirage', 0, 2023, 'Furtividade, Luta, Ação e Aventura', 'PlayStation 4|5, Xbox One, Xbox Series X|S e Windows', 'https://image.api.playstation.com/vulcan/ap/rnd/202208/1718/NFf86jgU4AeVYgJBEoEKBpxW.jpg', '[Wikipedia] - Assassin''s Creed Mirage é um futuro jogo desenvolvido e publicado pela Ubisoft. Será a décima terceira parcela principal da série Assassin''s Creed.', '[Wikipedia] - Situado principalmente na Bagdá do século IX durante a Era de Ouro Islâmica, o jogo seguirá Basim Ibn Ishaq (um personagem introduzido pela primeira vez em Valhalla e sua transição de ladrão de rua para membro de pleno direito da irmandade dos assassinos) que luta pela paz e liberdade, contra a Ordem dos Templários, que desejam a paz através do controle.'); +INSERT INTO tb_game (title, score, game_year, gender, platforms, img_url, short_description, long_description) VALUES ('God of War Ragnarök', 4.7, 2022, 'Role-playing (RPG), Luta, Ação e Aventura', 'PlayStation 4|5', 'https://image.api.playstation.com/vulcan/ap/rnd/202207/1210/EUg935xYj1xnRS8jkKAapzCp.png', '[Wikipedia] - God of War Ragnarök é um jogo eletrônico de ação e aventura desenvolvido pela Santa Monica Studio e publicado pela Sony Interactive Entertainment. É o nono título da série God of War, o nono em ordem cronológica.', '[Wikipedia] - Vagamente baseado na mitologia nórdica, o jogo se passa na antiga Escandinávia e apresenta os protagonistas Kratos e seu filho Atreus. Servindo como o final da era nórdica da série, o jogo dá início ao Ragnarök, uma série de eventos que trazem o fim dos tempos e retrata a morte de alguns dos deuses nórdicos, que foi predito no jogo anterior após Kratos ter matado o deus Æsir Baldur.'); +INSERT INTO tb_game (title, score, game_year, gender, platforms, img_url, short_description, long_description) VALUES ('Horizon Forbidden West', 4.4, 2022, 'Luta e Aventura', 'PlayStation 4|5', 'https://image.api.playstation.com/vulcan/ap/rnd/202107/3100/ki0STHGAkIF06Q4AU8Ow4OkV.png', '[Wikipedia] - Horizon Forbidden West é um jogo eletrônico de RPG de ação desenvolvido pela Guerrilla Games e publicado pela Sony Interactive Entertainment. É a sequência de Horizon Zero Dawn, sendo ambientada em um mundo aberto pós-apocalíptico.', '[Wikipedia] - Horizon Forbidden West é um jogo eletrônico de RPG de ação com uma perspectiva em terceira pessoa. Os jogadores controlam Aloy, uma caçadora em um mundo governado por máquinas. O jogo apresenta um mundo aberto ambientado numa Califórnia pós-apocalíptica. Os locais apresentados no trailer de anúncio do jogo incluem uma São Francisco em ruínas e Vale de Yosemite.'); +INSERT INTO tb_game (title, score, game_year, gender, platforms, img_url, short_description, long_description) VALUES ('Forza Horizon 5', 3.8, 2021, 'Corrida, Ação e Aventura', 'Xbox One, Xbox Series X|S, Xbox Cloud Gaming, Android e Windows', 'https://store-images.s-microsoft.com/image/apps.49800.13718773309227929.bebdcc0e-1ed5-4778-8732-f4ef65a2f445.9ac09d39-064d-466c-81ca-2f1b6f0b95c5', '[Wikipedia] - Forza Horizon 5 é um jogo eletrônico de corrida desenvolvido pela Playground Games e publicado pela Xbox Game Studios. É o décimo segundo título principal da franquia Forza.', '[Wikipedia] - Forza Horizon 5 é um jogo eletrônico de corrida ambientado em um ambiente de mundo aberto que se passa em uma representação ficcional do México. O jogo tem o maior mapa de toda a série Forza Horizon, sendo 50% maior do que o de Forza Horizon 4, além de também ter o ponto mais alto da série Horizon.'); +INSERT INTO tb_game (title, score, game_year, gender, platforms, img_url, short_description, long_description) VALUES ('Hitman 3', 4.3, 2021, 'Furtividade, Tiro, Ação e Aventura', 'PlayStation 4|5, Nintendo Switch, Xbox One, Xbox Series X|S, Google Stadia e Windows', 'https://image.api.playstation.com/vulcan/ap/rnd/202301/2315/AV5D2dPmPZL9CT3IdveGCGJZ.jpg', '[Wikipedia] - Hitman 3 é um jogo eletrônico de furtividade desenvolvido e publicado pela IO Interactive. É o oitavo título principal da série Hitman.', '[Wikipedia] - Hitman 3 é um jogo furtivo jogado numa perspetiva de terceira pessoa. Os jogadores assumem o papel do Agente 47 explorando vários locais ao redor do mundo com o objetivo de assassinar alvos contratados.Hitman 3 conclui a historia da trilogia, com o Agente 47 e os seus aliados a perseguir os lideres da Providence, uma organização secreta que controla os negócios mundiais.'); + +/* Inseri jogos na lista 'Todos os Jogos' */ +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (1, 1, 0); +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (1, 2, 1); +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (1, 3, 2); +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (1, 4, 3); +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (1, 5, 4); +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (1, 6, 5); +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (1, 7, 6); +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (1, 8, 7); +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (1, 9, 8); +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (1, 10, 9); + +/* Inseri jogos na lista 'Meus Favoritos' */ +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (2, 2, 0); +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (2, 4, 1); +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (2, 7, 2); +INSERT INTO tb_belonging (list_id, game_id, position) VALUES (2, 10, 3); \ No newline at end of file diff --git a/src/test/java/com/gabriel_torelo/game_list/GameListApplicationTests.java b/src/test/java/com/gabriel_torelo/game_list/GameListApplicationTests.java new file mode 100644 index 0000000..29cb009 --- /dev/null +++ b/src/test/java/com/gabriel_torelo/game_list/GameListApplicationTests.java @@ -0,0 +1,13 @@ +package com.gabriel_torelo.game_list; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class GameListApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/system.properties b/system.properties new file mode 100644 index 0000000..eafd676 --- /dev/null +++ b/system.properties @@ -0,0 +1 @@ +java.runtime.version=17