diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +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/ + +### 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..5f0536e --- /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.5/apache-maven-3.9.5-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..8ee7f9f --- /dev/null +++ b/pom.xml @@ -0,0 +1,94 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.1 + + + org.ecommerce.spring.boot + vegetable-project + 0.0.1-SNAPSHOT + vegetable-project + vegetable-project + + 17 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-mail + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-web + + + org.thymeleaf.extras + thymeleaf-extras-springsecurity6 + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/VegetableProjectApplication.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/VegetableProjectApplication.java new file mode 100644 index 0000000..f2f470c --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/VegetableProjectApplication.java @@ -0,0 +1,13 @@ +package org.ecommerce.spring.boot.vegetable.project; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class VegetableProjectApplication { + + public static void main(String[] args) { + SpringApplication.run(VegetableProjectApplication.class, args); + } + +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/config/SecurityConfig.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/config/SecurityConfig.java new file mode 100644 index 0000000..12565b7 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/config/SecurityConfig.java @@ -0,0 +1,70 @@ +package org.ecommerce.spring.boot.vegetable.project.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; + +@Configuration +@EnableWebSecurity +public class SecurityConfig { + + @Autowired + private UserDetailsService userDetailsService; + + private final static String[] paths = { + "/**", + "/error", + "/login", + "/registration/**", + "/img/**", + "/css/**" + }; + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + return http + .csrf(AbstractHttpConfigurer::disable) + .authorizeHttpRequests( + author -> author.requestMatchers(paths).permitAll() + .anyRequest().authenticated() + ) + .formLogin( + form -> form.loginPage("/login") + .loginProcessingUrl("/login") + .usernameParameter("email") + .defaultSuccessUrl("/") + .permitAll() + ) + .logout( + log -> log.invalidateHttpSession(true) + .clearAuthentication(true) + .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) + .logoutSuccessUrl("/") + .permitAll() + ) + .build(); + } + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(11); + } + + @Bean + public AuthenticationProvider authenticationProvider() { + DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider(); + authenticationProvider.setUserDetailsService(userDetailsService); + authenticationProvider.setPasswordEncoder(passwordEncoder()); + return authenticationProvider; + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/controller/HomeController.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/controller/HomeController.java new file mode 100644 index 0000000..9b8a933 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/controller/HomeController.java @@ -0,0 +1,183 @@ +package org.ecommerce.spring.boot.vegetable.project.controller; + +import org.ecommerce.spring.boot.vegetable.project.dto.BlogDto; +import org.ecommerce.spring.boot.vegetable.project.dto.ProductDto; +import org.ecommerce.spring.boot.vegetable.project.entity.Banner; +import org.ecommerce.spring.boot.vegetable.project.entity.Blog; +import org.ecommerce.spring.boot.vegetable.project.entity.Category; +import org.ecommerce.spring.boot.vegetable.project.entity.Product; +import org.ecommerce.spring.boot.vegetable.project.service.BannerService; +import org.ecommerce.spring.boot.vegetable.project.service.BlogService; +import org.ecommerce.spring.boot.vegetable.project.service.CategoryService; +import org.ecommerce.spring.boot.vegetable.project.service.ProductService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.ModelAndView; + +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +@Controller +@RequestMapping({"/", "/home"}) +public class HomeController { + + @Autowired + private CategoryService categoryService; + + @Autowired + private ProductService productService; + + @Autowired + private BannerService bannerService; + + @Autowired + private BlogService blogService; + + @GetMapping("/") + public ModelAndView home() throws ParseException { + ModelAndView modelAndView = new ModelAndView("home"); + List categories = categoryService.getCategoryList(); + List banners = bannerService.getBannerList(); + List blogs = blogService.getBlogList(); + modelAndView.addObject("categories", categories); + modelAndView.addObject("banners", banners); + modelAndView.addObject("blogs", blogs); + return modelAndView; + } + + @GetMapping("/login") + public String loginForm() { + return "login"; + } + + @PostMapping("/addCategory") + public ResponseEntity addCategory(@RequestParam("name") String name, @RequestParam("image")MultipartFile file) throws IOException { + categoryService.addCategory(name, file); + return ResponseEntity.ok("success"); + } + + @GetMapping("/getCategoryList") + public ModelAndView getCategoryList() { + ModelAndView modelAndView = new ModelAndView("home"); + List categories = categoryService.getCategoryList(); + modelAndView.addObject("categories", categories); + return modelAndView; + } + + @GetMapping("/getCategoryImage/{id}") + public ResponseEntity getCategoryImage(@PathVariable Long id) { + byte[] image = categoryService.getCategoryImage(id); + return ResponseEntity.status(HttpStatus.OK) + .contentType(MediaType.valueOf("image/png")) + .body(image); + } + + @PostMapping("/addProduct") + public ResponseEntity addProduct(@ModelAttribute ProductDto productDto) throws IOException { + Product p = productService.addProduct(productDto); + return ResponseEntity.ok("add product success"); + } + + @GetMapping("/getProductList/{pageNumber}") + @ResponseBody + public List getProductList(@PathVariable Integer pageNumber) { + ModelAndView modelAndView = new ModelAndView("home"); + List products = productService.getProductList(pageNumber); + return products; + } + + @GetMapping("/getProductImage/{id}") + public ResponseEntity getProductImage(@PathVariable Long id) { + byte[] image = productService.getProductImage(id); + return ResponseEntity.status(HttpStatus.OK) + .contentType(MediaType.valueOf("image/png")) + .body(image); + } + + @GetMapping("/getProductListByCategory/{categoryName}/{pageNumber}") + @ResponseBody + public List getProductListByCategory(@PathVariable String categoryName, @PathVariable Integer pageNumber) { + List products = productService.getProductListByCategory(categoryName, pageNumber); + return products; + } + + @GetMapping("/getTotalPages/{categoryName}") + @ResponseBody + public Long getTotalPages(@PathVariable String categoryName) { + long totalPage = productService.getTotalPages(categoryName); + return totalPage; + } + + @GetMapping("/getTotalPagesAll") + @ResponseBody + public Long getTotalPagesAll() { + long totalPage = productService.getTotalPagesAll(); + return totalPage; + } + + @PostMapping("/addBanner") + public ResponseEntity addBanner(@RequestParam String name, @RequestParam MultipartFile image) throws IOException { + bannerService.addBanner(name, image); + return ResponseEntity.ok("add banner successs"); + } + + @GetMapping("/getBannerList") + public ModelAndView getBannerList() { + ModelAndView modelAndView = new ModelAndView("home"); + List banners = bannerService.getBannerList(); + modelAndView.addObject("banners", banners); + return modelAndView; + } + + @GetMapping("/getBannerImage/{id}") + public ResponseEntity getBannerImageById(@PathVariable Long id) { + byte[] image = bannerService.getBannerImageById(id); + return ResponseEntity.status(HttpStatus.OK) + .contentType(MediaType.valueOf("image/png")) + .body(image); + } + + @PostMapping("/addBlog") + public ResponseEntity addBlog(@ModelAttribute BlogDto blogDto) throws IOException { + blogService.addBlog(blogDto); + return ResponseEntity.ok("add blog success"); + } + + @GetMapping("/getBlogImage/{id}") + public ResponseEntity getBlogImageById(@PathVariable Long id) { + byte[] image = blogService.getBlogImageById(id); + return ResponseEntity.status(HttpStatus.OK) + .contentType(MediaType.valueOf("image/png")) + .body(image); + } + +} + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/controller/RegistrationController.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/controller/RegistrationController.java new file mode 100644 index 0000000..e97b8d4 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/controller/RegistrationController.java @@ -0,0 +1,77 @@ +package org.ecommerce.spring.boot.vegetable.project.controller; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.ecommerce.spring.boot.vegetable.project.dto.UserDto; +import org.ecommerce.spring.boot.vegetable.project.entity.User; +import org.ecommerce.spring.boot.vegetable.project.entity.VerificationToken; +import org.ecommerce.spring.boot.vegetable.project.event.RegistrationCompleteEvent; +import org.ecommerce.spring.boot.vegetable.project.service.UserService; +import org.ecommerce.spring.boot.vegetable.project.service.VerificationTokenService; +import org.ecommerce.spring.boot.vegetable.project.utility.ApplicationUrl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + +import javax.naming.Binding; +import java.util.Optional; + +@Controller +@RequestMapping("/registration") +public class RegistrationController { + + @Autowired + private UserService userService; + + @Autowired + private VerificationTokenService verificationTokenService; + + @Autowired + private ApplicationEventPublisher publisher; + + @GetMapping("/register-form") + public ModelAndView showRegistrationForm() { + ModelAndView modelAndView = new ModelAndView("register"); + modelAndView.addObject("user", new UserDto()); + return modelAndView; + } + + @PostMapping("/register") + public String registerUser(@Valid @ModelAttribute UserDto userDto, + BindingResult result, Model model, HttpServletRequest request) { + if(!userDto.getPassword().equals(userDto.getConfirmPassword())) { + return "redirect:/registration/register-form?invalidc_f"; + } + if(result.hasErrors()) { + model.addAttribute("user", userDto); + } + System.out.println(result); + User user = userService.registerUser(userDto); + publisher.publishEvent(new RegistrationCompleteEvent(user, ApplicationUrl.getUrl(request))); + return "redirect:/registration/register-form?success"; + } + + @GetMapping("/verifyEmail") + public String verifyEmail(@RequestParam String token) { + Optional verificationTokenOptional = + verificationTokenService.findByToken(token); + if(verificationTokenOptional.isPresent() && verificationTokenOptional.get().getUser().getEnabled()) { + return "redirect:/login?verified"; + } + String result = verificationTokenService.validateVerificationToken(token); + switch (result.toLowerCase()) { + case "valid": + return "redirect:/login?valid"; + case "invalid": + return "redirect:/error?invalid"; + default: + return "redirect:/error?expired"; + } + } + +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/dto/BlogDto.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/dto/BlogDto.java new file mode 100644 index 0000000..c11ff96 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/dto/BlogDto.java @@ -0,0 +1,13 @@ +package org.ecommerce.spring.boot.vegetable.project.dto; + +import lombok.Data; +import org.springframework.web.multipart.MultipartFile; + +@Data +public class BlogDto { + private String title; + private String content; + private MultipartFile image; + private Long userId; + private String blogCategory; +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/dto/ProductDto.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/dto/ProductDto.java new file mode 100644 index 0000000..53bdb04 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/dto/ProductDto.java @@ -0,0 +1,14 @@ +package org.ecommerce.spring.boot.vegetable.project.dto; + +import lombok.Data; +import org.ecommerce.spring.boot.vegetable.project.entity.Category; +import org.springframework.web.multipart.MultipartFile; + +@Data +public class ProductDto { + private String name; + private double cost; + private MultipartFile image; + private String categoryName; + private String description; +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/dto/UserDto.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/dto/UserDto.java new file mode 100644 index 0000000..2e43553 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/dto/UserDto.java @@ -0,0 +1,26 @@ +package org.ecommerce.spring.boot.vegetable.project.dto; + +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +@Data +public class UserDto { + private Long id; + + @NotEmpty + private String firstName; + + @NotEmpty + private String lastName; + + @NotEmpty(message = "Email should not be empty") + private String email; + + @NotEmpty(message = "Password should not be empty") + private String password; + + @NotEmpty(message = "Confirm password should not be empty") + private String confirmPassword; + +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Banner.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Banner.java new file mode 100644 index 0000000..6d3dff2 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Banner.java @@ -0,0 +1,22 @@ +package org.ecommerce.spring.boot.vegetable.project.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Banner { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + @Lob() + @Column(length = 1000000000) + private byte[] image; +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Blog.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Blog.java new file mode 100644 index 0000000..8c9e6ed --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Blog.java @@ -0,0 +1,66 @@ +package org.ecommerce.spring.boot.vegetable.project.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; +import java.util.List; + +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Blog { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String title; + + @Temporal(TemporalType.TIMESTAMP) + @Column(nullable = false) + @DateTimeFormat(pattern = "MM-dd, YYYY") + private Date createDate; + + @Lob + @Column(length = 1000000000) + private String content; + + @Lob + @Column(length = 1000000000) + private byte[] image; + + @ManyToOne + @JoinColumn( + name = "user_id", + referencedColumnName = "id" + ) + private User user; + + @ManyToMany( + fetch = FetchType.EAGER, + cascade = CascadeType.ALL + ) + @JoinTable( + name = "blog_categories", + joinColumns = @JoinColumn( + name = "blog_id", + referencedColumnName = "id" + ), + inverseJoinColumns = @JoinColumn( + name = "blogCategory_id", + referencedColumnName = "id" + ) + ) + private List blogCategories; + + @PrePersist + private void onCreate() { + createDate = new Date(); + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/BlogCategory.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/BlogCategory.java new file mode 100644 index 0000000..d7e77ab --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/BlogCategory.java @@ -0,0 +1,23 @@ +package org.ecommerce.spring.boot.vegetable.project.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class BlogCategory { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + + public BlogCategory(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Category.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Category.java new file mode 100644 index 0000000..c290bee --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Category.java @@ -0,0 +1,22 @@ +package org.ecommerce.spring.boot.vegetable.project.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Category { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + @Lob() + @Column(length = 1000000000) + private byte[] image; +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Product.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Product.java new file mode 100644 index 0000000..040b5df --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Product.java @@ -0,0 +1,32 @@ +package org.ecommerce.spring.boot.vegetable.project.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Product { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + private double cost; + private String description; + @Lob + @Column(length = 1000000000) + private byte[] image; + + @ManyToOne + @JoinColumn( + name = "category_id", + referencedColumnName = "id" + ) + private Category category; + +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Role.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Role.java new file mode 100644 index 0000000..50880bc --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/Role.java @@ -0,0 +1,30 @@ +package org.ecommerce.spring.boot.vegetable.project.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Collate; + +import java.util.ArrayList; +import java.util.List; + +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Role { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @Column( + nullable = false + ) + private String name; + + public Role(String name) { + this.name = name; + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/User.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/User.java new file mode 100644 index 0000000..329afd3 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/User.java @@ -0,0 +1,49 @@ +package org.ecommerce.spring.boot.vegetable.project.entity; + +import jakarta.persistence.*; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class User { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String firstName; + + @Column(nullable = false) + private String lastName; + + @Column(nullable = false) + private String email; + + @Column(nullable = false) + private String password; + + @ManyToMany( + fetch = FetchType.EAGER, + cascade = CascadeType.ALL + ) + @JoinTable( + name = "user_roles", + joinColumns = @JoinColumn( + name = "user_id", + referencedColumnName = "id" + ), + inverseJoinColumns = @JoinColumn( + name = "role_id", + referencedColumnName = "id" + ) + ) + private List roles = new ArrayList<>(); + + private Boolean enabled = false; +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/VerificationToken.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/VerificationToken.java new file mode 100644 index 0000000..23617a8 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/entity/VerificationToken.java @@ -0,0 +1,41 @@ +package org.ecommerce.spring.boot.vegetable.project.entity; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.ecommerce.spring.boot.vegetable.project.utility.TokenExpirationTimeCalculus; + +import java.util.Date; + +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class VerificationToken { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String token; + private Date expirationTime; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn( + name = "user_id", + referencedColumnName = "id" + ) + private User user; + + public VerificationToken(User user, String token) { + this.user = user; + this.token = token; + this.expirationTime = TokenExpirationTimeCalculus.getExpirationTime(); + } + + public VerificationToken(String token) { + this.token = token; + this.expirationTime = TokenExpirationTimeCalculus.getExpirationTime(); + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/event/RegistrationCompleteEvent.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/event/RegistrationCompleteEvent.java new file mode 100644 index 0000000..6bc9c53 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/event/RegistrationCompleteEvent.java @@ -0,0 +1,21 @@ +package org.ecommerce.spring.boot.vegetable.project.event; + + +import lombok.Getter; +import lombok.Setter; +import org.ecommerce.spring.boot.vegetable.project.entity.User; +import org.springframework.context.ApplicationEvent; + +@Getter +@Setter +public class RegistrationCompleteEvent extends ApplicationEvent { + + private User user; + private String confirmationUrl; + + public RegistrationCompleteEvent(User user, String confirmationUrl) { + super(user); + this.user = user; + this.confirmationUrl = confirmationUrl; + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/event/listener/RegistrationCompleteListener.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/event/listener/RegistrationCompleteListener.java new file mode 100644 index 0000000..be7e7ae --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/event/listener/RegistrationCompleteListener.java @@ -0,0 +1,42 @@ +package org.ecommerce.spring.boot.vegetable.project.event.listener; + +import jakarta.mail.MessagingException; +import lombok.extern.slf4j.Slf4j; +import org.ecommerce.spring.boot.vegetable.project.entity.User; +import org.ecommerce.spring.boot.vegetable.project.event.RegistrationCompleteEvent; +import org.ecommerce.spring.boot.vegetable.project.service.VerificationTokenService; +import org.ecommerce.spring.boot.vegetable.project.utility.SendMail; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationListener; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.stereotype.Component; + +import java.io.UnsupportedEncodingException; +import java.util.UUID; + +@Component +@Slf4j +public class RegistrationCompleteListener implements ApplicationListener { + + @Autowired + private VerificationTokenService verificationTokenService; + + @Autowired + private SendMail sendMail; + + @Override + public void onApplicationEvent(RegistrationCompleteEvent event) { + User user = event.getUser(); + String token = UUID.randomUUID().toString(); + verificationTokenService.saveVerificationTokenForUser(user, token); + + String verifyMailUrl = event.getConfirmationUrl() + "/registration/verifyEmail?token=" + token; + + try { + sendMail.sendVerificationEmail(user, verifyMailUrl); + } catch (MessagingException | UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + log.info("Click the link to verify your account, {}", verifyMailUrl); + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/BannerRepository.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/BannerRepository.java new file mode 100644 index 0000000..ec14355 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/BannerRepository.java @@ -0,0 +1,12 @@ +package org.ecommerce.spring.boot.vegetable.project.repository; + +import org.ecommerce.spring.boot.vegetable.project.entity.Banner; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface BannerRepository extends JpaRepository { + List findTop2ByOrderByIdDesc(); +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/BlogRepository.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/BlogRepository.java new file mode 100644 index 0000000..142be24 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/BlogRepository.java @@ -0,0 +1,12 @@ +package org.ecommerce.spring.boot.vegetable.project.repository; + +import org.ecommerce.spring.boot.vegetable.project.entity.Blog; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface BlogRepository extends JpaRepository { + List findTop3ByOrderByIdDesc(); +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/CategoryRepository.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/CategoryRepository.java new file mode 100644 index 0000000..cdacb93 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/CategoryRepository.java @@ -0,0 +1,10 @@ +package org.ecommerce.spring.boot.vegetable.project.repository; + +import org.ecommerce.spring.boot.vegetable.project.entity.Category; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface CategoryRepository extends JpaRepository { + Category getByName(String categoryName); +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/ProductRepository.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/ProductRepository.java new file mode 100644 index 0000000..1ccdf07 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/ProductRepository.java @@ -0,0 +1,17 @@ +package org.ecommerce.spring.boot.vegetable.project.repository; + +import org.ecommerce.spring.boot.vegetable.project.entity.Category; +import org.ecommerce.spring.boot.vegetable.project.entity.Product; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface ProductRepository extends JpaRepository { + Page getProductListByCategory(Category category, Pageable pageable); + + Page findAllByCategory(Category category, Pageable pageable); +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/UserRepository.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/UserRepository.java new file mode 100644 index 0000000..53d9178 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/UserRepository.java @@ -0,0 +1,12 @@ +package org.ecommerce.spring.boot.vegetable.project.repository; + +import org.ecommerce.spring.boot.vegetable.project.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface UserRepository extends JpaRepository { + Optional findByEmail(String email); +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/VerificationTokenRepository.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/VerificationTokenRepository.java new file mode 100644 index 0000000..330498c --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/repository/VerificationTokenRepository.java @@ -0,0 +1,12 @@ +package org.ecommerce.spring.boot.vegetable.project.repository; + +import org.ecommerce.spring.boot.vegetable.project.entity.VerificationToken; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface VerificationTokenRepository extends JpaRepository { + Optional findByToken(String token); +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/security/CustomUserDetailService.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/security/CustomUserDetailService.java new file mode 100644 index 0000000..9a9a8b1 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/security/CustomUserDetailService.java @@ -0,0 +1,22 @@ +package org.ecommerce.spring.boot.vegetable.project.security; + +import org.ecommerce.spring.boot.vegetable.project.repository.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +@Service +public class CustomUserDetailService implements UserDetailsService { + + @Autowired + private UserRepository userRepository; + + @Override + public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { + return userRepository.findByEmail(email) + .map(CustomUserDetails::new) + .orElseThrow(()-> new UsernameNotFoundException("User not found")); + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/security/CustomUserDetails.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/security/CustomUserDetails.java new file mode 100644 index 0000000..435c404 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/security/CustomUserDetails.java @@ -0,0 +1,68 @@ +package org.ecommerce.spring.boot.vegetable.project.security; + +import lombok.Data; +import org.ecommerce.spring.boot.vegetable.project.entity.User; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collector; +import java.util.stream.Collectors; + +@Data +public class CustomUserDetails implements UserDetails { + + private String userName; + private String password; + private Boolean isEnabled; + private List authorities; + + CustomUserDetails(User user) { + this.userName = user.getEmail(); + this.password = user.getPassword(); + this.isEnabled = user.getEnabled(); + this.authorities = + Arrays.stream(user.getRoles().toString().split(",")) + .map(SimpleGrantedAuthority::new) + .collect(Collectors.toList()); + } + + + @Override + public Collection getAuthorities() { + return authorities; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public String getUsername() { + return userName; + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return isEnabled; + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/BannerService.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/BannerService.java new file mode 100644 index 0000000..a9f3b51 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/BannerService.java @@ -0,0 +1,15 @@ +package org.ecommerce.spring.boot.vegetable.project.service; + +import org.ecommerce.spring.boot.vegetable.project.entity.Banner; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.List; + +public interface BannerService { + void addBanner(String name, MultipartFile image) throws IOException; + + List getBannerList(); + + byte[] getBannerImageById(Long id); +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/BlogService.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/BlogService.java new file mode 100644 index 0000000..b27d8c9 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/BlogService.java @@ -0,0 +1,16 @@ +package org.ecommerce.spring.boot.vegetable.project.service; + +import org.ecommerce.spring.boot.vegetable.project.dto.BlogDto; +import org.ecommerce.spring.boot.vegetable.project.entity.Blog; + +import java.io.IOException; +import java.text.ParseException; +import java.util.List; + +public interface BlogService { + void addBlog(BlogDto blogDto) throws IOException; + + List getBlogList() throws ParseException; + + byte[] getBlogImageById(Long id); +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/CategoryService.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/CategoryService.java new file mode 100644 index 0000000..b23ba59 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/CategoryService.java @@ -0,0 +1,16 @@ +package org.ecommerce.spring.boot.vegetable.project.service; + +import org.ecommerce.spring.boot.vegetable.project.entity.Category; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.List; + +public interface CategoryService { + + void addCategory(String name, MultipartFile file) throws IOException; + + List getCategoryList(); + + byte[] getCategoryImage(Long id); +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/ProductService.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/ProductService.java new file mode 100644 index 0000000..f8cebb3 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/ProductService.java @@ -0,0 +1,21 @@ +package org.ecommerce.spring.boot.vegetable.project.service; + +import org.ecommerce.spring.boot.vegetable.project.dto.ProductDto; +import org.ecommerce.spring.boot.vegetable.project.entity.Product; + +import java.io.IOException; +import java.util.List; + +public interface ProductService { + Product addProduct(ProductDto productDto) throws IOException; + + List getProductList(Integer pageNumber); + + byte[] getProductImage(Long id); + + List getProductListByCategory(String categoryName, Integer pageNumber); + + Long getTotalPages(String categoryName); + + long getTotalPagesAll(); +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/UserService.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/UserService.java new file mode 100644 index 0000000..8c26599 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/UserService.java @@ -0,0 +1,9 @@ +package org.ecommerce.spring.boot.vegetable.project.service; + +import org.ecommerce.spring.boot.vegetable.project.dto.UserDto; +import org.ecommerce.spring.boot.vegetable.project.entity.User; + +public interface UserService { + User registerUser(UserDto userDto); + +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/VerificationTokenService.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/VerificationTokenService.java new file mode 100644 index 0000000..1c80e5e --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/VerificationTokenService.java @@ -0,0 +1,16 @@ +package org.ecommerce.spring.boot.vegetable.project.service; + +import org.ecommerce.spring.boot.vegetable.project.entity.User; +import org.ecommerce.spring.boot.vegetable.project.entity.VerificationToken; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +public interface VerificationTokenService { + void saveVerificationTokenForUser(User user, String token); + + Optional findByToken(String token); + + String validateVerificationToken(String token); + +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/BannerServiceImp.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/BannerServiceImp.java new file mode 100644 index 0000000..6ebb66c --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/BannerServiceImp.java @@ -0,0 +1,45 @@ +package org.ecommerce.spring.boot.vegetable.project.service.implement; + +import org.ecommerce.spring.boot.vegetable.project.entity.Banner; +import org.ecommerce.spring.boot.vegetable.project.repository.BannerRepository; +import org.ecommerce.spring.boot.vegetable.project.service.BannerService; +import org.ecommerce.spring.boot.vegetable.project.utility.ImageUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.List; + +@Service +public class BannerServiceImp implements BannerService { + + @Autowired + private ImageUtils imageUtils; + + @Autowired + private BannerRepository bannerRepository; + + @Override + public void addBanner(String name, MultipartFile image) throws IOException { + Banner banner = Banner.builder() + .name(name) + .image(imageUtils.compressImage(image.getBytes())) + .build(); + bannerRepository.save(banner); + } + + @Override + public List getBannerList() { + List banners = bannerRepository.findTop2ByOrderByIdDesc(); + return banners; + } + + @Override + public byte[] getBannerImageById(Long id) { + Banner banner = bannerRepository.findById(id).get(); + return imageUtils.decompressImage(banner.getImage()); + } + + +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/BlogServiceImp.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/BlogServiceImp.java new file mode 100644 index 0000000..927a901 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/BlogServiceImp.java @@ -0,0 +1,65 @@ +package org.ecommerce.spring.boot.vegetable.project.service.implement; + +import org.ecommerce.spring.boot.vegetable.project.dto.BlogDto; +import org.ecommerce.spring.boot.vegetable.project.entity.Blog; +import org.ecommerce.spring.boot.vegetable.project.entity.BlogCategory; +import org.ecommerce.spring.boot.vegetable.project.repository.BlogRepository; +import org.ecommerce.spring.boot.vegetable.project.repository.UserRepository; +import org.ecommerce.spring.boot.vegetable.project.service.BlogService; +import org.ecommerce.spring.boot.vegetable.project.utility.ImageUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class BlogServiceImp implements BlogService { + + @Autowired + private UserRepository userRepository; + + @Autowired + private ImageUtils imageUtils; + + @Autowired + private BlogRepository blogRepository; + + @Override + public void addBlog(BlogDto blogDto) throws IOException { + Blog blog = Blog.builder() + .title(blogDto.getTitle()) + .content(blogDto.getContent()) + .image(imageUtils.compressImage(blogDto.getImage().getBytes())) + .user(userRepository.findById(blogDto.getUserId()).get()) + .blogCategories(blogCategoryChangeList(blogDto.getBlogCategory())) + .build(); + blogRepository.save(blog); + } + + @Override + public List getBlogList() { + List blogs = blogRepository.findTop3ByOrderByIdDesc(); + return blogs; + } + + @Override + public byte[] getBlogImageById(Long id) { + Blog blog = blogRepository.findById(id).get(); + return imageUtils.decompressImage(blog.getImage()); + } + + private List blogCategoryChangeList(String blogCategoryString) { + List blogCategories = + Arrays.asList(blogCategoryString.split(",")).stream().map(categoryName -> new BlogCategory(categoryName.trim())) + .collect(Collectors.toList()); + return blogCategories; + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/CategoryServiceImp.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/CategoryServiceImp.java new file mode 100644 index 0000000..ef6beba --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/CategoryServiceImp.java @@ -0,0 +1,46 @@ +package org.ecommerce.spring.boot.vegetable.project.service.implement; + +import org.ecommerce.spring.boot.vegetable.project.entity.Category; +import org.ecommerce.spring.boot.vegetable.project.repository.CategoryRepository; +import org.ecommerce.spring.boot.vegetable.project.service.CategoryService; +import org.ecommerce.spring.boot.vegetable.project.utility.ImageUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.List; + +@Service +public class CategoryServiceImp implements CategoryService { + + @Autowired + private ImageUtils imageUtils; + + @Autowired + private CategoryRepository categoryRepository; + + @Override + public void addCategory(String name, MultipartFile file) throws IOException { + Category category = Category.builder() + .name(name) + .image(imageUtils.compressImage(file.getBytes())) + .build(); + categoryRepository.save(category); + } + + @Override + public List getCategoryList() { + List categories = categoryRepository.findAll(); + for(Category c : categories) { + c.setImage(imageUtils.decompressImage(c.getImage())); + } + return categories; + } + + @Override + public byte[] getCategoryImage(Long id) { + Category category = categoryRepository.findById(id).get(); + return imageUtils.decompressImage(category.getImage()); + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/ProductServiceImp.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/ProductServiceImp.java new file mode 100644 index 0000000..8e3094e --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/ProductServiceImp.java @@ -0,0 +1,74 @@ +package org.ecommerce.spring.boot.vegetable.project.service.implement; + +import org.ecommerce.spring.boot.vegetable.project.dto.ProductDto; +import org.ecommerce.spring.boot.vegetable.project.entity.Category; +import org.ecommerce.spring.boot.vegetable.project.entity.Product; +import org.ecommerce.spring.boot.vegetable.project.repository.CategoryRepository; +import org.ecommerce.spring.boot.vegetable.project.repository.ProductRepository; +import org.ecommerce.spring.boot.vegetable.project.service.ProductService; +import org.ecommerce.spring.boot.vegetable.project.utility.ImageUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.List; + +@Service +public class ProductServiceImp implements ProductService { + + @Autowired + private ProductRepository productRepository; + + @Autowired + private ImageUtils imageUtils; + + @Autowired + private CategoryRepository categoryRepository; + + @Override + public Product addProduct(ProductDto productDto) throws IOException { + Product product = Product.builder() + .name(productDto.getName()) + .cost(productDto.getCost()) + .description(productDto.getDescription()) + .image(imageUtils.compressImage(productDto.getImage().getBytes())) + .category(categoryRepository.getByName(productDto.getCategoryName())) + .build(); + return productRepository.save(product); + } + + @Override + public List getProductList(Integer pageNumber) { + return productRepository.findAll(PageRequest.of(pageNumber, 8)).getContent(); + } + + @Override + public byte[] getProductImage(Long id) { + return + imageUtils.decompressImage( + productRepository.findById(id).get().getImage() + ); + } + + @Override + public List getProductListByCategory(String categoryName, Integer pageNumber) { + Category category = categoryRepository.getByName(categoryName); + Pageable page = PageRequest.of(pageNumber, 8); + return productRepository.getProductListByCategory(category, page).getContent(); + } + + @Override + public Long getTotalPages(String categoryName) { + Category category = categoryRepository.getByName(categoryName); + Long totalPage = (long) productRepository.findAllByCategory(category, PageRequest.of(0, 8)).getTotalPages(); + return totalPage; + } + + @Override + public long getTotalPagesAll() { + Long totalPage = (long) productRepository.findAll(PageRequest.of(0, 8)).getTotalPages(); + return totalPage; + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/UserServiceImp.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/UserServiceImp.java new file mode 100644 index 0000000..5919e2e --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/UserServiceImp.java @@ -0,0 +1,35 @@ +package org.ecommerce.spring.boot.vegetable.project.service.implement; + +import org.ecommerce.spring.boot.vegetable.project.dto.UserDto; +import org.ecommerce.spring.boot.vegetable.project.entity.Role; +import org.ecommerce.spring.boot.vegetable.project.entity.User; +import org.ecommerce.spring.boot.vegetable.project.repository.UserRepository; +import org.ecommerce.spring.boot.vegetable.project.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; + +import java.util.Arrays; + +@Service +public class UserServiceImp implements UserService { + + @Autowired + private PasswordEncoder passwordEncoder; + + @Autowired + private UserRepository userRepository; + + @Override + public User registerUser(UserDto userDto) { + User user = User.builder() + .firstName(userDto.getFirstName()) + .lastName(userDto.getLastName()) + .email(userDto.getEmail()) + .password(passwordEncoder.encode(userDto.getPassword())) + .roles(Arrays.asList(new Role("USER"))) + .enabled(false) + .build(); + return userRepository.save(user); + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/VerificationTokenServiceImp.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/VerificationTokenServiceImp.java new file mode 100644 index 0000000..4104793 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/service/implement/VerificationTokenServiceImp.java @@ -0,0 +1,49 @@ +package org.ecommerce.spring.boot.vegetable.project.service.implement; + +import org.ecommerce.spring.boot.vegetable.project.entity.User; +import org.ecommerce.spring.boot.vegetable.project.entity.VerificationToken; +import org.ecommerce.spring.boot.vegetable.project.repository.UserRepository; +import org.ecommerce.spring.boot.vegetable.project.repository.VerificationTokenRepository; +import org.ecommerce.spring.boot.vegetable.project.service.VerificationTokenService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Calendar; +import java.util.Optional; + +@Service +public class VerificationTokenServiceImp implements VerificationTokenService { + + @Autowired + private VerificationTokenRepository verificationTokenRepository; + + @Autowired + private UserRepository userRepository; + + @Override + public void saveVerificationTokenForUser(User user, String token) { + VerificationToken verificationToken = new VerificationToken(user, token); + verificationTokenRepository.save(verificationToken); + } + + @Override + public Optional findByToken(String token) { + return verificationTokenRepository.findByToken(token); + } + + @Override + public String validateVerificationToken(String token) { + Optional verificationToken = verificationTokenRepository.findByToken(token); + if(verificationToken.isEmpty()) + return "invalid"; + User user = verificationToken.get().getUser(); + Calendar calendar = Calendar.getInstance(); + if(verificationToken.get().getExpirationTime().getTime() - calendar.getTime().getTime() <= 0) { + verificationTokenRepository.delete(verificationToken.get()); + return "expired"; + } + user.setEnabled(true); + userRepository.save(user); + return "valid"; + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/utility/ApplicationUrl.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/utility/ApplicationUrl.java new file mode 100644 index 0000000..d801033 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/utility/ApplicationUrl.java @@ -0,0 +1,10 @@ +package org.ecommerce.spring.boot.vegetable.project.utility; + +import jakarta.servlet.http.HttpServletRequest; + +public class ApplicationUrl { + public static String getUrl(HttpServletRequest request) { + String appUrl = request.getRequestURL().toString(); + return appUrl.replace(request.getServletPath(), ""); + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/utility/ImageUtils.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/utility/ImageUtils.java new file mode 100644 index 0000000..7ae7dc4 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/utility/ImageUtils.java @@ -0,0 +1,47 @@ +package org.ecommerce.spring.boot.vegetable.project.utility; + +import org.springframework.stereotype.Component; + +import java.io.ByteArrayOutputStream; +import java.util.zip.Deflater; +import java.util.zip.Inflater; + +@Component +public class ImageUtils { + public byte[] compressImage(byte[] data) { + Deflater deflater = new Deflater(); + deflater.setLevel(Deflater.BEST_COMPRESSION); + deflater.setInput(data); + deflater.finish(); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); + byte[] tmp = new byte[4*1024]; + while (!deflater.finished()) { + int size = deflater.deflate(tmp); + outputStream.write(tmp, 0, size); + } + try { + outputStream.close(); + } catch (Exception ignored) { + } + return outputStream.toByteArray(); + } + + + + public byte[] decompressImage(byte[] data) { + Inflater inflater = new Inflater(); + inflater.setInput(data); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); + byte[] tmp = new byte[4*1024]; + try { + while (!inflater.finished()) { + int count = inflater.inflate(tmp); + outputStream.write(tmp, 0, count); + } + outputStream.close(); + } catch (Exception ignored) { + } + return outputStream.toByteArray(); + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/utility/SendMail.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/utility/SendMail.java new file mode 100644 index 0000000..0b077df --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/utility/SendMail.java @@ -0,0 +1,53 @@ +package org.ecommerce.spring.boot.vegetable.project.utility; + +import jakarta.mail.MessagingException; +import jakarta.mail.internet.MimeMessage; +import lombok.RequiredArgsConstructor; +import org.ecommerce.spring.boot.vegetable.project.entity.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +import java.io.UnsupportedEncodingException; + +@Component +public class SendMail { + + @Autowired + private JavaMailSender mailSender; + + public void sendPasswordResetVerificationEmail(User user,String url) throws MessagingException, UnsupportedEncodingException { + String subject = "Password Reset Request Verification"; + String senderName = "Users Verification Service"; + String mailContent = "

