├── .gitignore ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── example │ │ └── demo │ │ ├── Ecommerce2Application.java │ │ ├── config │ │ ├── CorsConfig.java │ │ ├── JwtAuthenticationFilter.java │ │ └── SecurityConfig.java │ │ ├── controller │ │ ├── AuthController.java │ │ ├── CartController.java │ │ ├── CommentController.java │ │ ├── OrderController.java │ │ └── ProductController.java │ │ ├── dto │ │ ├── CartDTO.java │ │ ├── CartItemDTO.java │ │ ├── ChangePasswordRequest.java │ │ ├── CommentDTO.java │ │ ├── EmailConfirmationRequest.java │ │ ├── ErrorDetails.java │ │ ├── LoginRequest.java │ │ ├── OrderDTO.java │ │ ├── OrderItemDTO.java │ │ ├── ProductDTO.java │ │ └── ProductListDTO.java │ │ ├── exception │ │ ├── GlobalExceptionHandler.java │ │ ├── InsufficientStockException.java │ │ └── ResourceNotFoundException.java │ │ ├── mapper │ │ ├── CartMapper.java │ │ ├── CommentMapper.java │ │ ├── OrderMapper.java │ │ └── ProductMapper.java │ │ ├── model │ │ ├── Cart.java │ │ ├── CartItem.java │ │ ├── Comment.java │ │ ├── Order.java │ │ ├── OrderItem.java │ │ ├── Product.java │ │ └── User.java │ │ ├── repositories │ │ ├── CartRepository.java │ │ ├── CommentRepository.java │ │ ├── OrderRepository.java │ │ ├── ProductRepository.java │ │ └── UserRepository.java │ │ └── service │ │ ├── CartService.java │ │ ├── CommentService.java │ │ ├── EmailService.java │ │ ├── JwtService.java │ │ ├── OrderService.java │ │ ├── ProductService.java │ │ └── UserService.java └── resources │ ├── application.properties │ └── static │ └── images │ ├── 05134a2a-cb8e-4f5e-9680-22d0a479c918_1.png │ ├── 0a59d671-aaae-4aa4-8c10-7fcd483f8f8f_1.png │ ├── 1e5ba1cc-78e5-47c2-ba0c-fe01ba86cdb5_anime-night-city-f4uhf40u30rw7oxf.jpg │ ├── 30b5207e-f70d-4afa-86dd-7cbba4627c93_1.png │ ├── 31acfa7b-f6c1-4e56-adcd-79477cd257ea_1.png │ ├── 33df105f-b9a0-4459-94fc-cd1b53a20819_1.png │ ├── 3a7cbc90-c1a5-49e7-a818-889923a56e6f_anime-night-city-f4uhf40u30rw7oxf.jpg │ ├── 4debbd7f-a5fa-4e0a-bee7-4a275382ff5a_1.png │ ├── 540698ec-1bf0-4964-920a-8668460ae9ef_1.png │ ├── 599e8948-850b-4b19-9184-c348a60a968e_1.png │ ├── 5ab7a82f-7059-40c7-bb7f-b458e5bbeac6_1.png │ ├── a45e6d62-065b-43dc-94b1-17c931cbf6c5_1.png │ ├── b2038204-a865-4ab4-8986-26c7795e981d_1.png │ ├── dc66fef7-5023-477a-866b-423283e15ae6_Leonardo_Anime_XL_create_a_consistent_anime_character_with_neu_2.jpg │ ├── ddba168b-371a-40dd-836a-6a3282cb8213_1.png │ ├── efac1b1b-da37-4b15-9fed-86725f1fface_1.png │ └── f7c72cb4-7993-42b5-914d-3ddc37fd7fd1_Leonardo_Anime_XL_Create_a_young_Asian_woman_with_blonde_highl_1.webp └── test └── java └── com └── example └── demo └── Ecommerce2ApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | wrapperVersion=3.3.2 18 | distributionType=only-script 19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip 20 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Apache Maven Wrapper startup batch script, version 3.3.2 23 | # 24 | # Optional ENV vars 25 | # ----------------- 26 | # JAVA_HOME - location of a JDK home dir, required when download maven via java source 27 | # MVNW_REPOURL - repo url base for downloading maven distribution 28 | # MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 29 | # MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output 30 | # ---------------------------------------------------------------------------- 31 | 32 | set -euf 33 | [ "${MVNW_VERBOSE-}" != debug ] || set -x 34 | 35 | # OS specific support. 36 | native_path() { printf %s\\n "$1"; } 37 | case "$(uname)" in 38 | CYGWIN* | MINGW*) 39 | [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" 40 | native_path() { cygpath --path --windows "$1"; } 41 | ;; 42 | esac 43 | 44 | # set JAVACMD and JAVACCMD 45 | set_java_home() { 46 | # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched 47 | if [ -n "${JAVA_HOME-}" ]; then 48 | if [ -x "$JAVA_HOME/jre/sh/java" ]; then 49 | # IBM's JDK on AIX uses strange locations for the executables 50 | JAVACMD="$JAVA_HOME/jre/sh/java" 51 | JAVACCMD="$JAVA_HOME/jre/sh/javac" 52 | else 53 | JAVACMD="$JAVA_HOME/bin/java" 54 | JAVACCMD="$JAVA_HOME/bin/javac" 55 | 56 | if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then 57 | echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 58 | echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 59 | return 1 60 | fi 61 | fi 62 | else 63 | JAVACMD="$( 64 | 'set' +e 65 | 'unset' -f command 2>/dev/null 66 | 'command' -v java 67 | )" || : 68 | JAVACCMD="$( 69 | 'set' +e 70 | 'unset' -f command 2>/dev/null 71 | 'command' -v javac 72 | )" || : 73 | 74 | if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then 75 | echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 76 | return 1 77 | fi 78 | fi 79 | } 80 | 81 | # hash string like Java String::hashCode 82 | hash_string() { 83 | str="${1:-}" h=0 84 | while [ -n "$str" ]; do 85 | char="${str%"${str#?}"}" 86 | h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) 87 | str="${str#?}" 88 | done 89 | printf %x\\n $h 90 | } 91 | 92 | verbose() { :; } 93 | [ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } 94 | 95 | die() { 96 | printf %s\\n "$1" >&2 97 | exit 1 98 | } 99 | 100 | trim() { 101 | # MWRAPPER-139: 102 | # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. 103 | # Needed for removing poorly interpreted newline sequences when running in more 104 | # exotic environments such as mingw bash on Windows. 105 | printf "%s" "${1}" | tr -d '[:space:]' 106 | } 107 | 108 | # parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties 109 | while IFS="=" read -r key value; do 110 | case "${key-}" in 111 | distributionUrl) distributionUrl=$(trim "${value-}") ;; 112 | distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; 113 | esac 114 | done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" 115 | [ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" 116 | 117 | case "${distributionUrl##*/}" in 118 | maven-mvnd-*bin.*) 119 | MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ 120 | case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in 121 | *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; 122 | :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; 123 | :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; 124 | :Linux*x86_64*) distributionPlatform=linux-amd64 ;; 125 | *) 126 | echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 127 | distributionPlatform=linux-amd64 128 | ;; 129 | esac 130 | distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" 131 | ;; 132 | maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; 133 | *) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; 134 | esac 135 | 136 | # apply MVNW_REPOURL and calculate MAVEN_HOME 137 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 138 | [ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" 139 | distributionUrlName="${distributionUrl##*/}" 140 | distributionUrlNameMain="${distributionUrlName%.*}" 141 | distributionUrlNameMain="${distributionUrlNameMain%-bin}" 142 | MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" 143 | MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" 144 | 145 | exec_maven() { 146 | unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : 147 | exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" 148 | } 149 | 150 | if [ -d "$MAVEN_HOME" ]; then 151 | verbose "found existing MAVEN_HOME at $MAVEN_HOME" 152 | exec_maven "$@" 153 | fi 154 | 155 | case "${distributionUrl-}" in 156 | *?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; 157 | *) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; 158 | esac 159 | 160 | # prepare tmp dir 161 | if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then 162 | clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } 163 | trap clean HUP INT TERM EXIT 164 | else 165 | die "cannot create temp dir" 166 | fi 167 | 168 | mkdir -p -- "${MAVEN_HOME%/*}" 169 | 170 | # Download and Install Apache Maven 171 | verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 172 | verbose "Downloading from: $distributionUrl" 173 | verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 174 | 175 | # select .zip or .tar.gz 176 | if ! command -v unzip >/dev/null; then 177 | distributionUrl="${distributionUrl%.zip}.tar.gz" 178 | distributionUrlName="${distributionUrl##*/}" 179 | fi 180 | 181 | # verbose opt 182 | __MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' 183 | [ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v 184 | 185 | # normalize http auth 186 | case "${MVNW_PASSWORD:+has-password}" in 187 | '') MVNW_USERNAME='' MVNW_PASSWORD='' ;; 188 | has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; 189 | esac 190 | 191 | if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then 192 | verbose "Found wget ... using wget" 193 | wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" 194 | elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then 195 | verbose "Found curl ... using curl" 196 | curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" 197 | elif set_java_home; then 198 | verbose "Falling back to use Java to download" 199 | javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" 200 | targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" 201 | cat >"$javaSource" <<-END 202 | public class Downloader extends java.net.Authenticator 203 | { 204 | protected java.net.PasswordAuthentication getPasswordAuthentication() 205 | { 206 | return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); 207 | } 208 | public static void main( String[] args ) throws Exception 209 | { 210 | setDefault( new Downloader() ); 211 | java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); 212 | } 213 | } 214 | END 215 | # For Cygwin/MinGW, switch paths to Windows format before running javac and java 216 | verbose " - Compiling Downloader.java ..." 217 | "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" 218 | verbose " - Running Downloader.java ..." 219 | "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" 220 | fi 221 | 222 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 223 | if [ -n "${distributionSha256Sum-}" ]; then 224 | distributionSha256Result=false 225 | if [ "$MVN_CMD" = mvnd.sh ]; then 226 | echo "Checksum validation is not supported for maven-mvnd." >&2 227 | echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 228 | exit 1 229 | elif command -v sha256sum >/dev/null; then 230 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then 231 | distributionSha256Result=true 232 | fi 233 | elif command -v shasum >/dev/null; then 234 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then 235 | distributionSha256Result=true 236 | fi 237 | else 238 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 239 | echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 240 | exit 1 241 | fi 242 | if [ $distributionSha256Result = false ]; then 243 | echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 244 | echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 245 | exit 1 246 | fi 247 | fi 248 | 249 | # unzip and move 250 | if command -v unzip >/dev/null; then 251 | unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" 252 | else 253 | tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" 254 | fi 255 | printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" 256 | mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" 257 | 258 | clean || : 259 | exec_maven "$@" 260 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | <# : batch portion 2 | @REM ---------------------------------------------------------------------------- 3 | @REM Licensed to the Apache Software Foundation (ASF) under one 4 | @REM or more contributor license agreements. See the NOTICE file 5 | @REM distributed with this work for additional information 6 | @REM regarding copyright ownership. The ASF licenses this file 7 | @REM to you under the Apache License, Version 2.0 (the 8 | @REM "License"); you may not use this file except in compliance 9 | @REM with the License. You may obtain a copy of the License at 10 | @REM 11 | @REM https://www.apache.org/licenses/LICENSE-2.0 12 | @REM 13 | @REM Unless required by applicable law or agreed to in writing, 14 | @REM software distributed under the License is distributed on an 15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | @REM KIND, either express or implied. See the License for the 17 | @REM specific language governing permissions and limitations 18 | @REM under the License. 19 | @REM ---------------------------------------------------------------------------- 20 | 21 | @REM ---------------------------------------------------------------------------- 22 | @REM Apache Maven Wrapper startup batch script, version 3.3.2 23 | @REM 24 | @REM Optional ENV vars 25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution 26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output 28 | @REM ---------------------------------------------------------------------------- 29 | 30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) 31 | @SET __MVNW_CMD__= 32 | @SET __MVNW_ERROR__= 33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath% 34 | @SET PSModulePath= 35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( 36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) 37 | ) 38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE% 39 | @SET __MVNW_PSMODULEP_SAVE= 40 | @SET __MVNW_ARG0_NAME__= 41 | @SET MVNW_USERNAME= 42 | @SET MVNW_PASSWORD= 43 | @IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) 44 | @echo Cannot start maven from wrapper >&2 && exit /b 1 45 | @GOTO :EOF 46 | : end batch / begin powershell #> 47 | 48 | $ErrorActionPreference = "Stop" 49 | if ($env:MVNW_VERBOSE -eq "true") { 50 | $VerbosePreference = "Continue" 51 | } 52 | 53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties 54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl 55 | if (!$distributionUrl) { 56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" 57 | } 58 | 59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { 60 | "maven-mvnd-*" { 61 | $USE_MVND = $true 62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" 63 | $MVN_CMD = "mvnd.cmd" 64 | break 65 | } 66 | default { 67 | $USE_MVND = $false 68 | $MVN_CMD = $script -replace '^mvnw','mvn' 69 | break 70 | } 71 | } 72 | 73 | # apply MVNW_REPOURL and calculate MAVEN_HOME 74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 75 | if ($env:MVNW_REPOURL) { 76 | $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } 77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" 78 | } 79 | $distributionUrlName = $distributionUrl -replace '^.*/','' 80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' 81 | $MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" 82 | if ($env:MAVEN_USER_HOME) { 83 | $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" 84 | } 85 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' 86 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" 87 | 88 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { 89 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" 90 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 91 | exit $? 92 | } 93 | 94 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { 95 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" 96 | } 97 | 98 | # prepare tmp dir 99 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile 100 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" 101 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null 102 | trap { 103 | if ($TMP_DOWNLOAD_DIR.Exists) { 104 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 105 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 106 | } 107 | } 108 | 109 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null 110 | 111 | # Download and Install Apache Maven 112 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 113 | Write-Verbose "Downloading from: $distributionUrl" 114 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 115 | 116 | $webclient = New-Object System.Net.WebClient 117 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { 118 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) 119 | } 120 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 121 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null 122 | 123 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 124 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum 125 | if ($distributionSha256Sum) { 126 | if ($USE_MVND) { 127 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." 128 | } 129 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash 130 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { 131 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." 132 | } 133 | } 134 | 135 | # unzip and move 136 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null 137 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null 138 | try { 139 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null 140 | } catch { 141 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { 142 | Write-Error "fail to move MAVEN_HOME" 143 | } 144 | } finally { 145 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 146 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 147 | } 148 | 149 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 150 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.3.2 9 | 10 | 11 | com.example 12 | demo 13 | 0.0.1-SNAPSHOT 14 | ecommerce2 15 | Demo project for Spring Boot 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 17 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-data-jpa 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-web 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-devtools 45 | runtime 46 | true 47 | 48 | 49 | org.postgresql 50 | postgresql 51 | runtime 52 | 53 | 54 | org.projectlombok 55 | lombok 56 | true 57 | 58 | 59 | org.mapstruct 60 | mapstruct 61 | 1.5.5.Final 62 | 63 | 64 | org.mapstruct 65 | mapstruct-processor 66 | 1.5.5.Final 67 | provided 68 | 69 | 70 | io.jsonwebtoken 71 | jjwt 72 | 0.9.1 73 | 74 | 75 | org.springframework.boot 76 | spring-boot-starter-security 77 | 78 | 79 | org.springframework.boot 80 | spring-boot-starter-validation 81 | 82 | 83 | 84 | org.springframework.boot 85 | spring-boot-starter-test 86 | test 87 | 88 | 89 | org.springframework.security 90 | spring-security-test 91 | test 92 | 93 | 94 | 95 | javax.xml.bind 96 | jaxb-api 97 | 2.3.1 98 | 99 | 100 | org.glassfish.jaxb 101 | jaxb-runtime 102 | 2.3.1 103 | 104 | 105 | org.springframework.boot 106 | spring-boot-starter-mail 107 | 108 | 109 | 110 | 111 | 112 | 113 | org.springframework.boot 114 | spring-boot-maven-plugin 115 | 116 | 117 | 118 | org.projectlombok 119 | lombok 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/Ecommerce2Application.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 7 | 8 | @SpringBootApplication 9 | @EntityScan(basePackages = "com.example.demo.model") 10 | @EnableJpaRepositories(basePackages = "com.example.demo.repositories") 11 | public class Ecommerce2Application { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(Ecommerce2Application.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/config/CorsConfig.java: -------------------------------------------------------------------------------- 1 | //update 2 | package com.example.demo.config; 3 | 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | 9 | @Configuration 10 | public class CorsConfig { 11 | 12 | @Bean 13 | public WebMvcConfigurer corsConfigurer() { 14 | return new WebMvcConfigurer() { 15 | @Override 16 | public void addCorsMappings(CorsRegistry registry) { 17 | registry.addMapping("/**") // Apply CORS to all paths 18 | .allowedOrigins("http://localhost:3000") // Allow all origins, or specify specific origins 19 | .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // Specify allowed HTTP methods 20 | .allowedHeaders("*") // Allow all headers 21 | .allowCredentials(true); // Allow credentials (cookies, authorization headers) 22 | } 23 | }; 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/com/example/demo/config/JwtAuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.config; 2 | 3 | import com.example.demo.service.JwtService; 4 | import jakarta.servlet.FilterChain; 5 | import jakarta.servlet.ServletException; 6 | import jakarta.servlet.http.HttpServletRequest; 7 | import jakarta.servlet.http.HttpServletResponse; 8 | import lombok.RequiredArgsConstructor; 9 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 10 | import org.springframework.security.core.context.SecurityContextHolder; 11 | import org.springframework.security.core.userdetails.UserDetails; 12 | import org.springframework.security.core.userdetails.UserDetailsService; 13 | import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; 14 | import org.springframework.web.filter.OncePerRequestFilter; 15 | 16 | import java.io.IOException; 17 | 18 | @RequiredArgsConstructor 19 | public class JwtAuthenticationFilter extends OncePerRequestFilter { 20 | private final JwtService jwtService; 21 | private final UserDetailsService userDetailsService; 22 | 23 | @Override 24 | public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { 25 | final String authorizationHeader = request.getHeader("Authorization"); 26 | 27 | String username = null; 28 | String jwt = null; 29 | 30 | if(authorizationHeader != null && authorizationHeader.startsWith("Bearer ")){ 31 | jwt = authorizationHeader.substring(7); 32 | username = jwtService.extractUsername(jwt); 33 | } 34 | 35 | if(username != null && SecurityContextHolder.getContext().getAuthentication() == null){ 36 | UserDetails userDetails = this.userDetailsService.loadUserByUsername(username); 37 | if(jwtService.validateToken(jwt, userDetails)){ 38 | UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); 39 | authToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); 40 | SecurityContextHolder.getContext().setAuthentication(authToken); 41 | } 42 | } 43 | filterChain.doFilter(request, response); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.config; 2 | 3 | import com.example.demo.repositories.UserRepository; 4 | import com.example.demo.service.JwtService; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.security.authentication.AuthenticationManager; 10 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider; 11 | import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; 12 | import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; 13 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 14 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 15 | import org.springframework.security.config.http.SessionCreationPolicy; 16 | import org.springframework.security.core.userdetails.UserDetails; 17 | import org.springframework.security.core.userdetails.UserDetailsService; 18 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 19 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 20 | import org.springframework.security.crypto.password.PasswordEncoder; 21 | import org.springframework.security.web.SecurityFilterChain; 22 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 23 | 24 | @Configuration 25 | @EnableWebSecurity 26 | @EnableMethodSecurity 27 | @RequiredArgsConstructor 28 | public class SecurityConfig { 29 | private final UserRepository userRepository; 30 | private final JwtService jwtService; 31 | 32 | @Bean 33 | public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { 34 | http 35 | .csrf(csrf -> csrf.disable()) 36 | .authorizeHttpRequests(auth-> auth 37 | .requestMatchers("/").permitAll() 38 | .requestMatchers("/images/**").permitAll() 39 | .requestMatchers("/index.html").permitAll() 40 | .requestMatchers("/api/auth/**").permitAll() 41 | .requestMatchers(HttpMethod.GET, "/api/products/**").permitAll() 42 | .requestMatchers("/api/auth/change-password").authenticated() 43 | 44 | .anyRequest().authenticated() 45 | ) 46 | .sessionManagement(session -> session 47 | .sessionCreationPolicy(SessionCreationPolicy.STATELESS) 48 | ) 49 | .addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); 50 | 51 | return http.build(); 52 | } 53 | 54 | @Bean 55 | public JwtAuthenticationFilter jwtAuthenticationFilter(){ 56 | return new JwtAuthenticationFilter(jwtService, userDetailsService()); 57 | } 58 | 59 | @Bean 60 | public PasswordEncoder passwordEncoder(){ 61 | return new BCryptPasswordEncoder(); 62 | } 63 | @Bean 64 | public AuthenticationManager authenticationManager(AuthenticationConfiguration authConfig) throws Exception{ 65 | return authConfig.getAuthenticationManager(); 66 | } 67 | @Bean 68 | public UserDetailsService userDetailsService(){ 69 | return username -> (UserDetails) userRepository.findByEmail(username) 70 | .orElseThrow(()-> new UsernameNotFoundException("User not found")); 71 | } 72 | @Bean 73 | public DaoAuthenticationProvider authenticationProvider(){ 74 | DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); 75 | authProvider.setUserDetailsService(userDetailsService()); 76 | authProvider.setPasswordEncoder(passwordEncoder()); 77 | return authProvider; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/AuthController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | import com.example.demo.dto.ChangePasswordRequest; 4 | import com.example.demo.dto.EmailConfirmationRequest; 5 | import com.example.demo.dto.LoginRequest; 6 | import com.example.demo.exception.ResourceNotFoundException; 7 | import com.example.demo.model.User; 8 | import com.example.demo.service.JwtService; 9 | import com.example.demo.service.UserService; 10 | import jakarta.validation.Valid; 11 | import lombok.RequiredArgsConstructor; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.security.authentication.AuthenticationManager; 14 | import org.springframework.security.authentication.BadCredentialsException; 15 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 16 | import org.springframework.security.core.Authentication; 17 | import org.springframework.security.core.context.SecurityContextHolder; 18 | import org.springframework.security.core.userdetails.UserDetails; 19 | import org.springframework.web.bind.annotation.*; 20 | 21 | @RestController 22 | @RequestMapping("/api/auth") 23 | @RequiredArgsConstructor 24 | public class AuthController { 25 | private final AuthenticationManager authenticationManager; 26 | private final UserService userService; 27 | private final JwtService jwtService; 28 | 29 | @PostMapping("/login") 30 | public ResponseEntity login(@RequestBody LoginRequest loginRequest){ 31 | authenticationManager.authenticate( 32 | new UsernamePasswordAuthenticationToken(loginRequest.getEmail(), loginRequest.getPassword()) 33 | ); 34 | final UserDetails userDetails = userService.getUserByEmail(loginRequest.getEmail()); 35 | final String jwt = jwtService.generateToken(userDetails); 36 | return ResponseEntity.ok(jwt); 37 | } 38 | 39 | @PostMapping("/register") 40 | public ResponseEntity register(@Valid @RequestBody User user){ 41 | return ResponseEntity.ok(userService.registerUser(user)); 42 | } 43 | 44 | @PostMapping("/change-password") 45 | public ResponseEntity changePassword(@Valid @RequestBody ChangePasswordRequest request){ 46 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 47 | String email = authentication.getName(); 48 | userService.changePassword(email, request); 49 | return ResponseEntity.ok().body("Password changed"); 50 | } 51 | 52 | @PostMapping("/confirm-email") 53 | public ResponseEntity confirmEmail(@RequestBody EmailConfirmationRequest request){ 54 | try{ 55 | userService.confirmEmail(request.getEmail(), request.getConfirmationCode()); 56 | return ResponseEntity.ok().body("Email confirmed successfuly"); 57 | }catch (BadCredentialsException e){ 58 | return ResponseEntity.badRequest().body("Invalid confirmation code"); 59 | } 60 | catch (ResourceNotFoundException e){ 61 | return ResponseEntity.notFound().build(); 62 | } 63 | } 64 | 65 | //update 66 | @GetMapping("/user/role") 67 | public ResponseEntity getUserRole() { 68 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 69 | String email = authentication.getName(); 70 | User user = userService.getUserByEmail(email); 71 | 72 | if (user != null) { 73 | String role = String.valueOf(user.getRole()); 74 | return ResponseEntity.ok(role); 75 | } 76 | return ResponseEntity.notFound().build(); 77 | } 78 | 79 | //update 80 | @GetMapping("/user/{id}") 81 | public ResponseEntity getUserEmailById(@PathVariable Long id) { 82 | User user = userService.getUserById(id); // Ensure this method exists in your UserService 83 | if (user != null) { 84 | return ResponseEntity.ok(user.getEmail()); 85 | } 86 | return ResponseEntity.notFound().build(); 87 | } 88 | } 89 | 90 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/CartController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | import com.example.demo.dto.CartDTO; 4 | import com.example.demo.model.User; 5 | import com.example.demo.service.CartService; 6 | import lombok.RequiredArgsConstructor; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.security.access.prepost.PreAuthorize; 9 | import org.springframework.security.core.annotation.AuthenticationPrincipal; 10 | import org.springframework.security.core.userdetails.UserDetails; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | @RestController 14 | @RequestMapping("/api/cart") 15 | @RequiredArgsConstructor 16 | public class CartController { 17 | private final CartService cartService; 18 | 19 | @PostMapping("/add") 20 | @PreAuthorize("isAuthenticated()") 21 | public ResponseEntity addToCart(@AuthenticationPrincipal UserDetails userDetails, 22 | @RequestParam Long productId, 23 | @RequestParam Integer quantity){ 24 | Long userId = ((User) userDetails).getId(); 25 | return ResponseEntity.ok(cartService.addToCart(userId, productId, quantity)); 26 | } 27 | 28 | @GetMapping 29 | @PreAuthorize("isAuthenticated()") 30 | public ResponseEntity getCart(@AuthenticationPrincipal UserDetails userDetails){ 31 | Long userId = ((User) userDetails).getId(); 32 | return ResponseEntity.ok(cartService.getCart(userId)); 33 | } 34 | 35 | @DeleteMapping 36 | @PreAuthorize("isAuthenticated()") 37 | public ResponseEntity clearCart(@AuthenticationPrincipal UserDetails userDetails){ 38 | Long userId = ((User) userDetails).getId(); 39 | cartService.clearCart(userId); 40 | return ResponseEntity.noContent().build(); 41 | } 42 | 43 | //update 44 | @DeleteMapping("/{productId}") 45 | @PreAuthorize("isAuthenticated()") 46 | public ResponseEntity removeCartItem(@AuthenticationPrincipal UserDetails userDetails, 47 | @PathVariable Long productId) { 48 | Long userId = ((User) userDetails).getId(); 49 | cartService.removeCartItem(userId, productId); 50 | return ResponseEntity.noContent().build(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/CommentController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | import com.example.demo.dto.CommentDTO; 4 | import com.example.demo.model.User; 5 | import com.example.demo.service.CommentService; 6 | import jakarta.validation.Valid; 7 | import lombok.RequiredArgsConstructor; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.security.access.prepost.PreAuthorize; 10 | import org.springframework.security.core.annotation.AuthenticationPrincipal; 11 | import org.springframework.security.core.userdetails.UserDetails; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | import java.util.List; 15 | 16 | @RestController 17 | @RequestMapping("/api/comments") 18 | @RequiredArgsConstructor 19 | public class CommentController { 20 | private final CommentService commentService; 21 | 22 | @PostMapping("/product/{productId}") 23 | @PreAuthorize("isAuthenticated()") 24 | public ResponseEntity addComment(@PathVariable Long productId, 25 | @AuthenticationPrincipal UserDetails userDetails, 26 | @Valid @RequestBody CommentDTO commentDTO){ 27 | Long userId = ((User) userDetails).getId(); 28 | return ResponseEntity.ok(commentService.addComment(productId, userId, commentDTO)); 29 | } 30 | 31 | @GetMapping("/product/{productId}") 32 | public ResponseEntity> getCommentsByProduct(@PathVariable Long productId){ 33 | return ResponseEntity.ok(commentService.getCommentsByProduct(productId)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | import com.example.demo.dto.OrderDTO; 4 | import com.example.demo.model.Order; 5 | import com.example.demo.model.User; 6 | import com.example.demo.service.OrderService; 7 | import lombok.RequiredArgsConstructor; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.security.access.prepost.PreAuthorize; 10 | import org.springframework.security.core.annotation.AuthenticationPrincipal; 11 | import org.springframework.security.core.userdetails.UserDetails; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | import java.util.List; 15 | 16 | @RestController 17 | @RequestMapping("/api/orders") 18 | @RequiredArgsConstructor 19 | public class OrderController { 20 | private final OrderService orderService; 21 | 22 | @PostMapping 23 | @PreAuthorize("isAuthenticated()") 24 | public ResponseEntity createOrder(@AuthenticationPrincipal UserDetails userDetails, 25 | @RequestParam String address, 26 | @RequestParam String phoneNumber){ 27 | Long userId = ((User) userDetails).getId(); 28 | OrderDTO orderDTO = orderService.createOrder(userId, address, phoneNumber); 29 | return ResponseEntity.ok(orderDTO); 30 | } 31 | 32 | @GetMapping 33 | @PreAuthorize("hasRole('ADMIN')") 34 | public ResponseEntity> getAllOrders(){ 35 | List orders = orderService.getAllOrders(); 36 | return ResponseEntity.ok(orders); 37 | } 38 | @GetMapping("/user") 39 | @PreAuthorize("isAuthenticated()") 40 | public ResponseEntity> getUserOrders(@AuthenticationPrincipal UserDetails userDetails){ 41 | Long userId = ((User) userDetails).getId(); 42 | List orders = orderService.getUserOrders(userId); 43 | return ResponseEntity.ok(orders); 44 | } 45 | 46 | @PutMapping("/{orderId}/status") 47 | @PreAuthorize("hasRole('ADMIN')") 48 | public ResponseEntity updateOrderStatus(@PathVariable Long orderId, 49 | @RequestParam Order.OrderStatus status){ 50 | OrderDTO updatedOrder = orderService.updateOrderStatus(orderId, status); 51 | return ResponseEntity.ok(updatedOrder); 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/controller/ProductController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | import com.example.demo.dto.ProductDTO; 4 | import com.example.demo.dto.ProductListDTO; 5 | import com.example.demo.service.ProductService; 6 | import jakarta.validation.Valid; 7 | import lombok.RequiredArgsConstructor; 8 | import org.springframework.data.domain.Page; 9 | import org.springframework.data.domain.Pageable; 10 | import org.springframework.data.web.PageableDefault; 11 | import org.springframework.http.MediaType; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.security.access.prepost.PreAuthorize; 14 | import org.springframework.web.bind.annotation.*; 15 | import org.springframework.web.multipart.MultipartFile; 16 | 17 | import java.io.IOException; 18 | import java.util.List; 19 | 20 | @RestController 21 | @RequestMapping("/api/products") 22 | @RequiredArgsConstructor 23 | public class ProductController { 24 | private final ProductService productService; 25 | 26 | @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE) 27 | @PreAuthorize("hasRole('ADMIN')") 28 | public ResponseEntity createProduct(@RequestPart("product") @Valid ProductDTO productDTO, 29 | @RequestPart(value = "image", required = false) MultipartFile image) throws IOException { 30 | return ResponseEntity.ok(productService.createProduct(productDTO, image)); 31 | } 32 | 33 | @PutMapping(value = "/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) 34 | @PreAuthorize("hasRole('ADMIN')") 35 | public ResponseEntity updateProduct(@PathVariable Long id, 36 | @RequestPart("product") @Valid ProductDTO productDTO, 37 | @RequestPart(value = "image", required = false) MultipartFile image)throws IOException{ 38 | return ResponseEntity.ok(productService.updateProduct(id, productDTO, image)); 39 | } 40 | 41 | @DeleteMapping("/{id}") 42 | @PreAuthorize("hasRole('ADMIN')") 43 | public ResponseEntity deleteProduct(@PathVariable Long id){ 44 | productService.deleteProduct(id); 45 | return ResponseEntity.noContent().build(); 46 | } 47 | @GetMapping("/{id}") 48 | public ResponseEntity getProduct(@PathVariable Long id){ 49 | return ResponseEntity.ok(productService.getProduct(id)); 50 | } 51 | @GetMapping 52 | public ResponseEntity> getAllProducts(@PageableDefault(size=10) Pageable pageable){ 53 | return ResponseEntity.ok(productService.getAllProducts(pageable)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/dto/CartDTO.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | @Data 8 | public class CartDTO { 9 | private Long id; 10 | private Long userId; //usedId 11 | private List items; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/dto/CartItemDTO.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.dto; 2 | 3 | import jakarta.validation.constraints.Positive; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class CartItemDTO { 8 | private Long id; 9 | private Long productId; 10 | @Positive 11 | private Integer quantity; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/dto/ChangePasswordRequest.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.dto; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class ChangePasswordRequest { 7 | private String currentPassword; 8 | private String newPassword; 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/dto/CommentDTO.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.dto; 2 | 3 | import jakarta.validation.constraints.Max; 4 | import jakarta.validation.constraints.Min; 5 | import jakarta.validation.constraints.NotBlank; 6 | import jakarta.validation.constraints.Positive; 7 | import lombok.Data; 8 | 9 | @Data 10 | public class CommentDTO { 11 | private Long id; 12 | @NotBlank(message = "Content is required") 13 | private String content; 14 | @Min(value=1) 15 | @Max(value=5) 16 | private Integer score; 17 | private Long userId; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/dto/EmailConfirmationRequest.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.dto; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class EmailConfirmationRequest { 7 | private String email; 8 | private String confirmationCode; 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/dto/ErrorDetails.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | import java.util.Date; 7 | 8 | @Data 9 | @AllArgsConstructor 10 | public class ErrorDetails { 11 | private Date timestamp; 12 | private String message; 13 | private String details; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/dto/LoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class LoginRequest { 11 | private String email; 12 | private String password; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/dto/OrderDTO.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.dto; 2 | 3 | import jakarta.validation.constraints.NotBlank; 4 | import lombok.Data; 5 | 6 | import java.time.LocalDateTime; 7 | import java.util.List; 8 | import com.example.demo.model.Order; 9 | 10 | @Data 11 | public class OrderDTO { 12 | private Long id; 13 | private Long userId; 14 | @NotBlank(message = "Address is required") 15 | private String address; 16 | @NotBlank(message = "Phone name is required") 17 | private String phoneNumber; 18 | private Order.OrderStatus status; 19 | private LocalDateTime createdAt; 20 | private List orderItems; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/dto/OrderItemDTO.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.dto; 2 | 3 | import jakarta.validation.constraints.Positive; 4 | import lombok.Data; 5 | 6 | import java.math.BigDecimal; 7 | 8 | @Data 9 | public class OrderItemDTO { 10 | private Long id; 11 | private Long productId; 12 | @Positive 13 | private Integer quantity; 14 | @Positive 15 | private BigDecimal price; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/dto/ProductDTO.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.dto; 2 | 3 | import jakarta.validation.constraints.NotBlank; 4 | import jakarta.validation.constraints.Positive; 5 | import jakarta.validation.constraints.PositiveOrZero; 6 | import lombok.Data; 7 | 8 | import java.math.BigDecimal; 9 | import java.util.List; 10 | 11 | @Data 12 | public class ProductDTO { 13 | private Long id; 14 | @NotBlank(message = "Product name is required") 15 | private String name; 16 | @NotBlank(message = "Product description is required") 17 | private String description; 18 | @Positive(message = "Cannot be negative") 19 | private BigDecimal price; 20 | @PositiveOrZero(message = "Cannot be negative") 21 | private Integer quantity; 22 | private String image; //add image 23 | private List comments; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/dto/ProductListDTO.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.dto; 2 | 3 | import jakarta.validation.constraints.NotBlank; 4 | import jakarta.validation.constraints.Positive; 5 | import jakarta.validation.constraints.PositiveOrZero; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | 9 | import java.math.BigDecimal; 10 | 11 | @Data 12 | @AllArgsConstructor 13 | public class ProductListDTO { 14 | private Long id; 15 | @NotBlank(message = "Name is required") 16 | private String name; 17 | @NotBlank(message = "Description is required") 18 | private String description; 19 | @Positive(message = "Price must be positive") 20 | private BigDecimal price; 21 | @PositiveOrZero(message = "Qunatity must be positive or zero") 22 | private Integer quantity; 23 | private String image; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.exception; 2 | 3 | import com.example.demo.dto.ErrorDetails; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.ControllerAdvice; 7 | import org.springframework.web.bind.annotation.ExceptionHandler; 8 | import org.springframework.web.context.request.WebRequest; 9 | 10 | import java.util.Date; 11 | 12 | @ControllerAdvice 13 | public class GlobalExceptionHandler { 14 | @ExceptionHandler(ResourceNotFoundException.class) 15 | public ResponseEntity handleResourceNotFoundException(ResourceNotFoundException ex, WebRequest request){ 16 | ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false)); 17 | return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND); 18 | } 19 | @ExceptionHandler(InsufficientStockException.class) 20 | public ResponseEntity handleInsufficientStockException(InsufficientStockException ex, WebRequest request){ 21 | ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false)); 22 | return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND); 23 | } 24 | @ExceptionHandler(Exception.class) 25 | public ResponseEntity handleGlobalException(Exception ex, WebRequest request){ 26 | ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false)); 27 | return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/exception/InsufficientStockException.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.exception; 2 | 3 | public class InsufficientStockException extends RuntimeException{ 4 | public InsufficientStockException(String message){ super(message);} 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.exception; 2 | 3 | public class ResourceNotFoundException extends RuntimeException{ 4 | public ResourceNotFoundException(String message){ super(message);} 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/mapper/CartMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.mapper; 2 | 3 | import com.example.demo.dto.CartDTO; 4 | import com.example.demo.dto.CartItemDTO; 5 | import com.example.demo.model.Cart; 6 | import com.example.demo.model.CartItem; 7 | import org.mapstruct.Mapper; 8 | import org.mapstruct.Mapping; 9 | 10 | @Mapper(componentModel = "spring") 11 | public interface CartMapper { 12 | @Mapping(target = "userId", source = "user.id") 13 | CartDTO toDTO(Cart Cart); 14 | @Mapping(target="user.id", source = "userId") 15 | Cart toEntity(CartDTO cartDTO); 16 | 17 | @Mapping(target="productId", source="product.id") 18 | CartItemDTO toDTO(CartItem cartItem); 19 | 20 | @Mapping(target="product.id", source="productId") 21 | CartItem toEntity(CartItemDTO cartItemDTO); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/mapper/CommentMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.mapper; 2 | 3 | import com.example.demo.dto.CommentDTO; 4 | import com.example.demo.model.Comment; 5 | import org.mapstruct.Mapper; 6 | import org.mapstruct.Mapping; 7 | 8 | @Mapper(componentModel = "spring") 9 | public interface CommentMapper { 10 | @Mapping(target = "userId",source = "user.id") 11 | CommentDTO toDTO(Comment comment); 12 | @Mapping(target = "user.id", source = "userId") 13 | @Mapping(target = "product", ignore = true) 14 | Comment toEntity(CommentDTO commentDTO); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/mapper/OrderMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.mapper; 2 | 3 | import com.example.demo.dto.OrderDTO; 4 | import com.example.demo.dto.OrderItemDTO; 5 | import com.example.demo.model.Order; 6 | import com.example.demo.model.OrderItem; 7 | import org.mapstruct.Mapper; 8 | import org.mapstruct.Mapping; 9 | 10 | import java.util.List; 11 | 12 | @Mapper(componentModel = "spring") 13 | public interface OrderMapper { 14 | @Mapping(target = "userId", source = "user.id") 15 | @Mapping(target = "orderItems", source = "items") 16 | OrderDTO toDTO(Order order); 17 | 18 | @Mapping(target = "user.id", source = "userId") 19 | @Mapping(target = "items", source = "orderItems") 20 | Order toEntity(OrderDTO orderDTO); 21 | 22 | List toDTOs(List orders); 23 | List toEntities(List orderDTOS); 24 | @Mapping(target = "productId", source = "product.id") 25 | OrderItemDTO toOrderItemDTO(OrderItem orderItem); 26 | @Mapping(target = "product.id", source = "productId") 27 | OrderItem toOrderItemEntity(OrderItemDTO orderItemDTO); 28 | 29 | List toOrderItemDTOs(List orderItem); 30 | List toOrderItemEntities(List orderItemDTO); 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/mapper/ProductMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.mapper; 2 | 3 | import com.example.demo.dto.CommentDTO; 4 | import com.example.demo.dto.ProductDTO; 5 | import com.example.demo.model.Comment; 6 | import com.example.demo.model.Product; 7 | import org.mapstruct.Mapper; 8 | import org.mapstruct.Mapping; 9 | 10 | @Mapper(componentModel = "spring") 11 | public interface ProductMapper { 12 | @Mapping(target = "image", source = "image") //add mapping 13 | ProductDTO toDTO(Product product); 14 | 15 | @Mapping(target = "image", source = "image") //add mapping 16 | Product toEntity(ProductDTO productDTO); 17 | 18 | @Mapping(target = "userId",source = "user.id") 19 | CommentDTO toDTO(Comment comment); 20 | @Mapping(target = "user.id", source = "userId") 21 | @Mapping(target = "product", ignore = true) 22 | Comment toEntity(CommentDTO commentDTO); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/Cart.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | @Entity 12 | @Data 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class Cart { 16 | @Id 17 | @GeneratedValue(strategy = GenerationType.IDENTITY) 18 | private Long id; 19 | 20 | @OneToOne 21 | @JoinColumn(name="user_id", nullable = false) 22 | private User user; 23 | 24 | @OneToMany(mappedBy = "cart", cascade = CascadeType.ALL, orphanRemoval = true) 25 | private List items = new ArrayList<>(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/CartItem.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Entity 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class CartItem { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.IDENTITY) 15 | private Long id; 16 | 17 | @ManyToOne 18 | @JoinColumn(name = "cart_id", nullable = false) 19 | private Cart cart; 20 | 21 | @ManyToOne 22 | @JoinColumn(name="product_id", nullable = false) 23 | private Product product; 24 | 25 | private Integer quantity; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/Comment.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Entity 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class Comment { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.IDENTITY) 15 | private Long id; 16 | private String content; 17 | private Integer score; 18 | 19 | @ManyToOne 20 | @JoinColumn(name="product_id", nullable = false) 21 | private Product product; 22 | 23 | @ManyToOne 24 | @JoinColumn(name="user_id", nullable = false) 25 | private User user; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/Order.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.time.LocalDateTime; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | @Entity 13 | @Data 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | @Table(name="orders") 17 | public class Order { 18 | @Id 19 | @GeneratedValue(strategy = GenerationType.IDENTITY) 20 | private Long id; 21 | @ManyToOne 22 | @JoinColumn(name = "user_id", nullable = false) 23 | private User user; 24 | private String address; 25 | private String phoneNumber; 26 | @Enumerated(EnumType.STRING) 27 | private OrderStatus status; 28 | public enum OrderStatus { 29 | PREPARING, DELIVERING, DELIVERED, CANCELED 30 | } 31 | private LocalDateTime createdAt; 32 | @OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true) 33 | private List items = new ArrayList<>(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/OrderItem.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | import jakarta.persistence.*; 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import java.math.BigDecimal; 7 | @Entity 8 | @Data 9 | @NoArgsConstructor 10 | @AllArgsConstructor 11 | public class OrderItem { 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.IDENTITY) 14 | private Long id; 15 | @ManyToOne 16 | @JoinColumn(name="order_id", nullable = false) 17 | private Order order; 18 | @ManyToOne 19 | @JoinColumn(name="product_id", nullable = false) 20 | private Product product; 21 | private Integer quantity; 22 | private BigDecimal price; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/Product.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.math.BigDecimal; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | @Entity 13 | @Data 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | public class Product { 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.IDENTITY) 19 | private Long id; 20 | private String name; 21 | private String description; 22 | private BigDecimal price; 23 | private Integer quantity; 24 | private String image; //add image 25 | 26 | @OneToMany(mappedBy = "product", cascade = CascadeType.ALL, orphanRemoval = true) 27 | private List comments = new ArrayList<>(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/model/User.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.model; 2 | 3 | import jakarta.persistence.*; 4 | import jakarta.validation.constraints.Email; 5 | import jakarta.validation.constraints.NotBlank; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | import org.springframework.security.core.GrantedAuthority; 10 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 11 | import org.springframework.security.core.userdetails.UserDetails; 12 | 13 | import java.util.Collection; 14 | import java.util.List; 15 | 16 | @Entity 17 | @Data 18 | @NoArgsConstructor 19 | @AllArgsConstructor 20 | @Table(name="users") 21 | public class User implements UserDetails { 22 | @Id 23 | @GeneratedValue(strategy = GenerationType.IDENTITY) 24 | private Long id; 25 | @NotBlank 26 | @Email 27 | private String email; 28 | @NotBlank 29 | 30 | private String password; 31 | 32 | @Enumerated(EnumType.STRING) 33 | private Role role; 34 | 35 | @OneToOne(mappedBy = "user", cascade = CascadeType.ALL) 36 | private Cart cart; 37 | 38 | private boolean emailConfirmation; 39 | private String confirmationCode; 40 | 41 | @Override 42 | public Collection getAuthorities() { 43 | return List.of(new SimpleGrantedAuthority("ROLE_"+role.name())); 44 | } 45 | 46 | @Override 47 | public String getUsername() { 48 | return email; 49 | } 50 | 51 | @Override 52 | public boolean isAccountNonExpired() { 53 | return true; 54 | } 55 | 56 | @Override 57 | public boolean isAccountNonLocked() { 58 | return true; 59 | } 60 | 61 | @Override 62 | public boolean isCredentialsNonExpired() { 63 | return true; 64 | } 65 | 66 | @Override 67 | public boolean isEnabled() { 68 | return true; 69 | } 70 | 71 | public enum Role{ 72 | USER, ADMIN 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/repositories/CartRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.repositories; 2 | 3 | import com.example.demo.model.Cart; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.Optional; 7 | 8 | public interface CartRepository extends JpaRepository { 9 | Optional findByUserId(Long userId); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/repositories/CommentRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.repositories; 2 | 3 | import com.example.demo.model.Cart; 4 | import com.example.demo.model.Comment; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import java.util.List; 8 | import java.util.Optional; 9 | 10 | public interface CommentRepository extends JpaRepository { 11 | List findByProductId(Long productId); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/repositories/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.repositories; 2 | 3 | import com.example.demo.model.Cart; 4 | import com.example.demo.model.Comment; 5 | import com.example.demo.model.Order; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | 8 | import java.util.List; 9 | 10 | public interface OrderRepository extends JpaRepository { 11 | List findByUserId(Long userId); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/repositories/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.repositories; 2 | 3 | import com.example.demo.dto.ProductListDTO; 4 | import com.example.demo.model.Comment; 5 | import com.example.demo.model.Product; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.data.domain.Pageable; 8 | import org.springframework.data.jpa.repository.JpaRepository; 9 | import org.springframework.data.jpa.repository.Query; 10 | 11 | import java.util.List; 12 | 13 | public interface ProductRepository extends JpaRepository { 14 | @Query("SELECT new com.example.demo.dto.ProductListDTO(p.id, p.name, p.description, p.price, p.quantity, p.image) FROM Product p") 15 | Page findAllWithoutComments(Pageable pageable); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/repositories/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.repositories; 2 | 3 | import com.example.demo.model.Comment; 4 | import com.example.demo.model.User; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import java.util.List; 8 | import java.util.Optional; 9 | 10 | public interface UserRepository extends JpaRepository { 11 | Optional findByEmail(String email); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/CartService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import com.example.demo.dto.CartDTO; 4 | import com.example.demo.exception.InsufficientStockException; 5 | import com.example.demo.exception.ResourceNotFoundException; 6 | import com.example.demo.mapper.CartMapper; 7 | import com.example.demo.model.Cart; 8 | import com.example.demo.model.CartItem; 9 | import com.example.demo.model.Product; 10 | import com.example.demo.model.User; 11 | import com.example.demo.repositories.CartRepository; 12 | import com.example.demo.repositories.ProductRepository; 13 | import com.example.demo.repositories.UserRepository; 14 | import lombok.RequiredArgsConstructor; 15 | import org.springframework.stereotype.Service; 16 | 17 | import java.util.ArrayList; 18 | import java.util.Optional; 19 | 20 | @Service 21 | @RequiredArgsConstructor 22 | public class CartService { 23 | private final CartRepository cartRepository; 24 | private final ProductRepository productRepository; 25 | private final UserRepository userRepository; 26 | private final CartMapper cartMapper; 27 | 28 | public CartDTO addToCart(Long userId, Long productId, Integer quantity){ 29 | User user = userRepository.findById(userId) 30 | .orElseThrow(()->new ResourceNotFoundException("User not found")); 31 | Product product = productRepository.findById(productId) 32 | .orElseThrow(()->new ResourceNotFoundException("Product not found")); 33 | 34 | if(product.getQuantity()())); 40 | Optional existingCartItem = cart.getItems().stream() 41 | .filter(item -> item.getProduct().getId().equals(productId)) 42 | .findFirst(); 43 | 44 | if(existingCartItem.isPresent()){ 45 | CartItem cartItem = existingCartItem.get(); 46 | cartItem.setQuantity(cartItem.getQuantity()+quantity); 47 | }else{ 48 | CartItem cartItem = new CartItem(null, cart, product, quantity); 49 | cart.getItems().add(cartItem); 50 | } 51 | Cart savedCart = cartRepository.save(cart); 52 | return cartMapper.toDTO(savedCart); 53 | 54 | } 55 | 56 | public CartDTO getCart(Long userId){ 57 | Cart cart = cartRepository.findByUserId(userId) 58 | .orElseThrow(()->new ResourceNotFoundException("Cart not found")); 59 | 60 | return cartMapper.toDTO(cart); 61 | } 62 | public void clearCart(Long userId){ 63 | Cart cart = cartRepository.findByUserId(userId) 64 | .orElseThrow(()->new ResourceNotFoundException("Cart not found")); 65 | 66 | cart.getItems().clear(); 67 | cartRepository.save(cart); 68 | } 69 | 70 | //update 71 | public void removeCartItem(Long userId, Long productId) { 72 | Cart cart = cartRepository.findByUserId(userId) 73 | .orElseThrow(() -> new RuntimeException("Cart not found for user")); 74 | 75 | cart.getItems().removeIf(item -> item.getProduct().getId().equals(productId)); 76 | 77 | cartRepository.save(cart); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/CommentService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import com.example.demo.dto.CommentDTO; 4 | import com.example.demo.exception.ResourceNotFoundException; 5 | import com.example.demo.mapper.CommentMapper; 6 | import com.example.demo.model.Comment; 7 | import com.example.demo.model.Product; 8 | import com.example.demo.model.User; 9 | import com.example.demo.repositories.CommentRepository; 10 | import com.example.demo.repositories.ProductRepository; 11 | import com.example.demo.repositories.UserRepository; 12 | import lombok.RequiredArgsConstructor; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.util.List; 16 | import java.util.stream.Collectors; 17 | 18 | @Service 19 | @RequiredArgsConstructor 20 | public class CommentService { 21 | private final CommentRepository commentRepository; 22 | private final ProductRepository productRepository; 23 | private final UserRepository userRepository; 24 | private final CommentMapper commentMapper; 25 | 26 | public CommentDTO addComment(Long productId, Long userId, CommentDTO commentDTO){ 27 | Product product = productRepository.findById(productId) 28 | .orElseThrow(()-> new ResourceNotFoundException("Product not found")); 29 | User user = userRepository.findById(userId) 30 | .orElseThrow(()-> new ResourceNotFoundException("User not found")); 31 | 32 | Comment comment = commentMapper.toEntity(commentDTO); 33 | comment.setProduct(product); 34 | comment.setUser(user); 35 | Comment savedComment = commentRepository.save(comment); 36 | return commentMapper.toDTO(savedComment); 37 | 38 | } 39 | 40 | public List getCommentsByProduct(Long productId){ 41 | List comments = commentRepository.findByProductId(productId); 42 | return comments.stream() 43 | .map(commentMapper::toDTO) 44 | .collect(Collectors.toList()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/EmailService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import com.example.demo.model.Order; 4 | import com.example.demo.model.User; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.mail.SimpleMailMessage; 8 | import org.springframework.mail.javamail.JavaMailSender; 9 | import org.springframework.stereotype.Service; 10 | 11 | @Service 12 | @RequiredArgsConstructor 13 | public class EmailService { 14 | private final JavaMailSender mailSender; 15 | 16 | @Value("spring.mail.username") 17 | private String fromEmail; 18 | 19 | public void sendOrderConfirmation(Order order){ 20 | SimpleMailMessage message = new SimpleMailMessage(); 21 | message.setFrom(fromEmail); 22 | message.setTo(order.getUser().getEmail()); 23 | message.setSubject("Order confirmation"); 24 | message.setText("Your order has been confirmed. Order ID " + order.getId()); 25 | mailSender.send(message); 26 | } 27 | 28 | public void sendConfirmationCode(User user){ 29 | SimpleMailMessage message = new SimpleMailMessage(); 30 | message.setFrom(fromEmail); 31 | message.setTo(user.getEmail()); 32 | message.setSubject("Confirm your email"); 33 | message.setText("Please confirm your email by entering this code " + user.getConfirmationCode()); 34 | mailSender.send(message); 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/JwtService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import io.jsonwebtoken.Claims; 4 | import io.jsonwebtoken.Jwts; 5 | import io.jsonwebtoken.SignatureAlgorithm; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.security.core.userdetails.UserDetails; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.Date; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | import java.util.function.Function; 14 | 15 | @Service 16 | public class JwtService { 17 | @Value("${jwt.secret}") 18 | private String secret; 19 | @Value("${jwt.expiration}") 20 | private Long expiration; 21 | 22 | public String generateToken(UserDetails userDetails){ 23 | Map claims = new HashMap<>(); 24 | return createToken(claims, userDetails.getUsername()); 25 | } 26 | private String createToken(Map claims, String subject){ 27 | return Jwts.builder() 28 | .setClaims(claims) 29 | .setSubject(subject) 30 | .setIssuedAt(new Date(System.currentTimeMillis())) 31 | .setExpiration(new Date(System.currentTimeMillis()+expiration)) 32 | .signWith(SignatureAlgorithm.HS256, secret) 33 | .compact(); 34 | } 35 | 36 | public Boolean validateToken(String token, UserDetails userDetails){ 37 | final String username = extractUsername(token); 38 | return (username.equals(userDetails.getUsername()) && !isTokenExpired(token)); 39 | } 40 | 41 | public String extractUsername (String token){ 42 | return extractClaim(token, Claims::getSubject); 43 | } 44 | 45 | private T extractClaim(String token, Function claimsResolver){ 46 | final Claims claims = extractAllClaims(token); 47 | return claimsResolver.apply(claims); 48 | } 49 | private Claims extractAllClaims(String token){ 50 | return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody(); 51 | } 52 | 53 | private Boolean isTokenExpired(String token){ 54 | return extractExpiration(token).before(new Date()); 55 | } 56 | private Date extractExpiration(String token){ 57 | return extractClaim(token, Claims::getExpiration); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import com.example.demo.dto.CartDTO; 4 | import com.example.demo.dto.OrderDTO; 5 | import com.example.demo.exception.InsufficientStockException; 6 | import com.example.demo.exception.ResourceNotFoundException; 7 | import com.example.demo.mapper.CartMapper; 8 | import com.example.demo.mapper.OrderMapper; 9 | import com.example.demo.model.*; 10 | import com.example.demo.repositories.OrderRepository; 11 | import com.example.demo.repositories.ProductRepository; 12 | import com.example.demo.repositories.UserRepository; 13 | import jakarta.persistence.EntityNotFoundException; 14 | import jakarta.transaction.Transactional; 15 | import lombok.RequiredArgsConstructor; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | import org.springframework.mail.MailException; 19 | import org.springframework.stereotype.Service; 20 | 21 | import java.time.LocalDateTime; 22 | import java.util.List; 23 | import java.util.stream.Collectors; 24 | 25 | @Service 26 | @RequiredArgsConstructor 27 | public class OrderService { 28 | private final Logger logger = LoggerFactory.getLogger(OrderService.class); 29 | 30 | private final OrderRepository orderRepository; 31 | private final CartService cartService; 32 | private final ProductRepository productRepository; 33 | private final UserRepository userRepository; 34 | private final EmailService emailService; 35 | private final OrderMapper orderMapper; 36 | private final CartMapper cartMapper; 37 | 38 | @Transactional 39 | public OrderDTO createOrder(Long userId, String address, String phoneNumber){ 40 | User user = userRepository.findById(userId) 41 | .orElseThrow(()->new ResourceNotFoundException("User not found")); 42 | if(!user.isEmailConfirmation()){ 43 | throw new IllegalStateException("Email not confirmed. Please confirm email before placing order"); 44 | } 45 | CartDTO cartDTO = cartService.getCart(userId); 46 | Cart cart = cartMapper.toEntity(cartDTO); 47 | 48 | if(cart.getItems().isEmpty()){ 49 | throw new IllegalStateException("Cannot create an order with an empty cart"); 50 | } 51 | 52 | Order order = new Order(); 53 | order.setUser(user); 54 | order.setAddress(address); 55 | order.setPhoneNumber(phoneNumber); 56 | order.setStatus(Order.OrderStatus.PREPARING); 57 | order.setCreatedAt(LocalDateTime.now()); 58 | 59 | List orderItems = createOrderItems(cart, order); 60 | order.setItems(orderItems); 61 | 62 | Order savedOrder = orderRepository.save(order); 63 | cartService.clearCart(userId); 64 | 65 | try{ 66 | emailService.sendOrderConfirmation(savedOrder); 67 | }catch (MailException e){ 68 | logger.error("Failed to send order confirmation email for order ID "+savedOrder.getId(), e); 69 | } 70 | return orderMapper.toDTO(savedOrder); 71 | } 72 | 73 | private List createOrderItems(Cart cart, Order order){ 74 | return cart.getItems().stream().map(cartItem -> { 75 | Product product = productRepository.findById(cartItem.getProduct().getId()) 76 | .orElseThrow(()-> new EntityNotFoundException("Product not found with id: "+cartItem.getProduct().getId())); 77 | 78 | if(product.getQuantity() == null){ 79 | throw new IllegalStateException("Product quantity is not set for product "+product.getName()); 80 | } 81 | if(product.getQuantity() < cartItem.getQuantity()){ 82 | throw new InsufficientStockException("Not enough stock for product "+product.getName()); 83 | } 84 | product.setQuantity(product.getQuantity() - cartItem.getQuantity()); 85 | productRepository.save(product); 86 | 87 | return new OrderItem(null, order, product, cartItem.getQuantity(), product.getPrice()); 88 | }).collect(Collectors.toList()); 89 | } 90 | 91 | public List getAllOrders(){ 92 | return orderMapper.toDTOs(orderRepository.findAll()); 93 | } 94 | 95 | public List getUserOrders(Long userId){ 96 | return orderMapper.toDTOs(orderRepository.findByUserId(userId)); 97 | } 98 | 99 | public OrderDTO updateOrderStatus(Long orderId,Order.OrderStatus status){ 100 | Order order = orderRepository.findById(orderId) 101 | .orElseThrow(()->new ResourceNotFoundException("Order not found")); 102 | order.setStatus(status); 103 | Order updatedOrder = orderRepository.save(order); 104 | return orderMapper.toDTO(updatedOrder); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import com.example.demo.dto.ProductDTO; 4 | import com.example.demo.dto.ProductListDTO; 5 | import com.example.demo.exception.ResourceNotFoundException; 6 | import com.example.demo.mapper.ProductMapper; 7 | import com.example.demo.model.Product; 8 | import com.example.demo.repositories.ProductRepository; 9 | import jakarta.transaction.Transactional; 10 | import lombok.RequiredArgsConstructor; 11 | import org.springframework.data.domain.Page; 12 | import org.springframework.data.domain.Pageable; 13 | import org.springframework.stereotype.Service; 14 | import org.springframework.web.multipart.MultipartFile; 15 | 16 | import java.io.IOException; 17 | import java.nio.file.Files; 18 | import java.nio.file.Path; 19 | import java.nio.file.Paths; 20 | import java.util.List; 21 | import java.util.UUID; 22 | 23 | @Service 24 | @RequiredArgsConstructor 25 | public class ProductService { 26 | private final ProductRepository productRepository; 27 | private final ProductMapper productMapper; 28 | 29 | private static final String UPLOAD_DIR = "src/main/resources/static/images/"; 30 | 31 | @Transactional 32 | public ProductDTO createProduct(ProductDTO productDTO, MultipartFile image) throws IOException{ 33 | Product product = productMapper.toEntity(productDTO); 34 | if(image != null && !image.isEmpty()){ 35 | String fileName = saveImage(image); 36 | product.setImage("/images/"+fileName); 37 | } 38 | Product savedProduct = productRepository.save(product); 39 | return productMapper.toDTO(savedProduct); 40 | } 41 | 42 | @Transactional 43 | public ProductDTO updateProduct(Long id, ProductDTO productDTO, MultipartFile image) throws IOException{ 44 | Product existingProduct = productRepository.findById(id) 45 | .orElseThrow(()-> new ResourceNotFoundException("Product not found")); 46 | existingProduct.setName(productDTO.getName()); 47 | existingProduct.setDescription(productDTO.getDescription()); 48 | existingProduct.setPrice(productDTO.getPrice()); 49 | existingProduct.setQuantity(productDTO.getQuantity()); 50 | if(image != null && !image.isEmpty()){ 51 | String fileName = saveImage(image); 52 | existingProduct.setImage("/images/" + fileName); 53 | } 54 | Product updatedProduct = productRepository.save(existingProduct); 55 | return productMapper.toDTO(updatedProduct); 56 | } 57 | 58 | @Transactional 59 | public void deleteProduct(Long id){ 60 | if(!productRepository.existsById(id)){ 61 | throw new ResourceNotFoundException("Product not found"); 62 | } 63 | productRepository.deleteById(id); 64 | } 65 | 66 | public ProductDTO getProduct(Long id){ 67 | Product product = productRepository.findById(id) 68 | .orElseThrow(()-> new ResourceNotFoundException("Product not found")); 69 | return productMapper.toDTO(product); 70 | } 71 | 72 | public Page getAllProducts(Pageable pageable) { 73 | return productRepository.findAllWithoutComments(pageable); 74 | } 75 | private String saveImage(MultipartFile image) throws IOException{ 76 | String fileName = UUID.randomUUID().toString()+"_"+image.getOriginalFilename(); 77 | Path path = Paths.get(UPLOAD_DIR + fileName); 78 | Files.createDirectories(path.getParent()); 79 | Files.write(path, image.getBytes()); 80 | return fileName; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/example/demo/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.service; 2 | 3 | import com.example.demo.dto.ChangePasswordRequest; 4 | import com.example.demo.exception.ResourceNotFoundException; 5 | import com.example.demo.model.User; 6 | import com.example.demo.repositories.UserRepository; 7 | import lombok.RequiredArgsConstructor; 8 | import org.springframework.security.authentication.BadCredentialsException; 9 | import org.springframework.security.crypto.password.PasswordEncoder; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.Random; 13 | import java.util.UUID; 14 | 15 | @Service 16 | @RequiredArgsConstructor 17 | public class UserService { 18 | private final UserRepository userRepository; 19 | private final PasswordEncoder passwordEncoder; 20 | private final EmailService emailService; 21 | 22 | public User registerUser(User user){ 23 | if(userRepository.findByEmail(user.getEmail()).isPresent()) { 24 | throw new IllegalStateException("Email already taken"); 25 | } 26 | user.setPassword(passwordEncoder.encode(user.getPassword())); 27 | user.setRole(User.Role.USER); 28 | user.setConfirmationCode(generateConfirmationCode()); 29 | user.setEmailConfirmation(false); 30 | emailService.sendConfirmationCode(user); 31 | return userRepository.save(user); 32 | } 33 | 34 | public User getUserByEmail(String email){ 35 | return userRepository.findByEmail(email).orElseThrow(()-> new ResourceNotFoundException("User not found")); 36 | } 37 | 38 | public void changePassword(String email, ChangePasswordRequest request){ 39 | User user = getUserByEmail(email); 40 | if(!passwordEncoder.matches(request.getCurrentPassword(), user.getPassword())) { 41 | throw new BadCredentialsException("Current password is incorrect"); 42 | } 43 | 44 | user.setPassword(passwordEncoder.encode(request.getNewPassword())); 45 | userRepository.save(user); 46 | } 47 | 48 | public void confirmEmail(String email, String confirmationCode){ 49 | User user = getUserByEmail(email); 50 | if(user.getConfirmationCode().equals(confirmationCode)){ 51 | user.setEmailConfirmation(true); 52 | user.setConfirmationCode(null); 53 | userRepository.save(user); 54 | } 55 | else{ 56 | throw new BadCredentialsException("Invalid confirmation code"); 57 | } 58 | } 59 | 60 | private String generateConfirmationCode(){ 61 | Random random = new Random(); 62 | int code = 100000 + random.nextInt(900000); 63 | return String.valueOf(code); 64 | } 65 | 66 | //update 67 | public User getUserById(Long id) { 68 | return userRepository.findById(id) 69 | .orElseThrow(() -> new ResourceNotFoundException("User not found with id: " + id)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=ecommerce2 2 | # PostgreSQL database configuration 3 | spring.datasource.url=jdbc:postgresql://localhost:5432/mydatabase 4 | spring.datasource.username=myuser 5 | spring.datasource.password=mypassword 6 | spring.datasource.driver-class-name=org.postgresql.Driver 7 | 8 | spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect 9 | spring.jpa.show-sql=true 10 | spring.jpa.hibernate.ddl-auto=update 11 | 12 | 13 | # Server configuration 14 | spring.main.allow-bean-definition-overriding=true 15 | 16 | 17 | # JWT Configuration 18 | jwt.secret=eyJhbGciOiJIUzI1NiJ9.eyJSb2xlIjoiQWRtaW4iLCJJc3N9dPip32yQynt59595E 19 | jwt.expiration=86400000 20 | 21 | # Email Configuration (Mailtrap) 22 | spring.mail.host=sandbox.smtp.mailtrap.io 23 | spring.mail.port=2525 24 | spring.mail.username=3210de6d30d855 25 | spring.mail.password=69014a644841e4 26 | spring.mail.properties.mail.smtp.auth=true 27 | spring.mail.properties.mail.smtp.starttls.enable=true 28 | 29 | # Server Configuration 30 | server.port=8080 -------------------------------------------------------------------------------- /src/main/resources/static/images/05134a2a-cb8e-4f5e-9680-22d0a479c918_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/05134a2a-cb8e-4f5e-9680-22d0a479c918_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/0a59d671-aaae-4aa4-8c10-7fcd483f8f8f_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/0a59d671-aaae-4aa4-8c10-7fcd483f8f8f_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/1e5ba1cc-78e5-47c2-ba0c-fe01ba86cdb5_anime-night-city-f4uhf40u30rw7oxf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/1e5ba1cc-78e5-47c2-ba0c-fe01ba86cdb5_anime-night-city-f4uhf40u30rw7oxf.jpg -------------------------------------------------------------------------------- /src/main/resources/static/images/30b5207e-f70d-4afa-86dd-7cbba4627c93_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/30b5207e-f70d-4afa-86dd-7cbba4627c93_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/31acfa7b-f6c1-4e56-adcd-79477cd257ea_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/31acfa7b-f6c1-4e56-adcd-79477cd257ea_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/33df105f-b9a0-4459-94fc-cd1b53a20819_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/33df105f-b9a0-4459-94fc-cd1b53a20819_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/3a7cbc90-c1a5-49e7-a818-889923a56e6f_anime-night-city-f4uhf40u30rw7oxf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/3a7cbc90-c1a5-49e7-a818-889923a56e6f_anime-night-city-f4uhf40u30rw7oxf.jpg -------------------------------------------------------------------------------- /src/main/resources/static/images/4debbd7f-a5fa-4e0a-bee7-4a275382ff5a_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/4debbd7f-a5fa-4e0a-bee7-4a275382ff5a_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/540698ec-1bf0-4964-920a-8668460ae9ef_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/540698ec-1bf0-4964-920a-8668460ae9ef_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/599e8948-850b-4b19-9184-c348a60a968e_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/599e8948-850b-4b19-9184-c348a60a968e_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/5ab7a82f-7059-40c7-bb7f-b458e5bbeac6_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/5ab7a82f-7059-40c7-bb7f-b458e5bbeac6_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/a45e6d62-065b-43dc-94b1-17c931cbf6c5_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/a45e6d62-065b-43dc-94b1-17c931cbf6c5_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/b2038204-a865-4ab4-8986-26c7795e981d_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/b2038204-a865-4ab4-8986-26c7795e981d_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/dc66fef7-5023-477a-866b-423283e15ae6_Leonardo_Anime_XL_create_a_consistent_anime_character_with_neu_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/dc66fef7-5023-477a-866b-423283e15ae6_Leonardo_Anime_XL_create_a_consistent_anime_character_with_neu_2.jpg -------------------------------------------------------------------------------- /src/main/resources/static/images/ddba168b-371a-40dd-836a-6a3282cb8213_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/ddba168b-371a-40dd-836a-6a3282cb8213_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/efac1b1b-da37-4b15-9fed-86725f1fface_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/efac1b1b-da37-4b15-9fed-86725f1fface_1.png -------------------------------------------------------------------------------- /src/main/resources/static/images/f7c72cb4-7993-42b5-914d-3ddc37fd7fd1_Leonardo_Anime_XL_Create_a_young_Asian_woman_with_blonde_highl_1.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlemkhanIT/ecommerce-tutorial/aa7697207e47314a426e7743269c72fd0d21c4fd/src/main/resources/static/images/f7c72cb4-7993-42b5-914d-3ddc37fd7fd1_Leonardo_Anime_XL_Create_a_young_Asian_woman_with_blonde_highl_1.webp -------------------------------------------------------------------------------- /src/test/java/com/example/demo/Ecommerce2ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Ecommerce2ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------