├── backend ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── shopy │ │ │ ├── ShopyApplication.java │ │ │ ├── WebConfig.java │ │ │ ├── controller │ │ │ ├── AdminController.java │ │ │ ├── AdminLoginController.java │ │ │ ├── CartController.java │ │ │ ├── CategoryController.java │ │ │ ├── CustomerController.java │ │ │ ├── OrderController.java │ │ │ ├── ProductController.java │ │ │ └── UserLoginController.java │ │ │ ├── dto │ │ │ └── ExceptionDTO.java │ │ │ ├── exception │ │ │ ├── AdminException.java │ │ │ ├── BillException.java │ │ │ ├── CartException.java │ │ │ ├── CategoryException.java │ │ │ ├── CustomerException.java │ │ │ ├── GlobalExceptionHandler.java │ │ │ ├── LoginException.java │ │ │ ├── OrderException.java │ │ │ └── ProductException.java │ │ │ ├── model │ │ │ ├── Address.java │ │ │ ├── Admin.java │ │ │ ├── Cart.java │ │ │ ├── Category.java │ │ │ ├── CurrentAdminSession.java │ │ │ ├── CurrentUserSession.java │ │ │ ├── Customer.java │ │ │ ├── Login.java │ │ │ ├── Order.java │ │ │ ├── Product.java │ │ │ └── ProductDTO.java │ │ │ ├── repository │ │ │ ├── AdminRepo.java │ │ │ ├── AdminSessionRepo.java │ │ │ ├── CartRepo.java │ │ │ ├── CategoryRepo.java │ │ │ ├── CustomerRepo.java │ │ │ ├── OrderRepo.java │ │ │ ├── ProductRepo.java │ │ │ └── UserSessionRepo.java │ │ │ └── service │ │ │ ├── AdminLogin.java │ │ │ ├── AdminLoginImpl.java │ │ │ ├── AdminService.java │ │ │ ├── AdminServiceImpl.java │ │ │ ├── CartService.java │ │ │ ├── CartServiceImpl.java │ │ │ ├── CategoryService.java │ │ │ ├── CategoryServiceImpl.java │ │ │ ├── CustomerLogin.java │ │ │ ├── CustomerLoginImpl.java │ │ │ ├── CustomerService.java │ │ │ ├── CustomerServiceImpl.java │ │ │ ├── OrderService.java │ │ │ ├── OrderServiceImpl.java │ │ │ ├── ProductService.java │ │ │ └── ProductServiceImpl.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── shopy │ └── ShopyApplicationTests.java └── frontend ├── .vscode └── settings.json ├── admin.html ├── adminlogin.html ├── cart.html ├── cart2.html ├── category.html ├── index.html ├── js ├── admin.js ├── cart.js ├── category.js ├── index.js ├── order.js ├── product.js └── user.js ├── nav.css ├── order.html ├── product.html ├── style.css ├── user.html └── userprofile.html /backend/.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 | -------------------------------------------------------------------------------- /backend/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dineshjangid03/e-commerce_API/a8819628582bd79693fe9758dd14dc371b8779ee/backend/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /backend/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /backend/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 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /backend/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /backend/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.5 9 | 10 | 11 | com.example 12 | shopy 13 | 0.0.1-SNAPSHOT 14 | shopy 15 | Demo project for Spring Boot 16 | 17 | 17 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-data-jpa 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-validation 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-devtools 37 | runtime 38 | true 39 | 40 | 41 | com.mysql 42 | mysql-connector-j 43 | runtime 44 | 45 | 46 | org.projectlombok 47 | lombok 48 | true 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-starter-test 53 | test 54 | 55 | 56 | 57 | 58 | io.springfox 59 | springfox-swagger-ui 60 | 3.0.0 61 | 62 | 63 | io.springfox 64 | springfox-swagger2 65 | 3.0.0 66 | 67 | 68 | io.springfox 69 | springfox-boot-starter 70 | 3.0.0 71 | 72 | 73 | 74 | 75 | 76 | 77 | org.springframework.boot 78 | spring-boot-maven-plugin 79 | 80 | 81 | 82 | org.projectlombok 83 | lombok 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/ShopyApplication.java: -------------------------------------------------------------------------------- 1 | package com.shopy; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 7 | 8 | @SpringBootApplication 9 | @EnableSwagger2 10 | public class ShopyApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(ShopyApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/WebConfig.java: -------------------------------------------------------------------------------- 1 | package com.shopy; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | @Configuration 8 | public class WebConfig implements WebMvcConfigurer{ 9 | 10 | @Override 11 | public void addCorsMappings(CorsRegistry registry) { 12 | // TODO Auto-generated method stub 13 | registry.addMapping("/**").allowedMethods("*"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/controller/AdminController.java: -------------------------------------------------------------------------------- 1 | package com.shopy.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.DeleteMapping; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PostMapping; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestParam; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import com.shopy.exception.AdminException; 17 | import com.shopy.model.Admin; 18 | import com.shopy.service.AdminService; 19 | 20 | @RestController 21 | @RequestMapping("/admin") 22 | public class AdminController { 23 | 24 | @Autowired 25 | private AdminService as; 26 | 27 | @PostMapping("/register") 28 | public ResponseEntity registerAdmin(@RequestBody Admin admin, @RequestParam(required = true) String validationKey)throws AdminException{ 29 | Admin ad=as.registerAdmin(admin, validationKey); 30 | return new ResponseEntity(ad,HttpStatus.ACCEPTED); 31 | } 32 | 33 | @GetMapping("/viewAllAdmin") 34 | public ResponseEntity> viewAllAdmin(String key)throws AdminException{ 35 | Listlist=as.viewAllAdmin(key); 36 | return new ResponseEntity>(list,HttpStatus.ACCEPTED); 37 | } 38 | 39 | @DeleteMapping("/deleteAdmin") 40 | public ResponseEntity deleteAdmin(Admin admin, String key)throws AdminException{ 41 | Admin ad=as.deleteAdmin(admin, key); 42 | return new ResponseEntity(ad,HttpStatus.ACCEPTED); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/controller/AdminLoginController.java: -------------------------------------------------------------------------------- 1 | package com.shopy.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.PostMapping; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.shopy.exception.LoginException; 13 | import com.shopy.model.CurrentAdminSession; 14 | import com.shopy.model.Login; 15 | import com.shopy.service.AdminLogin; 16 | 17 | @RestController 18 | @RequestMapping("/adminlogin") 19 | public class AdminLoginController { 20 | 21 | @Autowired 22 | private AdminLogin al; 23 | 24 | @PostMapping("/login") 25 | public ResponseEntity adminLogin(@RequestBody Login dto) throws LoginException{ 26 | CurrentAdminSession res=al.adminLog(dto); 27 | return new ResponseEntity(res,HttpStatus.ACCEPTED); 28 | } 29 | 30 | @PostMapping("/logout") 31 | public ResponseEntity adminLogout(@RequestParam(required = false)String key) throws LoginException{ 32 | String res=al.adminLogOut(key); 33 | return new ResponseEntity(res,HttpStatus.ACCEPTED); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/controller/CartController.java: -------------------------------------------------------------------------------- 1 | package com.shopy.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.DeleteMapping; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.PutMapping; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import com.shopy.exception.CartException; 16 | import com.shopy.exception.CustomerException; 17 | import com.shopy.exception.ProductException; 18 | import com.shopy.model.Cart; 19 | import com.shopy.service.CartService; 20 | 21 | @RestController 22 | @RequestMapping("/cart") 23 | public class CartController { 24 | 25 | @Autowired 26 | private CartService cs; 27 | 28 | @GetMapping("/view/{uuidKey}") 29 | public ResponseEntity viewCart(@PathVariable("uuidKey") String key) throws CartException { 30 | Cart c=cs.cartByCustomerId(key); 31 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 32 | } 33 | 34 | // @PostMapping("/add/{uuidKey}") 35 | // public ResponseEntity addCart(@RequestBody Cart cart, @PathVariable("uuidKey") String key) throws CustomerException{ 36 | // Cart c=cs.addCart(cart,key); 37 | // return new ResponseEntity(c,HttpStatus.ACCEPTED); 38 | // } 39 | 40 | // @GetMapping("/view/{id}/{uuidKey}") 41 | // public ResponseEntity viewCart(@PathVariable("id") int cartId, @PathVariable("uuidKey") String key) throws CartException { 42 | // Cart c=cs.viewCart(cartId,key); 43 | // return new ResponseEntity(c,HttpStatus.ACCEPTED); 44 | // } 45 | 46 | @PutMapping("/addItemIntoCart/{productId}/{uuidKey}") 47 | public ResponseEntity addItemIntoCart(@PathVariable("productId") int productId, @PathVariable("uuidKey") String key) throws CartException, ProductException { 48 | Cart c=cs.addItemIntoCart(productId,key); 49 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 50 | } 51 | 52 | @PutMapping("/removeItemFromCart/{productId}/{uuidKey}") 53 | public ResponseEntity removeItemFromCart(@PathVariable("productId") int productId, @PathVariable("uuidKey") String key) throws CartException, ProductException { 54 | Cart c=cs.removeItemFromCart(productId,key); 55 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 56 | } 57 | 58 | @PutMapping("/increaseQuantity/{productId}/{uuidKey}") 59 | public ResponseEntity increaseQuantity(@PathVariable("productId") int productId, @PathVariable("uuidKey") String key) throws CartException, ProductException { 60 | Cart c=cs.increaseQuantity(productId, key); 61 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 62 | } 63 | 64 | @PutMapping("/decreaseQuantity/{productId}/{uuidKey}") 65 | public ResponseEntity decreaseQuantity(@PathVariable("productId") int productId, @PathVariable("uuidKey") String key) throws CartException, ProductException { 66 | Cart c=cs.decreaseQuantity(productId, key); 67 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 68 | } 69 | 70 | @PutMapping("/clearCart/{uuidKey}") 71 | public ResponseEntity clearCart(@PathVariable("uuidKey") String key) throws CartException { 72 | Cart c=cs.clearCart(key); 73 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 74 | } 75 | 76 | // @DeleteMapping("/deleteCart/{cartId}/{uuidKey}") 77 | // public ResponseEntity deleteCart(@PathVariable("cartId") int cartId, @PathVariable("uuidKey") String key) throws CartException { 78 | // Cart c=cs.deleteCart(cartId,key); 79 | // return new ResponseEntity(c,HttpStatus.ACCEPTED); 80 | // } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/controller/CategoryController.java: -------------------------------------------------------------------------------- 1 | package com.shopy.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.DeleteMapping; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | import org.springframework.web.bind.annotation.RequestBody; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import com.shopy.exception.CategoryException; 17 | import com.shopy.model.Category; 18 | import com.shopy.model.Product; 19 | import com.shopy.service.CategoryService; 20 | 21 | @RestController 22 | @RequestMapping("/category") 23 | public class CategoryController { 24 | 25 | @Autowired 26 | private CategoryService cs; 27 | 28 | @PostMapping("/add/{uuidKey}") 29 | public ResponseEntity addCategory(@RequestBody Category category, @PathVariable("uuidKey") String key) throws CategoryException { 30 | Category c=cs.addCategory(category,key); 31 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 32 | } 33 | 34 | @GetMapping("/view/{id}") 35 | public ResponseEntity viewCategory(@PathVariable("id") int categoryId) throws CategoryException { 36 | Category c=cs.viewCategory(categoryId); 37 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 38 | 39 | } 40 | 41 | @DeleteMapping("/delete/{id}/{uuidKey}") 42 | public ResponseEntity deleteCategory(@PathVariable("id") int categoryId, @PathVariable("uuidKey") String key) throws CategoryException { 43 | Category c=cs.deleteCategory(categoryId,key); 44 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 45 | } 46 | 47 | @GetMapping("/viewAll") 48 | public ResponseEntity> allCategory() throws CategoryException { 49 | Listc=cs.allCategory(); 50 | return new ResponseEntity>(c,HttpStatus.ACCEPTED); 51 | } 52 | 53 | @GetMapping("/viewProductByCategory/{id}") 54 | public ResponseEntity> productByCategory(@PathVariable("id") int categoryId) throws CategoryException { 55 | Listlist=cs.productByCategory(categoryId); 56 | return new ResponseEntity>(list,HttpStatus.ACCEPTED); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/controller/CustomerController.java: -------------------------------------------------------------------------------- 1 | package com.shopy.controller; 2 | 3 | import java.util.List; 4 | 5 | import javax.validation.Valid; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.web.bind.annotation.DeleteMapping; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.PathVariable; 13 | import org.springframework.web.bind.annotation.PostMapping; 14 | import org.springframework.web.bind.annotation.PutMapping; 15 | import org.springframework.web.bind.annotation.RequestBody; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RequestParam; 18 | import org.springframework.web.bind.annotation.RestController; 19 | 20 | import com.shopy.exception.CustomerException; 21 | import com.shopy.model.Customer; 22 | import com.shopy.model.Order; 23 | import com.shopy.service.CustomerService; 24 | 25 | @RestController 26 | @RequestMapping("/customer") 27 | public class CustomerController { 28 | 29 | @Autowired 30 | private CustomerService cs; 31 | 32 | @PostMapping("/register") 33 | public ResponseEntity registerCustomer(@Valid @RequestBody Customer customer) throws CustomerException { 34 | Customer c=cs.registerCustomer(customer); 35 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 36 | } 37 | 38 | @GetMapping("/view/{uuid}") 39 | public ResponseEntity viewCustomer(@PathVariable("uuid") String uuid) throws CustomerException { 40 | Customer c=cs.viewCustomer(uuid); 41 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 42 | } 43 | 44 | @PutMapping("/update") 45 | public ResponseEntity updateCustomer(@RequestBody Customer customer, @RequestParam(required = false) String key ) throws CustomerException { 46 | Customer c=cs.updateCustomer(customer, key); 47 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 48 | } 49 | 50 | @DeleteMapping("/delete/{id}") 51 | public ResponseEntity deleteCustomer(@PathVariable("id") int customerId, @RequestParam(required = false) String key) throws CustomerException { 52 | Customer c=cs.deleteCustomer(customerId, key); 53 | return new ResponseEntity(c,HttpStatus.ACCEPTED); 54 | } 55 | 56 | @GetMapping("/viewOrders/{uuid}") 57 | public ResponseEntity> viewOrders(@PathVariable("uuid") String uuid) throws CustomerException { 58 | Listlist=cs.viewOrders(uuid); 59 | return new ResponseEntity>(list,HttpStatus.ACCEPTED); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.shopy.controller; 2 | 3 | import java.time.LocalDate; 4 | import java.util.List; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.format.annotation.DateTimeFormat; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.web.bind.annotation.DeleteMapping; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.PathVariable; 13 | import org.springframework.web.bind.annotation.PostMapping; 14 | import org.springframework.web.bind.annotation.PutMapping; 15 | import org.springframework.web.bind.annotation.RequestBody; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | import com.shopy.exception.AdminException; 20 | import com.shopy.exception.CartException; 21 | import com.shopy.exception.OrderException; 22 | import com.shopy.model.Order; 23 | import com.shopy.service.OrderService; 24 | 25 | @RestController 26 | @RequestMapping("/order") 27 | public class OrderController { 28 | 29 | @Autowired 30 | private OrderService os; 31 | 32 | @PostMapping("/addOrder/{uuid}") 33 | public ResponseEntity addOrder(@PathVariable("uuid") String uuid) throws OrderException, CartException { 34 | Order o=os.addOrder(uuid); 35 | return new ResponseEntity(o,HttpStatus.ACCEPTED); 36 | } 37 | 38 | @GetMapping("/viewOrder/{orderId}") 39 | public ResponseEntity viewOrder(@PathVariable("orderId") int orderId) throws OrderException { 40 | Order o=os.viewOrder(orderId); 41 | return new ResponseEntity(o,HttpStatus.ACCEPTED); 42 | } 43 | 44 | @GetMapping("/viewOrdersByDate/{startDate}/{endDate}") 45 | public ResponseEntity> viewOrdersByDate(@PathVariable("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, @PathVariable("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) throws OrderException { 46 | List list=os.viewOrdersByDate(startDate, endDate); 47 | return new ResponseEntity>(list,HttpStatus.ACCEPTED); 48 | } 49 | 50 | @GetMapping("/viewAllOrder") 51 | public ResponseEntity> viewAllOrder() throws OrderException, AdminException { 52 | List list=os.viewAllOrder(); 53 | return new ResponseEntity>(list,HttpStatus.ACCEPTED); 54 | } 55 | 56 | @PutMapping("/updateOrderStatus/{orderId}/{status}") 57 | public ResponseEntity updateOrderStatus(@PathVariable("orderId") int orderId, @PathVariable("status") String status) throws OrderException { 58 | Order o=os.updateOrderStatus(orderId, status); 59 | return new ResponseEntity(o,HttpStatus.ACCEPTED); 60 | } 61 | 62 | @DeleteMapping("/deleteOrder/{orderId}") 63 | public ResponseEntity deleteOrder(@PathVariable("orderId") int orderId) throws OrderException { 64 | Order o=os.deleteOrder(orderId); 65 | return new ResponseEntity(o,HttpStatus.ACCEPTED); 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/controller/ProductController.java: -------------------------------------------------------------------------------- 1 | package com.shopy.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.DeleteMapping; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | import org.springframework.web.bind.annotation.PutMapping; 13 | import org.springframework.web.bind.annotation.RequestBody; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | import com.shopy.exception.CategoryException; 18 | import com.shopy.exception.ProductException; 19 | import com.shopy.model.Product; 20 | import com.shopy.service.ProductService; 21 | 22 | @RestController 23 | @RequestMapping("/product") 24 | public class ProductController { 25 | 26 | @Autowired 27 | private ProductService ps; 28 | 29 | @PostMapping("/add/{categoryId}/{uuidKey}") 30 | public ResponseEntity addProduct(@RequestBody Product product, @PathVariable("categoryId") int categoryId, @PathVariable("uuidKey") String key) throws ProductException, CategoryException { 31 | Product p=ps.addProduct(product, categoryId, key); 32 | return new ResponseEntity(p,HttpStatus.ACCEPTED); 33 | } 34 | 35 | @GetMapping("/view/{productId}") 36 | public ResponseEntity viewProduct(@PathVariable("productId") int productId) throws ProductException { 37 | Product p=ps.viewProduct(productId); 38 | return new ResponseEntity(p,HttpStatus.ACCEPTED); 39 | } 40 | 41 | @GetMapping("/viewAllProduct") 42 | public ResponseEntity> allProduct() throws ProductException { 43 | Listlist=ps.allProduct(); 44 | return new ResponseEntity>(list,HttpStatus.ACCEPTED); 45 | } 46 | 47 | @DeleteMapping("/delete/{productId}/{uuidKey}") 48 | public ResponseEntity removeProduct(@PathVariable("productId") int productId, @PathVariable("uuidKey") String key) throws ProductException { 49 | Product p=ps.removeProduct(productId, key); 50 | return new ResponseEntity(p,HttpStatus.ACCEPTED); 51 | } 52 | 53 | @PutMapping("/update/{uuidKey}") 54 | public ResponseEntity updateProduct(@RequestBody Product product, @PathVariable("uuidKey") String key) throws ProductException { 55 | Product p=ps.updateProduct(product, key); 56 | return new ResponseEntity(p,HttpStatus.ACCEPTED); 57 | } 58 | 59 | // @GetMapping("/productByName/{name}") 60 | // public ResponseEntity> productByName(@PathVariable("name") String name) throws ProductException { 61 | // Listlist=ps.productByName(name); 62 | // return new ResponseEntity>(list,HttpStatus.ACCEPTED); 63 | // } 64 | 65 | @GetMapping("/productByName/{name}") 66 | public ResponseEntity> productByNameLike(@PathVariable("name") String name) throws ProductException { 67 | Listlist=ps.productByNameLike(name); 68 | return new ResponseEntity>(list,HttpStatus.ACCEPTED); 69 | } 70 | 71 | @GetMapping("/top5") 72 | public ResponseEntity> top5() throws ProductException { 73 | Listlist=ps.top5(); 74 | return new ResponseEntity>(list,HttpStatus.ACCEPTED); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/controller/UserLoginController.java: -------------------------------------------------------------------------------- 1 | package com.shopy.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.PostMapping; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.shopy.exception.LoginException; 13 | import com.shopy.model.CurrentUserSession; 14 | import com.shopy.model.Login; 15 | import com.shopy.service.CustomerLogin; 16 | 17 | @RestController 18 | @RequestMapping("/userlogin") 19 | public class UserLoginController { 20 | 21 | @Autowired 22 | private CustomerLogin cl; 23 | 24 | @PostMapping("/login") 25 | public ResponseEntity userLogin(@RequestBody Login dto) throws LoginException{ 26 | CurrentUserSession res=cl.logIntoAccount(dto); 27 | return new ResponseEntity(res,HttpStatus.ACCEPTED); 28 | } 29 | 30 | @PostMapping("/logout") 31 | public ResponseEntity userLogout(@RequestParam(required = false)String key) throws LoginException{ 32 | String res=cl.logOutFromAccount(key); 33 | return new ResponseEntity(res,HttpStatus.ACCEPTED); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/dto/ExceptionDTO.java: -------------------------------------------------------------------------------- 1 | package com.shopy.dto; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import lombok.Data; 6 | 7 | @Data 8 | public class ExceptionDTO { 9 | 10 | private LocalDateTime dateAndTime; 11 | 12 | private String message; 13 | 14 | private String desc; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/exception/AdminException.java: -------------------------------------------------------------------------------- 1 | package com.shopy.exception; 2 | 3 | public class AdminException extends Exception{ 4 | 5 | public AdminException() { 6 | super(); 7 | // TODO Auto-generated constructor stub 8 | } 9 | 10 | public AdminException(String message) { 11 | super(message); 12 | // TODO Auto-generated constructor stub 13 | } 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/exception/BillException.java: -------------------------------------------------------------------------------- 1 | package com.shopy.exception; 2 | 3 | public class BillException extends Exception{ 4 | 5 | public BillException() { 6 | super(); 7 | // TODO Auto-generated constructor stub 8 | } 9 | 10 | public BillException(String message) { 11 | super(message); 12 | // TODO Auto-generated constructor stub 13 | } 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/exception/CartException.java: -------------------------------------------------------------------------------- 1 | package com.shopy.exception; 2 | 3 | public class CartException extends Exception{ 4 | 5 | public CartException() { 6 | super(); 7 | // TODO Auto-generated constructor stub 8 | } 9 | 10 | public CartException(String message) { 11 | super(message); 12 | // TODO Auto-generated constructor stub 13 | } 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/exception/CategoryException.java: -------------------------------------------------------------------------------- 1 | package com.shopy.exception; 2 | 3 | public class CategoryException extends Exception{ 4 | 5 | public CategoryException() { 6 | super(); 7 | // TODO Auto-generated constructor stub 8 | } 9 | 10 | public CategoryException(String message) { 11 | super(message); 12 | // TODO Auto-generated constructor stub 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/exception/CustomerException.java: -------------------------------------------------------------------------------- 1 | package com.shopy.exception; 2 | 3 | public class CustomerException extends Exception{ 4 | 5 | public CustomerException() { 6 | super(); 7 | // TODO Auto-generated constructor stub 8 | } 9 | 10 | public CustomerException(String message) { 11 | super(message); 12 | // TODO Auto-generated constructor stub 13 | } 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.shopy.exception; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.MethodArgumentNotValidException; 8 | import org.springframework.web.bind.annotation.ControllerAdvice; 9 | import org.springframework.web.bind.annotation.ExceptionHandler; 10 | import org.springframework.web.context.request.WebRequest; 11 | import org.springframework.web.servlet.NoHandlerFoundException; 12 | 13 | import com.shopy.dto.ExceptionDTO; 14 | 15 | @ControllerAdvice 16 | public class GlobalExceptionHandler { 17 | 18 | @ExceptionHandler(AdminException.class) 19 | public ResponseEntity adminExceptionHandler(AdminException e, WebRequest wr){ 20 | 21 | ExceptionDTO err=new ExceptionDTO(); 22 | err.setDateAndTime(LocalDateTime.now()); 23 | err.setMessage(e.getMessage()); 24 | err.setDesc(wr.getDescription(false)); 25 | 26 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST); 27 | 28 | } 29 | 30 | @ExceptionHandler(LoginException.class) 31 | public ResponseEntity loginExceptionHandler(LoginException e, WebRequest wr){ 32 | 33 | ExceptionDTO err=new ExceptionDTO(); 34 | err.setDateAndTime(LocalDateTime.now()); 35 | err.setMessage(e.getMessage()); 36 | err.setDesc(wr.getDescription(false)); 37 | 38 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST); 39 | 40 | } 41 | 42 | @ExceptionHandler(ProductException.class) 43 | public ResponseEntity productExceptionHandler(ProductException e, WebRequest wr){ 44 | 45 | ExceptionDTO err=new ExceptionDTO(); 46 | err.setDateAndTime(LocalDateTime.now()); 47 | err.setMessage(e.getMessage()); 48 | err.setDesc(wr.getDescription(false)); 49 | 50 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST); 51 | 52 | } 53 | 54 | @ExceptionHandler(OrderException.class) 55 | public ResponseEntity orderExceptionHandler(OrderException e, WebRequest wr){ 56 | 57 | ExceptionDTO err=new ExceptionDTO(); 58 | err.setDateAndTime(LocalDateTime.now()); 59 | err.setMessage(e.getMessage()); 60 | err.setDesc(wr.getDescription(false)); 61 | 62 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST); 63 | 64 | } 65 | 66 | @ExceptionHandler(CustomerException.class) 67 | public ResponseEntity customerExceptionHandler(CustomerException e, WebRequest wr){ 68 | 69 | ExceptionDTO err=new ExceptionDTO(); 70 | err.setDateAndTime(LocalDateTime.now()); 71 | err.setMessage(e.getMessage()); 72 | err.setDesc(wr.getDescription(false)); 73 | 74 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST); 75 | 76 | } 77 | 78 | @ExceptionHandler(CategoryException.class) 79 | public ResponseEntity categoryExceptionHandler(CategoryException e, WebRequest wr){ 80 | 81 | ExceptionDTO err=new ExceptionDTO(); 82 | err.setDateAndTime(LocalDateTime.now()); 83 | err.setMessage(e.getMessage()); 84 | err.setDesc(wr.getDescription(false)); 85 | 86 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST); 87 | 88 | } 89 | 90 | @ExceptionHandler(CartException.class) 91 | public ResponseEntity cartExceptionHandler(CartException e, WebRequest wr){ 92 | 93 | ExceptionDTO err=new ExceptionDTO(); 94 | err.setDateAndTime(LocalDateTime.now()); 95 | err.setMessage(e.getMessage()); 96 | err.setDesc(wr.getDescription(false)); 97 | 98 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST); 99 | 100 | } 101 | 102 | @ExceptionHandler(BillException.class) 103 | public ResponseEntity billExceptionHandler(BillException e, WebRequest wr){ 104 | 105 | ExceptionDTO err=new ExceptionDTO(); 106 | err.setDateAndTime(LocalDateTime.now()); 107 | err.setMessage(e.getMessage()); 108 | err.setDesc(wr.getDescription(false)); 109 | 110 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST); 111 | 112 | } 113 | 114 | 115 | // ========================================================================== 116 | 117 | 118 | 119 | @ExceptionHandler(MethodArgumentNotValidException.class) 120 | public ResponseEntity validationExceptionHandler(MethodArgumentNotValidException e){ 121 | 122 | ExceptionDTO err=new ExceptionDTO(); 123 | err.setDateAndTime(LocalDateTime.now()); 124 | err.setMessage(e.getMessage()); 125 | err.setDesc(e.getBindingResult().getFieldError().getDefaultMessage()); 126 | 127 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST); 128 | 129 | } 130 | 131 | 132 | @ExceptionHandler(NullPointerException.class) 133 | public ResponseEntity nullPointerExceptionHandler(NullPointerException e, WebRequest wr){ 134 | 135 | ExceptionDTO err=new ExceptionDTO(); 136 | err.setDateAndTime(LocalDateTime.now()); 137 | err.setMessage(e.getMessage()); 138 | err.setDesc(wr.getDescription(false)); 139 | 140 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST); 141 | 142 | } 143 | 144 | 145 | 146 | @ExceptionHandler(NoHandlerFoundException.class) 147 | public ResponseEntity noHandlerFoundException(NoHandlerFoundException e, WebRequest wr){ 148 | 149 | ExceptionDTO err=new ExceptionDTO(); 150 | err.setDateAndTime(LocalDateTime.now()); 151 | err.setMessage(e.getMessage()); 152 | err.setDesc(wr.getDescription(false)); 153 | 154 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST); 155 | 156 | } 157 | 158 | @ExceptionHandler(Exception.class) 159 | public ResponseEntity masterExceptionHandler(Exception e, WebRequest wr){ 160 | 161 | ExceptionDTO err=new ExceptionDTO(); 162 | err.setDateAndTime(LocalDateTime.now()); 163 | err.setMessage(e.getMessage()); 164 | err.setDesc(wr.getDescription(false)); 165 | 166 | return new ResponseEntity(err, HttpStatus.BAD_REQUEST); 167 | 168 | } 169 | 170 | } 171 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/exception/LoginException.java: -------------------------------------------------------------------------------- 1 | package com.shopy.exception; 2 | 3 | public class LoginException extends Exception{ 4 | 5 | public LoginException() { 6 | super(); 7 | // TODO Auto-generated constructor stub 8 | } 9 | 10 | public LoginException(String message) { 11 | super(message); 12 | // TODO Auto-generated constructor stub 13 | } 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/exception/OrderException.java: -------------------------------------------------------------------------------- 1 | package com.shopy.exception; 2 | 3 | public class OrderException extends Exception{ 4 | 5 | public OrderException() { 6 | super(); 7 | // TODO Auto-generated constructor stub 8 | } 9 | 10 | public OrderException(String message) { 11 | super(message); 12 | // TODO Auto-generated constructor stub 13 | } 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/exception/ProductException.java: -------------------------------------------------------------------------------- 1 | package com.shopy.exception; 2 | 3 | public class ProductException extends Exception{ 4 | 5 | public ProductException() { 6 | super(); 7 | // TODO Auto-generated constructor stub 8 | } 9 | 10 | public ProductException(String message) { 11 | super(message); 12 | // TODO Auto-generated constructor stub 13 | } 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/model/Address.java: -------------------------------------------------------------------------------- 1 | package com.shopy.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class Address { 7 | 8 | private Integer id; 9 | private String city; 10 | private String state; 11 | private String country; 12 | private String pincode; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/model/Admin.java: -------------------------------------------------------------------------------- 1 | package com.shopy.model; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.GenerationType; 7 | import javax.persistence.Id; 8 | 9 | import lombok.Data; 10 | 11 | @Data 12 | @Entity 13 | public class Admin { 14 | 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.AUTO) 17 | private Integer adminId; 18 | 19 | @Column(unique = true) 20 | private String adminMobile; 21 | 22 | @Column(unique = true) 23 | private String adminEmail; 24 | 25 | private String adminPassword; 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/model/Cart.java: -------------------------------------------------------------------------------- 1 | package com.shopy.model; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.CascadeType; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | import javax.persistence.OneToMany; 11 | import javax.persistence.OneToOne; 12 | import javax.persistence.Table; 13 | 14 | import com.fasterxml.jackson.annotation.JsonIgnore; 15 | 16 | import lombok.Data; 17 | 18 | @Data 19 | @Entity 20 | @Table(name = "carts") 21 | public class Cart { 22 | 23 | @Id 24 | @GeneratedValue(strategy = GenerationType.AUTO) 25 | private Integer cartId; 26 | 27 | private Integer totalPrice; 28 | 29 | private Integer totalItems; 30 | 31 | // @JsonIgnore 32 | @OneToOne(cascade = CascadeType.ALL) 33 | private Customer customer; 34 | 35 | @OneToMany(cascade = CascadeType.ALL) 36 | private Listproducts; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/model/Category.java: -------------------------------------------------------------------------------- 1 | package com.shopy.model; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.CascadeType; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | import javax.persistence.OneToMany; 11 | import javax.persistence.Table; 12 | import javax.validation.constraints.NotNull; 13 | 14 | import lombok.Data; 15 | 16 | @Data 17 | @Entity 18 | @Table(name = "categorys") 19 | public class Category { 20 | 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.AUTO) 23 | private Integer categoryId; 24 | 25 | @NotNull(message = "name canot be null") 26 | private String name; 27 | 28 | @OneToMany(mappedBy = "category", cascade = CascadeType.ALL) 29 | private List products; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/model/CurrentAdminSession.java: -------------------------------------------------------------------------------- 1 | package com.shopy.model; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.Id; 8 | 9 | import lombok.Data; 10 | 11 | @Data 12 | @Entity 13 | public class CurrentAdminSession { 14 | 15 | @Id 16 | @Column(unique = true) 17 | private Integer userId; 18 | 19 | private String uuid; 20 | 21 | private LocalDateTime localDateTime; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/model/CurrentUserSession.java: -------------------------------------------------------------------------------- 1 | package com.shopy.model; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.Id; 8 | 9 | import lombok.Data; 10 | 11 | @Data 12 | @Entity 13 | public class CurrentUserSession { 14 | 15 | @Id 16 | @Column(unique = true) 17 | private Integer userId; 18 | 19 | private String uuid; 20 | 21 | private LocalDateTime localDateTime; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/model/Customer.java: -------------------------------------------------------------------------------- 1 | package com.shopy.model; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.CascadeType; 6 | import javax.persistence.Column; 7 | import javax.persistence.Embedded; 8 | import javax.persistence.Entity; 9 | import javax.persistence.GeneratedValue; 10 | import javax.persistence.GenerationType; 11 | import javax.persistence.Id; 12 | import javax.persistence.OneToMany; 13 | import javax.persistence.OneToOne; 14 | import javax.persistence.Table; 15 | import javax.validation.constraints.Email; 16 | 17 | import com.fasterxml.jackson.annotation.JsonIgnore; 18 | 19 | import lombok.Data; 20 | 21 | @Data 22 | @Entity 23 | @Table(name = "customers") 24 | public class Customer { 25 | 26 | @Id 27 | @GeneratedValue(strategy = GenerationType.AUTO) 28 | private Integer customerId; 29 | 30 | private String customerName; 31 | 32 | @Column(unique = true) 33 | private String mobile; 34 | 35 | @Email(message = "Email is not in 'example@email.com' format") 36 | @Column(unique = true) 37 | private String email; 38 | 39 | private String password; 40 | 41 | @Embedded 42 | private Address address; 43 | 44 | @JsonIgnore 45 | @OneToOne(mappedBy = "customer",cascade = CascadeType.ALL) 46 | private Cart cart; 47 | 48 | @JsonIgnore 49 | @OneToMany(mappedBy = "customer" ,cascade = CascadeType.ALL) 50 | private List orders; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/model/Login.java: -------------------------------------------------------------------------------- 1 | package com.shopy.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class Login { 7 | 8 | private String mobile; 9 | private String password; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/model/Order.java: -------------------------------------------------------------------------------- 1 | package com.shopy.model; 2 | 3 | import java.time.LocalDate; 4 | import java.time.LocalTime; 5 | import java.util.List; 6 | 7 | import javax.persistence.CascadeType; 8 | import javax.persistence.Entity; 9 | import javax.persistence.GeneratedValue; 10 | import javax.persistence.GenerationType; 11 | import javax.persistence.Id; 12 | import javax.persistence.ManyToOne; 13 | import javax.persistence.OneToMany; 14 | import javax.persistence.Table; 15 | 16 | import lombok.Data; 17 | 18 | @Data 19 | @Entity 20 | @Table(name = "orders") 21 | public class Order { 22 | 23 | @Id 24 | @GeneratedValue(strategy = GenerationType.AUTO) 25 | private Integer orderId; 26 | 27 | private LocalDate orderDate; 28 | 29 | private LocalTime orderTime; 30 | 31 | private String status; 32 | 33 | @ManyToOne(cascade = CascadeType.ALL) 34 | private Customer customer; 35 | 36 | @OneToMany(cascade = CascadeType.ALL) 37 | private List products; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/model/Product.java: -------------------------------------------------------------------------------- 1 | package com.shopy.model; 2 | 3 | import javax.persistence.CascadeType; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.GenerationType; 7 | import javax.persistence.Id; 8 | import javax.persistence.ManyToOne; 9 | import javax.persistence.Table; 10 | import javax.validation.constraints.NotNull; 11 | 12 | import com.fasterxml.jackson.annotation.JsonIgnore; 13 | 14 | import lombok.Data; 15 | 16 | @Data 17 | @Entity 18 | @Table(name = "products") 19 | public class Product { 20 | 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.AUTO) 23 | private Integer productId; 24 | 25 | @NotNull(message = "Name cannot be null") 26 | private String productName; 27 | 28 | private String url; 29 | 30 | private Integer quantity; 31 | 32 | @NotNull(message = "price cannot be null") 33 | private Integer price; 34 | 35 | private Integer soldCount; 36 | 37 | private Double rating; 38 | 39 | private Integer ratingCount; 40 | 41 | private String description; 42 | 43 | @JsonIgnore 44 | @ManyToOne(cascade = CascadeType.ALL) 45 | private Category category; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/model/ProductDTO.java: -------------------------------------------------------------------------------- 1 | package com.shopy.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | 8 | import lombok.Data; 9 | 10 | @Data 11 | @Entity 12 | public class ProductDTO { 13 | 14 | @Id 15 | @GeneratedValue(strategy = GenerationType.AUTO) 16 | private Integer dtoID; 17 | 18 | private String productName; 19 | 20 | private Integer productId; 21 | 22 | private String url; 23 | 24 | private Integer quantity; 25 | 26 | private Integer availableProduct; 27 | 28 | private Integer price; 29 | 30 | private String description; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/repository/AdminRepo.java: -------------------------------------------------------------------------------- 1 | package com.shopy.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.shopy.model.Admin; 9 | 10 | @Repository 11 | public interface AdminRepo extends JpaRepository{ 12 | 13 | public List findByAdminMobile(String adminMobile); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/repository/AdminSessionRepo.java: -------------------------------------------------------------------------------- 1 | package com.shopy.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.shopy.model.CurrentAdminSession; 9 | 10 | @Repository 11 | public interface AdminSessionRepo extends JpaRepository{ 12 | 13 | public List findByUuid(String uuid); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/repository/CartRepo.java: -------------------------------------------------------------------------------- 1 | package com.shopy.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.data.jpa.repository.Query; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import com.shopy.model.Cart; 8 | 9 | @Repository 10 | public interface CartRepo extends JpaRepository{ 11 | 12 | @Query("select c from Customer cu join cu.cart c where cu.customerId = ?1") 13 | public Cart findByCustomerId(Integer customerId); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/repository/CategoryRepo.java: -------------------------------------------------------------------------------- 1 | package com.shopy.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.shopy.model.Category; 9 | 10 | @Repository 11 | public interface CategoryRepo extends JpaRepository{ 12 | 13 | public List findByName(String name); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/repository/CustomerRepo.java: -------------------------------------------------------------------------------- 1 | package com.shopy.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.shopy.model.Customer; 9 | 10 | @Repository 11 | public interface CustomerRepo extends JpaRepository{ 12 | 13 | public List findByMobile(String mobile); 14 | 15 | public List findByEmail(String email); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/repository/OrderRepo.java: -------------------------------------------------------------------------------- 1 | package com.shopy.repository; 2 | 3 | import java.time.LocalDate; 4 | import java.util.List; 5 | 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.query.Param; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import com.shopy.model.Order; 12 | 13 | @Repository 14 | public interface OrderRepo extends JpaRepository{ 15 | 16 | @Query(value = "from Order o where orderDate BETWEEN :startDate AND :endDate") 17 | public List orderBetweenDate(@Param("startDate")LocalDate startDate,@Param("endDate")LocalDate endDate); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/repository/ProductRepo.java: -------------------------------------------------------------------------------- 1 | package com.shopy.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.data.repository.query.Param; 8 | import org.springframework.stereotype.Repository; 9 | 10 | import com.shopy.model.Product; 11 | 12 | @Repository 13 | public interface ProductRepo extends JpaRepository{ 14 | 15 | public List findByProductName(String productName); 16 | 17 | @Query("SELECT p FROM Product p WHERE p.productName LIKE %:title%") 18 | public List findByProductNameLike(@Param("title") String likePattern); 19 | 20 | public List findTop5ByOrderBySoldCountDesc(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/repository/UserSessionRepo.java: -------------------------------------------------------------------------------- 1 | package com.shopy.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import com.shopy.model.CurrentUserSession; 9 | 10 | @Repository 11 | public interface UserSessionRepo extends JpaRepository{ 12 | 13 | public List findByUuid(String uuid); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/AdminLogin.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import com.shopy.exception.LoginException; 4 | import com.shopy.model.CurrentAdminSession; 5 | import com.shopy.model.Login; 6 | 7 | public interface AdminLogin { 8 | 9 | public CurrentAdminSession adminLog(Login dto)throws LoginException; 10 | 11 | public String adminLogOut(String key)throws LoginException; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/AdminLoginImpl.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.time.LocalDateTime; 4 | import java.util.List; 5 | import java.util.Optional; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import com.shopy.exception.LoginException; 11 | import com.shopy.model.Admin; 12 | import com.shopy.model.CurrentAdminSession; 13 | import com.shopy.model.Login; 14 | import com.shopy.repository.AdminRepo; 15 | import com.shopy.repository.AdminSessionRepo; 16 | 17 | import net.bytebuddy.utility.RandomString; 18 | 19 | @Service 20 | public class AdminLoginImpl implements AdminLogin{ 21 | 22 | @Autowired 23 | private AdminSessionRepo asr; 24 | 25 | @Autowired 26 | private AdminRepo arl; 27 | 28 | @Override 29 | public CurrentAdminSession adminLog(Login dto) throws LoginException { 30 | Listtemp=arl.findByAdminMobile(dto.getMobile()); 31 | if(temp.size()==0) 32 | throw new LoginException("please enter valid mobile number"); 33 | 34 | Admin admin=temp.get(0); 35 | 36 | Optional validation=asr.findById(admin.getAdminId()); 37 | if(validation.isPresent()) { 38 | 39 | if(admin.getAdminPassword().equals(dto.getPassword())) { 40 | return validation.get(); 41 | } 42 | 43 | throw new LoginException("please enter valid password"); 44 | } 45 | 46 | if(admin.getAdminPassword().equals(dto.getPassword())) { 47 | String key=RandomString.make(6); 48 | CurrentAdminSession cas=new CurrentAdminSession(); 49 | cas.setLocalDateTime(LocalDateTime.now()); 50 | cas.setUserId(admin.getAdminId()); 51 | cas.setUuid(key); 52 | asr.save(cas); 53 | return cas; 54 | } 55 | throw new LoginException("please enter valid password"); 56 | } 57 | 58 | @Override 59 | public String adminLogOut(String key) throws LoginException { 60 | Listvalidation=asr.findByUuid(key); 61 | if(validation.size()==0) { 62 | throw new LoginException("user not logged in with this number"); 63 | } 64 | asr.delete(validation.get(0)); 65 | return "Logged out !"; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/AdminService.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.util.List; 4 | 5 | import com.shopy.exception.AdminException; 6 | import com.shopy.model.Admin; 7 | 8 | public interface AdminService { 9 | 10 | public Admin registerAdmin(Admin admin, String validationKey)throws AdminException; 11 | 12 | public List viewAllAdmin(String key)throws AdminException; 13 | 14 | public Admin deleteAdmin(Admin admin, String key)throws AdminException; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/AdminServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.shopy.exception.AdminException; 10 | import com.shopy.model.Admin; 11 | import com.shopy.model.CurrentAdminSession; 12 | import com.shopy.repository.AdminRepo; 13 | import com.shopy.repository.AdminSessionRepo; 14 | 15 | @Service 16 | public class AdminServiceImpl implements AdminService{ 17 | 18 | @Autowired 19 | private AdminRepo ar; 20 | 21 | @Autowired 22 | private AdminSessionRepo asRepo; 23 | 24 | @Override 25 | public Admin registerAdmin(Admin admin, String validationKey) throws AdminException { 26 | if(!validationKey.equals("Demo@8696")) 27 | throw new AdminException("you don't have authority to register as admin"); 28 | 29 | return ar.save(admin); 30 | } 31 | 32 | @Override 33 | public List viewAllAdmin(String key) throws AdminException { 34 | Listcheck=asRepo.findByUuid(key); 35 | 36 | if(check.size()==0) 37 | throw new AdminException("you don't have authority to see admin list"); 38 | 39 | return ar.findAll(); 40 | 41 | } 42 | 43 | @Override 44 | public Admin deleteAdmin(Admin admin, String key) throws AdminException { 45 | Listcheck=asRepo.findByUuid(key); 46 | 47 | if(check.size()==0) 48 | throw new AdminException("you don't have authority to delete admin"); 49 | 50 | Optionalopt=ar.findById(admin.getAdminId()); 51 | 52 | if(opt.isEmpty()) 53 | throw new AdminException("admin not found with id "+admin.getAdminId()); 54 | 55 | ar.delete(opt.get()); 56 | 57 | return opt.get(); 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/CartService.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import com.shopy.exception.CartException; 4 | import com.shopy.exception.CustomerException; 5 | import com.shopy.exception.ProductException; 6 | import com.shopy.model.Cart; 7 | 8 | public interface CartService { 9 | 10 | public Cart addCart(Cart cart,String key)throws CustomerException; 11 | 12 | public Cart viewCart(int cartId,String key)throws CartException; 13 | 14 | public Cart addItemIntoCart(int productId,String key)throws CartException,ProductException; 15 | 16 | public Cart removeItemFromCart(int productId,String key)throws CartException,ProductException; 17 | 18 | public Cart increaseQuantity(int productId, String key)throws CartException,ProductException; 19 | 20 | public Cart decreaseQuantity(int productId, String key)throws CartException,ProductException; 21 | 22 | public Cart clearCart(String key)throws CartException; 23 | 24 | public Cart deleteCart(int cartId,String key)throws CartException; 25 | 26 | public Cart cartByCustomerId(String key)throws CartException; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/CartServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.shopy.exception.CartException; 10 | import com.shopy.exception.CustomerException; 11 | import com.shopy.exception.ProductException; 12 | import com.shopy.model.Cart; 13 | import com.shopy.model.CurrentUserSession; 14 | import com.shopy.model.Customer; 15 | import com.shopy.model.Product; 16 | import com.shopy.model.ProductDTO; 17 | import com.shopy.repository.CartRepo; 18 | import com.shopy.repository.CustomerRepo; 19 | import com.shopy.repository.ProductRepo; 20 | import com.shopy.repository.UserSessionRepo; 21 | 22 | @Service 23 | public class CartServiceImpl implements CartService{ 24 | 25 | @Autowired 26 | private CartRepo cr; 27 | 28 | @Autowired 29 | private CustomerRepo cusRepo; 30 | 31 | @Autowired 32 | private ProductRepo prepo; 33 | 34 | @Autowired 35 | private UserSessionRepo usrRepo; 36 | 37 | public int cartTotal(Listlist) { 38 | int total=0; 39 | for(ProductDTO p:list) { 40 | if(p.getQuantity()!=0) { 41 | total+=p.getPrice()*p.getQuantity(); 42 | } 43 | } 44 | return total; 45 | } 46 | 47 | public int cartTotalQuantity(Listlist) { 48 | int total=0; 49 | for(ProductDTO p:list) { 50 | if(p.getQuantity()!=0) { 51 | total+=p.getQuantity(); 52 | } 53 | } 54 | return total; 55 | } 56 | 57 | @Override 58 | public Cart addCart(Cart cart,String key) throws CustomerException{ 59 | ListcUser=usrRepo.findByUuid(key); 60 | if(cUser.size()==0) 61 | throw new CustomerException("you are not logged in please log in"); 62 | 63 | CurrentUserSession currentUser=cUser.get(0); 64 | 65 | Optionalcus=cusRepo.findById(cart.getCustomer().getCustomerId()); 66 | if(cus.isEmpty()) { 67 | throw new CustomerException("customer not found with id "+cart.getCustomer().getCustomerId()); 68 | } 69 | if(cus.get().getCart()!=null) { 70 | throw new CustomerException("customer "+cart.getCustomer().getCustomerId()+" already has cart "+cus.get().getCart().getCartId()); 71 | } 72 | Customer customer=cus.get(); 73 | 74 | if(customer.getCustomerId()!=currentUser.getUserId()) 75 | throw new CustomerException("user mismatch please try again"); 76 | 77 | cart.setCustomer(customer); 78 | 79 | return cr.save(cart); 80 | } 81 | 82 | @Override 83 | public Cart viewCart(int cartId,String key) throws CartException { 84 | ListcUser=usrRepo.findByUuid(key); 85 | if(cUser.size()==0) 86 | throw new CartException("you are not logged in please log in"); 87 | 88 | CurrentUserSession currentUser=cUser.get(0); 89 | 90 | Optionalcart=cr.findById(cartId); 91 | if(cart.isPresent()) { 92 | 93 | if(cart.get().getCustomer().getCustomerId()!=currentUser.getUserId()) 94 | throw new CartException("user mismatch please try again"); 95 | 96 | return cart.get(); 97 | } 98 | throw new CartException("cart not found with id "+cartId); 99 | } 100 | 101 | @Override 102 | public Cart addItemIntoCart(int productId,String key) throws CartException, ProductException { 103 | 104 | ListcUser=usrRepo.findByUuid(key); 105 | if(cUser.size()==0) 106 | throw new CartException("you are not logged in please log in"); 107 | 108 | CurrentUserSession currentUser=cUser.get(0); 109 | 110 | Cart cart=cr.findByCustomerId(currentUser.getUserId()); 111 | 112 | Optionalpro=prepo.findById(productId); 113 | if(pro.isEmpty()) { 114 | throw new ProductException("product mot found with id "+productId); 115 | } 116 | 117 | Product product=pro.get(); 118 | 119 | ProductDTO pdto=new ProductDTO(); 120 | pdto.setDescription(product.getDescription()); 121 | pdto.setPrice(product.getPrice()); 122 | pdto.setProductId(product.getProductId()); 123 | pdto.setProductName(product.getProductName()); 124 | pdto.setUrl(product.getUrl()); 125 | pdto.setAvailableProduct(product.getQuantity()); 126 | 127 | boolean flag=true; 128 | 129 | for(ProductDTO p:cart.getProducts()) { 130 | if(p.getProductId()==productId) { 131 | flag=false; 132 | p.setQuantity(p.getQuantity()+1); 133 | } 134 | } 135 | if(flag) { 136 | pdto.setQuantity(1); 137 | cart.getProducts().add(pdto); 138 | } 139 | 140 | cart.setTotalPrice(cartTotal(cart.getProducts())); 141 | cart.setTotalItems(cartTotalQuantity(cart.getProducts())); 142 | 143 | return cr.save(cart); 144 | 145 | } 146 | 147 | @Override 148 | public Cart removeItemFromCart(int productId, String key) throws CartException, ProductException { 149 | 150 | ListcUser=usrRepo.findByUuid(key); 151 | if(cUser.size()==0) 152 | throw new CartException("you are not logged in please log in"); 153 | 154 | CurrentUserSession currentUser=cUser.get(0); 155 | 156 | Cart cart=cr.findByCustomerId(currentUser.getUserId()); 157 | 158 | boolean flag=cart.getProducts().removeIf(p-> p.getProductId()==productId); 159 | 160 | if(!flag) { 161 | throw new ProductException("product "+productId+" is not there in cart "+cart.getCartId()); 162 | } 163 | 164 | cart.setTotalPrice(cartTotal(cart.getProducts())); 165 | cart.setTotalItems(cartTotalQuantity(cart.getProducts())); 166 | 167 | return cr.save(cart); 168 | } 169 | 170 | @Override 171 | public Cart increaseQuantity(int productId,String key) throws CartException, ProductException { 172 | 173 | 174 | ListcUser=usrRepo.findByUuid(key); 175 | if(cUser.size()==0) 176 | throw new CartException("you are not logged in please log in"); 177 | 178 | CurrentUserSession currentUser=cUser.get(0); 179 | 180 | Optionalpro=prepo.findById(productId); 181 | if(pro.isEmpty()) { 182 | throw new ProductException("product mot foumd with id "+productId); 183 | } 184 | 185 | Cart cart=cr.findByCustomerId(currentUser.getUserId()); 186 | 187 | if(cart.getCustomer().getCustomerId()!=currentUser.getUserId()) 188 | throw new CartException("user mismatch please try again"); 189 | 190 | 191 | cart.getProducts().forEach(p->{ 192 | if(p.getProductId()==productId) { 193 | p.setQuantity(p.getQuantity()+1); 194 | } 195 | }); 196 | cart.setTotalPrice(cartTotal(cart.getProducts())); 197 | cart.setTotalItems(cartTotalQuantity(cart.getProducts())); 198 | return cr.save(cart); 199 | } 200 | 201 | @Override 202 | public Cart decreaseQuantity(int productId, String key) throws CartException, ProductException { 203 | 204 | ListcUser=usrRepo.findByUuid(key); 205 | if(cUser.size()==0) 206 | throw new CartException("you are not logged in please log in"); 207 | 208 | CurrentUserSession currentUser=cUser.get(0); 209 | 210 | Optionalpro=prepo.findById(productId); 211 | 212 | if(pro.isEmpty()) { 213 | throw new ProductException("product not found with id "+productId); 214 | } 215 | Cart cart=cr.findByCustomerId(currentUser.getUserId()); 216 | 217 | 218 | cart.getProducts().forEach(p->{ 219 | if(p.getProductId()==productId) { 220 | p.setQuantity(p.getQuantity()-1); 221 | if(p.getQuantity()<1) { 222 | p.setQuantity(1); 223 | } 224 | } 225 | }); 226 | cart.setTotalPrice(cartTotal(cart.getProducts())); 227 | cart.setTotalItems(cartTotalQuantity(cart.getProducts())); 228 | return cr.save(cart); 229 | } 230 | 231 | @Override 232 | public Cart clearCart(String key) throws CartException { 233 | 234 | ListcUser=usrRepo.findByUuid(key); 235 | if(cUser.size()==0) 236 | throw new CartException("you are not logged in please log in"); 237 | 238 | CurrentUserSession currentUser=cUser.get(0); 239 | 240 | 241 | Cart cart=cr.findByCustomerId(currentUser.getUserId()); 242 | 243 | cart.getProducts().clear(); 244 | cart.setTotalPrice(0); 245 | cart.setTotalItems(0); 246 | return cr.save(cart); 247 | } 248 | 249 | @Override 250 | public Cart deleteCart(int cartId,String key) throws CartException { 251 | ListcUser=usrRepo.findByUuid(key); 252 | if(cUser.size()==0) 253 | throw new CartException("you are not logged in please log in"); 254 | 255 | CurrentUserSession currentUser=cUser.get(0); 256 | 257 | OptionalcartOp=cr.findById(cartId); 258 | if(cartOp.isEmpty()) { 259 | throw new CartException("cart not found with id "+cartId); 260 | } 261 | if(cartOp.get().getCustomer().getCustomerId()!=currentUser.getUserId()) 262 | throw new CartException("user mismatch please try again"); 263 | 264 | cr.delete(cartOp.get()); 265 | return cartOp.get(); 266 | } 267 | 268 | @Override 269 | public Cart cartByCustomerId(String key) throws CartException { 270 | ListcUser=usrRepo.findByUuid(key); 271 | if(cUser.size()==0) 272 | throw new CartException("you are not logged in please log in"); 273 | 274 | CurrentUserSession currentUser=cUser.get(0); 275 | 276 | Cart cart=cr.findByCustomerId(currentUser.getUserId()); 277 | List list=cart.getProducts(); 278 | for(ProductDTO p:list) { 279 | p.setAvailableProduct(prepo.findById(p.getProductId()).get().getQuantity()); 280 | } 281 | return cr.save(cart); 282 | } 283 | 284 | } 285 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/CategoryService.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.util.List; 4 | 5 | import com.shopy.exception.CategoryException; 6 | import com.shopy.model.Category; 7 | import com.shopy.model.Product; 8 | 9 | 10 | public interface CategoryService { 11 | 12 | public Category addCategory(Category category, String key)throws CategoryException; 13 | 14 | public Category viewCategory(int categoryId)throws CategoryException; 15 | 16 | public Category deleteCategory(int categoryId, String key)throws CategoryException; 17 | 18 | public List allCategory()throws CategoryException; 19 | 20 | public List productByCategory(int categoryId)throws CategoryException; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/CategoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.shopy.exception.CategoryException; 10 | import com.shopy.exception.ProductException; 11 | import com.shopy.model.Category; 12 | import com.shopy.model.CurrentAdminSession; 13 | import com.shopy.model.Product; 14 | import com.shopy.repository.AdminSessionRepo; 15 | import com.shopy.repository.CategoryRepo; 16 | 17 | @Service 18 | public class CategoryServiceImpl implements CategoryService{ 19 | 20 | @Autowired 21 | private CategoryRepo cr; 22 | 23 | @Autowired 24 | private AdminSessionRepo adsrepo; 25 | 26 | @Override 27 | public Category addCategory(Category category, String key) throws CategoryException { 28 | 29 | List list=adsrepo.findByUuid(key); 30 | 31 | if(list.size()==0) 32 | throw new CategoryException("you don't have authority to add category"); 33 | 34 | List cat=cr.findByName(category.getName()); 35 | 36 | if(cat.size()!=0) { 37 | throw new CategoryException("category already registered with this name id is "+cat.get(0).getCategoryId()); 38 | } 39 | 40 | return cr.save(category); 41 | } 42 | 43 | @Override 44 | public Category viewCategory(int categoryId) throws CategoryException { 45 | Optional c=cr.findById(categoryId); 46 | if(c.isPresent()) { 47 | return c.get(); 48 | } 49 | throw new CategoryException("category not found with id "+categoryId); 50 | } 51 | 52 | @Override 53 | public Category deleteCategory(int categoryId, String key) throws CategoryException { 54 | 55 | List list=adsrepo.findByUuid(key); 56 | 57 | if(list.size()==0) 58 | throw new CategoryException("you don't have authority to delete category"); 59 | 60 | Optional c=cr.findById(categoryId); 61 | if(c.isPresent()) { 62 | cr.delete(c.get()); 63 | return c.get(); 64 | } 65 | throw new CategoryException("category not found with id "+categoryId); 66 | } 67 | 68 | @Override 69 | public List allCategory() throws CategoryException { 70 | Listlist=cr.findAll(); 71 | if(list.size()==0) { 72 | throw new CategoryException("list empty"); 73 | } 74 | return list; 75 | } 76 | 77 | @Override 78 | public List productByCategory(int categoryId) throws CategoryException { 79 | Optional c=cr.findById(categoryId); 80 | if(c.isPresent()) { 81 | return c.get().getProducts(); 82 | } 83 | throw new CategoryException("category not found with id "+categoryId); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/CustomerLogin.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import com.shopy.exception.LoginException; 4 | import com.shopy.model.CurrentUserSession; 5 | import com.shopy.model.Login; 6 | 7 | public interface CustomerLogin { 8 | 9 | public CurrentUserSession logIntoAccount(Login dto)throws LoginException; 10 | 11 | public String logOutFromAccount(String key)throws LoginException; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/CustomerLoginImpl.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.time.LocalDateTime; 4 | import java.util.List; 5 | import java.util.Optional; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import com.shopy.exception.LoginException; 11 | import com.shopy.model.CurrentUserSession; 12 | import com.shopy.model.Customer; 13 | import com.shopy.model.Login; 14 | import com.shopy.repository.CustomerRepo; 15 | import com.shopy.repository.UserSessionRepo; 16 | 17 | import net.bytebuddy.utility.RandomString; 18 | 19 | @Service 20 | public class CustomerLoginImpl implements CustomerLogin{ 21 | 22 | @Autowired 23 | private UserSessionRepo usr; 24 | 25 | @Autowired 26 | private CustomerRepo crl; 27 | 28 | @Override 29 | public CurrentUserSession logIntoAccount(Login dto) throws LoginException { 30 | List list=crl.findByMobile(dto.getMobile()); 31 | 32 | if(list.size()==0) { 33 | throw new LoginException("please enter valid mobil number"); 34 | } 35 | 36 | Customer customer=list.get(0); 37 | Optional validation=usr.findById(customer.getCustomerId()); 38 | 39 | if(validation.isPresent()) { 40 | if(customer.getPassword().equals(dto.getPassword())) { 41 | return validation.get(); 42 | } 43 | throw new LoginException("Please enter valid password"); 44 | } 45 | 46 | if(customer.getPassword().equals(dto.getPassword())) { 47 | String key=RandomString.make(6); 48 | CurrentUserSession cus=new CurrentUserSession(); 49 | cus.setUserId(customer.getCustomerId()); 50 | cus.setUuid(key); 51 | cus.setLocalDateTime(LocalDateTime.now()); 52 | usr.save(cus); 53 | return cus; 54 | } 55 | 56 | throw new LoginException("please enter valid password"); 57 | } 58 | 59 | @Override 60 | public String logOutFromAccount(String key) throws LoginException { 61 | List validation=usr.findByUuid(key); 62 | if(validation.size()==0) { 63 | throw new LoginException("user not logged in with this number"); 64 | } 65 | usr.delete(validation.get(0)); 66 | return "Logged out !"; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/CustomerService.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.util.List; 4 | 5 | import com.shopy.exception.CustomerException; 6 | import com.shopy.model.Customer; 7 | import com.shopy.model.Order; 8 | 9 | public interface CustomerService { 10 | 11 | public Customer registerCustomer(Customer customer)throws CustomerException; 12 | 13 | public Customer viewCustomer(String key)throws CustomerException; 14 | 15 | public Customer updateCustomer(Customer customer, String key)throws CustomerException; 16 | 17 | public Customer deleteCustomer(int customerId, String key)throws CustomerException; 18 | 19 | public List viewOrders(String key)throws CustomerException; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/CustomerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import java.util.Optional; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import com.shopy.exception.CustomerException; 11 | import com.shopy.model.Address; 12 | import com.shopy.model.Cart; 13 | import com.shopy.model.CurrentUserSession; 14 | import com.shopy.model.Customer; 15 | import com.shopy.model.Order; 16 | import com.shopy.repository.CartRepo; 17 | import com.shopy.repository.CustomerRepo; 18 | import com.shopy.repository.UserSessionRepo; 19 | 20 | @Service 21 | public class CustomerServiceImpl implements CustomerService{ 22 | 23 | @Autowired 24 | private CustomerRepo cr; 25 | 26 | @Autowired 27 | private UserSessionRepo usRepo; 28 | 29 | @Autowired 30 | private CartRepo cartR; 31 | 32 | @Override 33 | public Customer registerCustomer(Customer customer) throws CustomerException { 34 | 35 | List byMail=cr.findByEmail(customer.getEmail()); 36 | List byMobile=cr.findByMobile(customer.getMobile()); 37 | 38 | if(byMobile.size()>0) { 39 | throw new CustomerException("mobile number already registered"); 40 | } 41 | if(byMail.size()>0) { 42 | throw new CustomerException("mail already registered"); 43 | } 44 | 45 | Customer saved=cr.save(customer); 46 | Cart cart=new Cart(); 47 | cart.setTotalItems(0); 48 | cart.setTotalPrice(0); 49 | cart.setCustomer(saved); 50 | cartR.save(cart); 51 | customer.setCart(cart); 52 | return saved; 53 | 54 | } 55 | 56 | @Override 57 | public Customer viewCustomer(String key) throws CustomerException { 58 | List extCu=usRepo.findByUuid(key); 59 | if(extCu.size()==0) 60 | throw new CustomerException("key is not valid"); 61 | 62 | Optional c=cr.findById(extCu.get(0).getUserId()); 63 | 64 | if(c.isPresent()) { 65 | return c.get(); 66 | } 67 | throw new CustomerException("user not found"); 68 | } 69 | 70 | @Override 71 | public Customer updateCustomer(Customer customer, String key) throws CustomerException { 72 | List extCu=usRepo.findByUuid(key); 73 | if(extCu.size()==0) 74 | throw new CustomerException("key is not valid"); 75 | 76 | Optional c=cr.findById(extCu.get(0).getUserId()); 77 | 78 | if(!c.isPresent()) { 79 | throw new CustomerException("user not found"); 80 | } 81 | 82 | Customer pre=c.get(); 83 | Address preA=pre.getAddress(); 84 | 85 | Address newA=customer.getAddress(); 86 | if(newA.getCity()!=null) { 87 | preA.setCity(newA.getCity()); 88 | } 89 | if(newA.getCountry()!=null) { 90 | preA.setCountry(newA.getCountry()); 91 | } 92 | if(newA.getPincode()!=null) { 93 | preA.setPincode(newA.getPincode()); 94 | } 95 | if(newA.getState()!=null) { 96 | preA.setState(newA.getState()); 97 | } 98 | 99 | if(customer.getCustomerName()!=null){ 100 | pre.setCustomerName(customer.getCustomerName()); 101 | } 102 | if(customer.getEmail()!=null){ 103 | pre.setEmail(customer.getEmail()); 104 | } 105 | if(customer.getMobile()!=null){ 106 | pre.setMobile(customer.getMobile()); 107 | } 108 | if(customer.getPassword()!=null){ 109 | pre.setPassword(customer.getPassword()); 110 | } 111 | 112 | pre.setAddress(preA); 113 | return cr.save(pre); 114 | } 115 | 116 | @Override 117 | public Customer deleteCustomer(int customerId, String key) throws CustomerException { 118 | List extCu=usRepo.findByUuid(key); 119 | if(extCu.size()==0) 120 | throw new CustomerException("key is not valid"); 121 | 122 | if(extCu.get(0).getUserId()!=customerId) 123 | throw new CustomerException("invalid customer id please fill valid id"); 124 | 125 | 126 | Optional c=cr.findById(customerId); 127 | if(c.isPresent()) { 128 | cr.delete(c.get()); 129 | return c.get(); 130 | } 131 | throw new CustomerException("user not found with id : "+customerId); 132 | } 133 | 134 | @Override 135 | public List viewOrders(String key) throws CustomerException { 136 | List extCu=usRepo.findByUuid(key); 137 | if(extCu.size()==0) 138 | throw new CustomerException("key is not valid"); 139 | 140 | Optional c=cr.findById(extCu.get(0).getUserId()); 141 | if(c.isPresent()) { 142 | Listlist=c.get().getOrders(); 143 | if(list.size()==0) { 144 | throw new CustomerException("order list is empty"); 145 | } 146 | Collections.reverse(list); 147 | return list; 148 | } 149 | throw new CustomerException("user not found"); 150 | } 151 | 152 | } 153 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.time.LocalDate; 4 | import java.util.List; 5 | 6 | import com.shopy.exception.AdminException; 7 | import com.shopy.exception.CartException; 8 | import com.shopy.exception.OrderException; 9 | import com.shopy.model.Order; 10 | 11 | public interface OrderService { 12 | 13 | public Order addOrder(String uuid)throws OrderException,CartException; 14 | 15 | public Order viewOrder(int orderId)throws OrderException; 16 | 17 | public List viewOrdersByDate(LocalDate startDate, LocalDate endDate)throws OrderException; 18 | 19 | public Order updateOrderStatus(int orderId, String status)throws OrderException; 20 | 21 | public Order deleteOrder(int orderId)throws OrderException; 22 | 23 | public List viewAllOrder()throws OrderException, AdminException; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.time.LocalDate; 4 | import java.time.LocalTime; 5 | import java.util.ArrayList; 6 | import java.util.Collections; 7 | import java.util.List; 8 | import java.util.Optional; 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | import com.shopy.exception.AdminException; 14 | import com.shopy.exception.CartException; 15 | import com.shopy.exception.CustomerException; 16 | import com.shopy.exception.OrderException; 17 | import com.shopy.model.Cart; 18 | import com.shopy.model.CurrentUserSession; 19 | import com.shopy.model.Customer; 20 | import com.shopy.model.Order; 21 | import com.shopy.model.Product; 22 | import com.shopy.model.ProductDTO; 23 | import com.shopy.repository.CartRepo; 24 | import com.shopy.repository.CustomerRepo; 25 | import com.shopy.repository.OrderRepo; 26 | import com.shopy.repository.ProductRepo; 27 | import com.shopy.repository.UserSessionRepo; 28 | 29 | @Service 30 | public class OrderServiceImpl implements OrderService{ 31 | 32 | @Autowired 33 | private OrderRepo or; 34 | 35 | @Autowired 36 | private CartRepo cartRepo; 37 | 38 | @Autowired 39 | private UserSessionRepo usRepo; 40 | 41 | @Autowired 42 | private CustomerRepo cr; 43 | 44 | @Autowired 45 | private ProductRepo prepo; 46 | 47 | 48 | @Override 49 | public Order addOrder(String uuid) throws OrderException, CartException { 50 | 51 | List extCu=usRepo.findByUuid(uuid); 52 | if(extCu.size()==0) 53 | throw new OrderException("key is not valid"); 54 | 55 | Optional c=cr.findById(extCu.get(0).getUserId()); 56 | 57 | if(!c.isPresent()) { 58 | throw new OrderException("user not found"); 59 | } 60 | 61 | Customer customer=c.get(); 62 | 63 | Optionalcar=cartRepo.findById(customer.getCart().getCartId()); 64 | if(car.isEmpty()) { 65 | throw new CartException("cart not found"); 66 | } 67 | 68 | Cart cart=car.get(); 69 | 70 | if(cart.getProducts().size()==0) { 71 | throw new OrderException("please add product in cart"); 72 | } 73 | 74 | Order order=new Order(); 75 | 76 | order.setCustomer(customer); 77 | order.setOrderDate(LocalDate.now()); 78 | order.setOrderTime(LocalTime.now()); 79 | order.setStatus("pending"); 80 | 81 | Listtemp=new ArrayList<>(); 82 | 83 | for(ProductDTO p:cart.getProducts()) { 84 | if(p.getAvailableProduct()list=cart.getProducts(); 93 | 94 | list.forEach(p->{ 95 | Product pro=prepo.findById(p.getProductId()).get(); 96 | pro.setSoldCount(pro.getSoldCount()+p.getQuantity()); 97 | pro.setQuantity(pro.getQuantity()-p.getQuantity()); 98 | prepo.save(pro); 99 | }); 100 | 101 | Order o=or.save(order); 102 | 103 | cart.getProducts().clear(); 104 | cart.setTotalItems(0); 105 | cart.setTotalPrice(0); 106 | cartRepo.save(cart); 107 | 108 | return o; 109 | } 110 | 111 | @Override 112 | public Order viewOrder(int orderId) throws OrderException { 113 | Optionalord=or.findById(orderId); 114 | if(ord.isEmpty()) { 115 | throw new OrderException("order not found with id "+orderId); 116 | } 117 | return ord.get(); 118 | } 119 | 120 | @Override 121 | public List viewOrdersByDate(LocalDate startDate, LocalDate endDate) throws OrderException { 122 | Listlist=or.orderBetweenDate(startDate, endDate); 123 | if(list.size()==0) 124 | throw new OrderException("no order found between "+startDate+" and "+endDate); 125 | return list; 126 | } 127 | 128 | @Override 129 | public Order updateOrderStatus(int orderId, String status) throws OrderException { 130 | Optionalord=or.findById(orderId); 131 | if(ord.isEmpty()) { 132 | throw new OrderException("order not found with id "+orderId); 133 | } 134 | ord.get().setStatus(status); 135 | return or.save(ord.get()); 136 | } 137 | 138 | @Override 139 | public Order deleteOrder(int orderId) throws OrderException { 140 | Optionalord=or.findById(orderId); 141 | if(ord.isEmpty()) { 142 | throw new OrderException("order not found with id "+orderId); 143 | } 144 | Order order=ord.get(); 145 | order.setCustomer(null); 146 | // order.setCart(null); 147 | or.delete(ord.get()); 148 | return ord.get(); 149 | } 150 | 151 | @Override 152 | public List viewAllOrder() throws OrderException, AdminException { 153 | Listlist=or.findAll(); 154 | if(list.size()==0) { 155 | throw new OrderException("no order found"); 156 | } 157 | Collections.reverse(list); 158 | return list; 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.util.List; 4 | 5 | import com.shopy.exception.CategoryException; 6 | import com.shopy.exception.ProductException; 7 | import com.shopy.model.Product; 8 | 9 | public interface ProductService { 10 | 11 | public Product addProduct(Product product, int categoryId, String key)throws ProductException,CategoryException; 12 | 13 | public Product viewProduct(int productId)throws ProductException; 14 | 15 | public List allProduct()throws ProductException; 16 | 17 | public Product removeProduct(int productId, String key)throws ProductException; 18 | 19 | public Product updateProduct(Product product, String key)throws ProductException; 20 | 21 | public List productByName(String name)throws ProductException; 22 | 23 | public List productByNameLike(String name)throws ProductException; 24 | 25 | public List top5()throws ProductException; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /backend/src/main/java/com/shopy/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.shopy.service; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.shopy.exception.CategoryException; 10 | import com.shopy.exception.ProductException; 11 | import com.shopy.model.Category; 12 | import com.shopy.model.CurrentAdminSession; 13 | import com.shopy.model.Product; 14 | import com.shopy.repository.AdminSessionRepo; 15 | import com.shopy.repository.CategoryRepo; 16 | import com.shopy.repository.ProductRepo; 17 | 18 | @Service 19 | public class ProductServiceImpl implements ProductService{ 20 | 21 | @Autowired 22 | private ProductRepo pr; 23 | 24 | @Autowired 25 | private CategoryRepo crepo; 26 | 27 | @Autowired 28 | private AdminSessionRepo adsr; 29 | 30 | @Override 31 | public Product addProduct(Product product, int categoryId, String key) throws ProductException, CategoryException { 32 | 33 | List list=adsr.findByUuid(key); 34 | 35 | if(list.size()==0) 36 | throw new ProductException("you don't have authority to add product"); 37 | 38 | Optional cat=crepo.findById(categoryId); 39 | if(!cat.isPresent()) { 40 | throw new CategoryException("category not found with id "+categoryId); 41 | } 42 | Category category=cat.get(); 43 | category.getProducts().add(product); 44 | 45 | product.setCategory(category); 46 | 47 | 48 | return pr.save(product); 49 | 50 | } 51 | 52 | @Override 53 | public Product viewProduct(int productId) throws ProductException { 54 | Optionalp=pr.findById(productId); 55 | if(p.isPresent()) { 56 | return p.get(); 57 | } 58 | throw new ProductException("product not found with id "+productId); 59 | } 60 | 61 | @Override 62 | public List allProduct() throws ProductException { 63 | Listlist=pr.findAll(); 64 | if(list.size()==0) { 65 | throw new ProductException("list is empty"); 66 | } 67 | return list; 68 | } 69 | 70 | @Override 71 | public Product removeProduct(int productId, String key) throws ProductException { 72 | 73 | List list=adsr.findByUuid(key); 74 | 75 | if(list.size()==0) 76 | throw new ProductException("you don't have authority to remove product"); 77 | 78 | 79 | Optionalp=pr.findById(productId); 80 | if(p.isPresent()) { 81 | p.get().setCategory(null); 82 | pr.delete(p.get()); 83 | return p.get(); 84 | } 85 | throw new ProductException("product not found with id "+productId); 86 | } 87 | 88 | @Override 89 | public Product updateProduct(Product product, String key) throws ProductException { 90 | 91 | List list=adsr.findByUuid(key); 92 | 93 | if(list.size()==0) 94 | throw new ProductException("you don't have authority to update product"); 95 | 96 | 97 | Optionalp=pr.findById(product.getProductId()); 98 | if(p.isPresent()) { 99 | Product pro=p.get(); 100 | 101 | if(product.getDescription()!="") 102 | pro.setDescription(product.getDescription()); 103 | 104 | if(product.getPrice()!=null) 105 | pro.setPrice(product.getPrice()); 106 | 107 | if(product.getProductName()!="") 108 | pro.setProductName(product.getProductName()); 109 | 110 | if(product.getQuantity()!=null) 111 | pro.setQuantity(product.getQuantity()); 112 | 113 | if(product.getUrl()!="") 114 | pro.setUrl(product.getUrl()); 115 | 116 | return pr.save(pro); 117 | } 118 | throw new ProductException("product not found with id "+product.getProductId()); 119 | } 120 | 121 | @Override 122 | public List productByName(String name) throws ProductException { 123 | Listlist=pr.findByProductName(name); 124 | if(list.size()==0) { 125 | throw new ProductException("product not found with name "+name); 126 | } 127 | return list; 128 | } 129 | 130 | @Override 131 | public List productByNameLike(String name) throws ProductException { 132 | Listlist=pr.findByProductNameLike(name); 133 | if(list.size()==0) { 134 | throw new ProductException("product not found with name "+name); 135 | } 136 | return list; 137 | } 138 | 139 | @Override 140 | public List top5() throws ProductException { 141 | Listlist=pr.findTop5ByOrderBySoldCountDesc(); 142 | if(list.size()==0) { 143 | throw new ProductException("product not found"); 144 | } 145 | return list; 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /backend/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8888 2 | 3 | #database specific properties 4 | spring.datasource.url=jdbc:mysql://localhost:3306/shopydb 5 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 6 | spring.datasource.username=root 7 | spring.datasource.password=root 8 | 9 | #ORM software specific properties 10 | spring.jpa.hibernate.ddl-auto=update 11 | spring.jpa.show-sql=true 12 | 13 | spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER 14 | 15 | #spring.jpa.properties.hibernate.globally_quoted_identifiers=true 16 | -------------------------------------------------------------------------------- /backend/src/test/java/com/shopy/ShopyApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.shopy; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ShopyApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /frontend/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "liveServer.settings.port": 5501 3 | } -------------------------------------------------------------------------------- /frontend/admin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 40 | 41 | 42 | 43 | 44 | 45 |
46 | 47 | 48 | 49 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 114 | 115 | 116 | 117 |
118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /frontend/adminlogin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 132 | 133 | 134 | 135 | 136 |
137 | 138 |
139 | 144 | 151 |
152 | 153 |
154 | 158 | 162 |
163 | 164 |
165 | 166 | 167 | 168 | 169 | 170 | 228 | 229 | 230 | -------------------------------------------------------------------------------- /frontend/cart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 185 | 186 | 201 | 202 | 203 | 204 |
205 |
206 |

Your Cart

207 |
208 |
209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 |
PhotoQtyProductPriceTotal 
Total: 
 
237 |
238 |
239 | 240 | 459 | 460 | 461 | 462 | -------------------------------------------------------------------------------- /frontend/cart2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Cart 8 | 9 | 10 | 52 | 53 | 54 | 55 |
56 | 57 | 58 | 59 |
60 | 61 |
62 | 63 |
64 | 65 |
66 | 67 |
68 | 69 | 70 | -------------------------------------------------------------------------------- /frontend/category.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Category 8 | 9 | 73 | 74 | 75 | 76 |
77 | 78 | 79 | 80 | 81 | 103 | 104 | 105 | 106 | 107 | 108 | 109 |
110 | 150 | 151 | 152 |
153 | 154 |
155 | 156 |
157 | 158 |
159 | 160 | 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 132 | 133 | 134 | 135 |
136 | 137 |
138 | 143 | 150 |
151 | 152 |
153 | 157 | 161 |
162 | 163 |
164 | 165 | 166 | 167 | 168 | 239 | 240 | -------------------------------------------------------------------------------- /frontend/js/admin.js: -------------------------------------------------------------------------------- 1 | fetch('http://localhost:8888/product/top5') 2 | .then((response) => response.json()) 3 | .then((data) => displayData(data)); 4 | 5 | 6 | fetch('http://localhost:8888/category/viewAll') 7 | .then((response) => response.json()) 8 | .then((data) => displayData1(data)); 9 | 10 | 11 | function displayData(data){ 12 | 13 | data.forEach(function(ele){ 14 | let tr=document.createElement("tr") 15 | let td1=document.createElement("td") 16 | let img=document.createElement("img") 17 | img.setAttribute("src",ele.url) 18 | td1.append(img) 19 | let td2=document.createElement("td") 20 | td2.setAttribute("class","mid") 21 | td2.innerText=ele.productName 22 | let td3=document.createElement("td") 23 | td3.innerText=ele.soldCount 24 | 25 | tr.append(td1,td2,td3) 26 | document.getElementById("tab").append(tr) 27 | // document.querySelector("tbody").append(tr) 28 | 29 | }); 30 | 31 | } 32 | 33 | function displayData1(data){ 34 | console.log(data) 35 | data.forEach(function(ele){ 36 | let tr=document.createElement("tr") 37 | let td1=document.createElement("td") 38 | td1.innerText=ele.categoryId; 39 | let td2=document.createElement("td") 40 | td2.setAttribute("class","mid") 41 | td2.innerText=ele.name 42 | let td3=document.createElement("td") 43 | td3.innerText=ele.products.length 44 | 45 | tr.append(td1,td2,td3) 46 | document.getElementById("tab1").append(tr) 47 | // document.querySelector("tbody").append(tr) 48 | 49 | }); 50 | 51 | } -------------------------------------------------------------------------------- /frontend/js/cart.js: -------------------------------------------------------------------------------- 1 | 2 | let user=JSON.parse(localStorage.getItem("user")) 3 | if(user==null){ 4 | alert("please login") 5 | window.location.href="index.html" 6 | } 7 | 8 | 9 | viewCart(); 10 | 11 | 12 | async function clearCart(){ 13 | let uuid=user.uuid; 14 | 15 | let api_link=`http://localhost:8888/cart/clearCart/${uuid}` 16 | let response=await fetch(api_link,{ 17 | method:"PUT", 18 | headers:{ 19 | 'Content-Type':'application/json' 20 | } 21 | }) 22 | let data=await response.json() 23 | 24 | if(data.message!=null){ 25 | alert(data.message); 26 | } 27 | else{ 28 | console.log(data) 29 | viewCart(); 30 | } 31 | } 32 | 33 | 34 | function viewCart(){ 35 | let uuid=user.uuid; 36 | fetch(`http://localhost:8888/cart/view/${uuid}`) 37 | .then((response) => response.json()) 38 | .then((data) => displayData(data)); 39 | } 40 | 41 | 42 | function displayData(data){ 43 | console.log(data) 44 | let quantity=document.createElement("p") 45 | quantity.innerText="total quantity "+data.totalItems; 46 | quantity.setAttribute("class","quantity") 47 | 48 | let price=document.createElement("p") 49 | price.innerText="Total ₹ "+data.totalPrice; 50 | price.setAttribute("class","price") 51 | document.querySelector("#totalp").innerHTML=""; 52 | document.querySelector("#totalp").append(quantity,price) 53 | 54 | displaymens(data.products); 55 | } 56 | 57 | 58 | function displaymens(mensData){ 59 | document.querySelector("#parent").innerHTML=""; 60 | mensData.forEach(function(el){ 61 | let div=document.createElement("div") 62 | let imag=document.createElement("img") 63 | imag.setAttribute("src",el.url) 64 | imag.setAttribute("class","image") 65 | 66 | let name=document.createElement("p") 67 | name.innerText=el.productName; 68 | name.setAttribute("class","name") 69 | 70 | let btn1=document.createElement("button") 71 | btn1.innerText="-" 72 | let btn2=document.createElement("button") 73 | btn2.innerText="+" 74 | btn1.setAttribute("class","butn") 75 | btn2.setAttribute("class","butn") 76 | 77 | let spn=document.createElement("span") 78 | 79 | let quantity=document.createElement("span") 80 | quantity.innerText=el.quantity; 81 | quantity.setAttribute("class","quantity") 82 | 83 | let quantity1=document.createElement("span") 84 | quantity1.innerText="quantity"; 85 | quantity1.setAttribute("class","quantity") 86 | 87 | spn.append(quantity1,btn1,quantity,btn2) 88 | 89 | let available=document.createElement("p") 90 | if(el.quantity>el.availableProduct){ 91 | available.innerText="out of stock"; 92 | } 93 | else if(el.availableProduct<=5){ 94 | available.innerText="only "+el.availableProduct+" product left"; 95 | } 96 | available.setAttribute("class","quantity") 97 | 98 | let price=document.createElement("p") 99 | price.innerText="price ₹ "+el.price 100 | price.setAttribute("class","price") 101 | 102 | let tprice=document.createElement("p") 103 | tprice.innerText="total ₹ "+el.price*el.quantity 104 | tprice.setAttribute("class","tprice") 105 | 106 | let btn=document.createElement("button") 107 | btn.innerText="Remove" 108 | btn.setAttribute("class","delete_from_cart") 109 | btn.addEventListener("click",function(){ 110 | removeFromCart(el); 111 | }) 112 | 113 | btn2.addEventListener("click",function(){ 114 | incr(el); 115 | }) 116 | btn1.addEventListener("click",function(){ 117 | decr(el); 118 | }) 119 | 120 | div.append(imag,name,spn,price,tprice,available,btn) 121 | document.querySelector("#parent").append(div) 122 | }) 123 | } 124 | 125 | 126 | async function removeFromCart(el){ 127 | let uuid=user.uuid; 128 | let pid=el.productId; 129 | let api_link=`http://localhost:8888/cart/removeItemFromCart/${pid}/${uuid}` 130 | let response=await fetch(api_link,{ 131 | method:"PUT", 132 | headers:{ 133 | 'Content-Type':'application/json' 134 | } 135 | }) 136 | let data=await response.json() 137 | 138 | if(data.message!=null){ 139 | alert(data.message); 140 | } 141 | else{ 142 | viewCart(); 143 | } 144 | } 145 | 146 | 147 | async function incr(el){ 148 | let uuid=user.uuid; 149 | let pid=el.productId; 150 | let api_link=`http://localhost:8888/cart/increaseQuantity/${pid}/${uuid}` 151 | let response=await fetch(api_link,{ 152 | method:"PUT", 153 | headers:{ 154 | 'Content-Type':'application/json' 155 | } 156 | }) 157 | let data=await response.json() 158 | 159 | if(data.message!=null){ 160 | alert(data.message); 161 | } 162 | else{ 163 | viewCart(); 164 | } 165 | } 166 | 167 | 168 | async function decr(el){ 169 | let uuid=user.uuid; 170 | let pid=el.productId; 171 | let api_link=`http://localhost:8888/cart/decreaseQuantity/${pid}/${uuid}` 172 | let response=await fetch(api_link,{ 173 | method:"PUT", 174 | headers:{ 175 | 'Content-Type':'application/json' 176 | } 177 | }) 178 | let data=await response.json() 179 | 180 | if(data.message!=null){ 181 | alert(data.message); 182 | } 183 | else{ 184 | viewCart(); 185 | } 186 | } 187 | 188 | 189 | async function checkout(){ 190 | 191 | let uuid=user.uuid; 192 | 193 | let api_link=`http://localhost:8888/order/addOrder/${uuid}` 194 | let response=await fetch(api_link,{ 195 | method:"POST", 196 | headers:{ 197 | 'Content-Type':'application/json' 198 | } 199 | }) 200 | let data=await response.json() 201 | 202 | if(data.message!=null){ 203 | alert(data.message); 204 | } 205 | else{ 206 | alert("order confirmed") 207 | console.log(data); 208 | } 209 | } -------------------------------------------------------------------------------- /frontend/js/category.js: -------------------------------------------------------------------------------- 1 | 2 | let admin=JSON.parse(localStorage.getItem("admin")) 3 | if(admin==null){ 4 | alert("please login") 5 | window.location.href="index.html" 6 | } 7 | 8 | async function addCat(){ 9 | // let key=document.getElementById("key").value; 10 | let key=admin.uuid; 11 | let cat_data={ 12 | name:document.getElementById("catname").value, 13 | } 14 | 15 | cat_data=JSON.stringify(cat_data) 16 | 17 | let api_link=`http://localhost:8888/category/add/${key}` 18 | let response=await fetch(api_link,{ 19 | method:"POST", 20 | body:cat_data, 21 | headers:{ 22 | 'Content-Type':'application/json' 23 | } 24 | }) 25 | let data=await response.json() 26 | console.log(data) 27 | 28 | if(data.message!=null){ 29 | alert(data.message); 30 | } 31 | else{ 32 | alert("categoryId: "+data.categoryId+" name: "+data.name+" added successfully"); 33 | } 34 | } 35 | 36 | 37 | async function viewAllCat(){ 38 | 39 | fetch('http://localhost:8888/category/viewAll') 40 | .then((response) => response.json()) 41 | .then((data) => displayData1(data)); 42 | 43 | // http://localhost:8888/product/viewAllProduct 44 | } 45 | 46 | 47 | async function viewCatById(){ 48 | let key=document.getElementById("catId").value; 49 | 50 | fetch(`http://localhost:8888/category/view/${key}`) 51 | .then((response) => response.json()) 52 | .then((data) => fc(data)); 53 | 54 | function fc(data){ 55 | if(data.message!=null){ 56 | alert(data.message); 57 | } 58 | else{ 59 | alert("categoryId: "+data.categoryId+" name: "+data.name+" total products: "+data.products.length); 60 | } 61 | } 62 | } 63 | 64 | 65 | async function viewProductByCat(){ 66 | let key=document.getElementById("catId1").value; 67 | 68 | fetch(`http://localhost:8888/category/viewProductByCategory/${key}`) 69 | .then((response) => response.json()) 70 | .then((data) => displayData2(data)); 71 | } 72 | 73 | 74 | async function deleteCat(){ 75 | let key=document.getElementById("catId2").value; 76 | let uuid=admin.uuid; 77 | 78 | let api_link=`http://localhost:8888/category/delete/${key}/${uuid}` 79 | let response=await fetch(api_link,{ 80 | method:"DELETE", 81 | headers:{ 82 | 'Content-Type':'application/json' 83 | } 84 | }) 85 | let data=await response.json() 86 | if(data.message!=null){ 87 | alert(data.message); 88 | } 89 | else{ 90 | alert("categoryId: "+data.categoryId+" name: "+data.name+" deleted successfully"); 91 | } 92 | 93 | } 94 | 95 | 96 | function displayData1(data){ 97 | 98 | let cont=document.getElementById("display") 99 | cont.innerHTML=null; 100 | 101 | let table=document.createElement("table"); 102 | let p=document.createElement("p"); 103 | p.setAttribute("class","proCat") 104 | p.innerText="Product Categories" 105 | 106 | let thead=document.createElement("thead"); 107 | let tr1=document.createElement("tr"); 108 | let th1=document.createElement("th"); 109 | th1.innerText="Id"; 110 | let th2=document.createElement("th"); 111 | th2.setAttribute("class","mid") 112 | th2.innerText="Name" 113 | let th3=document.createElement("th"); 114 | th3.innerText="Total Products" 115 | tr1.append(th1,th2,th3); 116 | thead.append(tr1); 117 | let tbody=document.createElement("tbody"); 118 | tbody.setAttribute("id","tab1") 119 | table.append(thead,tbody) 120 | cont.append(p,table); 121 | 122 | data.forEach(function(ele){ 123 | let tr=document.createElement("tr") 124 | let td1=document.createElement("td") 125 | td1.innerText=ele.categoryId; 126 | let td2=document.createElement("td") 127 | td2.setAttribute("class","mid") 128 | td2.innerText=ele.name 129 | let td3=document.createElement("td") 130 | td3.innerText=ele.products.length 131 | 132 | tr.append(td1,td2,td3) 133 | document.getElementById("tab1").append(tr) 134 | 135 | }); 136 | 137 | } 138 | 139 | 140 | function displayData2(data){ 141 | 142 | let cont=document.getElementById("display") 143 | cont.innerHTML=null; 144 | 145 | let table=document.createElement("table"); 146 | let p=document.createElement("p"); 147 | p.setAttribute("class","proCat") 148 | p.innerText="Products" 149 | 150 | let thead=document.createElement("thead"); 151 | 152 | let tr1=document.createElement("tr"); 153 | 154 | let th0=document.createElement("th"); 155 | th0.innerText="Image" 156 | let th1=document.createElement("th"); 157 | th1.innerText="Id"; 158 | let th2=document.createElement("th"); 159 | th2.innerText="Name" 160 | let th3=document.createElement("th"); 161 | th3.innerText="Description" 162 | let th4=document.createElement("th"); 163 | th4.innerText="Price" 164 | let th5=document.createElement("th"); 165 | th5.innerText="Quantity" 166 | let th6=document.createElement("th"); 167 | th6.innerText="Rating" 168 | let th7=document.createElement("th"); 169 | th7.innerText="Sold" 170 | 171 | tr1.append(th0,th1,th2,th3,th4,th5,th6,th7); 172 | thead.append(tr1); 173 | 174 | let tbody=document.createElement("tbody"); 175 | tbody.setAttribute("id","tab1") 176 | table.append(thead,tbody) 177 | cont.append(p,table); 178 | 179 | data.forEach(function(ele){ 180 | let tr=document.createElement("tr") 181 | let td1=document.createElement("td") 182 | td1.innerText=ele.productId; 183 | let td2=document.createElement("td") 184 | td2.innerText=ele.productName 185 | let td3=document.createElement("td") 186 | td3.innerText=ele.description 187 | let td4=document.createElement("td") 188 | td4.innerText=ele.price; 189 | let td5=document.createElement("td") 190 | td5.innerText=ele.quantity 191 | let td6=document.createElement("td") 192 | td6.innerText=ele.rating 193 | let td7=document.createElement("td") 194 | td7.innerText=ele.soldCount 195 | let td0=document.createElement("td") 196 | let img=document.createElement("img") 197 | img.setAttribute("src",ele.url) 198 | td0.append(img) 199 | 200 | tr.append(td0,td1,td2,td3,td4,td5,td6,td7) 201 | document.getElementById("tab1").append(tr) 202 | 203 | }); 204 | 205 | 206 | } 207 | -------------------------------------------------------------------------------- /frontend/js/index.js: -------------------------------------------------------------------------------- 1 | async function Register(){ 2 | let key=document.getElementById("key").value; 3 | let signup_data={ 4 | adminEmail:document.getElementById("email").value, 5 | adminPassword:document.getElementById("password").value, 6 | adminMobile:document.getElementById("mobile").value, 7 | } 8 | 9 | signup_data=JSON.stringify(signup_data) 10 | 11 | let signup_api_link=`http://localhost:8888/admin/register?validationKey=${key}` 12 | let response=await fetch(signup_api_link,{ 13 | method:"POST", 14 | body:signup_data, 15 | headers:{ 16 | 'Content-Type':'application/json' 17 | } 18 | }) 19 | let data=await response.json() 20 | console.log(data) 21 | } 22 | 23 | 24 | async function Login(){ 25 | 26 | let login_data={ 27 | mobile:document.getElementById("mobile1").value, 28 | password:document.getElementById("password1").value, 29 | } 30 | 31 | login_data=JSON.stringify(login_data) 32 | 33 | let login_api_link=`http://localhost:8888/adminlogin/login` 34 | let response=await fetch(login_api_link,{ 35 | method:"POST", 36 | body:login_data, 37 | headers:{ 38 | 'Content-Type':'application/json' 39 | } 40 | }) 41 | 42 | let data=await response.json() 43 | fun(data) 44 | 45 | // localDateTime : "2022-11-27T17:11:33.0402306" 46 | // userId : 24 47 | // uuid : "mZKfT0" 48 | 49 | } 50 | 51 | 52 | function fun(data){ 53 | if(data.uuid!=null){ 54 | localStorage.setItem("admin",JSON.stringify(data)) 55 | window.location.href="admin.html" 56 | } 57 | else{ 58 | alert(data.message) 59 | } 60 | } 61 | 62 | 63 | async function Register1(){ 64 | let signup_data={ 65 | customerName:document.getElementById("name2").value, 66 | email:document.getElementById("email2").value, 67 | password:document.getElementById("password2").value, 68 | mobile:document.getElementById("mobile2").value, 69 | address: { 70 | city: "", 71 | country: "", 72 | id: 0, 73 | pincode: "", 74 | state: "" 75 | }, 76 | } 77 | 78 | signup_data=JSON.stringify(signup_data) 79 | 80 | let signup_api_link=`http://localhost:8888/customer/register` 81 | let response=await fetch(signup_api_link,{ 82 | method:"POST", 83 | body:signup_data, 84 | headers:{ 85 | 'Content-Type':'application/json' 86 | } 87 | }) 88 | let data=await response.json() 89 | console.log(data) 90 | } 91 | 92 | 93 | async function Login1(){ 94 | 95 | let login_data={ 96 | mobile:document.getElementById("mobile3").value, 97 | password:document.getElementById("password3").value, 98 | } 99 | 100 | login_data=JSON.stringify(login_data) 101 | 102 | let login_api_link=`http://localhost:8888/userlogin/login` 103 | let response=await fetch(login_api_link,{ 104 | method:"POST", 105 | body:login_data, 106 | headers:{ 107 | 'Content-Type':'application/json' 108 | } 109 | }) 110 | 111 | let data=await response.json() 112 | fun1(data) 113 | } 114 | 115 | 116 | function fun1(data){ 117 | if(data.uuid!=null){ 118 | localStorage.setItem("user",JSON.stringify(data)) 119 | window.location.href="user.html" 120 | } 121 | else{ 122 | alert(data.message) 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /frontend/js/order.js: -------------------------------------------------------------------------------- 1 | 2 | let admin=JSON.parse(localStorage.getItem("admin")) 3 | if(admin==null){ 4 | alert("please login") 5 | window.location.href="index.html" 6 | } 7 | 8 | 9 | async function viewOrdersByDate(){ 10 | let s=document.getElementById("startdate").value; 11 | let e=document.getElementById("enddate").value; 12 | 13 | fetch(`http://localhost:8888/order/viewOrdersByDate/${s}/${e}`) 14 | .then((response) => response.json()) 15 | .then((data) => displayOrd(data)); 16 | } 17 | 18 | async function viewAllOrder(){ 19 | fetch(`http://localhost:8888/order/viewAllOrder`) 20 | .then((response) => response.json()) 21 | .then((data) => displayOrd(data)); 22 | } 23 | 24 | function displayOrd(data){ 25 | console.log(data) 26 | if(data.message!=null){ 27 | alert(data.message) 28 | } 29 | else{ 30 | let cont=document.getElementById("parent") 31 | cont.innerHTML=null; 32 | data.forEach(el => { 33 | console.log(el) 34 | let div=document.createElement("div"); 35 | let p1=document.createElement("p"); 36 | p1.innerText="order date : "+el.orderDate 37 | let p2=document.createElement("p"); 38 | p2.innerText="order time : "+el.orderTime 39 | let p3=document.createElement("p"); 40 | p3.innerText="order status : "+el.status 41 | 42 | let btn=document.createElement("button") 43 | btn.innerText="update status" 44 | btn.addEventListener("click",function(){ 45 | updateStatus(el); 46 | }) 47 | 48 | let p4=document.createElement("p"); 49 | p4.innerText="customer name : "+el.customer.customerName 50 | 51 | let p5=document.createElement("p"); 52 | p5.innerText="customer mobile : "+el.customer.mobile 53 | 54 | let p6=document.createElement("p"); 55 | p6.innerText="customer email : "+el.customer.email 56 | 57 | div.addEventListener("click",function(){ 58 | displayData2(el.products); 59 | }) 60 | 61 | div.append(p1,p2,p3,btn,p4,p5,p6) 62 | cont.append(div) 63 | }); 64 | } 65 | } 66 | 67 | async function updateStatus(el){ 68 | let status = prompt("enter status", "confirmed"); 69 | 70 | let api_link=`http://localhost:8888/order/updateOrderStatus/${el.orderId}/${status}` 71 | 72 | let response=await fetch(api_link,{ 73 | method:"PUT", 74 | headers:{ 75 | 'Content-Type':'application/json' 76 | } 77 | }) 78 | let data=await response.json() 79 | 80 | if(data.message!=null){ 81 | alert(data.message); 82 | } 83 | else{ 84 | console.log(data) 85 | window.location.reload(); 86 | } 87 | } 88 | 89 | 90 | function displayData2(data){ 91 | 92 | console.log(data) 93 | 94 | let cont=document.getElementById("display") 95 | cont.innerHTML=null; 96 | 97 | let table=document.createElement("table"); 98 | let p=document.createElement("p"); 99 | p.setAttribute("class","proCat") 100 | p.innerText="Products" 101 | 102 | let thead=document.createElement("thead"); 103 | 104 | let tr1=document.createElement("tr"); 105 | 106 | let th0=document.createElement("th"); 107 | th0.innerText="Image" 108 | let th1=document.createElement("th"); 109 | th1.innerText="Id"; 110 | let th2=document.createElement("th"); 111 | th2.innerText="Name" 112 | let th3=document.createElement("th"); 113 | th3.innerText="Description" 114 | let th4=document.createElement("th"); 115 | th4.innerText="Price" 116 | let th5=document.createElement("th"); 117 | th5.innerText="Quantity" 118 | 119 | tr1.append(th0,th1,th2,th3,th4,th5); 120 | thead.append(tr1); 121 | 122 | let tbody=document.createElement("tbody"); 123 | tbody.setAttribute("id","tab1") 124 | table.append(thead,tbody) 125 | cont.append(p,table); 126 | 127 | data.forEach(function(ele){ 128 | let tr=document.createElement("tr") 129 | let td1=document.createElement("td") 130 | td1.innerText=ele.productId; 131 | let td2=document.createElement("td") 132 | td2.innerText=ele.productName 133 | let td3=document.createElement("td") 134 | td3.innerText=ele.description 135 | let td4=document.createElement("td") 136 | td4.innerText=ele.price; 137 | let td5=document.createElement("td") 138 | td5.innerText=ele.quantity 139 | 140 | let td0=document.createElement("td") 141 | let img=document.createElement("img") 142 | img.setAttribute("src",ele.url) 143 | td0.append(img) 144 | 145 | tr.append(td0,td1,td2,td3,td4,td5) 146 | document.getElementById("tab1").append(tr) 147 | 148 | }); 149 | 150 | 151 | } 152 | 153 | viewAllOrder(); -------------------------------------------------------------------------------- /frontend/js/product.js: -------------------------------------------------------------------------------- 1 | 2 | let admin=JSON.parse(localStorage.getItem("admin")) 3 | if(admin==null){ 4 | alert("please login") 5 | window.location.href="index.html" 6 | } 7 | 8 | async function addProduct(){ 9 | 10 | let key=admin.uuid; 11 | let cat_id=document.getElementById("catid").value; 12 | 13 | let pro_data={ 14 | productName:document.getElementById("name").value, 15 | description:document.getElementById("desc").value, 16 | price:document.getElementById("price").value, 17 | quantity:document.getElementById("quan").value, 18 | url:document.getElementById("url").value, 19 | rating: 0, 20 | ratingCount: 0, 21 | soldCount: 0, 22 | } 23 | 24 | pro_data=JSON.stringify(pro_data) 25 | 26 | let api_link=`http://localhost:8888/product/add/${cat_id}/${key}` 27 | let response=await fetch(api_link,{ 28 | method:"POST", 29 | body:pro_data, 30 | headers:{ 31 | 'Content-Type':'application/json' 32 | } 33 | }) 34 | let data=await response.json() 35 | 36 | if(data.message!=null){ 37 | alert(data.message); 38 | } 39 | else{ 40 | displayData1(data) 41 | } 42 | } 43 | 44 | async function deletePro(){ 45 | let key=document.getElementById("proId2").value; 46 | let uuid=admin.uuid; 47 | 48 | let api_link=`http://localhost:8888/product/delete/${key}/${uuid}` 49 | let response=await fetch(api_link,{ 50 | method:"DELETE", 51 | headers:{ 52 | 'Content-Type':'application/json' 53 | } 54 | }) 55 | let data=await response.json() 56 | 57 | if(data.message!=null){ 58 | alert(data.message); 59 | } 60 | else{ 61 | displayData1(data) 62 | } 63 | 64 | } 65 | 66 | async function viewAllPro(){ 67 | 68 | fetch('http://localhost:8888/product/viewAllProduct') 69 | .then((response) => response.json()) 70 | .then((data) => displayData2(data)); 71 | 72 | } 73 | 74 | async function viewProByName(){ 75 | let key=document.getElementById("pro").value; 76 | 77 | fetch(`http://localhost:8888/product/productByName/${key}`) 78 | .then((response) => response.json()) 79 | .then((data) => displayData2(data)); 80 | } 81 | 82 | async function viewProById(){ 83 | let key=document.getElementById("proId").value; 84 | 85 | fetch(`http://localhost:8888/product/view/${key}`) 86 | .then((response) => response.json()) 87 | .then((data) => displayData1(data)); 88 | } 89 | 90 | async function updateProduct(){ 91 | 92 | let key=admin.uuid; 93 | 94 | let pro_data={ 95 | productId:document.getElementById("proId1").value, 96 | productName:document.getElementById("name1").value, 97 | description:document.getElementById("desc1").value, 98 | price:document.getElementById("price1").value, 99 | quantity:document.getElementById("quan1").value, 100 | url:document.getElementById("url1").value, 101 | } 102 | 103 | pro_data=JSON.stringify(pro_data) 104 | 105 | let api_link=`http://localhost:8888/product/update/${key}` 106 | let response=await fetch(api_link,{ 107 | method:"PUT", 108 | body:pro_data, 109 | headers:{ 110 | 'Content-Type':'application/json' 111 | } 112 | }) 113 | let data=await response.json() 114 | 115 | 116 | if(data.message!=null){ 117 | alert(data.message); 118 | } 119 | else{ 120 | displayData1(data) 121 | } 122 | } 123 | 124 | 125 | 126 | function displayData2(data){ 127 | 128 | let cont=document.getElementById("display") 129 | cont.innerHTML=null; 130 | 131 | let table=document.createElement("table"); 132 | let p=document.createElement("p"); 133 | p.setAttribute("class","proCat") 134 | p.innerText="Products" 135 | 136 | let thead=document.createElement("thead"); 137 | 138 | let tr1=document.createElement("tr"); 139 | 140 | let th0=document.createElement("th"); 141 | th0.innerText="Image" 142 | let th1=document.createElement("th"); 143 | th1.innerText="Id"; 144 | let th2=document.createElement("th"); 145 | th2.innerText="Name" 146 | let th3=document.createElement("th"); 147 | th3.innerText="Description" 148 | let th4=document.createElement("th"); 149 | th4.innerText="Price" 150 | let th5=document.createElement("th"); 151 | th5.innerText="Quantity" 152 | let th6=document.createElement("th"); 153 | th6.innerText="Rating" 154 | let th7=document.createElement("th"); 155 | th7.innerText="Sold" 156 | 157 | tr1.append(th0,th1,th2,th3,th4,th5,th6,th7); 158 | thead.append(tr1); 159 | 160 | let tbody=document.createElement("tbody"); 161 | tbody.setAttribute("id","tab1") 162 | table.append(thead,tbody) 163 | cont.append(p,table); 164 | 165 | data.forEach(function(ele){ 166 | let tr=document.createElement("tr") 167 | let td1=document.createElement("td") 168 | td1.innerText=ele.productId; 169 | let td2=document.createElement("td") 170 | td2.innerText=ele.productName 171 | let td3=document.createElement("td") 172 | td3.innerText=ele.description 173 | let td4=document.createElement("td") 174 | td4.innerText=ele.price; 175 | let td5=document.createElement("td") 176 | td5.innerText=ele.quantity 177 | let td6=document.createElement("td") 178 | td6.innerText=ele.rating 179 | let td7=document.createElement("td") 180 | td7.innerText=ele.soldCount 181 | let td0=document.createElement("td") 182 | let img=document.createElement("img") 183 | img.setAttribute("src",ele.url) 184 | td0.append(img) 185 | 186 | tr.append(td0,td1,td2,td3,td4,td5,td6,td7) 187 | document.getElementById("tab1").append(tr) 188 | 189 | }); 190 | 191 | 192 | } 193 | 194 | function displayData1(ele){ 195 | 196 | let cont=document.getElementById("display") 197 | cont.innerHTML=null; 198 | 199 | let table=document.createElement("table"); 200 | let p=document.createElement("p"); 201 | p.setAttribute("class","proCat") 202 | p.innerText="Product" 203 | 204 | let thead=document.createElement("thead"); 205 | 206 | let tr1=document.createElement("tr"); 207 | 208 | let th0=document.createElement("th"); 209 | th0.innerText="Image" 210 | let th1=document.createElement("th"); 211 | th1.innerText="Id"; 212 | let th2=document.createElement("th"); 213 | th2.innerText="Name" 214 | let th3=document.createElement("th"); 215 | th3.innerText="Description" 216 | let th4=document.createElement("th"); 217 | th4.innerText="Price" 218 | let th5=document.createElement("th"); 219 | th5.innerText="Quantity" 220 | let th6=document.createElement("th"); 221 | th6.innerText="Rating" 222 | let th7=document.createElement("th"); 223 | th7.innerText="Sold" 224 | 225 | tr1.append(th0,th1,th2,th3,th4,th5,th6,th7); 226 | thead.append(tr1); 227 | 228 | let tbody=document.createElement("tbody"); 229 | tbody.setAttribute("id","tab1") 230 | table.append(thead,tbody) 231 | cont.append(p,table); 232 | 233 | // data.forEach(function(ele){ 234 | let tr=document.createElement("tr") 235 | let td1=document.createElement("td") 236 | td1.innerText=ele.productId; 237 | let td2=document.createElement("td") 238 | td2.innerText=ele.productName 239 | let td3=document.createElement("td") 240 | td3.innerText=ele.description 241 | let td4=document.createElement("td") 242 | td4.innerText=ele.price; 243 | let td5=document.createElement("td") 244 | td5.innerText=ele.quantity 245 | let td6=document.createElement("td") 246 | td6.innerText=ele.rating 247 | let td7=document.createElement("td") 248 | td7.innerText=ele.soldCount 249 | let td0=document.createElement("td") 250 | let img=document.createElement("img") 251 | img.setAttribute("src",ele.url) 252 | td0.append(img) 253 | 254 | tr.append(td0,td1,td2,td3,td4,td5,td6,td7) 255 | document.getElementById("tab1").append(tr) 256 | 257 | // }); 258 | 259 | 260 | } 261 | -------------------------------------------------------------------------------- /frontend/js/user.js: -------------------------------------------------------------------------------- 1 | let user=JSON.parse(localStorage.getItem("user")) 2 | if(user==null){ 3 | alert("please login") 4 | window.location.href="index.html" 5 | } 6 | 7 | 8 | async function viewProByName(){ 9 | event.preventDefault() 10 | let key=document.getElementById("pro").value; 11 | 12 | fetch(`http://localhost:8888/product/productByName/${key}`) 13 | .then((response) => response.json()) 14 | .then((data) => displaymens(data)); 15 | } 16 | 17 | 18 | async function viewAllPro(){ 19 | 20 | fetch('http://localhost:8888/product/viewAllProduct') 21 | .then((response) => response.json()) 22 | .then((data) => displaymens(data)); 23 | 24 | } 25 | 26 | 27 | viewAllPro() 28 | 29 | 30 | function displaymens(mensData){ 31 | document.querySelector("#parent").innerHTML=""; 32 | mensData.forEach(function(el){ 33 | 34 | let div=document.createElement("div") 35 | div.setAttribute("class","product") 36 | 37 | let imag=document.createElement("img") 38 | imag.setAttribute("src",el.url) 39 | imag.setAttribute("class","image") 40 | 41 | let name=document.createElement("h3") 42 | name.innerText=el.productName; 43 | name.setAttribute("class","name") 44 | 45 | let desc=document.createElement("p") 46 | desc.innerText=el.description; 47 | desc.setAttribute("class","desc") 48 | 49 | let price=document.createElement("p") 50 | price.innerText="₹"+el.price 51 | price.setAttribute("class","price") 52 | 53 | let btn=document.createElement("button") 54 | btn.innerText="Add to Cart" 55 | btn.setAttribute("class","add_to_cart") 56 | btn.addEventListener("click",function(){ 57 | btn.disabled=true 58 | btn.innerText="Go to Cart" 59 | addToCart(el) 60 | }) 61 | 62 | div.append(imag,name,desc,price,btn) 63 | document.querySelector("#parent").append(div) 64 | }) 65 | } 66 | 67 | 68 | async function addToCart(el){ 69 | 70 | let pid=el.productId; 71 | let uuid=user.uuid; 72 | 73 | let api_link=`http://localhost:8888/cart/addItemIntoCart/${pid}/${uuid}` 74 | 75 | let response=await fetch(api_link,{ 76 | method:"PUT", 77 | headers:{ 78 | 'Content-Type':'application/json' 79 | } 80 | }) 81 | let data=await response.json() 82 | 83 | if(data.message!=null){ 84 | alert(data.message); 85 | } 86 | else{ 87 | console.log(data) 88 | } 89 | 90 | } 91 | 92 | 93 | async function viewAllCat(){ 94 | fetch('http://localhost:8888/category/viewAll') 95 | .then((response) => response.json()) 96 | .then((data) => discat(data)); 97 | } 98 | 99 | 100 | function discat(data){ 101 | document.querySelector("#parent").innerHTML=""; 102 | data.forEach(e => { 103 | let div=document.createElement("div"); 104 | div.innerText=e.name 105 | 106 | div.addEventListener("click",function(){ 107 | displaymens(e.products); 108 | }) 109 | 110 | document.getElementById("parent").append(div) 111 | }); 112 | } 113 | 114 | 115 | async function viewOrder(){ 116 | let uuid=user.uuid; 117 | fetch(`http://localhost:8888/customer/viewOrders/${uuid}`) 118 | .then((response) => response.json()) 119 | .then((data) => disOrder(data)); 120 | } 121 | 122 | 123 | function disOrder(data){ 124 | console.log(data) 125 | document.querySelector("#parent").innerHTML=""; 126 | data.forEach(e => { 127 | let div=document.createElement("div"); 128 | let p1=document.createElement("p"); 129 | p1.innerText="Order date : "+e.orderDate 130 | let p2=document.createElement("p"); 131 | p2.innerText="Order time : "+e.orderTime 132 | let p3=document.createElement("p"); 133 | p3.innerText="Order status : "+e.status 134 | let p4=document.createElement("p"); 135 | p4.innerText="total products : "+e.products.length 136 | div.append(p1,p2,p3,p4) 137 | 138 | div.addEventListener("click",function(){ 139 | displayOrder(e.products); 140 | }) 141 | 142 | document.getElementById("parent").append(div) 143 | }); 144 | } 145 | 146 | 147 | function displayOrder(mensData){ 148 | console.log(mensData) 149 | document.querySelector("#parent").innerHTML=""; 150 | mensData.forEach(function(el){ 151 | 152 | let div=document.createElement("div") 153 | let imag=document.createElement("img") 154 | imag.setAttribute("src",el.url) 155 | imag.setAttribute("class","image") 156 | 157 | let name=document.createElement("p") 158 | name.innerText=el.productName; 159 | name.setAttribute("class","name") 160 | 161 | let price=document.createElement("p") 162 | price.innerText="₹"+el.price 163 | price.setAttribute("class","price") 164 | 165 | let q=document.createElement("p") 166 | q.innerText="quantity "+el.quantity 167 | q.setAttribute("class","price") 168 | 169 | let btn=document.createElement("button") 170 | 171 | div.append(imag,name,price,q,btn) 172 | document.querySelector("#parent").append(div) 173 | }) 174 | } 175 | -------------------------------------------------------------------------------- /frontend/nav.css: -------------------------------------------------------------------------------- 1 | 2 | /* ===========css for navbar=========== */ 3 | .top-nav { 4 | /* font-family: 'Exo Space'; */ 5 | width: 100%; 6 | height: 50px; 7 | display: flex; 8 | flex-direction: row; 9 | align-items: center; 10 | justify-content: space-between; 11 | background-color: #E0E0E0; 12 | color: #001C55; 13 | padding: 1em; 14 | position:fixed; 15 | z-index: 1; 16 | top: 0; 17 | } 18 | 19 | .menu { 20 | display: flex; 21 | flex-direction: row; 22 | list-style-type: none; 23 | margin: 0; 24 | padding: 0; 25 | } 26 | 27 | .menu > li { 28 | margin: 0 1rem; 29 | overflow: hidden; 30 | } 31 | 32 | .menu-button-container { 33 | display: none; 34 | width: 30px; 35 | cursor: pointer; 36 | flex-direction: column; 37 | justify-content: center; 38 | align-items: center; 39 | } 40 | 41 | #menu-toggle { 42 | display: none; 43 | } 44 | 45 | .menu-button, 46 | .menu-button::before, 47 | .menu-button::after { 48 | display: block; 49 | background-color: black; 50 | position: absolute; 51 | height: 4px; 52 | width: 30px; 53 | transition: transform 400ms cubic-bezier(0.23, 1, 0.32, 1); 54 | border-radius: 2px; 55 | } 56 | 57 | .menu-button::before { 58 | content: ''; 59 | margin-top: -8px; 60 | } 61 | 62 | .menu-button::after { 63 | content: ''; 64 | margin-top: 8px; 65 | } 66 | 67 | #menu-toggle:checked + .menu-button-container .menu-button::before { 68 | margin-top: 0px; 69 | transform: rotate(405deg); 70 | } 71 | 72 | #menu-toggle:checked + .menu-button-container .menu-button { 73 | background: rgba(255, 255, 255, 0); 74 | } 75 | 76 | #menu-toggle:checked + .menu-button-container .menu-button::after { 77 | margin-top: 0px; 78 | transform: rotate(-405deg); 79 | } 80 | 81 | 82 | .tdn{ 83 | text-decoration: none; 84 | color: #001C55; 85 | } 86 | 87 | .menu>li{ 88 | font-weight: bold; 89 | } 90 | 91 | 92 | 93 | /* -----------------------------------media query for nav bar--------------------------------- */ 94 | /* -----------------------------------media query for nav bar--------------------------------- */ 95 | @media (max-width: 878px) { 96 | .menu-button-container { 97 | display: flex; 98 | } 99 | .menu { 100 | position: absolute; 101 | top: 0; 102 | margin-top: 50px; 103 | left: 0; 104 | flex-direction: column; 105 | width: 100%; 106 | justify-content: center; 107 | align-items: center; 108 | } 109 | #menu-toggle ~ .menu li { 110 | height: 0; 111 | margin: 0; 112 | padding: 0; 113 | border: 0; 114 | transition: height 400ms cubic-bezier(0.23, 1, 0.32, 1); 115 | } 116 | #menu-toggle:checked ~ .menu li { 117 | height: 2.5em; 118 | padding: 0.5em; 119 | transition: height 400ms cubic-bezier(0.23, 1, 0.32, 1); 120 | } 121 | .menu > li { 122 | display: flex; 123 | justify-content: center; 124 | margin: 0; 125 | padding: 0.5em 0; 126 | width: 100%; 127 | color: black; 128 | background-color: #fff; 129 | } 130 | } 131 | 132 | -------------------------------------------------------------------------------- /frontend/order.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Orders 8 | 9 | 10 | 85 | 86 | 87 | 88 | 89 |
90 | 91 | 92 | 93 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
122 | 130 | 131 | 132 | 133 |
134 | 135 |
136 | 137 |
138 | 139 |
140 | 141 |
142 | 143 | 144 | 145 | 146 |
147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /frontend/product.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Product 8 | 9 | 70 | 71 | 72 | 73 | 74 |
75 | 76 | 77 | 78 | 100 | 101 | 102 | 103 | 104 | 105 | 106 |
107 | 168 | 169 | 170 | 171 |
172 | 173 |
174 | 175 |
176 | 177 | 178 | 179 | 180 |
181 | 182 | 183 | 184 | 185 | -------------------------------------------------------------------------------- /frontend/style.css: -------------------------------------------------------------------------------- 1 | 2 | * { 3 | font-family: sans-serif; 4 | box-sizing: border-box; 5 | } 6 | 7 | body { 8 | margin: 0; 9 | background: #f3f5fb; 10 | } 11 | 12 | .flex-page { 13 | display: flex; 14 | } 15 | 16 | 17 | .side-nav { 18 | background: #FFFFFF; 19 | position: sticky; 20 | top: 0; 21 | left: 0; 22 | height: 100vh; 23 | } 24 | 25 | .side-nav ul { 26 | margin: 0; 27 | padding: 0; 28 | } 29 | 30 | .side-nav ul li a { 31 | padding: 0.75rem 1rem; 32 | color: black; 33 | text-decoration: none; 34 | cursor: pointer; 35 | display: block; 36 | border-top: 1px solid rgb(187, 224, 235); 37 | border-bottom: 1px solid rgb(187, 224, 235); 38 | } 39 | .side-nav ul li a svg{ 40 | width: 99%; 41 | margin: auto; 42 | } 43 | 44 | .side-nav ul li a p{ 45 | text-align: center; 46 | } 47 | 48 | .now{ 49 | background-color: rgb(246, 248, 252); 50 | border: 1px solid rgb(187, 224, 235); 51 | } 52 | 53 | #right{ 54 | padding: 20px; 55 | display: flex; 56 | gap: 20px; 57 | } 58 | -------------------------------------------------------------------------------- /frontend/user.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Home 8 | 9 | 10 | 11 | 53 | 54 | 55 | 56 | 57 | 152 | 153 | 154 | 155 | 156 |
157 |
158 | 159 |
160 | 161 | 164 | 177 | 178 |
179 | 180 |
181 | 182 |
183 | 184 |
185 | 186 |
187 | 188 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /frontend/userprofile.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 |
17 |

Edit Personal Information

18 |
19 |
20 |
21 | 22 | 23 |
24 |
25 |
26 |
27 |
28 |
29 | 30 | 31 |
32 |
33 |
34 |
35 |
36 |
37 | 38 | 39 |
40 |
41 |
42 |
43 |
44 |
45 | 46 | 47 |
48 |
49 |
50 | 51 |
52 |
53 |
54 | 55 | 56 |
57 |
58 |
59 |
60 |
61 |
62 | 63 | 64 |
65 |
66 |
67 | 68 |
69 |
70 |
71 | 72 | 73 |
74 |
75 |
76 |
77 |
78 |
79 | 80 | 81 |
82 |
83 |
84 | 85 |
86 |
87 |
88 | 89 |
90 |
91 |
92 |
93 | 94 |
95 |
96 |
97 |
98 |
99 |
100 | 101 | 102 | 103 | 104 | 105 | --------------------------------------------------------------------------------