Hi, "+ user.getFirstName()+ ",

"+ + "

You recently requested to reset your password,"+"" + + "Please, follow the link below to complete the action.

"+ + "Reset password"+ + "

Users Registration Portal Service"; + emailMessage(subject, senderName, mailContent, user); + } + + public void sendVerificationEmail(User user,String url) throws MessagingException, UnsupportedEncodingException { + String subject = "Verify your account"; + String senderName = "Users Verification Service"; + String mailContent = "

Hi, "+ user.getFirstName()+ ",

"+ + "

CLick follow link to verify your account,"+"" + + "Verify account"+ + "

Users Registration Portal Service"; + emailMessage(subject, senderName, mailContent, user); + } + + private void emailMessage(String subject, String senderName, + String mailContent, User theUser) + throws MessagingException, UnsupportedEncodingException { + MimeMessage message = mailSender.createMimeMessage(); + var messageHelper = new MimeMessageHelper(message); + messageHelper.setFrom("hoangquanph0204@gmail.com", senderName); + messageHelper.setTo(theUser.getEmail()); + messageHelper.setSubject(subject); + messageHelper.setText(mailContent, true); + mailSender.send(message); + } +} diff --git a/src/main/java/org/ecommerce/spring/boot/vegetable/project/utility/TokenExpirationTimeCalculus.java b/src/main/java/org/ecommerce/spring/boot/vegetable/project/utility/TokenExpirationTimeCalculus.java new file mode 100644 index 0000000..49ee997 --- /dev/null +++ b/src/main/java/org/ecommerce/spring/boot/vegetable/project/utility/TokenExpirationTimeCalculus.java @@ -0,0 +1,17 @@ +package org.ecommerce.spring.boot.vegetable.project.utility; + +import org.springframework.stereotype.Component; + +import java.util.Calendar; +import java.util.Date; + +public class TokenExpirationTimeCalculus { + private static int EXPIRATION_TIME = 10; + + public static Date getExpirationTime() { + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(new Date().getTime()); + calendar.add(Calendar.MINUTE, EXPIRATION_TIME); + return new Date(calendar.getTime().getTime()); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..915d787 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,24 @@ + +server: + port: 8080 +spring: + datasource: + url: jdbc:mysql://localhost:3306/vegetable-project + username: root + password: 01229050402a + driver-class-name: com.mysql.cj.jdbc.Driver + jpa: + hibernate: + ddl-auto: update + show-sql: true + mail: + host: smtp.gmail.com + port: 587 + username: hoangquanph0204@gmail.com + password: hspuorvvliiqgbgr + properties: + mail: + smtp: + auth: true + starttls: + enable: true diff --git a/src/main/resources/static/css/footer.css b/src/main/resources/static/css/footer.css new file mode 100644 index 0000000..c4f4dd0 --- /dev/null +++ b/src/main/resources/static/css/footer.css @@ -0,0 +1,57 @@ + +*, ::after, ::before { + box-sizing: border-box; + padding: 0; + margin: 0; +} + +.footer-wrapper { + background-color: rgb(243,246,250); + height: max-content; +} + +.footer-left-icon { + margin-bottom: 20px; +} + +.footer-left-information { + display: block; + font-size: 16px; + line-height: 25px; + margin: 5px 0; + color: #1c1c1c; +} + +.footer-left-contact { + font-weight: bold; + font-size: 16px; +} + +.footer-left-contact-item { + font-size: 22px; + color: black; + padding: 10px 15px; + border-radius: 40px; + background-color: white; + } + +.footer-left-contact-item:hover { + background-color: #7fad39; + color: white; +} + +.footer-right-description { + display: block; + margin: 8px 0 12px 0; + font-size: 13px; + color: #1c1c1c; +} + +.footer-right-email { + width: 120px; +} + +.footer-down-image { + display: flex; + margin-left: auto; +} \ No newline at end of file diff --git a/src/main/resources/static/css/header.css b/src/main/resources/static/css/header.css new file mode 100644 index 0000000..2cd20b9 --- /dev/null +++ b/src/main/resources/static/css/header.css @@ -0,0 +1,128 @@ + +* { + box-sizing: border-box; + padding: 0; + margin: 0; +} + +.header-top { + background-color: rgb(245,245,245); + height: 46px; + font-size: 14px; +} + +.header-top-left, .header-top-right { + margin: 0; + list-style-type: none; + padding: 12px 0 13px; +} + +.header-top-item { + display: inline-block; +} + +.header-top-left__mail { + margin-right: 40px ; +} + +.header-top-left__mail-icon { + margin-right: 3px; +} + +.header-top-left__mail::after, .header-top-item-separate::after { + position: absolute; + top: 12px; + margin: 0 20px; + width: 0.5px; + height: 20px; + background-color: black; + opacity: 0.1; + content: ""; +} + +.header-top-right { + width: max-content; + float: left; +} + +.header-top-right-icon { + color: black; + margin-right: 20px; +} + +.header-top-item-separate { + margin-right: 40px; + color: black; +} + +.header-top-login { + display: inline-block; + color: black; + text-decoration: none; +} + +.login-icon { + margin-right: 2px; +} + +.header-menu-nav { + background-color: white !important; +} + +.header-menu-item-btn { + color: black; + font-size: 14px; + font-weight: bold; + letter-spacing: 1px; +} + +.header-menu-item-btn:hover { + color: #7fad39; +} + +.active { + color: #7fad39; +} + +.header-menu-icon { + color: black; + font-size: 17px; + margin-right: 5px; +} + +.header-user-action, .header-menu-page { + background-color: black; + padding-bottom: 3px; + padding-top: 3px; + display: none; + border-radius: unset; + position: absolute; + box-shadow: 0 0 6px 1px rgba(0, 0, 0, 0.1); + z-index: 1; +} + +.header-top-item:hover .header-user-action { + display: block; +} + +.header-menu-page-wrapper:hover .header-menu-page { + display: block; +} + + +.header-user-action-item { + padding-top: 5px; + padding-bottom: 5px; + border: none; + line-height: 17px; + letter-spacing: 1px; + color: white; + background-color: black; + text-decoration: none; +} + +.header-user-action-item:hover { + color: #7fad39; + background-color: black; +} + diff --git a/src/main/resources/static/css/home.css b/src/main/resources/static/css/home.css new file mode 100644 index 0000000..eb58826 --- /dev/null +++ b/src/main/resources/static/css/home.css @@ -0,0 +1,410 @@ + + +*, ::after, ::before { + box-sizing: border-box; + padding: 0; + margin: 0; +} + +.mh-12 { + margin: 0 12px; +} + + +.search-content { + margin-top: 80px !important; +} + +.search-content-department-wrapper { +} + +.search-content-department { + font-weight: bold; + padding: 10px 30px; + font-size: 18px; + border-radius: unset; + background-color: #7fad39; + color: white; + border: none; +} + +.search-content-department:hover { + background-color: #7fad39; +} + +.search-content-department:visited { + background-color: #7fad39; +} + +.search-content-department:active { + background-color: #7fad39 !important; +} + +.dropdown-toggle::after { + display: inline-block; + margin-left: 20px; + vertical-align: .255em; + content: ""; + border: .3em solid; + border-right-color: transparent; + border-bottom: 0 none; + border-left-color: transparent; +} + +.search-content-dropdown-list { + padding: 10px 30px; + font-size: 16px; + border-radius: unset; + color: white; +} + +.search-content-dropdown-item { + padding: 8px 10px; + width: 202px; + border-bottom: none; + border-top: none; +} + +.search-bar { + height: 48px; +} + +.search-bar-input { + font-size: 14px; + border-radius: unset; + margin-right: 0 !important; + padding-left: 20px; + +} + +.search-bar-input::placeholder { + color: rgba(0, 0, 0, 0.4); + margin-left: 10px; +} + +.search-bar-input:focus { + outline: none !important; +} + +.search-bar-submit { + border-radius: unset; + width: 25%; + background-color: #7fad39; + color: white; + font-weight: bold; + font-size: 14px; + border: none; +} + +.search-bar-submit:hover { + background-color: #7fad39; + color: white; +} + +.phone-wrapper { + height: 48px; + padding-left: 50px; +} + +.phone-icon-wrapper { + content: ""; + padding: 10px 15px; + background-color: rgba(0,0,0,0.04); + border-radius: 50%; +} + +.phone-icon { + color: #7fad39; + font-size: 18px; + height: fit-content; +} + +.phone-number-wrapper { + padding-left: 20px; + font-size: 18px; +} + +.banner-img { + +} + +.banner-text { + position: absolute; + top: 90px; + left: 80px; +} + +.banner-text-category { + letter-spacing: 2px; + color: #7fad39; + line-height: 14px; + font-weight: bold; + font-size: 14px; +} + +.banner-text-title { + font-size: 46px; + font-weight: bold; + margin: 8px 0; +} + +.banner-text-description { + color: rgba(0, 0, 0, 0.5); + font-size: 16px; + margin-bottom: 40px; + display: block; +} + +.banner-text-btn { + padding: 8px 25px; + color: white; + font-weight: bold; + border-radius: unset; + font-size: 14px; + letter-spacing: 1px; + background-color: #7fad39; +} + +.banner-text-btn:hover { + background: #7fad39; + color: white; +} + +.category-bar { + flex-wrap: nowrap; + overflow: scroll; +} + +/* Hide scrollbar for Chrome, Safari and Opera */ +.category-bar::-webkit-scrollbar { + display: none; +} + + +.category-bar { + width: 100%; + display: flex; + overflow-x: auto; /* Use 'auto' to enable scrolling */ + scroll-behavior: smooth; /* Add smooth scrolling behavior */ + white-space: nowrap; + transition: all 0.5s ease-in-out; /* Apply transition effect to all properties */ +} + +.category-wrapper { + height: 270px; + position: relative; +} + +.category-bar-wrapper { + margin-bottom: 60px !important; +} + +.category-item-title-wrapper { + position: absolute; + bottom: 0; + right: 0; + left: 0; + margin: 0 auto; +} + +.category-item-title { + position: absolute; + bottom: 15px; + right: 27px; + left: 0; + margin: 0 auto; + width: fit-content; + background-color: white; + font-size: 18px; + letter-spacing: 1px; + font-weight: bold; + padding: 8px 40px; + text-decoration: unset; + color: black; + transform: translateX(6px); +} + +.category-item-img { + height: 100%; +} + +.category-bar-navigate-wrapper { + position: relative; + z-index: 1; +} + +.category-bar-navigate { + height: max-content; + width: max-content; + position: absolute; + top: 140px; + bottom: 0; + margin: auto 0; + z-index: 1; + padding: 23px 6px; + border: 1px solid rgba(0, 0, 0, 0.1); + background-color: white; +} + +.category-bar-navigate-left { + left: -60px; +} + +.category-bar-navigate-right { + right: -60px; +} + +.featured-product-title { + font-weight: bold; + font-size: 36px; +} + +.featured-product-title:after { + display: block; + height: 4px; + width: 80px; + background: #7fad39; + content: ""; + margin: 5px auto 0; +} + +.feature-product-navigate { + width: max-content; + margin: 0 auto; + margin-bottom: 10px; +} + +.feature-product-navigate-link { + font-size: 18px; + text-decoration: none; + color: black; + display: inline-block; + cursor: pointer; +} + +.choose::after { + content: ""; + display: block; + width: 100%; + height: 2px; + background-color: #7fad39; + margin-top: 2px; +} + +.feature-product-item-wrapper { + +} + +.feature-product-item { + margin-top: 35px; +} + +.feature-product-item-text { + line-height: 18px; + padding-top: 10px; +} + +.feature-product-item-title { + font-size: 16px; + font-weight: unset; + text-decoration: none; + color: black; + padding: 8px 0; +} + +.feature-product-item-img { + max-width: 100%; + height: 260px; +} + +.feature-product-item-cost { + font-size: 18px; + font-weight: bold; +} + +.product-page > .page-link { + color: rgba(0, 0, 0, 0.7); +} + +.active > .page-link { + background-color: #7fad39; + border: #7fad39; + color: white; +} + +.page-link { + cursor: pointer; +} + +.home_banner_wrapper { + height: 262px; +} + +.home_banner { + +} + +.home_banner_image { + width: 100%; + height: 100%; +} + +.blog-item { + +} + +.blog-item-image { + width: 100%; + height: 258px; +} + +.createDate { + +} + +.createDate-icon { + display: inline-block; + font-size: 16px; + color: rgba(0, 0, 0, 0.4); +} + +.createDate-time { + display: inline-block; + font-size: 16px; + color: rgba(0, 0, 0, 0.3); + margin: 3px 0 0 0; +} + +.blog-item-title { + display: -webkit-box; + line-height: 20px; + -webkit-line-clamp: 1; + -webkit-box-orient: vertical; + font-size: 20px; + font-weight: bold; + width: 100%; + clear: both; + color: black; + text-decoration: none; + overflow: hidden; + } + +.blog-item-content { + display: -webkit-box; + line-height: 18px; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + font-size: 16px; + width: 100%; + clear: both; + color: rgba(0, 0, 0, 0.6); + overflow: hidden; +} + + + + + + + + diff --git a/src/main/resources/static/css/login.css b/src/main/resources/static/css/login.css new file mode 100644 index 0000000..5495fca --- /dev/null +++ b/src/main/resources/static/css/login.css @@ -0,0 +1,33 @@ + +.body-login { + width: 100vw; + height: 100vh; + background-color: #7fad39; +} + +.login-container-wrapper { + background-color: white; + width: 600px; + height: 300px; + border-radius: 30px; + box-shadow: 0 0 6px 1px rgba(0, 0, 0, 0.7); + position: absolute; + right: 0; + left: 0; + top: 0; + bottom: 0; + margin: auto; + display: flex; + align-items: center; + justify-content: center; +} + + +.login-container { + display: flex; + flex-direction: column; + justify-content: center; +} + + + diff --git a/src/main/resources/static/css/main.css b/src/main/resources/static/css/main.css new file mode 100644 index 0000000..48afefb --- /dev/null +++ b/src/main/resources/static/css/main.css @@ -0,0 +1,11 @@ + +* { + box-sizing: border-box; + padding: 0; + margin: 0; +} + +.bg-active { + background: rgb(127,173,57) !important; +} + diff --git a/src/main/resources/static/css/register.css b/src/main/resources/static/css/register.css new file mode 100644 index 0000000..d78fc3c --- /dev/null +++ b/src/main/resources/static/css/register.css @@ -0,0 +1,5 @@ + +.login-container-wrapper { + min-height: 440px; + width: 700px; +} \ No newline at end of file diff --git a/src/main/resources/static/img/banner.jpg b/src/main/resources/static/img/banner.jpg new file mode 100644 index 0000000..aa610d6 Binary files /dev/null and b/src/main/resources/static/img/banner.jpg differ diff --git a/src/main/resources/static/img/logo.png b/src/main/resources/static/img/logo.png new file mode 100644 index 0000000..23a55a8 Binary files /dev/null and b/src/main/resources/static/img/logo.png differ diff --git a/src/main/resources/static/img/payment-item.png.webp b/src/main/resources/static/img/payment-item.png.webp new file mode 100644 index 0000000..04491b0 Binary files /dev/null and b/src/main/resources/static/img/payment-item.png.webp differ diff --git a/src/main/resources/static/js/home.js b/src/main/resources/static/js/home.js new file mode 100644 index 0000000..8a71c4a --- /dev/null +++ b/src/main/resources/static/js/home.js @@ -0,0 +1,97 @@ +function getAllProductByCategory(categoryName, pageNumber) { + $.ajax({ + type: "GET", + url: "/getProductListByCategory/" + categoryName + "/" + pageNumber, + success: function (data) { + var productHTML = ""; + data.forEach(function (product) { + productHTML += "

