├── .gitignore ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── online-store.jpg ├── settings.gradle └── src ├── main ├── java │ └── com │ │ └── example │ │ └── onlinestore │ │ ├── OnlineStoreApplication.java │ │ ├── config │ │ ├── MailConfig.java │ │ └── SecurityConfig.java │ │ ├── controller │ │ └── v1 │ │ │ ├── AuthenticationRestControllerV1.java │ │ │ ├── CommentControllerV1.java │ │ │ ├── DeviceControllerV1.java │ │ │ ├── MailControllerV1.java │ │ │ ├── UserRestControllerV1.java │ │ │ └── admin │ │ │ ├── AdminDeviceControllerV1.java │ │ │ └── AdminRestControllerV1.java │ │ ├── dto │ │ ├── device │ │ │ ├── BrandDto.java │ │ │ ├── CommentDto.java │ │ │ ├── DeviceDto.java │ │ │ ├── DeviceTypeDto.java │ │ │ ├── FullDeviceDto.java │ │ │ ├── NewDeviceDto.java │ │ │ └── PropertyDto.java │ │ └── user │ │ │ ├── AuthenticationRequestDto.java │ │ │ └── UserDto.java │ │ ├── entity │ │ ├── device │ │ │ ├── Brand.java │ │ │ ├── Comment.java │ │ │ ├── Device.java │ │ │ ├── DeviceType.java │ │ │ ├── Dislike.java │ │ │ ├── Like.java │ │ │ └── Property.java │ │ └── user │ │ │ ├── Basket.java │ │ │ ├── Favourite.java │ │ │ ├── Order.java │ │ │ ├── Role.java │ │ │ └── User.java │ │ ├── exceptions │ │ ├── existException │ │ │ ├── BrandAlreadyExist.java │ │ │ ├── DeviceAlreadyExist.java │ │ │ ├── DeviceTypeAlreadyExist.java │ │ │ ├── PropertyAlreadyExist.java │ │ │ └── UserAlreadyExistAuthException.java │ │ └── notFoundException │ │ │ ├── BrandNotFoundException.java │ │ │ ├── DeviceNotFoundException.java │ │ │ ├── DeviceTypeNotFoundException.java │ │ │ ├── ModelNotFoundException.java │ │ │ └── UserNotFoundException.java │ │ ├── repos │ │ ├── device │ │ │ ├── BrandRepo.java │ │ │ ├── CommentRepo.java │ │ │ ├── DeviceRepo.java │ │ │ ├── DeviceTypeRepo.java │ │ │ ├── DislikeRepo.java │ │ │ ├── LikeRepo.java │ │ │ └── PropertyRepo.java │ │ └── user │ │ │ ├── BasketRepo.java │ │ │ ├── FavouriteRepo.java │ │ │ ├── OrderRepo.java │ │ │ ├── RoleRepo.java │ │ │ └── UserRepo.java │ │ ├── security │ │ ├── JwtUserDetailsService.java │ │ └── jwt │ │ │ ├── JwtAuthenticationException.java │ │ │ ├── JwtConfigurer.java │ │ │ ├── JwtTokenFilter.java │ │ │ ├── JwtTokenProvider.java │ │ │ ├── JwtUser.java │ │ │ └── JwtUserFactory.java │ │ └── service │ │ ├── ImageService.java │ │ ├── device │ │ ├── BrandService.java │ │ ├── CommentService.java │ │ ├── DeviceService.java │ │ ├── DeviceTypeService.java │ │ └── PropertyService.java │ │ └── user │ │ ├── UserService.java │ │ └── impl │ │ └── UserServiceImpl.java └── resources │ ├── application.properties │ ├── db │ └── migration │ │ ├── V1__init_db.sql │ │ ├── V2__insert_into.sql │ │ ├── V3__add_dev_desk.sql │ │ ├── V4__add_creation.sql │ │ └── V5__add_likes.sql │ └── static │ └── img │ ├── 08a32ad4-3c47-416b-9f80-1f8c565b801e.jpg │ ├── 126b9073-b25b-4bfd-a17b-9f23c73f022e.jpg │ ├── 13135e8e-7f64-4642-98b8-5fe50e35d3dc.jpg │ ├── 1368d338-e94a-4ca1-bdb9-5a83c82f2ab6.jpg │ ├── 15558ef3-24fc-4494-82dc-8ce133de9f28.jpg │ ├── 18bddc87-84a3-4ecb-a979-68217f021943.jpg │ ├── 2453aa30-920f-4794-bb2d-5a437fd9790d.jpg │ ├── 251554e6-f7a9-43ae-a4ed-dff50125bf35.jpg │ ├── 27fc678d-e452-4f5f-aa34-edc4db5201a3.jpg │ ├── 2ad40117-1d7d-42c3-9c6a-b75d5db9c73f.jpg │ ├── 329d50a8-9b24-4191-87f8-1c36e50135b1.jpg │ ├── 3b0fb6dc-c27a-4877-8502-e977667f3882.jpg │ ├── 3c027f3e-5b1b-4460-b1c2-43488f887f80.jpg │ ├── 3d3110f5-c617-4f29-8779-b21dc4ee8011.jpg │ ├── 427166fd-15f7-46f8-b836-542a06510e1e.jpg │ ├── 4e2825d4-1279-48ac-9781-ec44af9bce7e.jpg │ ├── 4fe03f21-bc61-42ee-a9a1-078ee14c02cd.jpg │ ├── 532d5d53-5d40-4023-a01e-b89942231e50.jpg │ ├── 576fe923-7748-4e5e-bfa7-3a1bb829612a.jpg │ ├── 57a22e6a-e1d7-41d8-b580-710b9f7a20bc.jpg │ ├── 57dfa99d-e55e-4462-abb5-9941d6e3c3ad.jpg │ ├── 5892c924-bf4f-4f6e-a67e-9e86d9276178.jpg │ ├── 591babea-2f2a-4863-af22-2d2fd632d468.jpg │ ├── 59505d1c-9c37-4767-ab1b-8a875a9805ff.jpg │ ├── 8286cea2-fa16-4ff2-a0e9-2a091a464298.jpg │ ├── 84556e4e-555a-426e-8291-9c2e7b223577.jpg │ ├── 8b6fee5e-9e2d-477d-9067-df3d78b03475.jpg │ ├── 8c1afcaa-0dda-432c-8195-3e9563c59723.jpg │ ├── 960ab2c4-1392-4211-8408-48d1a6973b45.jpg │ ├── 9c2e9b20-e7eb-4269-8626-a32729772f7d.jpg │ ├── 9d55f709-f0a3-408b-ba96-bacbebe1584a.jpg │ ├── 9e61a016-a5d8-418c-aaf2-8e6fb19cba2c.jpg │ ├── ad7e05e4-68c8-4950-aa6d-628182432467.jpg │ ├── af298f8f-4a11-45f3-a73a-171936246303.jpg │ ├── af7896b1-988a-4b0f-b6fe-467d4c9af12c.jpg │ ├── avatar.jpg │ ├── b222769a-96bb-4a2f-a7e2-fa16e6b3c4b2.jpg │ ├── bd398816-cb34-4977-b3f5-76984e84737d.jpg │ ├── bdded511-4ec0-482f-ad58-d7fd1b15629e.jpg │ ├── bf9e9178-b566-41fd-a310-237dc1206689.jpg │ ├── c496b69b-11b9-48e2-985d-f8e799b9b107.jpg │ ├── cdac9a4a-05fb-4daa-b126-b4522dac8e51.jpg │ ├── d89425f5-5be2-49c9-891c-9b9e942d4245.jpg │ ├── daef9bb8-46b3-4ebd-b269-521eeedcbca2.jpg │ ├── dd137437-a499-4bbe-acb8-3138363f9713.jpg │ ├── e19f0e31-6bad-4a9c-b34d-521f015d857a.jpg │ ├── e54932ae-c541-4a88-a450-a9499c498250.jpg │ ├── e8e771c0-2022-42e2-b747-0f87685cd045.jpg │ ├── f5304ff0-10c1-43c1-be96-9190866030d0.jpg │ ├── f5714822-2b70-4029-b682-e04843fca757.jpg │ ├── f604b0a3-c545-4743-828c-cff9729bdafd.jpg │ ├── f69a10ef-7715-4940-aed8-2c822eaf35df.jpg │ ├── fd4aee57-9203-407e-9321-a6f5939c2c35.jpg │ └── fd879310-0284-4037-ac24-9083098ed465.jpg └── test └── java └── com └── example └── onlinestore └── OnlineStoreApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/** 6 | !**/src/test/** 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.2.7.RELEASE' 3 | id 'io.spring.dependency-management' version '1.0.9.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.example' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '11' 10 | 11 | configurations { 12 | developmentOnly 13 | runtimeClasspath { 14 | extendsFrom developmentOnly 15 | } 16 | compileOnly { 17 | extendsFrom annotationProcessor 18 | } 19 | } 20 | 21 | repositories { 22 | mavenCentral() 23 | } 24 | 25 | dependencies { 26 | compileOnly 'org.projectlombok:lombok:1.18.12' 27 | annotationProcessor 'org.projectlombok:lombok:1.18.12' 28 | 29 | testCompileOnly 'org.projectlombok:lombok:1.18.12' 30 | testAnnotationProcessor 'org.projectlombok:lombok:1.18.12' 31 | 32 | compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '2.3.1.RELEASE' 33 | 34 | implementation 'org.springframework.boot:spring-boot-starter-data-jpa' 35 | implementation 'org.springframework.boot:spring-boot-starter-web' 36 | implementation 'org.flywaydb:flyway-core' 37 | implementation 'org.springframework.boot:spring-boot-starter-security' 38 | implementation 'org.springframework.security:spring-security-test' 39 | // https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt 40 | compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1' 41 | 42 | // Swagger 43 | compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2' 44 | compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2' 45 | 46 | developmentOnly 'org.springframework.boot:spring-boot-devtools' 47 | runtimeOnly 'mysql:mysql-connector-java' 48 | 49 | testImplementation('org.springframework.boot:spring-boot-starter-test') { 50 | exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' 51 | } 52 | } 53 | 54 | test { 55 | useJUnitPlatform() 56 | } 57 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=`expr $i + 1` 158 | done 159 | case $i in 160 | 0) set -- ;; 161 | 1) set -- "$args0" ;; 162 | 2) set -- "$args0" "$args1" ;; 163 | 3) set -- "$args0" "$args1" "$args2" ;; 164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=`save "$@"` 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | exec "$JAVACMD" "$@" 184 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | @rem Execute Gradle 88 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 89 | 90 | :end 91 | @rem End local scope for the variables with windows NT shell 92 | if "%ERRORLEVEL%"=="0" goto mainEnd 93 | 94 | :fail 95 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 96 | rem the _cmd.exe /c_ return code! 97 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 98 | exit /b 1 99 | 100 | :mainEnd 101 | if "%OS%"=="Windows_NT" endlocal 102 | 103 | :omega 104 | -------------------------------------------------------------------------------- /online-store.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/online-store.jpg -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'online-store' 2 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/OnlineStoreApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.web.cors.CorsConfiguration; 7 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 8 | import org.springframework.web.filter.CorsFilter; 9 | import springfox.documentation.builders.PathSelectors; 10 | import springfox.documentation.builders.RequestHandlerSelectors; 11 | import springfox.documentation.spi.DocumentationType; 12 | import springfox.documentation.spring.web.plugins.Docket; 13 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 14 | 15 | @SpringBootApplication 16 | @EnableSwagger2 17 | public class OnlineStoreApplication { 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(OnlineStoreApplication.class, args); 21 | } 22 | 23 | 24 | @Bean 25 | public Docket productApi() { 26 | return new Docket(DocumentationType.SWAGGER_2). 27 | select() 28 | .apis(RequestHandlerSelectors.any()) 29 | .paths(PathSelectors.any()) 30 | .build(); 31 | } 32 | 33 | @Bean 34 | public CorsFilter corsFilter() { 35 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); 36 | CorsConfiguration config = new CorsConfiguration(); 37 | config.setAllowCredentials(true); 38 | config.addAllowedOrigin("*"); 39 | config.addAllowedHeader("*"); 40 | config.addAllowedMethod("OPTIONS"); 41 | config.addAllowedMethod("GET"); 42 | config.addAllowedMethod("POST"); 43 | config.addAllowedMethod("PUT"); 44 | config.addAllowedMethod("DELETE"); 45 | source.registerCorsConfiguration("/**", config); 46 | return new CorsFilter(source); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/config/MailConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.mail.javamail.JavaMailSender; 6 | import org.springframework.mail.javamail.JavaMailSenderImpl; 7 | 8 | import java.util.Properties; 9 | 10 | @Configuration 11 | public class MailConfig { 12 | 13 | @Bean 14 | public JavaMailSender getJavaMailSender() { 15 | JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); 16 | mailSender.setHost("smtp.gmail.com"); 17 | mailSender.setPort(587); 18 | 19 | mailSender.setUsername("timurproud07@gmail.com"); 20 | mailSender.setPassword("timur555"); 21 | 22 | Properties props = mailSender.getJavaMailProperties(); 23 | props.put("mail.transport.protocol", "smtp"); 24 | props.put("mail.smtp.auth", "true"); 25 | props.put("mail.smtp.starttls.enable", "true"); 26 | props.put("mail.debug", "true"); 27 | 28 | return mailSender; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.config; 2 | 3 | import com.example.onlinestore.security.jwt.JwtConfigurer; 4 | import com.example.onlinestore.security.jwt.JwtTokenProvider; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.security.authentication.AuthenticationManager; 9 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 10 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 11 | import org.springframework.security.config.http.SessionCreationPolicy; 12 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 13 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 14 | 15 | @Configuration 16 | public class SecurityConfig extends WebSecurityConfigurerAdapter implements WebMvcConfigurer { 17 | 18 | private final JwtTokenProvider jwtTokenProvider; 19 | 20 | // Whitelist 21 | private static final String ADMIN_ENDPOINT = "/api/v1/admin/**"; 22 | private static final String DEVICE_ENDPOINT = "/api/v1/devices/**"; 23 | private static final String LOGIN_ENDPOINT = "/api/v1/auth/**"; 24 | private static final String COMMENT_ENDPOINT = "/api/v1/comments"; 25 | private static final String MAIL_ENDPOINT = "/api/v1/mail/**"; 26 | private static final String[] SWAGGER_ENDPOINT = { 27 | "/v2/api-docs", 28 | "/swagger-resources/**", 29 | "/swagger-ui.html", 30 | "/webjars/springfox-swagger-ui/**" 31 | }; 32 | 33 | @Autowired 34 | public SecurityConfig(JwtTokenProvider jwtTokenProvider) { 35 | this.jwtTokenProvider = jwtTokenProvider; 36 | } 37 | 38 | @Bean 39 | @Override 40 | public AuthenticationManager authenticationManagerBean() throws Exception { 41 | return super.authenticationManagerBean(); 42 | } 43 | 44 | @Override 45 | protected void configure(HttpSecurity http) throws Exception { 46 | http 47 | .httpBasic().disable() 48 | .csrf().disable() 49 | .cors() 50 | .and() 51 | .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) 52 | .and() 53 | .authorizeRequests() 54 | .antMatchers(LOGIN_ENDPOINT).permitAll() 55 | .antMatchers(ADMIN_ENDPOINT).hasRole("ADMIN") 56 | .antMatchers(SWAGGER_ENDPOINT).permitAll() 57 | .antMatchers(DEVICE_ENDPOINT).permitAll() 58 | .antMatchers(COMMENT_ENDPOINT).permitAll() 59 | .antMatchers(MAIL_ENDPOINT).permitAll() 60 | .anyRequest().authenticated() 61 | .and() 62 | .apply(new JwtConfigurer(jwtTokenProvider)); 63 | } 64 | 65 | // @Override 66 | // public void addCorsMappings(CorsRegistry registry) { 67 | // registry.addMapping("/**") 68 | // .allowedOrigins("http://localhost:3000") 69 | // .allowedMethods("*") 70 | // .allowedHeaders("*"); 71 | // } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/controller/v1/AuthenticationRestControllerV1.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.controller.v1; 2 | 3 | import com.example.onlinestore.dto.user.AuthenticationRequestDto; 4 | import com.example.onlinestore.dto.user.UserDto; 5 | import com.example.onlinestore.entity.user.User; 6 | import com.example.onlinestore.exceptions.existException.UserAlreadyExistAuthException; 7 | import com.example.onlinestore.security.jwt.JwtAuthenticationException; 8 | import com.example.onlinestore.security.jwt.JwtTokenProvider; 9 | import com.example.onlinestore.service.user.UserService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.HttpStatus; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.security.authentication.AuthenticationManager; 14 | import org.springframework.security.authentication.BadCredentialsException; 15 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 16 | import org.springframework.security.core.AuthenticationException; 17 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 18 | import org.springframework.web.bind.annotation.*; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | 24 | @RestController 25 | @RequestMapping(value = "/api/v1/auth") 26 | public class AuthenticationRestControllerV1 { 27 | 28 | private final AuthenticationManager authenticationManager; 29 | 30 | private final JwtTokenProvider jwtTokenProvider; 31 | 32 | private final UserService userService; 33 | 34 | @Autowired 35 | public AuthenticationRestControllerV1(AuthenticationManager authenticationManager, JwtTokenProvider jwtTokenProvider, UserService userService) { 36 | this.authenticationManager = authenticationManager; 37 | this.jwtTokenProvider = jwtTokenProvider; 38 | this.userService = userService; 39 | } 40 | 41 | @PostMapping("/login") 42 | public ResponseEntity login(@RequestBody AuthenticationRequestDto requestDto) { 43 | try { 44 | String username = requestDto.getUsername(); 45 | authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, requestDto.getPassword())); 46 | User user = userService.getByUsername(username); 47 | 48 | if (user == null) { 49 | throw new UsernameNotFoundException("User with username: " + username + " not found"); 50 | } 51 | 52 | String token = jwtTokenProvider.createToken(username, user.getRoles(), user.getId()); 53 | 54 | Map response = new HashMap<>(); 55 | response.put("user", UserDto.fromUser(user)); 56 | response.put("token", token); 57 | 58 | return ResponseEntity.ok(response); 59 | } catch (AuthenticationException e) { 60 | throw new BadCredentialsException("Invalid username or password"); 61 | } 62 | } 63 | 64 | @PostMapping("/registration") 65 | public ResponseEntity registration(@RequestBody User user) { 66 | if (userService.getByUsername(user.getUsername()) != null) { 67 | throw new UserAlreadyExistAuthException("User already exist"); 68 | } else { 69 | User newUser = userService.register(user); 70 | return getResponseEntity(user, newUser); 71 | } 72 | } 73 | 74 | private ResponseEntity getResponseEntity(@RequestBody User user, User newUser) { 75 | String token = jwtTokenProvider.createToken(newUser.getUsername(), user.getRoles(), user.getId()); 76 | 77 | Map response = new HashMap<>(); 78 | response.put("user", UserDto.fromUser(newUser)); 79 | response.put("token", token); 80 | return new ResponseEntity(response, HttpStatus.OK); 81 | } 82 | 83 | @GetMapping 84 | public ResponseEntity getUserByToken(@RequestHeader("Authorization") String authHeader) { 85 | if(authHeader == null || authHeader.equals("")){ 86 | System.out.println("token " + authHeader); 87 | throw new JwtAuthenticationException("Token is invalid"); 88 | } 89 | String token = authHeader.substring(7); 90 | System.out.println("token " + token); 91 | 92 | User user = userService.getById(jwtTokenProvider.getId(token)); 93 | return getResponseEntity(user, user); 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/controller/v1/CommentControllerV1.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.controller.v1; 2 | 3 | 4 | import com.example.onlinestore.dto.device.CommentDto; 5 | import com.example.onlinestore.entity.device.Comment; 6 | import com.example.onlinestore.entity.device.Device; 7 | import com.example.onlinestore.entity.device.Like; 8 | import com.example.onlinestore.entity.user.User; 9 | import com.example.onlinestore.exceptions.notFoundException.DeviceNotFoundException; 10 | import com.example.onlinestore.repos.device.LikeRepo; 11 | import com.example.onlinestore.service.device.CommentService; 12 | import com.example.onlinestore.service.device.DeviceService; 13 | import com.example.onlinestore.service.user.UserService; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.*; 16 | 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | import java.util.stream.Collectors; 20 | 21 | @RestController 22 | @RequestMapping("/api/v1/comments") 23 | @CrossOrigin 24 | public class CommentControllerV1 { 25 | 26 | private final CommentService commentService; 27 | private final DeviceService deviceService; 28 | private final UserService userService; 29 | private final LikeRepo likeRepo; 30 | 31 | public CommentControllerV1(CommentService commentService, DeviceService deviceService, UserService userService, LikeRepo likeRepo) { 32 | this.commentService = commentService; 33 | this.deviceService = deviceService; 34 | this.userService = userService; 35 | this.likeRepo = likeRepo; 36 | } 37 | 38 | 39 | @PostMapping("/add") 40 | public ResponseEntity addComment(@RequestBody Comment comment) throws DeviceNotFoundException { 41 | Float rateSum = new Float(0); 42 | User user = userService.getById(comment.getUser().getId()); 43 | Device device = deviceService.getById(comment.getDevice().getId()); 44 | comment.setUser(user); 45 | comment.setDevice(device); 46 | 47 | for (Comment com: device.getComments()) { 48 | rateSum+= com.getRating(); 49 | } 50 | rateSum+=comment.getRating(); 51 | 52 | device.setRating(rateSum / (device.getComments().size()+1)); 53 | deviceService.update(device); 54 | 55 | Map response = new HashMap<>(); 56 | response.put("rating", device.getRating()); 57 | response.put("comment", CommentDto.fromComment(commentService.save(comment),user.getId())); 58 | return ResponseEntity.ok(response); 59 | } 60 | 61 | @GetMapping 62 | public ResponseEntity getByDeviceId(@RequestParam("device_id") Long deviceId, 63 | @RequestParam("user_id") Long userId) { 64 | return ResponseEntity.ok(commentService.getByDeviceId(deviceId).stream() 65 | .map(comment -> CommentDto.fromComment(comment, userId)).collect(Collectors.toList())); 66 | } 67 | 68 | @PostMapping("/like") 69 | public ResponseEntity like(@RequestBody Like like) { 70 | User user = userService.getById(like.getUser().getId()); 71 | Comment comment = commentService.getById(like.getComment().getId()); 72 | like.setUser(user); 73 | like.setComment(comment); 74 | if (likeRepo.findByUserIdAndCommentId(user.getId(), comment.getId()) == null) { 75 | comment.getLikes().add(like); 76 | comment.setLikeCount(comment.getLikeCount()+1); 77 | } else { 78 | comment.setLikeCount(comment.getLikeCount()-1); 79 | likeRepo.deleteById(likeRepo.findByUserIdAndCommentId(user.getId(), comment.getId()).getId()); 80 | } 81 | 82 | 83 | return ResponseEntity.ok(CommentDto.fromComment(commentService.save(comment), like.getUser().getId())); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/controller/v1/DeviceControllerV1.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.controller.v1; 2 | 3 | 4 | import com.example.onlinestore.dto.device.BrandDto; 5 | import com.example.onlinestore.dto.device.DeviceDto; 6 | import com.example.onlinestore.dto.device.DeviceTypeDto; 7 | import com.example.onlinestore.dto.device.FullDeviceDto; 8 | import com.example.onlinestore.entity.device.Brand; 9 | import com.example.onlinestore.entity.device.Device; 10 | import com.example.onlinestore.entity.device.DeviceType; 11 | import com.example.onlinestore.exceptions.notFoundException.BrandNotFoundException; 12 | import com.example.onlinestore.exceptions.notFoundException.DeviceNotFoundException; 13 | import com.example.onlinestore.exceptions.notFoundException.DeviceTypeNotFoundException; 14 | import com.example.onlinestore.service.device.BrandService; 15 | import com.example.onlinestore.service.device.DeviceService; 16 | import com.example.onlinestore.service.device.DeviceTypeService; 17 | import com.example.onlinestore.service.user.UserService; 18 | import org.hibernate.sql.OracleJoinFragment; 19 | import org.springframework.http.HttpStatus; 20 | import org.springframework.http.ResponseEntity; 21 | import org.springframework.web.bind.annotation.*; 22 | 23 | import java.util.ArrayList; 24 | import java.util.HashMap; 25 | import java.util.List; 26 | import java.util.Map; 27 | import java.util.stream.Collectors; 28 | 29 | @RestController 30 | @CrossOrigin 31 | @RequestMapping("/api/v1/devices") 32 | public class DeviceControllerV1 { 33 | 34 | private final UserService userService; 35 | private final DeviceService deviceService; 36 | private final DeviceTypeService deviceTypeService; 37 | private final BrandService brandService; 38 | 39 | public DeviceControllerV1(UserService userService, DeviceService deviceService, DeviceTypeService deviceTypeService, BrandService brandService) { 40 | this.userService = userService; 41 | this.deviceService = deviceService; 42 | this.deviceTypeService = deviceTypeService; 43 | this.brandService = brandService; 44 | } 45 | 46 | @GetMapping("/type") 47 | public ResponseEntity getTypes() throws DeviceTypeNotFoundException { 48 | return new ResponseEntity<>(deviceTypeService.getAll().stream() 49 | .map(DeviceTypeDto::fromDeviceType) 50 | .collect(Collectors.toList()), HttpStatus.OK); 51 | } 52 | 53 | @GetMapping("/brand") 54 | public ResponseEntity getBrands() throws BrandNotFoundException { 55 | return new ResponseEntity<>(brandService.getAll().stream() 56 | .map(BrandDto::fromBrand) 57 | .collect(Collectors.toList()), HttpStatus.OK); 58 | } 59 | 60 | @GetMapping("/brand/{id}") 61 | public ResponseEntity> getBrandsByTypeId(@PathVariable Long id) throws BrandNotFoundException { 62 | return new ResponseEntity<>(brandService.getAllByDeviceTypeId(id), HttpStatus.OK); 63 | } 64 | 65 | 66 | @GetMapping 67 | public ResponseEntity getAllDevices() throws DeviceNotFoundException { 68 | List devices = deviceService.getAll().stream() 69 | .map(DeviceDto::fromDevice) 70 | .collect(Collectors.toList()); 71 | 72 | return new ResponseEntity<>(devices, HttpStatus.OK); 73 | } 74 | 75 | @GetMapping("/pagination") 76 | public ResponseEntity getDevicesByPage( 77 | @RequestParam(defaultValue = "1") Long page, 78 | @RequestParam(defaultValue = "9") Long count, 79 | @RequestParam(defaultValue = "0", name = "type_id") Long typeId, 80 | @RequestParam(defaultValue = "0", name = "brand_id") Long brandId) throws DeviceNotFoundException { 81 | List devices = new ArrayList<>(); 82 | if (brandId == 0 && typeId == 0) { 83 | devices = deviceService.getAll(); 84 | } 85 | if (brandId == 0 && typeId != 0) { 86 | devices = deviceService.getAllByTypeId(typeId); 87 | } 88 | if (brandId != 0 && typeId != 0) { 89 | devices = deviceService.getAllByTypeIdAndBrandId(typeId, brandId); 90 | } 91 | Map response = new HashMap<>(); 92 | List deviceDtos = devices.stream().skip((page - 1) * count).limit(count).map(DeviceDto::fromDevice).collect(Collectors.toList()); 93 | response.put("devices", deviceDtos); 94 | response.put("totalCount", devices.size()); 95 | 96 | return new ResponseEntity(response, HttpStatus.OK); 97 | } 98 | 99 | 100 | @GetMapping("/{id}") 101 | public ResponseEntity getDevice(@PathVariable Long id, @RequestParam("user_id") Long userId) throws DeviceNotFoundException { 102 | Device device = deviceService.getById(id); 103 | 104 | return new ResponseEntity<>(FullDeviceDto.fromDevice(device, userId), HttpStatus.OK); 105 | } 106 | 107 | @GetMapping("/{type_id}/{brand_id}") 108 | public ResponseEntity> getDevicesByBrandId(@PathVariable Long type_id, 109 | @PathVariable Long brand_id) throws DeviceNotFoundException { 110 | List devices = deviceService.getAllByTypeIdAndBrandId(type_id, brand_id).stream() 111 | .map(DeviceDto::fromDevice) 112 | .collect(Collectors.toList()); 113 | 114 | return new ResponseEntity<>( devices, HttpStatus.OK); 115 | } 116 | 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/controller/v1/MailControllerV1.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.controller.v1; 2 | 3 | import com.example.onlinestore.dto.user.AuthenticationRequestDto; 4 | import com.example.onlinestore.dto.user.UserDto; 5 | import com.example.onlinestore.entity.user.User; 6 | import com.example.onlinestore.security.jwt.JwtAuthenticationException; 7 | import com.example.onlinestore.security.jwt.JwtTokenProvider; 8 | import com.example.onlinestore.service.user.impl.UserServiceImpl; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.mail.SimpleMailMessage; 11 | import org.springframework.mail.javamail.JavaMailSender; 12 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | @RestController 19 | @CrossOrigin 20 | @RequestMapping("/api/v1/mail") 21 | public class MailControllerV1 { 22 | 23 | 24 | private final JavaMailSender emailSender; 25 | private final UserServiceImpl userService; 26 | private final JwtTokenProvider jwtTokenProvider; 27 | private final BCryptPasswordEncoder passwordEncoder; 28 | 29 | 30 | public MailControllerV1(JavaMailSender emailSender, UserServiceImpl userService, JwtTokenProvider jwtTokenProvider, BCryptPasswordEncoder passwordEncoder) { 31 | this.emailSender = emailSender; 32 | this.userService = userService; 33 | this.jwtTokenProvider = jwtTokenProvider; 34 | this.passwordEncoder = passwordEncoder; 35 | } 36 | 37 | @GetMapping("/recovery") 38 | public String Recovery(@RequestParam String mail) { 39 | User user = userService.getByMail(mail); 40 | 41 | String token = jwtTokenProvider.createToken(user.getUsername(), user.getRoles(), user.getId()); 42 | 43 | // Create a Simple MailMessage. 44 | SimpleMailMessage message = new SimpleMailMessage(); 45 | 46 | message.setTo(mail); 47 | message.setSubject("Device store pass recovery"); 48 | message.setText("Open link to reset password " + "http://localhost:3000/recover/"+token); 49 | 50 | // Send Message! 51 | this.emailSender.send(message); 52 | 53 | return "Email Sent!"; 54 | } 55 | 56 | @PostMapping("/password") 57 | public ResponseEntity passwordRecovery(@RequestBody AuthenticationRequestDto authenticationRequestDto, 58 | @RequestHeader("Authorization") String authHeader) { 59 | 60 | if(authHeader == null || authHeader.equals("")){ 61 | throw new JwtAuthenticationException("Token is invalid"); 62 | } 63 | String token = authHeader.substring(7); 64 | 65 | User user = userService.getById(jwtTokenProvider.getId(token)); 66 | 67 | user.setPassword(passwordEncoder.encode(authenticationRequestDto.getPassword())); 68 | userService.update(user); 69 | Map response = new HashMap(); 70 | response.put("token", token); 71 | response.put("user", UserDto.fromUser(user)); 72 | return ResponseEntity.ok(response); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/controller/v1/UserRestControllerV1.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.controller.v1; 2 | 3 | import com.example.onlinestore.dto.user.UserDto; 4 | import com.example.onlinestore.entity.user.User; 5 | import com.example.onlinestore.service.ImageService; 6 | import com.example.onlinestore.service.user.UserService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.MediaType; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | import org.springframework.web.multipart.MultipartFile; 13 | 14 | import java.io.File; 15 | import java.io.FileOutputStream; 16 | import java.io.IOException; 17 | import java.util.Arrays; 18 | import java.util.Collection; 19 | import java.util.UUID; 20 | 21 | 22 | 23 | @RestController 24 | @RequestMapping(value = "/api/v1/users") 25 | @CrossOrigin 26 | public class UserRestControllerV1 { 27 | private final UserService userService; 28 | 29 | @Autowired 30 | public UserRestControllerV1(UserService userService) { 31 | this.userService = userService; 32 | } 33 | 34 | @PostMapping(value = "/avatar", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) 35 | public ResponseEntity setAvatar(@RequestParam(value = "img", required = false) MultipartFile img, 36 | @RequestParam("user_id") Long userId) throws IOException { 37 | 38 | User user = userService.getById(userId); 39 | user.setAvatar(ImageService.saveFile(img)); 40 | userService.update(user); 41 | 42 | return new ResponseEntity<>(UserDto.fromUser(user), HttpStatus.OK); 43 | } 44 | 45 | @GetMapping 46 | public ResponseEntity getUser(@RequestParam Long id){ 47 | User user = userService.getById(id); 48 | return new ResponseEntity<>(UserDto.fromUser(user), HttpStatus.OK); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/controller/v1/admin/AdminDeviceControllerV1.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.controller.v1.admin; 2 | 3 | 4 | import com.example.onlinestore.dto.device.*; 5 | import com.example.onlinestore.entity.device.Brand; 6 | import com.example.onlinestore.entity.device.Device; 7 | import com.example.onlinestore.entity.device.DeviceType; 8 | import com.example.onlinestore.entity.device.Property; 9 | import com.example.onlinestore.exceptions.notFoundException.BrandNotFoundException; 10 | import com.example.onlinestore.exceptions.notFoundException.DeviceNotFoundException; 11 | import com.example.onlinestore.exceptions.notFoundException.DeviceTypeNotFoundException; 12 | import com.example.onlinestore.service.ImageService; 13 | import com.example.onlinestore.service.device.BrandService; 14 | import com.example.onlinestore.service.device.DeviceService; 15 | import com.example.onlinestore.service.device.DeviceTypeService; 16 | import com.example.onlinestore.service.device.PropertyService; 17 | import com.example.onlinestore.service.user.UserService; 18 | import org.springframework.http.HttpStatus; 19 | import org.springframework.http.MediaType; 20 | import org.springframework.http.ResponseEntity; 21 | import org.springframework.web.bind.annotation.*; 22 | import org.springframework.web.multipart.MultipartFile; 23 | 24 | import java.io.IOException; 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | import java.util.stream.Collectors; 28 | 29 | @RestController 30 | @RequestMapping(value = "/api/v1/admin/devices") 31 | @CrossOrigin 32 | public class AdminDeviceControllerV1 { 33 | 34 | private final UserService userService; 35 | private final DeviceService deviceService; 36 | private final DeviceTypeService deviceTypeService; 37 | private final BrandService brandService; 38 | private final PropertyService propertyService; 39 | 40 | public AdminDeviceControllerV1(UserService userService, 41 | DeviceService deviceService, 42 | DeviceTypeService deviceTypeService, 43 | BrandService brandService, PropertyService propertyService) { 44 | this.userService = userService; 45 | this.deviceService = deviceService; 46 | this.deviceTypeService = deviceTypeService; 47 | this.brandService = brandService; 48 | this.propertyService = propertyService; 49 | } 50 | 51 | 52 | 53 | 54 | @PostMapping("/type") 55 | public ResponseEntity saveType(@RequestBody DeviceType deviceType) { 56 | return new ResponseEntity<>(deviceTypeService.save(deviceType), HttpStatus.OK); 57 | } 58 | 59 | @DeleteMapping("/type") 60 | public ResponseEntity deleteType(@RequestParam String name) throws DeviceTypeNotFoundException { 61 | deviceTypeService.deleteByName(name); 62 | return new ResponseEntity(HttpStatus.OK); 63 | } 64 | 65 | 66 | 67 | 68 | @PostMapping("/brand") 69 | public ResponseEntity saveBrand(@RequestBody BrandDto brandDto) throws DeviceTypeNotFoundException { 70 | Brand brand = BrandDto.toBrand(brandDto); 71 | brand.setDeviceType(deviceTypeService.getByName(brandDto.getDeviceTypeName())); 72 | brandService.save(brand); 73 | return new ResponseEntity<>(brandDto, HttpStatus.OK); 74 | } 75 | 76 | @DeleteMapping("/brand") 77 | public ResponseEntity deleteBrand(@RequestParam String name, @RequestParam(name = "type_name") String typeName) throws BrandNotFoundException { 78 | System.out.println(name + " " + typeName); 79 | brandService.deleteByNameAndTypeName(name, typeName); 80 | return new ResponseEntity( HttpStatus.OK); 81 | } 82 | 83 | 84 | @PostMapping( consumes = MediaType.MULTIPART_FORM_DATA_VALUE) 85 | public ResponseEntity saveDevice(@RequestParam String name, 86 | @RequestParam String brandName, 87 | @RequestParam String typeName, 88 | @RequestParam String description, 89 | @RequestParam Long price, 90 | @RequestParam MultipartFile file) throws BrandNotFoundException, IOException, DeviceTypeNotFoundException { 91 | Device device = new Device(); 92 | device.setName(name); 93 | device.setBrand(brandService.getByNameAndTypeName(brandName, typeName)); 94 | device.setDeviceType(deviceTypeService.getByName(typeName)); 95 | device.setPrice(price); 96 | device.setDescription(description); 97 | device.setImage(ImageService.saveFile(file)); 98 | deviceService.save(device); 99 | return new ResponseEntity<>(DeviceDto.fromDevice(device), HttpStatus.OK); 100 | } 101 | 102 | @GetMapping 103 | public ResponseEntity getAllDevices() throws DeviceNotFoundException { 104 | 105 | Map response = new HashMap<>(); 106 | response.put("devices", deviceService.getAll().stream() 107 | .map(DeviceDto::fromDevice).collect(Collectors.toList())); 108 | return new ResponseEntity( response ,HttpStatus.OK); 109 | } 110 | 111 | @PostMapping("/property") 112 | public ResponseEntity saveProperty(@RequestBody PropertyDto propertyDto) throws BrandNotFoundException, IOException, DeviceTypeNotFoundException, DeviceNotFoundException { 113 | Device device = deviceService.getDeviceByTypeBrandDevice( 114 | propertyDto.getDeviceName(), 115 | propertyDto.getBrandName(), 116 | propertyDto.getTypeName() ); 117 | if(propertyDto.getName().equals("Описание")) { 118 | device.setDescription(propertyDto.getDescription()); 119 | deviceService.update(device); 120 | return new ResponseEntity(HttpStatus.OK); 121 | } 122 | else{ 123 | Property property = PropertyDto.toProperty(propertyDto, device); 124 | return new ResponseEntity(propertyService.save(property), HttpStatus.OK); 125 | } 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/controller/v1/admin/AdminRestControllerV1.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.controller.v1.admin; 2 | 3 | 4 | import com.example.onlinestore.dto.user.UserDto; 5 | import com.example.onlinestore.entity.user.User; 6 | import com.example.onlinestore.service.user.UserService; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import java.util.ArrayList; 14 | import java.util.LinkedList; 15 | import java.util.List; 16 | import java.util.stream.Collector; 17 | import java.util.stream.Collectors; 18 | 19 | @RestController 20 | @RequestMapping(value = "/api/v1/admin") 21 | public class AdminRestControllerV1 { 22 | 23 | private final UserService userService; 24 | 25 | public AdminRestControllerV1(UserService userService) { 26 | this.userService = userService; 27 | } 28 | 29 | @GetMapping("/users") 30 | public ResponseEntity> getAllUsers() { 31 | List usersDto = userService.getAll() 32 | .stream().map(UserDto::fromUser) 33 | .collect(Collectors.toList()); 34 | 35 | return new ResponseEntity<>(usersDto,HttpStatus.OK); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/dto/device/BrandDto.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.dto.device; 2 | 3 | import com.example.onlinestore.entity.device.Brand; 4 | import com.example.onlinestore.exceptions.notFoundException.DeviceTypeNotFoundException; 5 | import com.example.onlinestore.service.device.BrandService; 6 | import com.example.onlinestore.service.device.DeviceTypeService; 7 | import com.fasterxml.jackson.annotation.JsonIgnore; 8 | import lombok.Data; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | 11 | import java.beans.Transient; 12 | 13 | @Data 14 | public class BrandDto { 15 | private Long id; 16 | private String name; 17 | private String deviceTypeName; 18 | private Long typeId; 19 | 20 | public static Brand toBrand(BrandDto brandDto) throws DeviceTypeNotFoundException { 21 | Brand brand = new Brand(); 22 | brand.setName(brandDto.getName()); 23 | return brand; 24 | } 25 | 26 | public static BrandDto fromBrand(Brand brand) { 27 | BrandDto brandDto = new BrandDto(); 28 | brandDto.setId(brand.getId()); 29 | brandDto.setName(brand.getName()); 30 | brandDto.setDeviceTypeName(brand.getDeviceType().getName()); 31 | brandDto.setTypeId(brand.getDeviceType().getId()); 32 | return brandDto; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/dto/device/CommentDto.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.dto.device; 2 | 3 | import com.example.onlinestore.dto.user.UserDto; 4 | import com.example.onlinestore.entity.device.Comment; 5 | import com.example.onlinestore.entity.device.Like; 6 | import lombok.Data; 7 | 8 | @Data 9 | public class CommentDto { 10 | private Long id; 11 | private Long deviceId; 12 | private UserDto user; 13 | 14 | private String text; 15 | 16 | private Long likeCount; 17 | private Long dislikeCount; 18 | 19 | private String created; 20 | private Long rating; 21 | 22 | private Boolean isLiked; 23 | 24 | public static CommentDto fromComment(Comment comment, Long userId) { 25 | CommentDto commentDto = new CommentDto(); 26 | commentDto.setId(comment.getId()); 27 | commentDto.setUser(UserDto.fromUser(comment.getUser())); 28 | commentDto.setLikeCount(comment.getLikeCount()); 29 | commentDto.setDislikeCount(comment.getDislikeCount()); 30 | commentDto.setCreated(comment.getCreated()); 31 | commentDto.setText(comment.getText()); 32 | commentDto.setRating(comment.getRating()); 33 | commentDto.setDeviceId(comment.getDevice().getId()); 34 | if (comment.getLikes() != null) { 35 | for (Like like: comment.getLikes()) { 36 | if (like.getUser().getId().equals(userId)) { 37 | commentDto.setIsLiked(true); 38 | } else { 39 | commentDto.setIsLiked(false); 40 | } 41 | } 42 | } 43 | return commentDto; 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/dto/device/DeviceDto.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.dto.device; 2 | 3 | import com.example.onlinestore.entity.device.Device; 4 | import com.example.onlinestore.service.ImageService; 5 | import lombok.Data; 6 | 7 | import java.io.File; 8 | 9 | @Data 10 | public class DeviceDto { 11 | private Long id; 12 | private String name; 13 | private Long brandId; 14 | private String brandName; 15 | private Long typeId; 16 | private String typeName; 17 | private Long price; 18 | private Float rating; 19 | private String image; 20 | private String description; 21 | 22 | 23 | public static DeviceDto fromDevice(Device device) { 24 | DeviceDto deviceDto = new DeviceDto(); 25 | deviceDto.setId(device.getId()); 26 | deviceDto.setName(device.getName()); 27 | deviceDto.setBrandId(device.getBrand().getId()); 28 | deviceDto.setTypeId(device.getDeviceType().getId()); 29 | deviceDto.setPrice(device.getPrice()); 30 | deviceDto.setRating(device.getRating()); 31 | deviceDto.setBrandName(device.getBrand().getName()); 32 | deviceDto.setTypeName(device.getDeviceType().getName()); 33 | deviceDto.setDescription(device.getDescription()); 34 | 35 | if (device.getImage() != null) { 36 | String imgPath = ImageService.IMAGE_PATH + device.getImage(); 37 | File file = new File(imgPath); 38 | if(file.exists()) { 39 | deviceDto.setImage(ImageService.encodeFileToBase64Binary(file)); 40 | } 41 | } 42 | return deviceDto; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/dto/device/DeviceTypeDto.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.dto.device; 2 | 3 | import com.example.onlinestore.entity.device.DeviceType; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class DeviceTypeDto { 8 | private Long id; 9 | private String name; 10 | 11 | public static DeviceTypeDto fromDeviceType(DeviceType deviceType) { 12 | DeviceTypeDto deviceTypeDto = new DeviceTypeDto(); 13 | deviceTypeDto.setId(deviceType.getId()); 14 | deviceTypeDto.setName(deviceType.getName()); 15 | return deviceTypeDto; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/dto/device/FullDeviceDto.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.dto.device; 2 | 3 | 4 | import com.example.onlinestore.entity.device.Comment; 5 | import com.example.onlinestore.entity.device.Device; 6 | import com.example.onlinestore.entity.device.Property; 7 | import com.example.onlinestore.service.ImageService; 8 | import lombok.Data; 9 | 10 | import java.io.File; 11 | import java.util.List; 12 | import java.util.stream.Collectors; 13 | 14 | @Data 15 | public class FullDeviceDto extends DeviceDto{ 16 | 17 | private List properties; 18 | 19 | private List comments; 20 | 21 | 22 | public static FullDeviceDto fromDevice(Device device, Long userId) { 23 | FullDeviceDto deviceDto = new FullDeviceDto(); 24 | deviceDto.setId(device.getId()); 25 | deviceDto.setName(device.getName()); 26 | deviceDto.setBrandId(device.getBrand().getId()); 27 | deviceDto.setTypeId(device.getDeviceType().getId()); 28 | deviceDto.setPrice(device.getPrice()); 29 | deviceDto.setRating(device.getRating()); 30 | deviceDto.setBrandName(device.getBrand().getName()); 31 | deviceDto.setTypeName(device.getDeviceType().getName()); 32 | deviceDto.setDescription(device.getDescription()); 33 | 34 | deviceDto.setComments(device.getComments().stream().map((comment) -> CommentDto.fromComment(comment, userId)).collect(Collectors.toList())); 35 | deviceDto.setProperties(device.getProperties()); 36 | if (device.getImage() != null) { 37 | String imgPath = ImageService.IMAGE_PATH + device.getImage(); 38 | File file = new File(imgPath); 39 | if(file.exists()) { 40 | deviceDto.setImage(ImageService.encodeFileToBase64Binary(file)); 41 | } 42 | } 43 | return deviceDto; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/dto/device/NewDeviceDto.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.dto.device; 2 | 3 | import com.example.onlinestore.entity.device.Brand; 4 | import com.example.onlinestore.entity.device.Device; 5 | import lombok.Data; 6 | 7 | @Data 8 | public class NewDeviceDto { 9 | private String name; 10 | private Brand brand; 11 | private Long price; 12 | 13 | public static Device ToDevice(NewDeviceDto newDeviceDto) { 14 | Device device = new Device(); 15 | device.setName(newDeviceDto.getName()); 16 | device.setBrand(newDeviceDto.getBrand()); 17 | device.setPrice(newDeviceDto.getPrice()); 18 | return device; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/dto/device/PropertyDto.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.dto.device; 2 | 3 | import com.example.onlinestore.entity.device.Device; 4 | import com.example.onlinestore.entity.device.Property; 5 | import lombok.Data; 6 | 7 | @Data 8 | public class PropertyDto { 9 | private String id; 10 | private String typeName; 11 | private String brandName; 12 | private String deviceName; 13 | private String name; 14 | private String description; 15 | 16 | public static Property toProperty(PropertyDto propertyDto, Device device) { 17 | Property property = new Property(); 18 | property.setName(propertyDto.getName()); 19 | property.setDescription(propertyDto.getDescription()); 20 | property.setDevice(device); 21 | return property; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/dto/user/AuthenticationRequestDto.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class AuthenticationRequestDto { 7 | private String username; 8 | private String password; 9 | } -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/dto/user/UserDto.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.dto.user; 2 | 3 | import com.example.onlinestore.entity.user.Role; 4 | import com.example.onlinestore.entity.user.User; 5 | import com.example.onlinestore.service.ImageService; 6 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 7 | import lombok.Data; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | 10 | import java.io.File; 11 | import java.util.List; 12 | 13 | @Data 14 | @JsonIgnoreProperties(ignoreUnknown = true) 15 | public class UserDto { 16 | 17 | private Long id; 18 | private String username; 19 | private String mail; 20 | private String phoneNumber; 21 | private String avatar; 22 | private List roles; 23 | 24 | public User toUser() { 25 | User user = new User(); 26 | user.setId(id); 27 | user.setUsername(username); 28 | user.setMail(mail); 29 | user.setAvatar(avatar); 30 | user.setPhoneNumber(phoneNumber); 31 | return user; 32 | } 33 | 34 | public static UserDto fromUser(User user) { 35 | UserDto userDto = new UserDto(); 36 | userDto.setId(user.getId()); 37 | userDto.setUsername(user.getUsername()); 38 | userDto.setMail(user.getMail()); 39 | userDto.setPhoneNumber(user.getPhoneNumber()); 40 | userDto.setRoles(user.getRoles()); 41 | 42 | if(user.getAvatar() != null) { 43 | String img = ImageService.IMAGE_PATH + user.getAvatar(); 44 | File imgFile = new File(img); 45 | if (imgFile.exists()) { 46 | userDto.setAvatar(ImageService.encodeFileToBase64Binary(imgFile)); 47 | } 48 | } else { 49 | String img = ImageService.IMAGE_PATH +"avatar.jpg"; 50 | File imgFile = new File(img); 51 | if (imgFile.exists()) { 52 | userDto.setAvatar(ImageService.encodeFileToBase64Binary(imgFile)); 53 | } 54 | } 55 | 56 | 57 | return userDto; 58 | } 59 | } -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/entity/device/Brand.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.entity.device; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | 7 | import javax.persistence.*; 8 | import java.util.List; 9 | 10 | @Entity 11 | @Getter 12 | @Setter 13 | public class Brand { 14 | @Id 15 | @GeneratedValue(strategy = GenerationType.IDENTITY) 16 | private Long id; 17 | 18 | private String name; 19 | 20 | @OneToMany(mappedBy = "brand", cascade = CascadeType.ALL) 21 | private List models; 22 | 23 | @ManyToOne 24 | @JoinColumn(name = "device_type_id") 25 | @JsonIgnore 26 | private DeviceType deviceType; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/entity/device/Comment.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.entity.device; 2 | 3 | import com.example.onlinestore.entity.user.User; 4 | import com.fasterxml.jackson.annotation.JsonIgnore; 5 | import lombok.Data; 6 | 7 | import javax.persistence.*; 8 | import java.text.SimpleDateFormat; 9 | import java.util.Date; 10 | import java.util.List; 11 | 12 | @Entity 13 | @Data 14 | public class Comment{ 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private Long id; 18 | 19 | @ManyToOne 20 | @JoinColumn(name = "device_id") 21 | private Device device; 22 | 23 | @ManyToOne 24 | @JoinColumn(name = "user_id") 25 | private User user; 26 | 27 | private String text; 28 | 29 | private Long likeCount = new Long(0); 30 | 31 | private Long dislikeCount = new Long(0); 32 | private String created = new SimpleDateFormat("dd.MM.yyyy").format(new Date()); 33 | private Long rating = new Long(0); 34 | 35 | @OneToMany(mappedBy = "comment", cascade = CascadeType.ALL) 36 | private List likes; 37 | 38 | @OneToMany(mappedBy = "comment", cascade = CascadeType.ALL) 39 | private List dislikes; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/entity/device/Device.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.entity.device; 2 | 3 | 4 | import com.fasterxml.jackson.annotation.JsonIgnore; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import javax.persistence.*; 10 | import java.util.List; 11 | 12 | @Entity 13 | @Getter 14 | @Setter 15 | @NoArgsConstructor 16 | public class Device { 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.IDENTITY) 19 | private Long id; 20 | 21 | private Long count = new Long(0); 22 | 23 | @ManyToOne 24 | @JoinColumn(name = "brand_id", referencedColumnName = "id") 25 | @JsonIgnore 26 | private Brand brand; 27 | 28 | private String name; 29 | 30 | private Long price; 31 | 32 | private Float rating = new Float(0); 33 | 34 | private String image; 35 | 36 | private String description; 37 | 38 | @OneToMany(mappedBy = "device", cascade = CascadeType.ALL) 39 | private List properties; 40 | 41 | @OneToMany(mappedBy = "device", cascade = CascadeType.ALL) 42 | private List comments; 43 | 44 | @ManyToOne 45 | @JoinColumn(name ="type_id") 46 | private DeviceType deviceType; 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/entity/device/DeviceType.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.entity.device; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | 6 | import javax.persistence.*; 7 | import java.util.List; 8 | 9 | @Entity 10 | @Table(name = "device_type") 11 | @Getter 12 | @Setter 13 | public class DeviceType { 14 | @Id 15 | @GeneratedValue(strategy = GenerationType.IDENTITY) 16 | private Long id; 17 | 18 | private String name; 19 | 20 | @OneToMany(mappedBy = "deviceType", cascade = CascadeType.ALL) 21 | private List brands; 22 | @OneToMany(mappedBy = "deviceType", cascade = CascadeType.ALL) 23 | private List devices; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/entity/device/Dislike.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.entity.device; 2 | 3 | import com.example.onlinestore.entity.user.User; 4 | import lombok.Data; 5 | 6 | import javax.persistence.*; 7 | 8 | @Data 9 | @Entity 10 | @Table(name = "dislikes") 11 | public class Dislike { 12 | 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.IDENTITY) 15 | private Long id; 16 | 17 | @ManyToOne 18 | @JoinColumn(name = "user_id") 19 | private User user; 20 | 21 | 22 | @ManyToOne 23 | @JoinColumn(name = "comment_id") 24 | private Comment comment; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/entity/device/Like.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.entity.device; 2 | 3 | 4 | import com.example.onlinestore.entity.user.User; 5 | import com.fasterxml.jackson.annotation.JsonBackReference; 6 | import lombok.Data; 7 | 8 | import javax.persistence.*; 9 | 10 | @Data 11 | @Entity 12 | @Table(name = "likes") 13 | public class Like { 14 | 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private Long id; 18 | 19 | @ManyToOne 20 | @JoinColumn(name = "user_id") 21 | private User user; 22 | 23 | @ManyToOne 24 | @JoinColumn(name = "comment_id") 25 | private Comment comment; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/entity/device/Property.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.entity.device; 2 | 3 | 4 | import com.fasterxml.jackson.annotation.JsonIgnore; 5 | import lombok.Data; 6 | 7 | import javax.persistence.*; 8 | 9 | @Entity 10 | @Data 11 | public class Property { 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.IDENTITY) 14 | private Long id; 15 | 16 | @ManyToOne 17 | @JoinColumn(name = "device_id") 18 | @JsonIgnore 19 | private Device device; 20 | 21 | private String name; 22 | 23 | private String description; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/entity/user/Basket.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.entity.user; 2 | 3 | import com.example.onlinestore.entity.device.Device; 4 | import lombok.Data; 5 | 6 | import javax.persistence.*; 7 | 8 | @Entity 9 | @Data 10 | public class Basket { 11 | @Id 12 | @GeneratedValue(strategy = GenerationType.IDENTITY) 13 | private Long id; 14 | 15 | @ManyToOne 16 | @JoinColumn(name = "user_id") 17 | private User user; 18 | 19 | @ManyToOne 20 | @JoinColumn(name = "device_id") 21 | private Device device; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/entity/user/Favourite.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.entity.user; 2 | 3 | import com.example.onlinestore.entity.device.Device; 4 | import lombok.Data; 5 | 6 | import javax.persistence.*; 7 | 8 | @Entity 9 | @Data 10 | public class Favourite { 11 | @Id 12 | @GeneratedValue(strategy = GenerationType.IDENTITY) 13 | private Long id; 14 | 15 | @ManyToOne 16 | @JoinColumn(name = "user_id") 17 | private User user; 18 | 19 | @ManyToOne 20 | @JoinColumn(name = "device_id") 21 | private Device device; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/entity/user/Order.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.entity.user; 2 | 3 | 4 | import com.example.onlinestore.entity.device.Device; 5 | import com.fasterxml.jackson.annotation.JsonIgnore; 6 | import lombok.Data; 7 | 8 | import javax.persistence.*; 9 | 10 | @Entity 11 | @Data 12 | @Table(name = "orders") 13 | public class Order { 14 | 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private Long id; 18 | 19 | @ManyToOne 20 | @JoinColumn(name = "user_id") 21 | @JsonIgnore 22 | private User user; 23 | 24 | @ManyToOne 25 | @JoinColumn(name = "device_id") 26 | private Device device; 27 | 28 | private String address; 29 | 30 | private String deliveryDate; 31 | 32 | private String comment; 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/entity/user/Role.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.entity.user; 2 | 3 | 4 | import com.fasterxml.jackson.annotation.JsonIgnore; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import javax.persistence.*; 10 | import java.util.List; 11 | 12 | @Entity 13 | @Table(name = "roles") 14 | @Getter 15 | @Setter 16 | @NoArgsConstructor 17 | public class Role { 18 | @Id 19 | @GeneratedValue(strategy = GenerationType.IDENTITY) 20 | private Long id; 21 | 22 | private String role; 23 | 24 | @JsonIgnore 25 | @ManyToMany(mappedBy = "roles", fetch = FetchType.LAZY) 26 | private List users; 27 | 28 | @Override 29 | public String toString() { 30 | return "Role{" + 31 | "id: " + getId() + ", " + 32 | "name: " + role + "}"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/entity/user/User.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.entity.user; 2 | 3 | import com.example.onlinestore.entity.device.Dislike; 4 | import com.example.onlinestore.entity.device.Like; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import javax.persistence.*; 9 | import javax.validation.constraints.Email; 10 | import javax.validation.constraints.Size; 11 | import java.util.List; 12 | 13 | @Entity 14 | @Table(name = "usr") 15 | @Data 16 | @NoArgsConstructor 17 | public class User { 18 | 19 | @Id 20 | @GeneratedValue(strategy = GenerationType.IDENTITY) 21 | private Long id; 22 | private String password; 23 | 24 | @Size(min = 3, max = 15, message = "Uncorrect username") 25 | private String username; 26 | 27 | @Email(message = "Uncorrect email") 28 | private String mail; 29 | 30 | private String phoneNumber; 31 | 32 | private String avatar; 33 | 34 | @ManyToMany(fetch = FetchType.EAGER) 35 | @JoinTable(name = "user_roles", 36 | joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")}, 37 | inverseJoinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")}) 38 | private List roles; 39 | 40 | 41 | @OneToMany(mappedBy = "user") 42 | private List orders; 43 | 44 | @OneToMany(mappedBy = "user") 45 | private List baskets; 46 | 47 | @OneToMany(mappedBy = "user") 48 | private List favourites; 49 | 50 | @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) 51 | private List likes; 52 | 53 | @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) 54 | private List dislikes; 55 | 56 | @Override 57 | public String toString() { 58 | return "User{" + 59 | "password='" + password + '\'' + 60 | ", username='" + username + '\'' + 61 | ", mail='" + mail + '\'' + 62 | ", phoneNumber='" + phoneNumber + '\'' + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/exceptions/existException/BrandAlreadyExist.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.exceptions.existException; 2 | 3 | public class BrandAlreadyExist extends RuntimeException { 4 | public BrandAlreadyExist(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/exceptions/existException/DeviceAlreadyExist.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.exceptions.existException; 2 | 3 | public class DeviceAlreadyExist extends RuntimeException { 4 | public DeviceAlreadyExist(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/exceptions/existException/DeviceTypeAlreadyExist.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.exceptions.existException; 2 | 3 | public class DeviceTypeAlreadyExist extends RuntimeException { 4 | public DeviceTypeAlreadyExist(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/exceptions/existException/PropertyAlreadyExist.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.exceptions.existException; 2 | 3 | public class PropertyAlreadyExist extends RuntimeException { 4 | public PropertyAlreadyExist(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/exceptions/existException/UserAlreadyExistAuthException.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.exceptions.existException; 2 | 3 | import org.springframework.security.core.AuthenticationException; 4 | 5 | public class UserAlreadyExistAuthException extends AuthenticationException { 6 | public UserAlreadyExistAuthException(String msg) { 7 | super(msg); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/exceptions/notFoundException/BrandNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.exceptions.notFoundException; 2 | 3 | import javassist.NotFoundException; 4 | 5 | public class BrandNotFoundException extends NotFoundException { 6 | public BrandNotFoundException(String msg) { 7 | super(msg); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/exceptions/notFoundException/DeviceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.exceptions.notFoundException; 2 | 3 | import javassist.NotFoundException; 4 | 5 | public class DeviceNotFoundException extends NotFoundException { 6 | public DeviceNotFoundException(String msg) { 7 | super(msg); 8 | } 9 | 10 | public DeviceNotFoundException(String msg, Exception e) { 11 | super(msg, e); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/exceptions/notFoundException/DeviceTypeNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.exceptions.notFoundException; 2 | 3 | import javassist.NotFoundException; 4 | 5 | public class DeviceTypeNotFoundException extends NotFoundException { 6 | public DeviceTypeNotFoundException(String msg) { 7 | super(msg); 8 | } 9 | 10 | public DeviceTypeNotFoundException(String msg, Exception e) { 11 | super(msg, e); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/exceptions/notFoundException/ModelNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.exceptions.notFoundException; 2 | 3 | public class ModelNotFoundException extends RuntimeException { 4 | public ModelNotFoundException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/exceptions/notFoundException/UserNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.exceptions.notFoundException; 2 | 3 | public class UserNotFoundException extends RuntimeException { 4 | public UserNotFoundException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/repos/device/BrandRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.repos.device; 2 | 3 | import com.example.onlinestore.entity.device.Brand; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | import java.util.List; 7 | 8 | public interface BrandRepo extends CrudRepository { 9 | List findBrandsByDeviceTypeId(Long deviceTypeId); 10 | 11 | Brand findByName(String name); 12 | Brand findByNameAndDeviceTypeId(String name, Long deviceTypeId ); 13 | Brand findByNameAndDeviceTypeName(String name, String deviceTypeName ); 14 | 15 | List findAll(); 16 | 17 | void deleteByNameAndDeviceTypeName(String name, String deviceTypeName); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/repos/device/CommentRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.repos.device; 2 | 3 | import com.example.onlinestore.entity.device.Comment; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | import java.util.List; 7 | 8 | public interface CommentRepo extends CrudRepository { 9 | 10 | List findCommentsByDeviceId(Long deviceId); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/repos/device/DeviceRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.repos.device; 2 | 3 | import com.example.onlinestore.entity.device.Device; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | import java.util.List; 7 | 8 | public interface DeviceRepo extends CrudRepository { 9 | List findAll(); 10 | 11 | List findDevicesByBrandId(Long brandId); 12 | List findDevicesByDeviceTypeId(Long deviceTypeId); 13 | List findDevicesByDeviceTypeIdAndBrandId(Long deviceTypeId, Long brandId); 14 | 15 | Device findByNameAndBrandNameAndDeviceTypeName( String deviceName, String brandName, String typeName); 16 | 17 | Device findByName(String name); 18 | Device deleteByName(String name); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/repos/device/DeviceTypeRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.repos.device; 2 | 3 | import com.example.onlinestore.entity.device.DeviceType; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | import java.util.List; 7 | 8 | public interface DeviceTypeRepo extends CrudRepository { 9 | List findAll(); 10 | 11 | DeviceType findByName(String name); 12 | void deleteByName(String name); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/repos/device/DislikeRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.repos.device; 2 | 3 | import com.example.onlinestore.entity.device.Dislike; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface DislikeRepo extends CrudRepository { 7 | Dislike findByCommentId(Long commentId); 8 | 9 | Dislike findByUserId(Long userId); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/repos/device/LikeRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.repos.device; 2 | 3 | import com.example.onlinestore.entity.device.Like; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface LikeRepo extends CrudRepository { 7 | Like findByCommentId(Long commentId); 8 | 9 | Like findByUserId(Long userId); 10 | 11 | Like findByUserIdAndCommentId(Long userId, Long commentId); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/repos/device/PropertyRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.repos.device; 2 | 3 | import com.example.onlinestore.entity.device.Property; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface PropertyRepo extends CrudRepository { 7 | public Property findByName(String name); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/repos/user/BasketRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.repos.user; 2 | 3 | import com.example.onlinestore.entity.user.Basket; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface BasketRepo extends CrudRepository { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/repos/user/FavouriteRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.repos.user; 2 | 3 | import com.example.onlinestore.entity.user.Favourite; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface FavouriteRepo extends CrudRepository { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/repos/user/OrderRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.repos.user; 2 | 3 | import com.example.onlinestore.entity.user.Order; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface OrderRepo extends CrudRepository { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/repos/user/RoleRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.repos.user; 2 | 3 | import com.example.onlinestore.entity.user.Role; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface RoleRepo extends CrudRepository { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/repos/user/UserRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.repos.user; 2 | 3 | import com.example.onlinestore.entity.user.User; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | import java.util.List; 7 | 8 | public interface UserRepo extends CrudRepository { 9 | User findByUsername(String username); 10 | 11 | List findAll(); 12 | 13 | User findByMail(String mail); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/security/JwtUserDetailsService.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.security; 2 | 3 | import com.example.onlinestore.entity.user.User; 4 | import com.example.onlinestore.security.jwt.JwtUser; 5 | import com.example.onlinestore.security.jwt.JwtUserFactory; 6 | import com.example.onlinestore.service.user.UserService; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.security.core.userdetails.UserDetails; 10 | import org.springframework.security.core.userdetails.UserDetailsService; 11 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 12 | import org.springframework.stereotype.Service; 13 | 14 | 15 | @Service 16 | @Slf4j 17 | public class JwtUserDetailsService implements UserDetailsService { 18 | 19 | private final UserService userService; 20 | 21 | @Autowired 22 | public JwtUserDetailsService(UserService userService) { 23 | this.userService = userService; 24 | } 25 | 26 | @Override 27 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 28 | User user = userService.getByUsername(username); 29 | 30 | if (user == null) { 31 | throw new UsernameNotFoundException("User with username " + username + " not found"); 32 | } 33 | JwtUser jwtUser = JwtUserFactory.create(user); 34 | log.info("IN loadUserByUsername - user with username: {} successfully loaded", username); 35 | 36 | return jwtUser; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/security/jwt/JwtAuthenticationException.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.security.jwt; 2 | 3 | import org.springframework.security.core.AuthenticationException; 4 | 5 | 6 | public class JwtAuthenticationException extends AuthenticationException { 7 | public JwtAuthenticationException(String msg, Throwable t) { 8 | super(msg, t); 9 | } 10 | 11 | public JwtAuthenticationException(String msg) { 12 | super(msg); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/security/jwt/JwtConfigurer.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.security.jwt; 2 | 3 | import org.springframework.security.config.annotation.SecurityConfigurerAdapter; 4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 5 | import org.springframework.security.web.DefaultSecurityFilterChain; 6 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 7 | 8 | 9 | 10 | public class JwtConfigurer extends SecurityConfigurerAdapter { 11 | private JwtTokenProvider jwtTokenProvider; 12 | 13 | public JwtConfigurer(JwtTokenProvider jwtTokenProvider) { 14 | this.jwtTokenProvider = jwtTokenProvider; 15 | } 16 | 17 | @Override 18 | public void configure(HttpSecurity httpSecurity) throws Exception { 19 | JwtTokenFilter jwtTokenFilter = new JwtTokenFilter(jwtTokenProvider); 20 | httpSecurity.addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/security/jwt/JwtTokenFilter.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.security.jwt; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.security.core.context.SecurityContextHolder; 5 | import org.springframework.web.filter.GenericFilterBean; 6 | 7 | import javax.servlet.FilterChain; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.ServletRequest; 10 | import javax.servlet.ServletResponse; 11 | import javax.servlet.http.HttpServletRequest; 12 | import java.io.IOException; 13 | 14 | 15 | public class JwtTokenFilter extends GenericFilterBean { 16 | 17 | private JwtTokenProvider jwtTokenProvider; 18 | 19 | public JwtTokenFilter(JwtTokenProvider jwtTokenProvider) { 20 | this.jwtTokenProvider = jwtTokenProvider; 21 | } 22 | 23 | @Override 24 | public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) 25 | throws IOException, ServletException { 26 | 27 | String token = jwtTokenProvider.resolveToken((HttpServletRequest) req); 28 | if (token != null && jwtTokenProvider.validateToken(token)) { 29 | Authentication auth = jwtTokenProvider.getAuthentication(token); 30 | 31 | if (auth != null) { 32 | SecurityContextHolder.getContext().setAuthentication(auth); 33 | } 34 | } 35 | filterChain.doFilter(req, res); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/security/jwt/JwtTokenProvider.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.security.jwt; 2 | 3 | import com.example.onlinestore.entity.user.Role; 4 | import com.example.onlinestore.entity.user.User; 5 | import io.jsonwebtoken.*; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 10 | import org.springframework.security.core.Authentication; 11 | import org.springframework.security.core.userdetails.UserDetails; 12 | import org.springframework.security.core.userdetails.UserDetailsService; 13 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 14 | import org.springframework.stereotype.Component; 15 | 16 | import javax.annotation.PostConstruct; 17 | import javax.servlet.http.HttpServletRequest; 18 | import java.util.ArrayList; 19 | import java.util.Base64; 20 | import java.util.Date; 21 | import java.util.List; 22 | 23 | 24 | @Component 25 | public class JwtTokenProvider { 26 | 27 | @Value("${jwt.token.secret}") 28 | private String secret; 29 | 30 | @Value("${jwt.token.expired}") 31 | private long validityInMilliseconds; 32 | 33 | 34 | @Autowired 35 | private UserDetailsService userDetailsService; 36 | 37 | @Bean 38 | public BCryptPasswordEncoder passwordEncoder() { 39 | BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); 40 | return bCryptPasswordEncoder; 41 | } 42 | 43 | @PostConstruct 44 | protected void init() { 45 | secret = Base64.getEncoder().encodeToString(secret.getBytes()); 46 | } 47 | 48 | public String createToken(String username, List roles, Long id) { 49 | 50 | Claims claims = Jwts.claims().setSubject(username); 51 | claims.put("roles", getRoleNames(roles)); 52 | claims.put("id", id); 53 | 54 | Date now = new Date(); 55 | Date validity = new Date(now.getTime() + validityInMilliseconds); 56 | 57 | return Jwts.builder()// 58 | .setClaims(claims)// 59 | .setIssuedAt(now)// 60 | .setExpiration(validity)// 61 | .signWith(SignatureAlgorithm.HS256, secret)// 62 | .compact(); 63 | } 64 | 65 | public Authentication getAuthentication(String token) { 66 | UserDetails userDetails = this.userDetailsService.loadUserByUsername(getUsername(token)); 67 | System.out.println(token);; 68 | return new UsernamePasswordAuthenticationToken(userDetails, "", userDetails.getAuthorities()); 69 | } 70 | 71 | public String getUsername(String token) { 72 | System.out.println("id "+ Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody().get("id")); 73 | return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody().getSubject(); 74 | } 75 | 76 | public Long getId(String token) { 77 | return Long.parseLong(Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody().get("id").toString()); 78 | } 79 | 80 | public String resolveToken(HttpServletRequest req) { 81 | String bearerToken = req.getHeader("Authorization"); 82 | if (bearerToken != null && bearerToken.startsWith("Bearer ")) { 83 | return bearerToken.substring(7, bearerToken.length()); 84 | } 85 | return null; 86 | } 87 | 88 | public boolean validateToken(String token) { 89 | try { 90 | Jws claims = Jwts.parser().setSigningKey(secret).parseClaimsJws(token); 91 | 92 | if (claims.getBody().getExpiration().before(new Date())) { 93 | return false; 94 | } 95 | 96 | return true; 97 | } catch (JwtException | IllegalArgumentException e) { 98 | throw new JwtAuthenticationException("JWT token is expired or invalid"); 99 | } 100 | } 101 | 102 | private List getRoleNames(List userRoles) { 103 | List result = new ArrayList<>(); 104 | 105 | userRoles.forEach(role -> { 106 | result.add(role.getRole()); 107 | }); 108 | 109 | return result; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/security/jwt/JwtUser.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.security.jwt; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import org.springframework.security.core.GrantedAuthority; 5 | import org.springframework.security.core.userdetails.UserDetails; 6 | 7 | import java.util.Collection; 8 | import java.util.Date; 9 | 10 | 11 | 12 | public class JwtUser implements UserDetails { 13 | 14 | private final Long id; 15 | private final String username; 16 | private final String password; 17 | private final boolean enabled; 18 | private final Collection authorities; 19 | 20 | public JwtUser( 21 | Long id, 22 | String username, 23 | String password, Collection authorities, 24 | boolean enabled 25 | ) { 26 | this.id = id; 27 | this.username = username; 28 | this.password = password; 29 | this.authorities = authorities; 30 | this.enabled = enabled; 31 | } 32 | 33 | @JsonIgnore 34 | public Long getId() { 35 | return id; 36 | } 37 | 38 | @Override 39 | public String getUsername() { 40 | return username; 41 | } 42 | 43 | @JsonIgnore 44 | @Override 45 | public boolean isAccountNonExpired() { 46 | return true; 47 | } 48 | 49 | @JsonIgnore 50 | @Override 51 | public boolean isAccountNonLocked() { 52 | return true; 53 | } 54 | 55 | @JsonIgnore 56 | @Override 57 | public boolean isCredentialsNonExpired() { 58 | return true; 59 | } 60 | 61 | @JsonIgnore 62 | @Override 63 | public String getPassword() { 64 | return password; 65 | } 66 | 67 | @Override 68 | public Collection getAuthorities() { 69 | return authorities; 70 | } 71 | 72 | @Override 73 | public boolean isEnabled() { 74 | return enabled; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/security/jwt/JwtUserFactory.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.security.jwt; 2 | 3 | import com.example.onlinestore.entity.user.Role; 4 | import com.example.onlinestore.entity.user.User; 5 | import org.springframework.security.core.GrantedAuthority; 6 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.stream.Collectors; 11 | 12 | 13 | public final class JwtUserFactory { 14 | 15 | public JwtUserFactory() { 16 | } 17 | 18 | public static JwtUser create(User user) { 19 | return new JwtUser( 20 | user.getId(), 21 | user.getUsername(), 22 | user.getPassword(), 23 | mapToGrantedAuthorities(new ArrayList<>(user.getRoles())), 24 | true 25 | ); 26 | } 27 | 28 | private static List mapToGrantedAuthorities(List userRoles) { 29 | return userRoles.stream() 30 | .map(role -> 31 | new SimpleGrantedAuthority(role.getRole()) 32 | ).collect(Collectors.toList()); 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/service/ImageService.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.service; 2 | 3 | import org.apache.tomcat.util.codec.binary.Base64; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.web.multipart.MultipartFile; 6 | 7 | import java.io.*; 8 | import java.util.UUID; 9 | 10 | public class ImageService { 11 | public static final String IMAGE_PATH = "C:\\Users\\tim\\Desktop\\online-store\\online-store\\src\\main\\resources\\static\\img\\"; 12 | 13 | 14 | public static String encodeFileToBase64Binary(File file) { 15 | String encodedfile = null; 16 | try { 17 | FileInputStream fileInputStreamReader = new FileInputStream(file); 18 | byte[] bytes = new byte[(int) file.length()]; 19 | fileInputStreamReader.read(bytes); 20 | encodedfile = new String(Base64.encodeBase64(bytes), "UTF-8"); 21 | } catch (FileNotFoundException e) { 22 | e.printStackTrace(); 23 | } catch (IOException e) { 24 | e.printStackTrace(); 25 | } 26 | 27 | return encodedfile; 28 | } 29 | 30 | public static String saveFile(MultipartFile img) throws IOException { 31 | if(img != null) { 32 | String fileName = UUID.randomUUID().toString() + ".jpg"; 33 | File convertFile = new File(IMAGE_PATH + fileName); 34 | convertFile.createNewFile(); 35 | FileOutputStream fout = new FileOutputStream(convertFile); 36 | fout.write(img.getBytes()); 37 | fout.close(); 38 | return fileName; 39 | } 40 | return null; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/service/device/BrandService.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.service.device; 2 | 3 | import com.example.onlinestore.entity.device.Brand; 4 | import com.example.onlinestore.exceptions.existException.BrandAlreadyExist; 5 | import com.example.onlinestore.exceptions.notFoundException.BrandNotFoundException; 6 | import com.example.onlinestore.repos.device.BrandRepo; 7 | import com.example.onlinestore.repos.device.DeviceTypeRepo; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.stereotype.Service; 11 | 12 | import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI; 13 | import javax.transaction.Transactional; 14 | import java.util.List; 15 | 16 | @Service 17 | public class BrandService { 18 | 19 | 20 | private final BrandRepo brandRepo; 21 | 22 | public BrandService(BrandRepo brandRepo) { 23 | this.brandRepo = brandRepo; 24 | } 25 | 26 | public List getAllByDeviceTypeId(Long id) throws BrandNotFoundException { 27 | List brands = brandRepo.findBrandsByDeviceTypeId(id); 28 | if(brands.size()==0){ 29 | throw new BrandNotFoundException("Brands with device type id " + id + " not fount"); 30 | } 31 | return brands; 32 | } 33 | 34 | public Brand save(Brand brand) { 35 | if(brandRepo.findByNameAndDeviceTypeId(brand.getName(), brand.getDeviceType().getId()) != null) { 36 | throw new BrandAlreadyExist("Brand with name " + brand.getName() + " already exist"); 37 | } 38 | return brandRepo.save(brand); 39 | } 40 | 41 | public List getAll() throws BrandNotFoundException { 42 | List brands = brandRepo.findAll(); 43 | if (brands.size() == 0) { 44 | throw new BrandNotFoundException("Brands not found"); 45 | } 46 | return brands; 47 | } 48 | 49 | public Brand getByName(String name) throws BrandNotFoundException { 50 | Brand brand = brandRepo.findByName(name); 51 | if (brand == null) { 52 | throw new BrandNotFoundException("Brands not found"); 53 | } 54 | return brand; 55 | } 56 | public Brand getByNameAndTypeName(String name, String typeName) throws BrandNotFoundException { 57 | Brand brand = brandRepo.findByNameAndDeviceTypeName(name, typeName); 58 | if (brand == null) { 59 | throw new BrandNotFoundException("Brands not found"); 60 | } 61 | return brand; 62 | } 63 | 64 | @Transactional 65 | public void deleteByNameAndTypeName(String name, String typeName) throws BrandNotFoundException { 66 | if (brandRepo.findByNameAndDeviceTypeName(name, typeName) == null) { 67 | throw new BrandNotFoundException("Brand not found"); 68 | } 69 | brandRepo.deleteByNameAndDeviceTypeName(name, typeName); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/service/device/CommentService.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.service.device; 2 | 3 | import com.example.onlinestore.entity.device.Comment; 4 | import com.example.onlinestore.repos.device.CommentRepo; 5 | import org.springframework.stereotype.Service; 6 | 7 | import java.util.List; 8 | 9 | @Service 10 | public class CommentService { 11 | 12 | private final CommentRepo commentRepo; 13 | 14 | public CommentService(CommentRepo commentRepo) { 15 | this.commentRepo = commentRepo; 16 | } 17 | 18 | public Comment save(Comment comment) { 19 | return commentRepo.save(comment); 20 | } 21 | 22 | public List getByDeviceId(Long deviceId) { 23 | return commentRepo.findCommentsByDeviceId(deviceId); 24 | } 25 | 26 | public Comment getById(Long id) { 27 | return commentRepo.findById(id).get(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/service/device/DeviceService.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.service.device; 2 | 3 | 4 | import com.example.onlinestore.entity.device.Device; 5 | import com.example.onlinestore.exceptions.existException.DeviceAlreadyExist; 6 | import com.example.onlinestore.exceptions.existException.DeviceTypeAlreadyExist; 7 | import com.example.onlinestore.exceptions.notFoundException.DeviceNotFoundException; 8 | import com.example.onlinestore.repos.device.DeviceRepo; 9 | import com.example.onlinestore.service.ImageService; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.web.multipart.MultipartFile; 12 | 13 | import java.io.File; 14 | import java.io.FileNotFoundException; 15 | import java.io.FileOutputStream; 16 | import java.io.IOException; 17 | import java.util.List; 18 | import java.util.UUID; 19 | 20 | @Service 21 | public class DeviceService { 22 | 23 | private final DeviceRepo deviceRepo; 24 | 25 | public DeviceService(DeviceRepo deviceRepo) { 26 | this.deviceRepo = deviceRepo; 27 | } 28 | 29 | public Device getById(Long id) throws DeviceNotFoundException { 30 | if(deviceRepo.findById(id) == null){ 31 | throw new DeviceNotFoundException("Device with id " + id + " not found"); 32 | } 33 | return deviceRepo.findById(id).get(); 34 | } 35 | 36 | public List getAllByBrandId(Long brandId) throws DeviceNotFoundException { 37 | List devices = deviceRepo.findDevicesByBrandId(brandId); 38 | if (devices.size() == 0) { 39 | throw new DeviceNotFoundException("Devices with brand id " + brandId + " not found"); 40 | } 41 | return devices; 42 | } 43 | 44 | public List getAllByTypeId(Long deviceTypeId) throws DeviceNotFoundException { 45 | List devices = deviceRepo.findDevicesByDeviceTypeId(deviceTypeId); 46 | if (devices.size() == 0) { 47 | throw new DeviceNotFoundException("Devices with type id " + deviceTypeId + " not found"); 48 | } 49 | return devices; 50 | } 51 | 52 | public List getAllByTypeIdAndBrandId(Long deviceTypeId, Long brandId) throws DeviceNotFoundException { 53 | List devices = deviceRepo.findDevicesByDeviceTypeIdAndBrandId(deviceTypeId,brandId); 54 | if (devices.size() == 0) { 55 | throw new DeviceNotFoundException("Devices with type id " + deviceTypeId + " not found"); 56 | } 57 | return devices; 58 | } 59 | 60 | public List getAll() throws DeviceNotFoundException { 61 | List devices = deviceRepo.findAll(); 62 | if(devices.size() == 0){ 63 | throw new DeviceNotFoundException("Devices not found"); 64 | } 65 | return devices; 66 | } 67 | 68 | public Device getDeviceByTypeBrandDevice(String deviceName, String brandName,String typeName ) throws DeviceNotFoundException { 69 | Device device = deviceRepo.findByNameAndBrandNameAndDeviceTypeName(deviceName, brandName,typeName); 70 | if (device == null) { 71 | throw new DeviceNotFoundException("Devices with type name " + deviceName + " not found"); 72 | } 73 | return device; 74 | } 75 | 76 | public Device save(Device device) { 77 | if (deviceRepo.findByName(device.getName()) != null) { 78 | throw new DeviceAlreadyExist("Device with name " + device.getName() + " already exist"); 79 | } 80 | return deviceRepo.save(device); 81 | } 82 | 83 | 84 | 85 | public void update(Device device) { 86 | deviceRepo.save(device); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/service/device/DeviceTypeService.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.service.device; 2 | 3 | import com.example.onlinestore.entity.device.DeviceType; 4 | import com.example.onlinestore.exceptions.existException.DeviceTypeAlreadyExist; 5 | import com.example.onlinestore.exceptions.notFoundException.DeviceTypeNotFoundException; 6 | import com.example.onlinestore.repos.device.DeviceTypeRepo; 7 | import org.springframework.stereotype.Service; 8 | 9 | import javax.transaction.Transactional; 10 | import java.util.List; 11 | 12 | @Service 13 | public class DeviceTypeService { 14 | private final DeviceTypeRepo deviceTypeRepo; 15 | 16 | public DeviceTypeService(DeviceTypeRepo deviceTypeRepo) { 17 | this.deviceTypeRepo = deviceTypeRepo; 18 | } 19 | 20 | public DeviceType getById(Long id) throws DeviceTypeNotFoundException { 21 | if(deviceTypeRepo.findById(id).get() == null){ 22 | throw new DeviceTypeNotFoundException("Device type with id " + id + " not found"); 23 | } 24 | return deviceTypeRepo.findById(id).get(); 25 | } 26 | 27 | public DeviceType getByName(String name) throws DeviceTypeNotFoundException { 28 | if(deviceTypeRepo.findByName(name) == null){ 29 | throw new DeviceTypeNotFoundException("Device type with name " + name + " not found"); 30 | } 31 | return deviceTypeRepo.findByName(name); 32 | } 33 | 34 | public List getAll() throws DeviceTypeNotFoundException { 35 | List devices = deviceTypeRepo.findAll(); 36 | if(devices.size() == 0){ 37 | throw new DeviceTypeNotFoundException("Device types not found"); 38 | } 39 | return devices; 40 | } 41 | 42 | public DeviceType save(DeviceType deviceType) throws DeviceTypeAlreadyExist { 43 | if(deviceTypeRepo.findByName(deviceType.getName()) != null){ 44 | throw new DeviceTypeAlreadyExist("Device types not found"); 45 | } else{ 46 | return deviceTypeRepo.save(deviceType); 47 | } 48 | } 49 | 50 | @Transactional 51 | public void deleteByName(String name) throws DeviceTypeNotFoundException { 52 | if(deviceTypeRepo.findByName(name) == null){ 53 | throw new DeviceTypeNotFoundException("Device types not found"); 54 | } else{ 55 | deviceTypeRepo.deleteByName(name); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/service/device/PropertyService.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.service.device; 2 | 3 | import com.example.onlinestore.entity.device.Property; 4 | import com.example.onlinestore.exceptions.existException.PropertyAlreadyExist; 5 | import com.example.onlinestore.repos.device.PropertyRepo; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class PropertyService { 10 | private final PropertyRepo propertyRepo; 11 | 12 | public PropertyService(PropertyRepo propertyRepo) { 13 | this.propertyRepo = propertyRepo; 14 | } 15 | 16 | public Property save(Property property) { 17 | if (propertyRepo.findByName(property.getName()) != null) { 18 | throw new PropertyAlreadyExist("Property with name " + property.getName() + " already exist"); 19 | } 20 | return propertyRepo.save(property); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/service/user/UserService.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.service.user; 2 | 3 | 4 | import com.example.onlinestore.entity.user.User; 5 | 6 | import java.util.List; 7 | 8 | public interface UserService { 9 | 10 | User register(User user); 11 | 12 | User getByUsername(String username); 13 | 14 | User getByMail(String mail); 15 | 16 | User getById(Long id); 17 | 18 | List getAll(); 19 | 20 | void delete(Long id); 21 | 22 | void update(User user); 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/example/onlinestore/service/user/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore.service.user.impl; 2 | 3 | import com.example.onlinestore.entity.user.Role; 4 | import com.example.onlinestore.entity.user.User; 5 | import com.example.onlinestore.exceptions.notFoundException.UserNotFoundException; 6 | import com.example.onlinestore.repos.user.RoleRepo; 7 | import com.example.onlinestore.repos.user.UserRepo; 8 | import com.example.onlinestore.service.user.UserService; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 12 | import org.springframework.stereotype.Service; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.Random; 17 | 18 | 19 | @Service 20 | @Slf4j 21 | public class UserServiceImpl implements UserService { 22 | 23 | private final UserRepo userRepository; 24 | private final RoleRepo roleRepository; 25 | private final BCryptPasswordEncoder passwordEncoder; 26 | 27 | @Autowired 28 | public UserServiceImpl(UserRepo userRepository, RoleRepo roleRepository, BCryptPasswordEncoder passwordEncoder) { 29 | this.userRepository = userRepository; 30 | this.roleRepository = roleRepository; 31 | this.passwordEncoder = passwordEncoder; 32 | } 33 | 34 | @Override 35 | public User register(User user) { 36 | Role roleUser = roleRepository.findById(new Long(1)).get(); 37 | List userRoles = new ArrayList<>(); 38 | userRoles.add(roleUser); 39 | 40 | user.setPassword(passwordEncoder.encode(user.getPassword())); 41 | user.setRoles(userRoles); 42 | 43 | User registeredUser = userRepository.save(user); 44 | 45 | log.info("IN register - user: {} successfully registered", registeredUser); 46 | 47 | return registeredUser; 48 | } 49 | 50 | 51 | @Override 52 | public User getByUsername(String username) { 53 | User result = userRepository.findByUsername(username); 54 | log.info("IN findByUsername - user: {} found by username: {}", result, username); 55 | 56 | return result; 57 | } 58 | 59 | @Override 60 | public User getByMail(String mail) { 61 | User user = userRepository.findByMail(mail); 62 | if (user == null) { 63 | throw new UserNotFoundException("User not found"); 64 | } 65 | return user; 66 | } 67 | 68 | @Override 69 | public User getById(Long id) { 70 | User result = userRepository.findById(id).orElse(null); 71 | 72 | if (result == null) { 73 | return null; 74 | } 75 | log.warn("IN findById - no user found by id: {}", id); 76 | 77 | return result; 78 | } 79 | 80 | @Override 81 | public List getAll() { 82 | List users = userRepository.findAll(); 83 | if (users.size() == 0) { 84 | throw new UserNotFoundException("Users not found"); 85 | } 86 | return users; 87 | } 88 | 89 | @Override 90 | public void delete(Long id) { 91 | userRepository.deleteById(id); 92 | } 93 | 94 | @Override 95 | public void update(User user) { 96 | userRepository.save(user); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.jpa.hibernate.ddl-auto=validate 2 | spring.jpa.show-sql=true 3 | spring.jpa.generate-ddl = true 4 | spring.datasource.url=jdbc:mysql://localhost:3306/electronic_store?useUnicode=true&useSSL=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC 5 | spring.datasource.username=root 6 | spring.datasource.password=root 7 | spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect 8 | 9 | 10 | spring.servlet.multipart.max-file-size=5000KB 11 | spring.servlet.multipart.max-request-size=5000KB 12 | 13 | jwt.token.secret= onlinestore 14 | jwt.token.expired= 3600000 15 | 16 | spring.mail.host=smtp.gmail.com 17 | spring.mail.port=587 18 | spring.mail.username=timurproud07@gmail.com 19 | spring.mail.password=timur555 20 | spring.mail.properties.mail.smtp.auth=true 21 | spring.mail.properties.mail.smtp.starttls.enable=true 22 | 23 | -------------------------------------------------------------------------------- /src/main/resources/db/migration/V1__init_db.sql: -------------------------------------------------------------------------------- 1 | create table hibernate_sequence ( 2 | next_val bigint 3 | ) engine=MyISAM; 4 | 5 | insert into hibernate_sequence values ( 1 ); 6 | insert into hibernate_sequence values ( 1 ); 7 | 8 | CREATE TABLE usr ( 9 | id BIGINT NOT NULL AUTO_INCREMENT, 10 | password VARCHAR(64) NOT NULL, 11 | username VARCHAR(64) NOT NULL, 12 | mail VARCHAR(64) NOT NULL, 13 | phone_number VARCHAR(11), 14 | avatar VARCHAR(64), 15 | PRIMARY KEY (id) 16 | ) engine=myISAM; 17 | 18 | CREATE TABLE roles ( 19 | id BIGINT NOT NULL AUTO_INCREMENT, 20 | role VARCHAR(32) NOT NULL, 21 | PRIMARY KEY (id) 22 | ) engine=myISAM; 23 | 24 | CREATE TABLE basket ( 25 | id BIGINT NOT NULL AUTO_INCREMENT, 26 | device_id BIGINT NOT NULL references device, 27 | user_id BIGINT NOT NULL references usr, 28 | PRIMARY KEY (id) 29 | ) engine=myISAM; 30 | 31 | CREATE TABLE favourite ( 32 | id BIGINT NOT NULL AUTO_INCREMENT, 33 | device_id BIGINT NOT NULL references device, 34 | user_id BIGINT NOT NULL references usr, 35 | PRIMARY KEY (id) 36 | ) engine=myISAM; 37 | 38 | CREATE TABLE orders ( 39 | id BIGINT NOT NULL AUTO_INCREMENT, 40 | device_id BIGINT NOT NULL references device, 41 | user_id BIGINT NOT NULL references usr, 42 | address VARCHAR(255) NOT NULL, 43 | delivery_date VARCHAR(64) NOT NULL, 44 | comment VARCHAR(255), 45 | PRIMARY KEY (id) 46 | ) engine=myISAM; 47 | 48 | 49 | 50 | 51 | CREATE TABLE device ( 52 | id BIGINT NOT NULL AUTO_INCREMENT, 53 | count BIGINT DEFAULT 0, 54 | name VARCHAR(255) NOT NULL, 55 | brand_id BIGINT NOT NULL REFERENCES brand, 56 | type_id BIGINT NOT NULL REFERENCES device_type, 57 | image VARCHAR(255) default NULL, 58 | price BIGINT NOT NULL , 59 | rating FLOAT DEFAULT 0, 60 | PRIMARY KEY (id) 61 | ) engine=myISAM; 62 | 63 | CREATE TABLE brand( 64 | id BIGINT NOT NULL AUTO_INCREMENT, 65 | device_type_id BIGINT NOT NULL REFERENCES device_type, 66 | name VARCHAR(64) NOT NULL, 67 | PRIMARY KEY (id) 68 | ) engine=myISAM; 69 | 70 | CREATE TABLE device_type( 71 | id BIGINT NOT NULL AUTO_INCREMENT, 72 | name VARCHAR(64) NOT NULL, 73 | PRIMARY KEY (id) 74 | ) engine=myISAM; 75 | 76 | 77 | 78 | CREATE TABLE comment ( 79 | id BIGINT NOT NULL AUTO_INCREMENT, 80 | device_id BIGINT NOT NULL references device, 81 | user_id BIGINT NOT NULL references usr, 82 | text varchar(512) NOT NULL, 83 | like_count BIGINT DEFAULT 0, 84 | dislike_count BIGINT DEFAULT 0, 85 | PRIMARY KEY (id) 86 | ) engine=myISAM; 87 | 88 | CREATE TABLE property ( 89 | id BIGINT NOT NULL AUTO_INCREMENT, 90 | device_id BIGINT NOT NULL references device, 91 | name VARCHAR (32) NOT NULL, 92 | description VARCHAR(512) NOT NULL, 93 | PRIMARY KEY (id) 94 | ) engine=myISAM; 95 | 96 | 97 | CREATE TABLE user_roles ( 98 | user_id BIGINT NOT NULL references usr, 99 | role_id BIGINT NOT NULL references role, 100 | PRIMARY KEY (user_id, role_id) 101 | ) engine=myISAM; 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /src/main/resources/db/migration/V2__insert_into.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO roles values (1, "ROLE_USER"); 2 | INSERT INTO roles values (2, "ROLE_ADMIN"); 3 | 4 | INSERT INTO usr(password, username, mail, phone_number) 5 | values("$2a$04$zUk5psHVasW8ZTh6yLE/T.tIkJM1M5aNgeXb0E6inUihrTGl0CY5e", "admin", "admin@mail.ru", "89670000101"); 6 | 7 | INSERT INTO usr(password, username, mail, phone_number) 8 | values("$2a$04$zUk5psHVasW8ZTh6yLE/T.tIkJM1M5aNgeXb0E6inUihrTGl0CY5e", "usr", "user@mail.ru", "89670000107"); 9 | 10 | INSERT INTO usr(password, username, mail, phone_number) 11 | values("$2a$04$zUk5psHVasW8ZTh6yLE/T.tIkJM1M5aNgeXb0E6inUihrTGl0CY5e", "test", "test@mail.ru", "89670000107"); 12 | 13 | 14 | INSERT INTO device_type values (1, "Смартфоны"); 15 | INSERT INTO device_type values (2, "Ноутбуки"); 16 | 17 | INSERT INTO brand values (1,1, "Apple"); 18 | INSERT INTO brand values (2,1, "Samsung"); 19 | INSERT INTO brand values (3,2, "Samsung"); 20 | 21 | INSERT INTO user_roles values (1,1); 22 | INSERT INTO user_roles values (1,2); 23 | 24 | INSERT INTO user_roles values (2,1); 25 | INSERT INTO user_roles values (3,1); 26 | INSERT INTO user_roles values (3,2); 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/main/resources/db/migration/V3__add_dev_desk.sql: -------------------------------------------------------------------------------- 1 | alter table device add column description varchar(2048); -------------------------------------------------------------------------------- /src/main/resources/db/migration/V4__add_creation.sql: -------------------------------------------------------------------------------- 1 | alter table comment add column created varchar(255) default null ; 2 | alter table comment add column rating bigint; -------------------------------------------------------------------------------- /src/main/resources/db/migration/V5__add_likes.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE likes ( 2 | id BIGINT NOT NULL AUTO_INCREMENT, 3 | comment_id BIGINT NOT NULL references comment, 4 | user_id BIGINT NOT NULL references usr, 5 | PRIMARY KEY (id) 6 | ) engine=myISAM; 7 | 8 | CREATE TABLE dislikes ( 9 | id BIGINT NOT NULL AUTO_INCREMENT, 10 | comment_id BIGINT NOT NULL references comment, 11 | user_id BIGINT NOT NULL references usr, 12 | PRIMARY KEY (id) 13 | ) engine=myISAM; 14 | -------------------------------------------------------------------------------- /src/main/resources/static/img/08a32ad4-3c47-416b-9f80-1f8c565b801e.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/08a32ad4-3c47-416b-9f80-1f8c565b801e.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/126b9073-b25b-4bfd-a17b-9f23c73f022e.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/126b9073-b25b-4bfd-a17b-9f23c73f022e.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/13135e8e-7f64-4642-98b8-5fe50e35d3dc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/13135e8e-7f64-4642-98b8-5fe50e35d3dc.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/1368d338-e94a-4ca1-bdb9-5a83c82f2ab6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/1368d338-e94a-4ca1-bdb9-5a83c82f2ab6.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/15558ef3-24fc-4494-82dc-8ce133de9f28.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/15558ef3-24fc-4494-82dc-8ce133de9f28.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/18bddc87-84a3-4ecb-a979-68217f021943.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/18bddc87-84a3-4ecb-a979-68217f021943.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/2453aa30-920f-4794-bb2d-5a437fd9790d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/2453aa30-920f-4794-bb2d-5a437fd9790d.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/251554e6-f7a9-43ae-a4ed-dff50125bf35.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/251554e6-f7a9-43ae-a4ed-dff50125bf35.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/27fc678d-e452-4f5f-aa34-edc4db5201a3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/27fc678d-e452-4f5f-aa34-edc4db5201a3.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/2ad40117-1d7d-42c3-9c6a-b75d5db9c73f.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/2ad40117-1d7d-42c3-9c6a-b75d5db9c73f.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/329d50a8-9b24-4191-87f8-1c36e50135b1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/329d50a8-9b24-4191-87f8-1c36e50135b1.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/3b0fb6dc-c27a-4877-8502-e977667f3882.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/3b0fb6dc-c27a-4877-8502-e977667f3882.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/3c027f3e-5b1b-4460-b1c2-43488f887f80.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/3c027f3e-5b1b-4460-b1c2-43488f887f80.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/3d3110f5-c617-4f29-8779-b21dc4ee8011.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/3d3110f5-c617-4f29-8779-b21dc4ee8011.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/427166fd-15f7-46f8-b836-542a06510e1e.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/427166fd-15f7-46f8-b836-542a06510e1e.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/4e2825d4-1279-48ac-9781-ec44af9bce7e.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/4e2825d4-1279-48ac-9781-ec44af9bce7e.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/4fe03f21-bc61-42ee-a9a1-078ee14c02cd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/4fe03f21-bc61-42ee-a9a1-078ee14c02cd.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/532d5d53-5d40-4023-a01e-b89942231e50.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/532d5d53-5d40-4023-a01e-b89942231e50.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/576fe923-7748-4e5e-bfa7-3a1bb829612a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/576fe923-7748-4e5e-bfa7-3a1bb829612a.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/57a22e6a-e1d7-41d8-b580-710b9f7a20bc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/57a22e6a-e1d7-41d8-b580-710b9f7a20bc.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/57dfa99d-e55e-4462-abb5-9941d6e3c3ad.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/57dfa99d-e55e-4462-abb5-9941d6e3c3ad.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/5892c924-bf4f-4f6e-a67e-9e86d9276178.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/5892c924-bf4f-4f6e-a67e-9e86d9276178.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/591babea-2f2a-4863-af22-2d2fd632d468.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/591babea-2f2a-4863-af22-2d2fd632d468.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/59505d1c-9c37-4767-ab1b-8a875a9805ff.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/59505d1c-9c37-4767-ab1b-8a875a9805ff.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/8286cea2-fa16-4ff2-a0e9-2a091a464298.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/8286cea2-fa16-4ff2-a0e9-2a091a464298.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/84556e4e-555a-426e-8291-9c2e7b223577.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/84556e4e-555a-426e-8291-9c2e7b223577.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/8b6fee5e-9e2d-477d-9067-df3d78b03475.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/8b6fee5e-9e2d-477d-9067-df3d78b03475.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/8c1afcaa-0dda-432c-8195-3e9563c59723.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/8c1afcaa-0dda-432c-8195-3e9563c59723.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/960ab2c4-1392-4211-8408-48d1a6973b45.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/960ab2c4-1392-4211-8408-48d1a6973b45.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/9c2e9b20-e7eb-4269-8626-a32729772f7d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/9c2e9b20-e7eb-4269-8626-a32729772f7d.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/9d55f709-f0a3-408b-ba96-bacbebe1584a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/9d55f709-f0a3-408b-ba96-bacbebe1584a.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/9e61a016-a5d8-418c-aaf2-8e6fb19cba2c.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/9e61a016-a5d8-418c-aaf2-8e6fb19cba2c.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/ad7e05e4-68c8-4950-aa6d-628182432467.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/ad7e05e4-68c8-4950-aa6d-628182432467.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/af298f8f-4a11-45f3-a73a-171936246303.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/af298f8f-4a11-45f3-a73a-171936246303.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/af7896b1-988a-4b0f-b6fe-467d4c9af12c.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/af7896b1-988a-4b0f-b6fe-467d4c9af12c.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/avatar.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/avatar.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/b222769a-96bb-4a2f-a7e2-fa16e6b3c4b2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/b222769a-96bb-4a2f-a7e2-fa16e6b3c4b2.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/bd398816-cb34-4977-b3f5-76984e84737d.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/bd398816-cb34-4977-b3f5-76984e84737d.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/bdded511-4ec0-482f-ad58-d7fd1b15629e.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/bdded511-4ec0-482f-ad58-d7fd1b15629e.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/bf9e9178-b566-41fd-a310-237dc1206689.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/bf9e9178-b566-41fd-a310-237dc1206689.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/c496b69b-11b9-48e2-985d-f8e799b9b107.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/c496b69b-11b9-48e2-985d-f8e799b9b107.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/cdac9a4a-05fb-4daa-b126-b4522dac8e51.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/cdac9a4a-05fb-4daa-b126-b4522dac8e51.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/d89425f5-5be2-49c9-891c-9b9e942d4245.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/d89425f5-5be2-49c9-891c-9b9e942d4245.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/daef9bb8-46b3-4ebd-b269-521eeedcbca2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/daef9bb8-46b3-4ebd-b269-521eeedcbca2.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/dd137437-a499-4bbe-acb8-3138363f9713.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/dd137437-a499-4bbe-acb8-3138363f9713.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/e19f0e31-6bad-4a9c-b34d-521f015d857a.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/e19f0e31-6bad-4a9c-b34d-521f015d857a.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/e54932ae-c541-4a88-a450-a9499c498250.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/e54932ae-c541-4a88-a450-a9499c498250.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/e8e771c0-2022-42e2-b747-0f87685cd045.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/e8e771c0-2022-42e2-b747-0f87685cd045.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/f5304ff0-10c1-43c1-be96-9190866030d0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/f5304ff0-10c1-43c1-be96-9190866030d0.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/f5714822-2b70-4029-b682-e04843fca757.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/f5714822-2b70-4029-b682-e04843fca757.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/f604b0a3-c545-4743-828c-cff9729bdafd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/f604b0a3-c545-4743-828c-cff9729bdafd.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/f69a10ef-7715-4940-aed8-2c822eaf35df.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/f69a10ef-7715-4940-aed8-2c822eaf35df.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/fd4aee57-9203-407e-9321-a6f5939c2c35.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/fd4aee57-9203-407e-9321-a6f5939c2c35.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/fd879310-0284-4037-ac24-9083098ed465.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utimur/electronic_store_backend/fcefbc50a08c5bcb29173fc4ef9b7028ef00667b/src/main/resources/static/img/fd879310-0284-4037-ac24-9083098ed465.jpg -------------------------------------------------------------------------------- /src/test/java/com/example/onlinestore/OnlineStoreApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.onlinestore; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class OnlineStoreApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------