"; + productHTML += ""; + productHTML += "
"; + productHTML += "" + product.name + ""; + productHTML += "
" + "$" + product.cost + ".00
"; + productHTML += "
"; + productHTML += "
"; + }); + $('.feature-product-item-wrapper').html(productHTML); + } + }); +} + +$(document).ready(function(){ + getAllProduct(0); // This will run the getAllProduct function when the document is fully loaded + getTotalPagesAll(); +}); + +function getAllProduct(pageNumber) { + $.ajax({ + type: "GET", + url: "/getProductList/" + pageNumber, + success: function (data) { + var productHTML = ""; + data.forEach(function (product) { + productHTML += "
"; + productHTML += ""; + productHTML += "
"; + productHTML += "" + product.name + ""; + productHTML += "
" + "$" + product.cost + ".00
"; + productHTML += "
"; + productHTML += "
"; + }); + $('.feature-product-item-wrapper').html(productHTML); + } + }); +} + +function pageChoose(val) { + console.log(val); + $('.pagination.pagination-sm .page-item').removeClass('active'); // Xóa class active ở tất cả các nút paging + var newElement = $('.pagination.pagination-sm .product-page').eq(val - 1).addClass('active'); + // newElement.addClass('active'); // Thêm class active cho nút paging được chọn +} + +function getTotalPagesAll() { + $.ajax({ + type: "GET", + url: "/getTotalPagesAll", + success: function (data) { + var pageHTML = ""; + for(var i = 1; i <= data; i++) { + if(i == 1) + pageHTML += "
  • "; + else + pageHTML += "
  • "; + pageHTML += "" + i + ""; + pageHTML += "
  • "; + } + $('.pagination.pagination-sm').html(pageHTML); + } + }); +} + + +function getTotalPages(categoryName) { + $.ajax({ + type: "GET", + url: "/getTotalPages/" + categoryName, + success: function (data) { + var pageHTML = ""; + for(var i = 1; i <= data; i++) { + if(i == 1) + pageHTML += "
  • "; + else + pageHTML += "
  • "; + pageHTML += "" + i + ""; + pageHTML += "
  • "; + } + $('.pagination.pagination-sm').html(pageHTML); + } + }); +} + + + + + diff --git a/src/main/resources/templates/fragments/footer.html b/src/main/resources/templates/fragments/footer.html new file mode 100644 index 0000000..3274b2f --- /dev/null +++ b/src/main/resources/templates/fragments/footer.html @@ -0,0 +1,54 @@ + + + + + Title + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/fragments/fragments.html b/src/main/resources/templates/fragments/fragments.html new file mode 100644 index 0000000..b55b1bc --- /dev/null +++ b/src/main/resources/templates/fragments/fragments.html @@ -0,0 +1,110 @@ + + + + + + + + + +
    +
    +
    +
    +
    +
      +
    • + + hello@colorlib.com +
    • +
    • Free Shipping for all Order of $99
    • +
    +
    +
    + +
    +
    + + +
    + +
    +
    +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html new file mode 100644 index 0000000..3efbff2 --- /dev/null +++ b/src/main/resources/templates/home.html @@ -0,0 +1,216 @@ + + + + + Home + + + + + + + + + + + +
    +
    +
    + +
    + +
    +
    + + + +
    + +84 938601892 + support 24/7 time +
    +
    +
    + +
    +
    + +
    + + +
    +
    + + +
    +
    +
    +
    + +
    + +
    +
    +
    + + + + +
    +
    + +
    +
    + + +
    + +
    +
    + +
    + +
    +
    + +

    +
    +
    +
    + +
    + + +
    + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html new file mode 100644 index 0000000..e4ba4a8 --- /dev/null +++ b/src/main/resources/templates/login.html @@ -0,0 +1,44 @@ + + + + + Login + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/register.html b/src/main/resources/templates/register.html new file mode 100644 index 0000000..e486aa0 --- /dev/null +++ b/src/main/resources/templates/register.html @@ -0,0 +1,61 @@ + + + + + Title + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/org/ecommerce/spring/boot/vegetable/project/VegetableProjectApplicationTests.java b/src/test/java/org/ecommerce/spring/boot/vegetable/project/VegetableProjectApplicationTests.java new file mode 100644 index 0000000..f35e8ee --- /dev/null +++ b/src/test/java/org/ecommerce/spring/boot/vegetable/project/VegetableProjectApplicationTests.java @@ -0,0 +1,13 @@ +package org.ecommerce.spring.boot.vegetable.project; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class VegetableProjectApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/src/test/java/org/ecommerce/spring/boot/vegetable/project/repository/VerificationTokenRepositoryTest.java b/src/test/java/org/ecommerce/spring/boot/vegetable/project/repository/VerificationTokenRepositoryTest.java new file mode 100644 index 0000000..5a5d0ef --- /dev/null +++ b/src/test/java/org/ecommerce/spring/boot/vegetable/project/repository/VerificationTokenRepositoryTest.java @@ -0,0 +1,20 @@ +package org.ecommerce.spring.boot.vegetable.project.repository; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +class VerificationTokenRepositoryTest { + + @Autowired + private VerificationTokenRepository verificationTokenRepository; + + @Test + public void deleteVerificationTokenTest() { + verificationTokenRepository.deleteById(2L); + } + +} \ No newline at end of file