├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml ├── src ├── main │ ├── java │ │ └── koredebank │ │ │ └── example │ │ │ └── bank │ │ │ ├── BankApplication.java │ │ │ ├── CloudinaryConfiguration.java │ │ │ ├── Email │ │ │ ├── EmailConfig.java │ │ │ ├── EmailResponse.java │ │ │ ├── EmailService.java │ │ │ └── EmailServiceImpl.java │ │ │ ├── ModelMapperConfig.java │ │ │ ├── SpringFoxConfig.java │ │ │ ├── cloudinaryService │ │ │ ├── CloudStorageService.java │ │ │ ├── CloudinaryConfig.java │ │ │ └── CloudinaryStorageServiceImpl.java │ │ │ ├── controller │ │ │ ├── AccountManagerController.java │ │ │ ├── TransactionController.java │ │ │ └── UserController.java │ │ │ ├── dto │ │ │ ├── AccountListResponseDto.java │ │ │ ├── AccountManagerBlockUserRequestDto.java │ │ │ ├── AccountManagerChangePassword.java │ │ │ ├── AccountManagerForgotPassword.java │ │ │ ├── AccountManagerSignUpRequestDto.java │ │ │ ├── AccountManagerSignUpResponseDto.java │ │ │ ├── AccountManagerUnblockUserRequestDto.java │ │ │ ├── AccountResponseDto.java │ │ │ ├── CustomerCompliantDaysLength.java │ │ │ ├── TransactionListResponseDto.java │ │ │ ├── TransactionResponseDto.java │ │ │ ├── UserChangePasswordRequestDto.java │ │ │ ├── UserCheckAccountBalanceRequestDto.java │ │ │ ├── UserCheckAccountBalanceResponseDto.java │ │ │ ├── UserCompliantFormRequestDto.java │ │ │ ├── UserCompliantFormResponseDto.java │ │ │ ├── UserCompliantListResponseDto.java │ │ │ ├── UserCreateAccountRequestDto.java │ │ │ ├── UserCreateAccountResponseDto.java │ │ │ ├── UserDepositsFundsRequestDto.java │ │ │ ├── UserDepositsFundsResponseDto.java │ │ │ ├── UserForgotPasswordRequestDto.java │ │ │ ├── UserLoginDto.java │ │ │ ├── UserLoginResponseDto.java │ │ │ ├── UserLoginValidationRequestDto.java │ │ │ ├── UserRetrieveForgotPasswordRequestDto.java │ │ │ ├── UserRetrieveForgotPasswordResponseDto.java │ │ │ ├── UserSignUpRequestDto.java │ │ │ ├── UserSignUpResponseDto.java │ │ │ ├── UserTransferFundsRequestDto.java │ │ │ ├── UserTransferFundsResponseDto.java │ │ │ ├── UserWithdrawFundsRequestDto.java │ │ │ └── UserWithdrawFundsResponseDto.java │ │ │ ├── model │ │ │ ├── AccountManager.java │ │ │ ├── CustomerCompliantForm.java │ │ │ ├── Roles.java │ │ │ ├── Transaction.java │ │ │ ├── Usage.java │ │ │ ├── UserAccount.java │ │ │ ├── UserEntity.java │ │ │ └── audit │ │ │ │ ├── DateAudit.java │ │ │ │ └── UserDateAudit.java │ │ │ ├── payload │ │ │ ├── CreateAccountDto.java │ │ │ ├── TransferDto.java │ │ │ ├── UserAccountDto.java │ │ │ ├── UserAccountGeneratorDto.java │ │ │ └── Validator.java │ │ │ ├── repository │ │ │ ├── AccountManagerRepository.java │ │ │ ├── CustomerCompliantFormRepository.java │ │ │ ├── TransactionRepository.java │ │ │ ├── UserAccountRepository.java │ │ │ └── UserRepository.java │ │ │ ├── security │ │ │ ├── WebSecurityConfig.java │ │ │ ├── config │ │ │ │ └── PasswordConfig.java │ │ │ ├── exceptions │ │ │ │ ├── AccountCreationException.java │ │ │ │ ├── AuthorizationException.java │ │ │ │ ├── GeneralServiceException.java │ │ │ │ ├── ImageUploadException.java │ │ │ │ └── IncorrectPasswordException.java │ │ │ ├── securityServices │ │ │ │ ├── AppAuthenticationProvider.java │ │ │ │ ├── ApplicationUser.java │ │ │ │ ├── TokenProviderService.java │ │ │ │ ├── TokenProviderServiceImpl.java │ │ │ │ └── UserPrincipalService.java │ │ │ └── securityUtils │ │ │ │ ├── JWTToken.java │ │ │ │ ├── SecurityConstants.java │ │ │ │ └── TokenType.java │ │ │ ├── service │ │ │ ├── accountManagerService │ │ │ │ ├── AccountManagerServiceImpl.java │ │ │ │ └── AccountManagerServices.java │ │ │ ├── transactionService │ │ │ │ ├── TransactionServiceImpl.java │ │ │ │ └── TransactionServices.java │ │ │ └── userService │ │ │ │ ├── UserServiceImpl.java │ │ │ │ └── UserServices.java │ │ │ ├── serviceUtil │ │ │ ├── IdGenerator.java │ │ │ └── StringUtil.java │ │ │ ├── tool │ │ │ └── AccountGenerator.java │ │ │ └── util │ │ │ ├── ApiRoutes.java │ │ │ └── constants.java │ └── resources │ │ ├── application-dev.properties │ │ ├── application-prod.properties │ │ └── application.properties └── test │ └── java │ └── koredebank │ └── example │ └── bank │ └── BankApplicationTests.java └── system.properties /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kordedekehine/SpringBoot-Bank-App/71fb4486aa94346da9d3ccef78f4e1bb11c9e514/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpringBoot-Bank-App 2 | 3 | # KOREDE-Spring-Boot-Bank-App API 4 | ![img.png](img.png) 5 | ![img_1.png](img_1.png) 6 | ![img_2.png](img_2.png) 7 | 8 | ## Environment 9 | Install JDK 11 (https://www.oracle.com/java/technologies/javase-jdk11-downloads.html) 10 | , IDE Intellij IDEA 11 | 12 | ## How to run 13 | 20 | 21 | ### For documentation (http://localhost:8080/swagger-ui.html#/) 22 | 23 | Replicate the basic functions of digital banking. 24 | The app should provide parents with: 25 | 26 | The Basic API OF BANK 27 | 28 | Architecture and Design part: 29 | 30 | Creating Diagrams: 31 | 32 | Class 33 | 34 | Use cases 35 | 36 | Deployment 37 | 38 | Package 39 | 40 | To analyse 41 | 42 | Sequence 43 | 44 | Object 45 | 46 | SpringBoot Back-End part: 47 | 48 | Connection With The MySQL database through php myadmin. 49 | 50 | Creation of Entity tables. 51 | 52 | Creation of Relations Between Entity Tables. 53 | 54 | Creation of Crud (View, Delete, Add, Edit). 55 | 56 | Creation of Advanced Trades. 57 | 58 | Creation of Services. 59 | 60 | Consumption of Rest. 61 | 62 | Creation of APIs (Messaging, Email, Mapp,Authentication,Virtual Meet schedule) 63 | 64 | 65 | #https://springboot-bank-app-production.up.railway.app/swagger-ui.html#/ 66 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/Library/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a userEntity defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.3 9 | 10 | 11 | koredebank.example 12 | bank 13 | 0.0.1-SNAPSHOT 14 | bank 15 | Demo project for Spring Boot Bank App 16 | 17 | 17 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-data-jpa 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-mail 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | org.postgresql 35 | postgresql 36 | 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-security 42 | 43 | 44 | 45 | io.jsonwebtoken 46 | jjwt 47 | 0.9.1 48 | compile 49 | 50 | 51 | 52 | org.springframework.security 53 | spring-security-core 54 | 55 | 56 | 57 | org.springframework.security 58 | spring-security-web 59 | 60 | 61 | 62 | org.hibernate.validator 63 | hibernate-validator 64 | 7.0.3.Final 65 | 66 | 67 | 68 | javax.mail 69 | mail 70 | 1.4.7 71 | 72 | 73 | 74 | org.modelmapper 75 | modelmapper 76 | 3.0.0 77 | 78 | 79 | 80 | com.auth0 81 | java-jwt 82 | 3.18.3 83 | 84 | 85 | 86 | org.projectlombok 87 | lombok 88 | true 89 | 90 | 91 | 92 | 93 | com.fasterxml.jackson.datatype 94 | jackson-datatype-jsr310 95 | 96 | 97 | 98 | org.springframework.boot 99 | spring-boot-starter-test 100 | test 101 | 102 | 103 | 104 | org.springframework.boot 105 | spring-boot-starter-validation 106 | 2.4.1 107 | 108 | 109 | 110 | 111 | io.springfox 112 | springfox-swagger2 113 | 2.8.0 114 | compile 115 | 116 | 117 | 118 | com.github.mifmif 119 | generex 120 | 1.0.2 121 | 122 | 123 | 124 | 125 | com.cloudinary 126 | cloudinary-http44 127 | 1.29.0 128 | 129 | 130 | 131 | io.springfox 132 | springfox-swagger-ui 133 | 2.8.0 134 | compile 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | org.springframework.boot 147 | spring-boot-maven-plugin 148 | ${project.parent.version} 149 | 150 | 151 | org.apache.maven.plugins 152 | maven-compiler-plugin 153 | 154 | 11 155 | 11 156 | 157 | 158 | 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/BankApplication.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 6 | 7 | @SpringBootApplication 8 | @EnableSwagger2 9 | public class BankApplication { 10 | 11 | public static void main(String[] args) { 12 | 13 | SpringApplication.run(BankApplication.class, args); 14 | System.out.println("Finished running People's Bank App"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/CloudinaryConfiguration.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank; 2 | 3 | import com.cloudinary.Cloudinary; 4 | import com.cloudinary.utils.ObjectUtils; 5 | import koredebank.example.bank.cloudinaryService.CloudinaryConfig; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.stereotype.Component; 9 | 10 | @Component 11 | public class CloudinaryConfiguration { 12 | 13 | @Autowired 14 | CloudinaryConfig cloudinaryConfig; 15 | 16 | @Bean 17 | public Cloudinary getCloudinaryConfig(){ 18 | return new Cloudinary(ObjectUtils.asMap("cloud_name",cloudinaryConfig.getCloudName(), 19 | "api_key",cloudinaryConfig.getApikey(),"api_secret",cloudinaryConfig.getSecretKey())); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/Email/EmailConfig.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.Email; 2 | 3 | 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.mail.javamail.JavaMailSender; 9 | import org.springframework.mail.javamail.JavaMailSenderImpl; 10 | import org.springframework.stereotype.Component; 11 | 12 | import javax.validation.constraints.NotNull; 13 | import java.util.Properties; 14 | 15 | 16 | 17 | @Setter 18 | @Getter 19 | @Component 20 | public class EmailConfig { 21 | 22 | @NotNull 23 | 24 | @Value("${spring.mail.host}") 25 | private String host; 26 | 27 | @NotNull 28 | @Value("${spring.mail.port}") 29 | private int port; 30 | 31 | @NotNull 32 | @Value("${spring.mail.username}") 33 | private String username; 34 | 35 | @NotNull 36 | @Value("${spring.mail.password}") 37 | private String password; 38 | 39 | public String getHost() { 40 | return host; 41 | } 42 | 43 | public void setHost(String host) { 44 | this.host = host; 45 | } 46 | 47 | public int getPort() { 48 | return port; 49 | } 50 | 51 | public void setPort(int port) { 52 | this.port = port; 53 | } 54 | 55 | public String getUsername() { 56 | return username; 57 | } 58 | 59 | public void setUsername(String username) { 60 | this.username = username; 61 | } 62 | 63 | public String getPassword() { 64 | return password; 65 | } 66 | 67 | public void setPassword(String password) { 68 | this.password = password; 69 | } 70 | 71 | @Bean 72 | public JavaMailSender getJavaMailSender() { 73 | JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); 74 | mailSender.setUsername(getUsername()); 75 | mailSender.setPassword(getPassword()); 76 | mailSender.setPort(getPort()); 77 | mailSender.setHost(getHost()); 78 | 79 | 80 | 81 | 82 | Properties javaMailProperties = new Properties(); 83 | javaMailProperties.put("mail.smtp.starttls.enable", "true"); 84 | javaMailProperties.put("mail.smtp.auth", "true"); 85 | javaMailProperties.put("mail.transport.protocol", "smtp"); 86 | javaMailProperties.put("mail.debug", "true"); 87 | mailSender.setJavaMailProperties(javaMailProperties); 88 | return mailSender; 89 | } 90 | 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/Email/EmailResponse.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.Email; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import org.springframework.validation.annotation.Validated; 6 | 7 | @Getter 8 | @Setter 9 | @Validated 10 | public class EmailResponse { 11 | 12 | private String message; 13 | 14 | private String status; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/Email/EmailService.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.Email; 2 | 3 | 4 | import koredebank.example.bank.model.CustomerCompliantForm; 5 | import koredebank.example.bank.model.Transaction; 6 | import koredebank.example.bank.model.UserEntity; 7 | import koredebank.example.bank.model.UserAccount; 8 | 9 | import javax.mail.MessagingException; 10 | import java.util.Optional; 11 | 12 | public interface EmailService { 13 | void sendRegistrationSuccessfulEmail(UserEntity userEntityEmail, String token)throws MessagingException; 14 | void sendVerificationMessage(Optional user) throws MessagingException; 15 | 16 | void sendChangePasswordMessage(Optional usersEntity) throws MessagingException; 17 | 18 | void sendForgotPasswordMessage(UserEntity userEntityEmail, String token) throws MessagingException; 19 | 20 | void sendAccountCreationSuccessfulEmail(UserAccount userAccount) throws MessagingException; 21 | 22 | void sendTransactionSuccessfulMessage(Transaction transaction, UserEntity userEntity) throws MessagingException; 23 | 24 | void sendAlertReceivedMessage(Transaction transaction) throws MessagingException; 25 | 26 | void sendDepositSuccessfulMessage(UserEntity userEntity, UserAccount userAccount) throws MessagingException; 27 | 28 | void sendWithdrawSuccessfulMessage(UserEntity userEntity, UserAccount userAccount) throws MessagingException; 29 | 30 | void sendCompliantNotification(CustomerCompliantForm customerCompliantForm) throws MessagingException; 31 | 32 | void sendAccountSuspendedNotification(UserEntity userEntity) throws MessagingException; 33 | 34 | void sendAccountSuspendedRevertNotification(UserEntity userEntity) throws MessagingException; 35 | 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/Email/EmailServiceImpl.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.Email; 2 | 3 | 4 | import koredebank.example.bank.model.CustomerCompliantForm; 5 | import koredebank.example.bank.model.Transaction; 6 | import koredebank.example.bank.model.UserEntity; 7 | import koredebank.example.bank.model.UserAccount; 8 | import org.springframework.mail.SimpleMailMessage; 9 | import org.springframework.mail.javamail.JavaMailSender; 10 | import org.springframework.stereotype.Service; 11 | 12 | import javax.mail.MessagingException; 13 | import java.util.Optional; 14 | 15 | @Service 16 | public class EmailServiceImpl implements EmailService { 17 | 18 | 19 | private final JavaMailSender javaMailSender; 20 | 21 | 22 | private final SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); 23 | private final String REGISTRATION_ERROR_MESSAGE = "Registration Not Successful"; 24 | 25 | private final String FORGOT_PASSWORD_ERROR_MESSAGE = "Password Recovery Not Successful"; 26 | 27 | private final String MESSAGE_NOT_SENT_MESSAGE = "Message Not sent from bank"; 28 | 29 | private final String ACCOUNT_CREATION_ERROR = "Account not created due to some issues"; 30 | 31 | private final String TRANSACTION_FAILURE = "Cannot send funds!"; 32 | 33 | private final String DEPOSIT_FAILURE = "Fail to deposit Funds"; 34 | 35 | private final String WITHDRAW_FAILURE = "Fail to withdraw Funds"; 36 | 37 | private final String SCHEDULE_NOT_SENT= "Schedule not sent! Kindly retry"; 38 | 39 | 40 | public EmailServiceImpl(JavaMailSender javaMailSender) { 41 | this.javaMailSender = javaMailSender; 42 | } 43 | 44 | @Override 45 | public void sendRegistrationSuccessfulEmail(UserEntity userEntityEmail, String token) throws MessagingException { 46 | String link = "http://localhost:9090" + token; 47 | 48 | simpleMailMessage.setTo(userEntityEmail.getEmail()); 49 | simpleMailMessage.setSubject("Welcome To People's Bank"); 50 | simpleMailMessage.setFrom("salamikehinde345@gmail.com"); 51 | String template = "Dear [[name]],\n" 52 | + "Thanks for registering on people bank.\n" 53 | + "Kindly use the code below to validate your account and activate your account:\n" 54 | + "[[code]]\n" 55 | + "Thank you.\n" 56 | + "Bank team"; 57 | template = template.replace("[[name]]", userEntityEmail.getFirstname()); 58 | template = template.replace("[[code]]", token); 59 | simpleMailMessage.setText(template); 60 | 61 | try { 62 | javaMailSender.send(simpleMailMessage); 63 | } catch (Exception exception) { 64 | exception.printStackTrace(); 65 | throw new MessagingException(String.format(REGISTRATION_ERROR_MESSAGE)); 66 | } 67 | } 68 | 69 | @Override 70 | public void sendVerificationMessage(Optional user) throws MessagingException { 71 | 72 | SimpleMailMessage message = new SimpleMailMessage(); 73 | simpleMailMessage.setText("People's Bank"); 74 | simpleMailMessage.setFrom("salamikehinde345@gmail.com"); 75 | simpleMailMessage.setTo(user.get().getEmail()); 76 | simpleMailMessage.setSubject("Welcome to people bank"); 77 | String template = "Dear [[name]],\n" 78 | + "Your account has been verified, kindly login to explore\n" 79 | + "[[URL]]\n" 80 | + "Thank you,\n\n" 81 | + "The Bank Team"; 82 | // template = template.replace("[[name]]", usersEntity.getFirstName()); 83 | template = template.replace("[[name]]", user.get().getFirstname()); 84 | template = template.replace("[[URL]]", "africa bank"); 85 | // message.setText(template); 86 | simpleMailMessage.setText(template); 87 | try { 88 | // javaMailSender.send(message); 89 | javaMailSender.send(simpleMailMessage); 90 | } catch (Exception exception) { 91 | throw new MessagingException(MESSAGE_NOT_SENT_MESSAGE); 92 | } 93 | } 94 | 95 | 96 | @Override 97 | public void sendChangePasswordMessage(Optional user) throws MessagingException { 98 | 99 | SimpleMailMessage message = new SimpleMailMessage(); 100 | simpleMailMessage.setText("bank"); 101 | simpleMailMessage.setFrom("salamikehinde345@gmail.com"); 102 | //simpleMailMessage.setTo(usersEntity.getEmail()); 103 | simpleMailMessage.setTo(user.get().getEmail()); 104 | simpleMailMessage.setSubject("bank"); 105 | String template = "Dear [[name]],\n" 106 | // + "Your account has been verified, kindly login to explore\n" 107 | + "You have successfully change your password!" 108 | + " Kindly reach out to us, if you have any incoherence from your side \n" 109 | + "[[URL]]\n" 110 | + "Thank you,\n\n" 111 | + "The Bank Team"; 112 | // template = template.replace("[[name]]", usersEntity.getFirstName()); 113 | template = template.replace("[[name]]", user.get().getFirstname()); 114 | template = template.replace("[[URL]]", "africa bank"); 115 | // message.setText(template); 116 | simpleMailMessage.setText(template); 117 | try { 118 | // javaMailSender.send(message); 119 | javaMailSender.send(simpleMailMessage); 120 | } catch (Exception exception) { 121 | throw new MessagingException(MESSAGE_NOT_SENT_MESSAGE); 122 | } 123 | } 124 | 125 | @Override 126 | public void sendForgotPasswordMessage(UserEntity userEntityEmail, String token) throws MessagingException { 127 | String link = "http://localhost:9090" + token; 128 | simpleMailMessage.setTo(userEntityEmail.getEmail()); 129 | simpleMailMessage.setSubject("Password Recovery"); 130 | simpleMailMessage.setFrom("salamikehinde345@gmail.com"); 131 | String template = "Dear [[name]],\n" 132 | + "Thanks for registering on people bank.\n" 133 | + "Kindly use the code below to validate your account, and recover your account:\n" 134 | + "[[code]]\n" 135 | + "Thank you.\n" 136 | + "Bank team"; 137 | template = template.replace("[[name]]", userEntityEmail.getFirstname()); 138 | template = template.replace("[[code]]", token); 139 | simpleMailMessage.setText(template); 140 | 141 | try { 142 | javaMailSender.send(simpleMailMessage); 143 | } catch (Exception exception) { 144 | exception.printStackTrace(); 145 | throw new MessagingException(String.format(FORGOT_PASSWORD_ERROR_MESSAGE)); 146 | } 147 | } 148 | 149 | @Override 150 | public void sendAccountCreationSuccessfulEmail(UserAccount userAccount) throws MessagingException { 151 | simpleMailMessage.setTo(userAccount.getUserEntity().getEmail()); 152 | simpleMailMessage.setSubject("Account Creation Successful"); 153 | simpleMailMessage.setFrom("salamikehinde345@gmail.com"); 154 | String template = "Dear [[name]],\n" 155 | + "Thanks for registering on people bank.\n" 156 | + "Congratulations! Your account has successfully being created\n" 157 | + "Thank you.\n" 158 | + "Bank team"; 159 | template = template.replace("[[name]]", userAccount.getUserEntity().getFirstname()); 160 | // template = template.replace("[[code]]", token); 161 | simpleMailMessage.setText(template); 162 | 163 | try { 164 | javaMailSender.send(simpleMailMessage); 165 | } catch (Exception exception) { 166 | exception.printStackTrace(); 167 | throw new MessagingException(String.format(ACCOUNT_CREATION_ERROR)); 168 | } 169 | } 170 | 171 | @Override 172 | public void sendTransactionSuccessfulMessage(Transaction transaction, UserEntity userEntity) throws MessagingException { 173 | 174 | simpleMailMessage.setTo(userEntity.getEmail()); 175 | simpleMailMessage.setSubject("Transaction Successful"); 176 | simpleMailMessage.setFrom("salamikehinde345@gmail.com"); 177 | String template = "Dear [[name]],\n" 178 | + "Transaction Successful!\n" 179 | + "You have successfully transfer " +transaction.getAmount() + " to " +transaction.getTargetOwnerName() 180 | + " owner of the ID " + transaction.getTargetAccountId() 181 | + "Thank you for using People's Bank.\n" 182 | + "Bank team"; 183 | template = template.replace("[[name]]", transaction.getUserEntity().getFirstname()); 184 | // template = template.replace("[[code]]", token); 185 | simpleMailMessage.setText(template); 186 | 187 | try { 188 | javaMailSender.send(simpleMailMessage); 189 | } catch (Exception exception) { 190 | exception.printStackTrace(); 191 | throw new MessagingException(String.format(TRANSACTION_FAILURE)); 192 | } 193 | } 194 | 195 | @Override 196 | public void sendAlertReceivedMessage(Transaction transaction) throws MessagingException { 197 | 198 | simpleMailMessage.setTo(transaction.getTargetEmail()); 199 | simpleMailMessage.setSubject("Alert Mail"); 200 | simpleMailMessage.setFrom("salamikehinde345@gmail.com"); 201 | String template = "Dear [[name]],\n" 202 | + "You have successfully received " +transaction.getAmount() + " from \n" 203 | + transaction.getUserEntity().getFirstname() + " the owner of the id " + transaction.getSourceAccountId() 204 | + "Congratulations! Your account has successfully being credited\n" 205 | + "Thank you.\n" 206 | + "Bank team"; 207 | template = template.replace("[[name]]", transaction.getTargetOwnerName()); 208 | // template = template.replace("[[code]]", token); 209 | simpleMailMessage.setText(template); 210 | 211 | try { 212 | javaMailSender.send(simpleMailMessage); 213 | } catch (Exception exception) { 214 | exception.printStackTrace(); 215 | throw new MessagingException(String.format("")); 216 | } 217 | } 218 | 219 | @Override 220 | public void sendDepositSuccessfulMessage(UserEntity userEntity, UserAccount userAccount) throws MessagingException { 221 | 222 | simpleMailMessage.setTo(userEntity.getEmail()); 223 | simpleMailMessage.setSubject("Deposit Successful"); 224 | simpleMailMessage.setFrom("salamikehinde345@gmail.com"); 225 | String template = "Dear [[name]],\n" 226 | + "You have successfully deposit some funds into your account\n" 227 | + "into Your account \n" 228 | + "Balance : " + userAccount.getCurrentBalance() + " \n" 229 | + " Thank you.\n" 230 | + "Bank team"; 231 | template = template.replace("[[name]]", userAccount.getOwnerName()); 232 | simpleMailMessage.setText(template); 233 | try { 234 | javaMailSender.send(simpleMailMessage); 235 | } catch (Exception exception) { 236 | exception.printStackTrace(); 237 | throw new MessagingException(String.format(DEPOSIT_FAILURE)); 238 | } 239 | } 240 | 241 | @Override 242 | public void sendWithdrawSuccessfulMessage(UserEntity userEntity, UserAccount userAccount) throws MessagingException { 243 | 244 | simpleMailMessage.setTo(userEntity.getEmail()); 245 | simpleMailMessage.setSubject("Withdraw Successful"); 246 | simpleMailMessage.setFrom("salamikehinde345@gmail.com"); 247 | String template = "Dear [[name]],\n" 248 | + "You have successfully withdraw some funds into your account\n" 249 | + "into Your account \n" 250 | + "Balance : " + userAccount.getCurrentBalance() + " \n" 251 | + " Thank you.\n" 252 | + "Bank team"; 253 | template = template.replace("[[name]]", userAccount.getOwnerName()); 254 | simpleMailMessage.setText(template); 255 | try { 256 | javaMailSender.send(simpleMailMessage); 257 | } catch (Exception exception) { 258 | exception.printStackTrace(); 259 | throw new MessagingException(String.format(WITHDRAW_FAILURE)); 260 | } 261 | } 262 | 263 | @Override 264 | public void sendCompliantNotification(CustomerCompliantForm customerCompliantForm) throws MessagingException { 265 | 266 | simpleMailMessage.setTo(customerCompliantForm.getUser().getEmail()); 267 | simpleMailMessage.setSubject("Com[liant Request Successful"); 268 | simpleMailMessage.setFrom("salamikehinde345@gmail.com"); 269 | String template = "Dear [[name]],\n" 270 | + "You have successfully book a session with us\n" 271 | + "Kindly show up before and after 30 minutes of the booked time \n" 272 | + "Thank you.\n" 273 | + "Bank team"; 274 | template = template.replace("[[name]]", customerCompliantForm.getUser().getFirstname()); 275 | simpleMailMessage.setText(template); 276 | 277 | try { 278 | javaMailSender.send(simpleMailMessage); 279 | } catch (Exception exception) { 280 | exception.printStackTrace(); 281 | throw new MessagingException(String.format(SCHEDULE_NOT_SENT)); 282 | } 283 | } 284 | 285 | @Override 286 | public void sendAccountSuspendedNotification(UserEntity userEntity) throws MessagingException { 287 | 288 | simpleMailMessage.setTo(userEntity.getEmail()); 289 | simpleMailMessage.setSubject("Account Suspension"); 290 | simpleMailMessage.setFrom("salamikehinde345@gmail.com"); 291 | String template = "Dear [[name]],\n" 292 | + "Your account has been suspended till further notice! " 293 | +"As your recent activities is not inline with our principles \n" 294 | + "Thank you.\n" 295 | + "Bank team"; 296 | template = template.replace("[[name]]", userEntity.getFirstname()); 297 | simpleMailMessage.setText(template); 298 | 299 | try { 300 | javaMailSender.send(simpleMailMessage); 301 | } catch (Exception exception) { 302 | exception.printStackTrace(); 303 | throw new MessagingException(String.format(MESSAGE_NOT_SENT_MESSAGE)); 304 | } 305 | } 306 | 307 | @Override 308 | public void sendAccountSuspendedRevertNotification(UserEntity userEntity) throws MessagingException { 309 | 310 | simpleMailMessage.setTo(userEntity.getEmail()); 311 | simpleMailMessage.setSubject("Suspension Reversion"); 312 | simpleMailMessage.setFrom("salamikehinde345@gmail.com"); 313 | String template = "Dear [[name]],\n" 314 | + "The suspension on your account has been reverted! " 315 | +"Kindly stick to our rules and regulations to avoid such harsh judgement from henceforth\n" 316 | + "Thank you.\n" 317 | + "Bank team"; 318 | template = template.replace("[[name]]", userEntity.getFirstname()); 319 | simpleMailMessage.setText(template); 320 | 321 | try { 322 | javaMailSender.send(simpleMailMessage); 323 | } catch (Exception exception) { 324 | exception.printStackTrace(); 325 | throw new MessagingException(String.format(MESSAGE_NOT_SENT_MESSAGE)); 326 | } 327 | } 328 | } 329 | //{ 330 | // "id": "3ec85cd2-ee67-4d1a-9bd1-08248d7816b9", 331 | // "firstName": "taiwo", 332 | // "lastName": "yemisi", 333 | // "phoneNumber": "07065435621", 334 | // "email": "salamtaye0@gmail.com", 335 | // "roles": "BASE_USER", 336 | // "token": { 337 | // "accessToken": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzYWxhbXRheWUwQGdtYWlsLmNvbSIsInJvbGVzIjoiQkFTRV9VU0VSIiwiaXNzIjoiQVVUT1giLCJpYXQiOjE2NjQ1MjgyMjgsImV4cCI6MTY2NDYxNDYyOH0.ZBPM1J-vPVWTMKBbjvgtAiVDmslbLjrKpFU8Vg5Sx7Fk-_12k5SHsAAo_iWhiMXtO-vm-vQvz9n_zShIRk0-4A", 338 | // "tokenType": "BEARER_TOKEN" 339 | // } 340 | //} -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/ModelMapperConfig.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank; 2 | 3 | import org.modelmapper.ModelMapper; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | public class ModelMapperConfig { 9 | 10 | @Bean 11 | public ModelMapper modelMapper(){ 12 | return new ModelMapper(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/SpringFoxConfig.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.service.ApiInfo; 10 | import springfox.documentation.service.Contact; 11 | import springfox.documentation.spi.DocumentationType; 12 | import springfox.documentation.spring.web.plugins.Docket; 13 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 14 | 15 | import java.util.Collections; 16 | 17 | 18 | @Configuration 19 | @EnableSwagger2 20 | //@Import(SpringDataRestConfiguration.class) 21 | public class SpringFoxConfig extends WebMvcConfigurationSupport { 22 | 23 | @Override 24 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 25 | registry.addResourceHandler("swagger-ui.html") 26 | .addResourceLocations("classpath:/META-INF/resources/"); 27 | registry.addResourceHandler("/webjars/**") 28 | .addResourceLocations("classpath:/META-INF/resources/webjars/"); 29 | } 30 | 31 | 32 | @Bean 33 | public Docket api() { 34 | return new Docket(DocumentationType.SWAGGER_2) 35 | .select() 36 | .paths(PathSelectors.any()) 37 | .apis(RequestHandlerSelectors.basePackage("koredebank.example.bank")) 38 | .build() 39 | .apiInfo(apiDetails()); 40 | } 41 | 42 | private ApiInfo apiDetails(){ 43 | return new ApiInfo( 44 | "PEOPLE BANK API", 45 | "Set of Apis for BANK", 46 | "1.0", 47 | "For BANK only", 48 | new Contact("BANK","BANK","BANK"), 49 | "People's Bank License", 50 | "BANK", 51 | Collections.emptyList() 52 | ); 53 | //link address http://localhost:8080/v2/api-docs 54 | //final link address http://localhost:8080/swagger-ui.html#/ 55 | //http://localhost:8080/api/swagger-ui.html 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/cloudinaryService/CloudStorageService.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.cloudinaryService; 2 | 3 | import org.springframework.web.multipart.MultipartFile; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.util.Map; 8 | 9 | public interface CloudStorageService { 10 | 11 | Map uploadImage(File file, Map imageProperties) throws IOException; 12 | 13 | Map uploadImage(MultipartFile multipartFile, Map imageProperties) throws IOException; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/cloudinaryService/CloudinaryConfig.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.cloudinaryService; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class CloudinaryConfig { 8 | 9 | @Value("${CLOUD_NAME}") 10 | private String cloudName; 11 | @Value("${API_KEY}") 12 | private String apikey; 13 | @Value("${API_SECRET}") 14 | private String secretKey; 15 | 16 | public String getCloudName() { 17 | return cloudName; 18 | } 19 | 20 | public void setCloudName(String cloudName) { 21 | this.cloudName = cloudName; 22 | } 23 | 24 | public String getApikey() { 25 | return apikey; 26 | } 27 | 28 | public void setApikey(String apikey) { 29 | this.apikey = apikey; 30 | } 31 | 32 | public String getSecretKey() { 33 | return secretKey; 34 | } 35 | 36 | public void setSecretKey(String secretKey) { 37 | this.secretKey = secretKey; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/cloudinaryService/CloudinaryStorageServiceImpl.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.cloudinaryService; 2 | 3 | import com.cloudinary.Cloudinary; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import org.springframework.web.multipart.MultipartFile; 7 | 8 | import java.io.File; 9 | import java.io.IOException; 10 | import java.util.Map; 11 | 12 | @Service 13 | public class CloudinaryStorageServiceImpl implements CloudStorageService{ 14 | 15 | @Autowired 16 | Cloudinary cloudinary; 17 | 18 | @Override 19 | public Map uploadImage(File file, Map imageProperties) throws IOException { 20 | return cloudinary.uploader().upload(file,imageProperties); 21 | } 22 | 23 | @Override 24 | public Map uploadImage(MultipartFile multipartFile, Map imageProperties) throws IOException { 25 | return cloudinary.uploader().upload(multipartFile.getBytes(),imageProperties); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/controller/AccountManagerController.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.controller; 2 | 3 | import koredebank.example.bank.dto.*; 4 | import koredebank.example.bank.security.exceptions.AccountCreationException; 5 | import koredebank.example.bank.security.exceptions.AuthorizationException; 6 | import koredebank.example.bank.security.exceptions.GeneralServiceException; 7 | import koredebank.example.bank.service.accountManagerService.AccountManagerServices; 8 | import koredebank.example.bank.util.ApiRoutes; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.http.HttpStatus; 13 | import org.springframework.http.ResponseEntity; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | import javax.mail.MessagingException; 17 | 18 | @RestController 19 | @RequestMapping(ApiRoutes.BANK) 20 | public class AccountManagerController { 21 | private static Logger log = LoggerFactory.getLogger(AccountManagerController.class); 22 | 23 | @Autowired 24 | AccountManagerServices accountManagerServices; 25 | 26 | 27 | @PostMapping(ApiRoutes.ACCOUNTMANAGER +"/register") 28 | public ResponseEntity Registration(@RequestBody AccountManagerSignUpRequestDto accountManagerSignUpRequestDto) throws AccountCreationException { 29 | log.info(accountManagerSignUpRequestDto.toString()); 30 | 31 | return new ResponseEntity<>(accountManagerServices.registerAccountManager(accountManagerSignUpRequestDto), HttpStatus.OK); 32 | 33 | } 34 | 35 | 36 | @PutMapping(ApiRoutes.ACCOUNTMANAGER+"/change-password") 37 | public ResponseEntity ChangePassword(@RequestParam(name = "id") String id, @RequestBody AccountManagerChangePassword accountManagerChangePassword) throws AuthorizationException, GeneralServiceException { 38 | 39 | return new ResponseEntity<>(accountManagerServices.changeAccountManagerPassword(accountManagerChangePassword,id), HttpStatus.OK); 40 | 41 | } 42 | 43 | @PutMapping(ApiRoutes.ACCOUNTMANAGER+ "/forgot-password") 44 | public ResponseEntity ForgotPassword(@RequestBody AccountManagerForgotPassword accountManagerForgotPassword) throws GeneralServiceException { 45 | 46 | return new ResponseEntity<>(accountManagerServices.forgotAccountManagerPassword(accountManagerForgotPassword), HttpStatus.OK); 47 | 48 | } 49 | 50 | @PostMapping(ApiRoutes.ACCOUNTMANAGER+ "/block-user") 51 | public ResponseEntity BlockUser(@RequestBody AccountManagerBlockUserRequestDto accountManagerBlockUserRequestDto) throws MessagingException, GeneralServiceException { 52 | 53 | return new ResponseEntity<>(accountManagerServices.blockAccountUser(accountManagerBlockUserRequestDto), HttpStatus.OK); 54 | } 55 | 56 | @PostMapping(ApiRoutes.ACCOUNTMANAGER+ "/unblock-user") 57 | public ResponseEntity UnBlockUser(@RequestBody AccountManagerUnblockUserRequestDto accountManagerUnblockUserRequestDto) throws MessagingException, GeneralServiceException { 58 | 59 | return new ResponseEntity<>(accountManagerServices.unblockAccountUser(accountManagerUnblockUserRequestDto), HttpStatus.OK); 60 | 61 | } 62 | 63 | 64 | @GetMapping(ApiRoutes.ACCOUNTMANAGER+"/list-all-transactions") 65 | public ResponseEntity listAllTransactions(@RequestParam(value = "page",defaultValue = "1") int page, 66 | @RequestParam(value = "size",defaultValue = "3") int size) throws AuthorizationException { 67 | 68 | return new ResponseEntity<>(accountManagerServices.listTransactions(page,size), HttpStatus.OK); 69 | 70 | } 71 | 72 | @GetMapping(ApiRoutes.ACCOUNTMANAGER+"/list-all-userAccounts-History") 73 | public ResponseEntity listAllUserAccountsHistory(@RequestParam(value = "page",defaultValue = "1") int page, @RequestParam(value = "size",defaultValue = "3") int size) throws AuthorizationException { 74 | 75 | return new ResponseEntity<>(accountManagerServices.listUsersAccounts(page,size), HttpStatus.OK); 76 | 77 | } 78 | 79 | @GetMapping(ApiRoutes.ACCOUNTMANAGER+"/list-all-usersComplain-Form") 80 | public ResponseEntity listAllUsersComplainForm(@RequestParam(value = "page",defaultValue = "1") int page, @RequestParam(value = "size",defaultValue = "3") int size) throws AuthorizationException { 81 | 82 | return new ResponseEntity<>(accountManagerServices.listUserCompliantAndSchedules(page,size), HttpStatus.OK); 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/controller/TransactionController.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.controller; 2 | 3 | import koredebank.example.bank.dto.*; 4 | import koredebank.example.bank.security.exceptions.AccountCreationException; 5 | import koredebank.example.bank.security.exceptions.AuthorizationException; 6 | import koredebank.example.bank.security.exceptions.GeneralServiceException; 7 | import koredebank.example.bank.security.exceptions.ImageUploadException; 8 | import koredebank.example.bank.service.transactionService.TransactionServices; 9 | import koredebank.example.bank.service.userService.UserServices; 10 | import koredebank.example.bank.util.ApiRoutes; 11 | import lombok.extern.slf4j.Slf4j; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.web.bind.annotation.*; 16 | 17 | import javax.mail.MessagingException; 18 | 19 | @Slf4j 20 | @RestController 21 | @RequestMapping(ApiRoutes.BANK) 22 | public class TransactionController { 23 | 24 | @Autowired 25 | TransactionServices transacts; 26 | 27 | 28 | @GetMapping(ApiRoutes.Transaction+"/check-accBal") 29 | public ResponseEntity checkAccBalance(@RequestHeader("Authorization")String authentication, @RequestBody UserCheckAccountBalanceRequestDto userCheckAccountBalanceRequestDto) throws AuthorizationException, MessagingException, GeneralServiceException, AccountCreationException { 30 | 31 | return new ResponseEntity<>(transacts.checkAccBalance(userCheckAccountBalanceRequestDto,authentication), HttpStatus.OK); 32 | } 33 | 34 | @PostMapping(ApiRoutes.Transaction+"/transfer-funds") 35 | public ResponseEntity transferFunds( @RequestHeader("Authorization")String authentication, @RequestBody UserTransferFundsRequestDto userTransferFundsRequestDto) throws AuthorizationException, MessagingException, GeneralServiceException { 36 | 37 | return new ResponseEntity<>(transacts.transferFunds(userTransferFundsRequestDto,authentication),HttpStatus.OK); 38 | 39 | } 40 | 41 | @PostMapping(ApiRoutes.Transaction+"/deposit-funds") 42 | public ResponseEntity depositFunds( @RequestHeader("Authorization")String authentication, @RequestBody UserDepositsFundsRequestDto userDepositsFundsRequestDto) throws AuthorizationException, MessagingException, GeneralServiceException { 43 | 44 | return new ResponseEntity<>(transacts.depositFunds(userDepositsFundsRequestDto,authentication),HttpStatus.OK); 45 | 46 | } 47 | 48 | @GetMapping(ApiRoutes.Transaction+"/withdraw-funds") 49 | public ResponseEntity withdrawFunds( @RequestHeader("Authorization")String authentication, @RequestBody UserWithdrawFundsRequestDto userWithdrawFundsRequestDto) throws AuthorizationException, MessagingException, GeneralServiceException { 50 | 51 | return new ResponseEntity<>(transacts.withdrawFunds(userWithdrawFundsRequestDto,authentication),HttpStatus.OK); 52 | } 53 | 54 | @PostMapping(ApiRoutes.Transaction+"/user-complaint") 55 | public ResponseEntity userComplain( @RequestHeader("Authorization")String authentication, @ModelAttribute UserCompliantFormRequestDto userCompliantFormRequestDto) throws ImageUploadException, AuthorizationException, MessagingException, GeneralServiceException { 56 | 57 | return new ResponseEntity<>(transacts.usersCompliant(authentication,userCompliantFormRequestDto),HttpStatus.OK); 58 | } 59 | 60 | @GetMapping(ApiRoutes.Transaction+"/get-account") 61 | public ResponseEntity userComplain( String accountNumber) { 62 | 63 | return new ResponseEntity<>(transacts.getAccount(accountNumber),HttpStatus.OK); 64 | } 65 | 66 | @GetMapping(ApiRoutes.Transaction+"/list-all-transactions") 67 | public ResponseEntity listAllTransactions(@RequestHeader("Authorization")String authentication,@RequestParam(value = "page",defaultValue = "1") int page, 68 | @RequestParam(value = "size",defaultValue = "3") int size) throws AuthorizationException { 69 | 70 | 71 | return new ResponseEntity<>(transacts.listTransactions(authentication,page,size), HttpStatus.OK); 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.controller; 2 | 3 | import koredebank.example.bank.dto.*; 4 | import koredebank.example.bank.security.exceptions.*; 5 | import koredebank.example.bank.service.userService.UserServices; 6 | import koredebank.example.bank.util.ApiRoutes; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.http.HttpStatus; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import javax.mail.MessagingException; 14 | 15 | @Slf4j 16 | @RestController 17 | @RequestMapping(ApiRoutes.BANK) 18 | public class UserController { 19 | 20 | @Autowired 21 | UserServices userServices; 22 | 23 | @PostMapping(ApiRoutes.User+"/validate") 24 | public ResponseEntity Registration(@RequestBody UserLoginValidationRequestDto userLoginValidationRequestDto) throws MessagingException, GeneralServiceException, AccountCreationException { 25 | 26 | return new ResponseEntity<>(userServices.validateUserAccount(userLoginValidationRequestDto), HttpStatus.OK); 27 | 28 | } 29 | 30 | @PostMapping(ApiRoutes.User+"/signUp") 31 | public ResponseEntity Registration(@RequestBody UserSignUpRequestDto userSignUpRequestDto) throws MessagingException, GeneralServiceException, AccountCreationException { 32 | log.info(userSignUpRequestDto.toString()); 33 | 34 | return new ResponseEntity<>(userServices.signUp(userSignUpRequestDto),HttpStatus.OK); 35 | } 36 | 37 | @PostMapping(ApiRoutes.User+"/login") 38 | public ResponseEntity SignIn(@RequestBody UserLoginDto userLoginDto) throws IncorrectPasswordException, GeneralServiceException { 39 | 40 | return new ResponseEntity<>(userServices.login(userLoginDto),HttpStatus.OK); 41 | 42 | } 43 | 44 | @PostMapping(ApiRoutes.User+"/validateTokenAndPassword") 45 | public ResponseEntity RetrievePassword(@RequestBody UserRetrieveForgotPasswordRequestDto userRetrieveForgotPasswordRequestDto) throws MessagingException, AuthorizationException, GeneralServiceException { 46 | 47 | return new ResponseEntity<>(userServices.validateForgotTokenAndNewForgotPassword(userRetrieveForgotPasswordRequestDto),HttpStatus.OK); 48 | } 49 | 50 | @PutMapping(ApiRoutes.User+"/change-password") 51 | public ResponseEntity ChangePassword(@RequestHeader("Authorization")String authentication, @RequestBody UserChangePasswordRequestDto userChangePasswordRequestDto) throws AuthorizationException, MessagingException, GeneralServiceException { 52 | 53 | return new ResponseEntity<>(userServices.userChangePassword(userChangePasswordRequestDto ,authentication),HttpStatus.OK); 54 | 55 | } 56 | 57 | @PostMapping(ApiRoutes.User+"/forgot-password") 58 | public ResponseEntity forgotPassword(UserForgotPasswordRequestDto forgotPasswordRequestDto) throws MessagingException, AuthorizationException, GeneralServiceException { 59 | 60 | return new ResponseEntity<>(userServices.userForgotPassword(forgotPasswordRequestDto),HttpStatus.OK); 61 | 62 | } 63 | 64 | } 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/AccountListResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class AccountListResponseDto { 7 | 8 | private int sizeOfList; 9 | 10 | private List accountResponseDtoList= new ArrayList<>(); 11 | 12 | public int getSizeOfList() { 13 | return sizeOfList; 14 | } 15 | 16 | public void setSizeOfList(int sizeOfList) { 17 | this.sizeOfList = sizeOfList; 18 | } 19 | 20 | public List getAccountResponseDtoList() { 21 | return accountResponseDtoList; 22 | } 23 | 24 | public void setAccountResponseDtoList(List accountResponseDtoList) { 25 | this.accountResponseDtoList = accountResponseDtoList; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/AccountManagerBlockUserRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | public class AccountManagerBlockUserRequestDto { 4 | 5 | private String accountNumber; 6 | 7 | public String getAccountNumber() { 8 | return accountNumber; 9 | } 10 | 11 | public void setAccountNumber(String accountNumber) { 12 | this.accountNumber = accountNumber; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/AccountManagerChangePassword.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | public class AccountManagerChangePassword { 4 | 5 | private String oldPassword; 6 | private String newPassword; 7 | private String confirmPassword; 8 | 9 | public String getOldPassword() { 10 | return oldPassword; 11 | } 12 | 13 | public void setOldPassword(String oldPassword) { 14 | this.oldPassword = oldPassword; 15 | } 16 | 17 | public String getNewPassword() { 18 | return newPassword; 19 | } 20 | 21 | public void setNewPassword(String newPassword) { 22 | this.newPassword = newPassword; 23 | } 24 | 25 | public String getConfirmPassword() { 26 | return confirmPassword; 27 | } 28 | 29 | public void setConfirmPassword(String confirmPassword) { 30 | this.confirmPassword = confirmPassword; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/AccountManagerForgotPassword.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | public class AccountManagerForgotPassword { 4 | 5 | private String email; 6 | 7 | private String newPassword; 8 | 9 | 10 | public String getEmail() { 11 | return email; 12 | } 13 | 14 | public void setEmail(String email) { 15 | this.email = email; 16 | } 17 | 18 | public String getNewPassword() { 19 | return newPassword; 20 | } 21 | 22 | public void setNewPassword(String newPassword) { 23 | this.newPassword = newPassword; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/AccountManagerSignUpRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import javax.validation.constraints.Email; 4 | 5 | public class AccountManagerSignUpRequestDto { 6 | 7 | @Email 8 | private String email; 9 | 10 | private String password; 11 | 12 | private String confirmPassword; 13 | 14 | public String getEmail() { 15 | return email; 16 | } 17 | 18 | public void setEmail(String email) { 19 | this.email = email; 20 | } 21 | 22 | public String getPassword() { 23 | return password; 24 | } 25 | 26 | public void setPassword(String password) { 27 | this.password = password; 28 | } 29 | 30 | public String getConfirmPassword() { 31 | return confirmPassword; 32 | } 33 | 34 | public void setConfirmPassword(String confirmPassword) { 35 | this.confirmPassword = confirmPassword; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/AccountManagerSignUpResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import koredebank.example.bank.model.Roles; 4 | 5 | import javax.validation.constraints.Email; 6 | 7 | public class AccountManagerSignUpResponseDto { 8 | 9 | private String id; 10 | 11 | private String email; 12 | 13 | 14 | private Roles role; 15 | 16 | public String getId() { 17 | return id; 18 | } 19 | 20 | public void setId(String id) { 21 | this.id = id; 22 | } 23 | 24 | public String getEmail() { 25 | return email; 26 | } 27 | 28 | public void setEmail(String email) { 29 | this.email = email; 30 | } 31 | 32 | public Roles getRole() { 33 | return role; 34 | } 35 | 36 | public void setRole(Roles role) { 37 | this.role = role; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/AccountManagerUnblockUserRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | public class AccountManagerUnblockUserRequestDto { 4 | 5 | private String accountNumber; 6 | 7 | public String getAccountNumber() { 8 | return accountNumber; 9 | } 10 | 11 | public void setAccountNumber(String accountNumber) { 12 | this.accountNumber = accountNumber; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/AccountResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import javax.validation.constraints.Email; 4 | 5 | public class AccountResponseDto { 6 | 7 | private long id; 8 | 9 | private String sortCode; 10 | 11 | private String accountNumber; 12 | 13 | private double currentBalance; 14 | 15 | private String accountEmail; 16 | 17 | private String bankName; 18 | 19 | private String ownerName; 20 | 21 | public long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(long id) { 26 | this.id = id; 27 | } 28 | 29 | public String getSortCode() { 30 | return sortCode; 31 | } 32 | 33 | public void setSortCode(String sortCode) { 34 | this.sortCode = sortCode; 35 | } 36 | 37 | public String getAccountNumber() { 38 | return accountNumber; 39 | } 40 | 41 | public void setAccountNumber(String accountNumber) { 42 | this.accountNumber = accountNumber; 43 | } 44 | 45 | public double getCurrentBalance() { 46 | return currentBalance; 47 | } 48 | 49 | public void setCurrentBalance(double currentBalance) { 50 | this.currentBalance = currentBalance; 51 | } 52 | 53 | public String getAccountEmail() { 54 | return accountEmail; 55 | } 56 | 57 | public void setAccountEmail(String accountEmail) { 58 | this.accountEmail = accountEmail; 59 | } 60 | 61 | public String getBankName() { 62 | return bankName; 63 | } 64 | 65 | public void setBankName(String bankName) { 66 | this.bankName = bankName; 67 | } 68 | 69 | public String getOwnerName() { 70 | return ownerName; 71 | } 72 | 73 | public void setOwnerName(String ownerName) { 74 | this.ownerName = ownerName; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/CustomerCompliantDaysLength.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import javax.validation.constraints.Max; 4 | import javax.validation.constraints.NotNull; 5 | 6 | public class CustomerCompliantDaysLength { 7 | 8 | @NotNull 9 | @Max(7) 10 | private Integer days; 11 | 12 | @NotNull 13 | @Max(23) 14 | private Integer hours; 15 | 16 | public Integer getDays() { 17 | return days; 18 | } 19 | 20 | public void setDays(Integer days) { 21 | this.days = days; 22 | } 23 | 24 | public Integer getHours() { 25 | return hours; 26 | } 27 | 28 | public void setHours(Integer hours) { 29 | this.hours = hours; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/TransactionListResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class TransactionListResponseDto { 7 | 8 | private int sizeOfList; 9 | private List transactionResponseDtoList= new ArrayList<>(); 10 | 11 | 12 | public int getSizeOfList() { 13 | return sizeOfList; 14 | } 15 | 16 | public void setSizeOfList(int sizeOfList) { 17 | this.sizeOfList = sizeOfList; 18 | } 19 | 20 | public List getTransactionResponseDtoList() { 21 | return transactionResponseDtoList; 22 | } 23 | 24 | public void setTransactionResponseDtoList(List transactionResponseDtoList) { 25 | this.transactionResponseDtoList = transactionResponseDtoList; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/TransactionResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | public class TransactionResponseDto { 6 | 7 | private long id; 8 | 9 | private long sourceAccountId; 10 | 11 | private long targetAccountId; 12 | 13 | private String targetOwnerName; 14 | 15 | private String targetEmail; 16 | 17 | private double amount; 18 | 19 | private LocalDateTime initiationDate; 20 | 21 | private LocalDateTime completionDate; 22 | 23 | private String reference; 24 | 25 | public long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(long id) { 30 | this.id = id; 31 | } 32 | 33 | public long getSourceAccountId() { 34 | return sourceAccountId; 35 | } 36 | 37 | public void setSourceAccountId(long sourceAccountId) { 38 | this.sourceAccountId = sourceAccountId; 39 | } 40 | 41 | public long getTargetAccountId() { 42 | return targetAccountId; 43 | } 44 | 45 | public void setTargetAccountId(long targetAccountId) { 46 | this.targetAccountId = targetAccountId; 47 | } 48 | 49 | public String getTargetOwnerName() { 50 | return targetOwnerName; 51 | } 52 | 53 | public void setTargetOwnerName(String targetOwnerName) { 54 | this.targetOwnerName = targetOwnerName; 55 | } 56 | 57 | public String getTargetEmail() { 58 | return targetEmail; 59 | } 60 | 61 | public void setTargetEmail(String targetEmail) { 62 | this.targetEmail = targetEmail; 63 | } 64 | 65 | public double getAmount() { 66 | return amount; 67 | } 68 | 69 | public void setAmount(double amount) { 70 | this.amount = amount; 71 | } 72 | 73 | public LocalDateTime getInitiationDate() { 74 | return initiationDate; 75 | } 76 | 77 | public void setInitiationDate(LocalDateTime initiationDate) { 78 | this.initiationDate = initiationDate; 79 | } 80 | 81 | public LocalDateTime getCompletionDate() { 82 | return completionDate; 83 | } 84 | 85 | public void setCompletionDate(LocalDateTime completionDate) { 86 | this.completionDate = completionDate; 87 | } 88 | 89 | public String getReference() { 90 | return reference; 91 | } 92 | 93 | public void setReference(String reference) { 94 | this.reference = reference; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserChangePasswordRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | public class UserChangePasswordRequestDto { 3 | private String oldPassword; 4 | private String newPassword; 5 | private String confirmPassword; 6 | 7 | public String getOldPassword() { 8 | return oldPassword; 9 | } 10 | 11 | public void setOldPassword(String oldPassword) { 12 | this.oldPassword = oldPassword; 13 | } 14 | 15 | public String getNewPassword() { 16 | return newPassword; 17 | } 18 | 19 | public void setNewPassword(String newPassword) { 20 | this.newPassword = newPassword; 21 | } 22 | 23 | public String getConfirmPassword() { 24 | return confirmPassword; 25 | } 26 | 27 | public void setConfirmPassword(String confirmPassword) { 28 | this.confirmPassword = confirmPassword; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserCheckAccountBalanceRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | public class UserCheckAccountBalanceRequestDto { 4 | 5 | private String accountNumber; 6 | 7 | private String sortCode; 8 | 9 | public String getAccountNumber() { 10 | return accountNumber; 11 | } 12 | 13 | public void setAccountNumber(String accountNumber) { 14 | this.accountNumber = accountNumber; 15 | } 16 | 17 | public String getSortCode() { 18 | return sortCode; 19 | } 20 | 21 | public void setSortCode(String sortCode) { 22 | this.sortCode = sortCode; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserCheckAccountBalanceResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | public class UserCheckAccountBalanceResponseDto { 4 | 5 | private String accountNumber; 6 | 7 | private String sortCode; 8 | 9 | public String getAccountNumber() { 10 | return accountNumber; 11 | } 12 | 13 | public void setAccountNumber(String accountNumber) { 14 | this.accountNumber = accountNumber; 15 | } 16 | 17 | public String getSortCode() { 18 | return sortCode; 19 | } 20 | 21 | public void setSortCode(String sortCode) { 22 | this.sortCode = sortCode; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserCompliantFormRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import com.sun.istack.NotNull; 4 | import org.springframework.web.multipart.MultipartFile; 5 | 6 | import javax.persistence.Column; 7 | 8 | public class UserCompliantFormRequestDto { 9 | 10 | private String title; 11 | 12 | private String description; 13 | 14 | private String modeOfMeeting; 15 | 16 | private MultipartFile image1; 17 | 18 | 19 | private MultipartFile image2; 20 | 21 | 22 | private MultipartFile image3; 23 | 24 | 25 | private CustomerCompliantDaysLength customerCompliantDaysLength; 26 | 27 | public String getTitle() { 28 | return title; 29 | } 30 | 31 | public void setTitle(String title) { 32 | this.title = title; 33 | } 34 | 35 | public String getDescription() { 36 | return description; 37 | } 38 | 39 | public void setDescription(String description) { 40 | this.description = description; 41 | } 42 | 43 | public String getModeOfMeeting() { 44 | return modeOfMeeting; 45 | } 46 | 47 | public void setModeOfMeeting(String modeOfMeeting) { 48 | this.modeOfMeeting = modeOfMeeting; 49 | } 50 | 51 | public CustomerCompliantDaysLength getCustomerCompliantDaysLength() { 52 | return customerCompliantDaysLength; 53 | } 54 | 55 | public void setCustomerCompliantDaysLength(CustomerCompliantDaysLength customerCompliantDaysLength) { 56 | this.customerCompliantDaysLength = customerCompliantDaysLength; 57 | } 58 | 59 | 60 | public MultipartFile getImage1() { 61 | return image1; 62 | } 63 | 64 | public void setImage1(MultipartFile image1) { 65 | this.image1 = image1; 66 | } 67 | 68 | public MultipartFile getImage2() { 69 | return image2; 70 | } 71 | 72 | public void setImage2(MultipartFile image2) { 73 | this.image2 = image2; 74 | } 75 | 76 | public MultipartFile getImage3() { 77 | return image3; 78 | } 79 | 80 | public void setImage3(MultipartFile image3) { 81 | this.image3 = image3; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserCompliantFormResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import org.springframework.web.multipart.MultipartFile; 4 | 5 | public class UserCompliantFormResponseDto { 6 | 7 | private String title; 8 | 9 | private String description; 10 | 11 | private String modeOfMeeting; 12 | 13 | 14 | private String image1; 15 | 16 | 17 | private String image2; 18 | 19 | 20 | private String image3; 21 | private CustomerCompliantDaysLength customerCompliantDaysLength; 22 | 23 | 24 | public String getTitle() { 25 | return title; 26 | } 27 | 28 | public void setTitle(String title) { 29 | this.title = title; 30 | } 31 | 32 | public String getDescription() { 33 | return description; 34 | } 35 | 36 | public void setDescription(String description) { 37 | this.description = description; 38 | } 39 | 40 | public String getModeOfMeeting() { 41 | return modeOfMeeting; 42 | } 43 | 44 | public void setModeOfMeeting(String modeOfMeeting) { 45 | this.modeOfMeeting = modeOfMeeting; 46 | } 47 | 48 | public CustomerCompliantDaysLength getCustomerCompliantDaysLength() { 49 | return customerCompliantDaysLength; 50 | } 51 | 52 | public void setCustomerCompliantDaysLength(CustomerCompliantDaysLength customerCompliantDaysLength) { 53 | this.customerCompliantDaysLength = customerCompliantDaysLength; 54 | } 55 | 56 | 57 | public String getImage1() { 58 | return image1; 59 | } 60 | 61 | public void setImage1(String image1) { 62 | this.image1 = image1; 63 | } 64 | 65 | public String getImage2() { 66 | return image2; 67 | } 68 | 69 | public void setImage2(String image2) { 70 | this.image2 = image2; 71 | } 72 | 73 | public String getImage3() { 74 | return image3; 75 | } 76 | 77 | public void setImage3(String image3) { 78 | this.image3 = image3; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserCompliantListResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class UserCompliantListResponseDto { 7 | 8 | private int sizeOfList; 9 | 10 | private List userCompliantFormResponseDtoList= new ArrayList<>(); 11 | 12 | 13 | public int getSizeOfList() { 14 | return sizeOfList; 15 | } 16 | 17 | public void setSizeOfList(int sizeOfList) { 18 | this.sizeOfList = sizeOfList; 19 | } 20 | 21 | public List getUserCompliantFormResponseDtoList() { 22 | return userCompliantFormResponseDtoList; 23 | } 24 | 25 | public void setUserCompliantFormResponseDtoList(List userCompliantFormResponseDtoList) { 26 | this.userCompliantFormResponseDtoList = userCompliantFormResponseDtoList; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserCreateAccountRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | 4 | import javax.validation.constraints.NotBlank; 5 | 6 | public class UserCreateAccountRequestDto { 7 | 8 | @NotBlank(message = "Bank name is mandatory") 9 | private String bankName; 10 | 11 | @NotBlank(message = "Owner name is mandatory") 12 | private String ownerName; 13 | 14 | 15 | public String getBankName() { 16 | return bankName; 17 | } 18 | 19 | public void setBankName(String bankName) { 20 | this.bankName = bankName; 21 | } 22 | 23 | public String getOwnerName() { 24 | return ownerName; 25 | } 26 | 27 | public void setOwnerName(String ownerName) { 28 | this.ownerName = ownerName; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserCreateAccountResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import javax.validation.constraints.NotBlank; 4 | 5 | public class UserCreateAccountResponseDto { 6 | 7 | @NotBlank(message = "Bank name is mandatory") 8 | private String bankName; 9 | 10 | 11 | @NotBlank(message = "Owner name is mandatory") 12 | private String ownerName; 13 | 14 | public String getBankName() { 15 | return bankName; 16 | } 17 | 18 | public void setBankName(String bankName) { 19 | this.bankName = bankName; 20 | } 21 | 22 | public String getOwnerName() { 23 | return ownerName; 24 | } 25 | 26 | public void setOwnerName(String ownerName) { 27 | this.ownerName = ownerName; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserDepositsFundsRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import javax.validation.constraints.NotBlank; 4 | import javax.validation.constraints.Positive; 5 | 6 | public class UserDepositsFundsRequestDto { 7 | 8 | 9 | @NotBlank(message = "Target account no is mandatory") 10 | private String targetAccountNo; 11 | 12 | private String nameOfDepositor; 13 | 14 | // Prevent fraudulent transfers attempting to abuse currency conversion errors 15 | @Positive(message = "Transfer amount must be positive") 16 | private double amount; 17 | 18 | 19 | public String getNameOfDepositor() { 20 | return nameOfDepositor; 21 | } 22 | 23 | public void setNameOfDepositor(String nameOfDepositor) { 24 | this.nameOfDepositor = nameOfDepositor; 25 | } 26 | 27 | public String getTargetAccountNo() { 28 | return targetAccountNo; 29 | } 30 | 31 | public void setTargetAccountNo(String targetAccountNo) { 32 | this.targetAccountNo = targetAccountNo; 33 | } 34 | 35 | public double getAmount() { 36 | return amount; 37 | } 38 | 39 | public void setAmount(double amount) { 40 | this.amount = amount; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserDepositsFundsResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import javax.validation.constraints.*; 4 | 5 | public class UserDepositsFundsResponseDto { 6 | 7 | @NotBlank(message = "Target account no is mandatory") 8 | private String targetAccountNo; 9 | 10 | private String nameOfDepositor; 11 | 12 | // Prevent fraudulent transfers attempting to abuse currency conversion errors 13 | @Positive(message = "Transfer amount must be positive") 14 | private double amount; 15 | 16 | public String getNameOfDepositor() { 17 | return nameOfDepositor; 18 | } 19 | 20 | public void setNameOfDepositor(String nameOfDepositor) { 21 | this.nameOfDepositor = nameOfDepositor; 22 | } 23 | 24 | public String getTargetAccountNo() { 25 | return targetAccountNo; 26 | } 27 | 28 | public void setTargetAccountNo(String targetAccountNo) { 29 | this.targetAccountNo = targetAccountNo; 30 | } 31 | 32 | public double getAmount() { 33 | return amount; 34 | } 35 | 36 | public void setAmount(double amount) { 37 | this.amount = amount; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserForgotPasswordRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | public class UserForgotPasswordRequestDto { 4 | 5 | private String email; 6 | 7 | public void setEmail(String email){ 8 | this.email = email; 9 | } 10 | 11 | public String getEmail(){ 12 | return email; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserLoginDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | 4 | public class UserLoginDto { 5 | 6 | private String email; 7 | 8 | private String password; 9 | 10 | 11 | public String getEmail() { 12 | return email; 13 | } 14 | 15 | public void setEmail(String email) { 16 | this.email = email; 17 | } 18 | 19 | public String getPassword() { 20 | return password; 21 | } 22 | 23 | public void setPassword(String password) { 24 | this.password = password; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserLoginResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | 4 | import koredebank.example.bank.model.Roles; 5 | import koredebank.example.bank.security.securityUtils.JWTToken; 6 | 7 | public class UserLoginResponseDto { 8 | 9 | private String id; 10 | private String firstName; 11 | private String lastName; 12 | private String phoneNumber; 13 | private String email; 14 | private Roles roles; 15 | private JWTToken token; 16 | 17 | public String getId() { 18 | return id; 19 | } 20 | 21 | public void setId(String id) { 22 | this.id = id; 23 | } 24 | 25 | public String getFirstName() { 26 | return firstName; 27 | } 28 | 29 | public void setFirstName(String firstName) { 30 | this.firstName = firstName; 31 | } 32 | 33 | public String getLastName() { 34 | return lastName; 35 | } 36 | 37 | public void setLastName(String lastName) { 38 | this.lastName = lastName; 39 | } 40 | 41 | public String getPhoneNumber() { 42 | return phoneNumber; 43 | } 44 | 45 | public void setPhoneNumber(String phoneNumber) { 46 | this.phoneNumber = phoneNumber; 47 | } 48 | 49 | public String getEmail() { 50 | return email; 51 | } 52 | 53 | public void setEmail(String email) { 54 | this.email = email; 55 | } 56 | 57 | public Roles getRoles() { 58 | return roles; 59 | } 60 | 61 | public void setRoles(Roles roles) { 62 | this.roles = roles; 63 | } 64 | 65 | public JWTToken getToken() { 66 | return token; 67 | } 68 | 69 | public void setToken(JWTToken token) { 70 | this.token = token; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserLoginValidationRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | public class UserLoginValidationRequestDto { 4 | 5 | private String email; 6 | private String token; 7 | 8 | public String getEmail() { 9 | return email; 10 | } 11 | 12 | public void setEmail(String email) { 13 | this.email = email; 14 | } 15 | 16 | public String getToken() { 17 | return token; 18 | } 19 | 20 | public void setToken(String token) { 21 | this.token = token; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserRetrieveForgotPasswordRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | public class UserRetrieveForgotPasswordRequestDto { 4 | 5 | private String token; 6 | 7 | private String email; 8 | private String newPassword; 9 | private String confirmPassword; 10 | 11 | public String getEmail() { 12 | return email; 13 | } 14 | 15 | public void setEmail(String email) { 16 | this.email = email; 17 | } 18 | 19 | public String getNewPassword() { 20 | return newPassword; 21 | } 22 | 23 | public void setNewPassword(String newPassword) { 24 | this.newPassword = newPassword; 25 | } 26 | 27 | public String getConfirmPassword() { 28 | return confirmPassword; 29 | } 30 | 31 | public void setConfirmPassword(String confirmPassword) { 32 | this.confirmPassword = confirmPassword; 33 | } 34 | 35 | public String getToken() { 36 | return token; 37 | } 38 | 39 | public void setToken(String token) { 40 | this.token = token; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserRetrieveForgotPasswordResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | public class UserRetrieveForgotPasswordResponseDto { 4 | 5 | private String token; 6 | 7 | private String email; 8 | 9 | public String getToken() { 10 | return token; 11 | } 12 | 13 | public void setToken(String token) { 14 | this.token = token; 15 | } 16 | 17 | public String getEmail() { 18 | return email; 19 | } 20 | 21 | public void setEmail(String email) { 22 | this.email = email; 23 | } 24 | 25 | private String newPassword; 26 | private String confirmPassword; 27 | 28 | public String getNewPassword() { 29 | return newPassword; 30 | } 31 | 32 | public void setNewPassword(String newPassword) { 33 | this.newPassword = newPassword; 34 | } 35 | 36 | public String getConfirmPassword() { 37 | return confirmPassword; 38 | } 39 | 40 | public void setConfirmPassword(String confirmPassword) { 41 | this.confirmPassword = confirmPassword; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserSignUpRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import lombok.ToString; 4 | 5 | @ToString 6 | public class UserSignUpRequestDto { 7 | 8 | 9 | private String firstName; 10 | 11 | private String lastName; 12 | 13 | private String phoneNumber; 14 | 15 | private String email; 16 | 17 | private String password; 18 | 19 | private String confirmPassword; 20 | 21 | public String getFirstName() { 22 | return firstName; 23 | } 24 | 25 | public void setFirstName(String firstName) { 26 | this.firstName = firstName; 27 | } 28 | 29 | public String getLastName() { 30 | return lastName; 31 | } 32 | 33 | public void setLastName(String lastName) { 34 | this.lastName = lastName; 35 | } 36 | 37 | public String getPhoneNumber() { 38 | return phoneNumber; 39 | } 40 | 41 | public void setPhoneNumber(String phoneNumber) { 42 | this.phoneNumber = phoneNumber; 43 | } 44 | 45 | public String getEmail(){ 46 | return email; 47 | } 48 | 49 | public void setEmail(String email) { 50 | this.email = email; 51 | } 52 | 53 | public String getPassword() { 54 | return password; 55 | } 56 | 57 | public void setPassword(String password) { 58 | this.password = password; 59 | } 60 | 61 | public String getConfirmPassword() { 62 | return confirmPassword; 63 | } 64 | 65 | public void setConfirmPassword(String confirmPassword) { 66 | this.confirmPassword = confirmPassword; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserSignUpResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | import koredebank.example.bank.model.Roles; 3 | 4 | public class UserSignUpResponseDto { 5 | 6 | private String id; 7 | 8 | private String firstName; 9 | 10 | private String lastName; 11 | 12 | private String phoneNumber; 13 | 14 | private String email; 15 | 16 | private Roles role; 17 | 18 | public String getId() { 19 | return id; 20 | } 21 | 22 | public void setId(String id) { 23 | this.id = id; 24 | } 25 | 26 | public String getFirstName() { 27 | return firstName; 28 | } 29 | 30 | public void setFirstName(String firstName) { 31 | this.firstName = firstName; 32 | } 33 | 34 | public String getLastName() { 35 | return lastName; 36 | } 37 | 38 | public void setLastName(String lastName) { 39 | this.lastName = lastName; 40 | } 41 | 42 | public String getPhoneNumber() { 43 | return phoneNumber; 44 | } 45 | 46 | public void setPhoneNumber(String phoneNumber) { 47 | this.phoneNumber = phoneNumber; 48 | } 49 | 50 | public String getEmail() { 51 | return email; 52 | } 53 | 54 | public void setEmail(String email) { 55 | this.email = email; 56 | } 57 | 58 | public Roles getRole() { 59 | return role; 60 | } 61 | 62 | public void setRole(Roles role) { 63 | this.role = role; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserTransferFundsRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import koredebank.example.bank.payload.UserAccountDto; 4 | 5 | import javax.validation.constraints.Min; 6 | import javax.validation.constraints.Positive; 7 | 8 | public class UserTransferFundsRequestDto { 9 | 10 | private UserAccountDto sourceAccount; 11 | 12 | private UserAccountDto targetAccount; 13 | 14 | @Positive(message = "Transfer amount must be positive") 15 | @Min(value = 1, message = "Amount must be larger than 1") 16 | private double amount; 17 | 18 | private String reference; 19 | 20 | private String targetEmail; 21 | 22 | 23 | public String getTargetEmail() { 24 | return targetEmail; 25 | } 26 | 27 | public void setTargetEmail(String targetEmail) { 28 | this.targetEmail = targetEmail; 29 | } 30 | 31 | public UserAccountDto getSourceAccount() { 32 | return sourceAccount; 33 | } 34 | 35 | public void setSourceAccount(UserAccountDto sourceAccount) { 36 | this.sourceAccount = sourceAccount; 37 | } 38 | 39 | public UserAccountDto getTargetAccount() { 40 | return targetAccount; 41 | } 42 | 43 | public void setTargetAccount(UserAccountDto targetAccount) { 44 | this.targetAccount = targetAccount; 45 | } 46 | 47 | public double getAmount() { 48 | return amount; 49 | } 50 | 51 | public void setAmount(double amount) { 52 | this.amount = amount; 53 | } 54 | 55 | public String getReference() { 56 | return reference; 57 | } 58 | 59 | public void setReference(String reference) { 60 | this.reference = reference; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserTransferFundsResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import koredebank.example.bank.payload.UserAccountDto; 4 | 5 | import javax.validation.constraints.Min; 6 | import javax.validation.constraints.Positive; 7 | 8 | public class UserTransferFundsResponseDto { 9 | 10 | private UserAccountDto sourceAccount; 11 | 12 | private UserAccountDto targetAccount; 13 | 14 | 15 | @Positive(message = "Transfer amount must be positive") 16 | @Min(value = 1, message = "Amount must be larger than 1") 17 | private double amount; 18 | 19 | private String reference; 20 | 21 | private String targetEmail; 22 | 23 | 24 | public String getTargetEmail() { 25 | return targetEmail; 26 | } 27 | 28 | public void setTargetEmail(String targetEmail) { 29 | this.targetEmail = targetEmail; 30 | } 31 | 32 | public UserAccountDto getSourceAccount() { 33 | return sourceAccount; 34 | } 35 | 36 | public void setSourceAccount(UserAccountDto sourceAccount) { 37 | this.sourceAccount = sourceAccount; 38 | } 39 | 40 | public UserAccountDto getTargetAccount() { 41 | return targetAccount; 42 | } 43 | 44 | public void setTargetAccount(UserAccountDto targetAccount) { 45 | this.targetAccount = targetAccount; 46 | } 47 | 48 | public double getAmount() { 49 | return amount; 50 | } 51 | 52 | public void setAmount(double amount) { 53 | this.amount = amount; 54 | } 55 | 56 | public String getReference() { 57 | return reference; 58 | } 59 | 60 | public void setReference(String reference) { 61 | this.reference = reference; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserWithdrawFundsRequestDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import javax.validation.constraints.Positive; 4 | 5 | public class UserWithdrawFundsRequestDto { 6 | 7 | private String accountNumber; 8 | 9 | private String sortCode; 10 | @Positive(message = "Transfer amount must be positive") 11 | private double amount; 12 | 13 | public String getAccountNumber() { 14 | return accountNumber; 15 | } 16 | 17 | public void setAccountNumber(String accountNumber) { 18 | this.accountNumber = accountNumber; 19 | } 20 | 21 | public String getSortCode() { 22 | return sortCode; 23 | } 24 | 25 | public void setSortCode(String sortCode) { 26 | this.sortCode = sortCode; 27 | } 28 | 29 | public double getAmount() { 30 | return amount; 31 | } 32 | 33 | public void setAmount(double amount) { 34 | this.amount = amount; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/dto/UserWithdrawFundsResponseDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.dto; 2 | 3 | import javax.validation.constraints.Positive; 4 | 5 | public class UserWithdrawFundsResponseDto { 6 | 7 | private String accountNumber; 8 | 9 | private String sortCode; 10 | @Positive(message = "Transfer amount must be positive") 11 | private double amount; 12 | 13 | public String getAccountNumber() { 14 | return accountNumber; 15 | } 16 | 17 | public void setAccountNumber(String accountNumber) { 18 | this.accountNumber = accountNumber; 19 | } 20 | 21 | public String getSortCode() { 22 | return sortCode; 23 | } 24 | 25 | public void setSortCode(String sortCode) { 26 | this.sortCode = sortCode; 27 | } 28 | 29 | public double getAmount() { 30 | return amount; 31 | } 32 | 33 | public void setAmount(double amount) { 34 | this.amount = amount; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/model/AccountManager.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.model; 2 | 3 | import javax.persistence.*; 4 | import java.io.Serializable; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | @Entity 9 | public class AccountManager implements Serializable { 10 | @Id 11 | private String id; 12 | @Column 13 | private String email; 14 | @Enumerated 15 | private Roles roles; 16 | @Column 17 | private String password; 18 | 19 | @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY) 20 | @JoinColumn 21 | private List transactionList=new ArrayList<>(); 22 | 23 | @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY) 24 | @JoinColumn 25 | private List userAccountsList=new ArrayList<>(); 26 | 27 | @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY) 28 | @JoinColumn 29 | private List customerCompliantFormList = new ArrayList<>(); 30 | 31 | @ManyToOne 32 | @JoinColumn(name = "users_id") 33 | private UserEntity userEntity; 34 | 35 | @ManyToOne 36 | @JoinColumn(name = "user_account_id") 37 | private UserAccount userAccount; 38 | 39 | public UserAccount getUserAccount() { 40 | return userAccount; 41 | } 42 | 43 | public void setUserAccount(UserAccount userAccount) { 44 | this.userAccount = userAccount; 45 | } 46 | 47 | public UserEntity getUser() { 48 | return userEntity; 49 | } 50 | 51 | public void setUser(UserEntity userEntity) { 52 | this.userEntity = userEntity; 53 | } 54 | 55 | public String getId() { 56 | return id; 57 | } 58 | 59 | public void setId(String id) { 60 | this.id = id; 61 | } 62 | 63 | public String getEmail() { 64 | return email; 65 | } 66 | 67 | public void setEmail(String email) { 68 | this.email = email; 69 | } 70 | 71 | public Roles getRoles() { 72 | return roles; 73 | } 74 | 75 | public void setRoles(Roles roles) { 76 | this.roles = Roles.ACCOUNT_MANAGER; 77 | } 78 | 79 | public String getPassword() { 80 | return password; 81 | } 82 | 83 | public void setPassword(String password) { 84 | this.password = password; 85 | } 86 | 87 | 88 | public List getTransactionList() { 89 | return transactionList; 90 | } 91 | 92 | public void setTransactionList(List transactionList) { 93 | this.transactionList = transactionList; 94 | } 95 | 96 | public List getUserAccountsList() { 97 | return userAccountsList; 98 | } 99 | 100 | public void setUserAccountsList(List userAccountsList) { 101 | this.userAccountsList = userAccountsList; 102 | } 103 | 104 | 105 | public List getCustomerCompliantFormList() { 106 | return customerCompliantFormList; 107 | } 108 | 109 | public void setCustomerCompliantFormList(List customerCompliantFormList) { 110 | this.customerCompliantFormList = customerCompliantFormList; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/model/CustomerCompliantForm.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.model; 2 | 3 | import com.sun.istack.NotNull; 4 | 5 | import javax.persistence.*; 6 | import java.time.Instant; 7 | 8 | @Entity 9 | @Table(name = "compliant_form") 10 | public class CustomerCompliantForm { 11 | 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.SEQUENCE) 14 | private long id; 15 | 16 | @Column 17 | private String title; 18 | 19 | @Column 20 | private String description; 21 | 22 | @Column 23 | private String image1; 24 | 25 | @Column 26 | private String image2; 27 | 28 | @Column 29 | private String image3; 30 | 31 | @NotNull 32 | private Instant expirationDate; 33 | 34 | @Column 35 | private String modeOfMeeting; 36 | 37 | @ManyToOne(fetch = FetchType.LAZY) 38 | @JoinColumn(columnDefinition = "users_compliant_id") 39 | private UserEntity userEntity; 40 | 41 | public long getId() { 42 | return id; 43 | } 44 | 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | public String getTitle() { 50 | return title; 51 | } 52 | 53 | public void setTitle(String title) { 54 | this.title = title; 55 | } 56 | 57 | public String getDescription() { 58 | return description; 59 | } 60 | 61 | public void setDescription(String description) { 62 | this.description = description; 63 | } 64 | 65 | public Instant getExpirationDate() { 66 | return expirationDate; 67 | } 68 | 69 | public void setExpirationDate(Instant expirationDate) { 70 | this.expirationDate = expirationDate; 71 | } 72 | 73 | public String getModeOfMeeting() { 74 | return modeOfMeeting; 75 | } 76 | 77 | public void setModeOfMeeting(String modeOfMeeting) { 78 | this.modeOfMeeting = modeOfMeeting; 79 | } 80 | 81 | public UserEntity getUser() { 82 | return userEntity; 83 | } 84 | 85 | public void setUser(UserEntity userEntity) { 86 | this.userEntity = userEntity; 87 | } 88 | 89 | 90 | public String getImage1() { 91 | return image1; 92 | } 93 | 94 | public void setImage1(String image1) { 95 | this.image1 = image1; 96 | } 97 | 98 | public String getImage2() { 99 | return image2; 100 | } 101 | 102 | public void setImage2(String image2) { 103 | this.image2 = image2; 104 | } 105 | 106 | public String getImage3() { 107 | return image3; 108 | } 109 | 110 | public void setImage3(String image3) { 111 | this.image3 = image3; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/model/Roles.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.model; 2 | 3 | public enum Roles { 4 | BASE_USER,ACCOUNT_MANAGER,HEAD_BRANCH 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/model/Transaction.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.model; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | import lombok.ToString; 6 | 7 | import javax.persistence.*; 8 | import java.time.LocalDateTime; 9 | 10 | 11 | @Entity 12 | @Table(name = "transaction") 13 | @Data 14 | @NoArgsConstructor 15 | @ToString 16 | public class Transaction { 17 | 18 | @Id 19 | @GeneratedValue(strategy = GenerationType.SEQUENCE) 20 | private long id; 21 | 22 | private long sourceAccountId; 23 | 24 | private long targetAccountId; 25 | 26 | private String targetOwnerName; 27 | 28 | private String targetEmail; 29 | 30 | private double amount; 31 | 32 | @ManyToOne(fetch = FetchType.EAGER) 33 | @JoinColumn(name = "users_id") 34 | private UserEntity userEntity; 35 | 36 | private LocalDateTime initiationDate; 37 | 38 | private LocalDateTime completionDate; 39 | 40 | private String reference; 41 | 42 | // Add support for Bank charges, currency conversion, setup repeat payment/ standing order 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/model/Usage.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.model; 2 | 3 | public enum Usage { 4 | TRANSFER,WITHDRAW,DEPOSIT 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/model/UserAccount.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.model; 2 | 3 | import lombok.Data; 4 | import lombok.ToString; 5 | 6 | import javax.persistence.*; 7 | import javax.validation.constraints.Email; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | @Data 12 | @ToString 13 | @Entity 14 | @Table(name = "account") 15 | public class UserAccount { 16 | 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.AUTO) 19 | private long id; 20 | 21 | private String sortCode; 22 | 23 | private String accountNumber; 24 | 25 | private double currentBalance; 26 | 27 | @Email 28 | private String accountEmail; 29 | 30 | private String bankName; 31 | 32 | 33 | private String ownerName; 34 | 35 | @ManyToOne(fetch = FetchType.EAGER) 36 | @JoinColumn(name = "users_id") 37 | private UserEntity userEntity; 38 | 39 | @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER) 40 | @JoinColumn 41 | private ListtransactionList=new ArrayList<>(); //paging or the normal conventional way 42 | 43 | public UserAccount() { 44 | 45 | } 46 | 47 | public UserAccount(String bankName, String ownerName, String generateSortCode, String generateAccountNumber, double currentBalance) { 48 | this.sortCode = generateSortCode; 49 | this.accountNumber = generateAccountNumber; 50 | this.currentBalance = currentBalance; 51 | this.bankName = bankName; 52 | this.ownerName = ownerName; 53 | } 54 | // public UserAccount(long id, String sortCode, String accountNumber, double currentBalance, String bankName, String ownerName,int age) { 55 | // this.id = id; 56 | // this.sortCode = sortCode; 57 | // this.accountNumber = accountNumber; 58 | // this.currentBalance = currentBalance; 59 | // this.bankName = bankName; 60 | // this.ownerName = ownerName; 61 | // } 62 | // 63 | // public UserAccount(long id, String sortCode, String accountNumber, double currentBalance, String bankName, String ownerName,int age) { 64 | // this.id = id; 65 | // this.sortCode = sortCode; 66 | // this.accountNumber = accountNumber; 67 | // this.currentBalance = currentBalance; 68 | // this.bankName = bankName; 69 | // this.ownerName = ownerName; 70 | // } 71 | 72 | 73 | 74 | // later Add support for multiple account types (business, savings, etc.) 75 | // later Add support for foreign currency accounts 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/model/UserEntity.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.model; 2 | 3 | import koredebank.example.bank.model.audit.DateAudit; 4 | import org.springframework.data.annotation.CreatedDate; 5 | import org.springframework.data.annotation.LastModifiedDate; 6 | 7 | import javax.persistence.*; 8 | import javax.validation.constraints.*; 9 | import java.time.Instant; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | @Entity 14 | @Table 15 | public class UserEntity extends DateAudit { 16 | 17 | @Id 18 | private String id; //customise reader plans 19 | 20 | @Column 21 | @NotEmpty(message = "The firstname field cannot be empty") 22 | @Size(min = 3,message = "The firstname field must be greater than 3 characters") 23 | private String firstname; 24 | 25 | @Column 26 | @NotEmpty(message = "The firstname field cannot be empty") 27 | @Size(min = 3,message = "The firstname field must be greater than 3 characters") 28 | private String lastname; 29 | 30 | @Column 31 | private String phoneNumber; 32 | @Column 33 | @Email 34 | @NotEmpty 35 | private String email; 36 | 37 | @Enumerated 38 | private Roles roles; 39 | 40 | @Column 41 | @NotNull 42 | @NotEmpty 43 | private String password; 44 | 45 | @CreatedDate 46 | private Instant createdAt; 47 | 48 | @LastModifiedDate 49 | private Instant updatedAt; 50 | 51 | @Transient 52 | private String confirmPassword; 53 | 54 | @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY) 55 | @JoinColumn 56 | private ListtransactionList=new ArrayList<>(); 57 | 58 | @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY) 59 | @JoinColumn 60 | private List userAccountsList=new ArrayList<>(); 61 | 62 | @Column 63 | private Boolean locked=false; 64 | 65 | @Column 66 | private Boolean enabled=false; 67 | 68 | @Column 69 | private String validationToken; 70 | 71 | @Column 72 | private String resetPasswordToken; 73 | 74 | @Override 75 | public Instant getCreatedAt() { 76 | return createdAt; 77 | } 78 | 79 | @Override 80 | public void setCreatedAt(Instant createdAt) { 81 | this.createdAt = createdAt; 82 | } 83 | 84 | @Override 85 | public Instant getUpdatedAt() { 86 | return updatedAt; 87 | } 88 | 89 | @Override 90 | public void setUpdatedAt(Instant updatedAt) { 91 | this.updatedAt = updatedAt; 92 | } 93 | 94 | public String getId() { 95 | return id; 96 | } 97 | 98 | public void setId(String id) { 99 | this.id = id; 100 | } 101 | 102 | public String getFirstname() { 103 | return firstname; 104 | } 105 | 106 | public void setFirstname(String firstname) { 107 | this.firstname = firstname; 108 | } 109 | 110 | public String getLastname() { 111 | return lastname; 112 | } 113 | 114 | public void setLastname(String lastname) { 115 | this.lastname = lastname; 116 | } 117 | 118 | public String getEmail() { 119 | return email; 120 | } 121 | 122 | public void setEmail(String email) { 123 | this.email = email; 124 | } 125 | 126 | public Roles getRoles() { 127 | return roles; 128 | } 129 | 130 | public void setRoles(Roles roles) { 131 | this.roles = roles; 132 | } 133 | 134 | public String getPassword() { 135 | return password; 136 | } 137 | 138 | public void setPassword(String password) { 139 | this.password = password; 140 | } 141 | 142 | public String getConfirmPassword() { 143 | return confirmPassword; 144 | } 145 | 146 | public void setConfirmPassword(String confirmPassword) { 147 | this.confirmPassword = confirmPassword; 148 | } 149 | 150 | public Boolean getLocked() { 151 | return locked; 152 | } 153 | 154 | public void setLocked(Boolean locked) { 155 | this.locked = locked; 156 | } 157 | 158 | public Boolean getEnabled() { 159 | return enabled; 160 | } 161 | 162 | public void setEnabled(Boolean enabled) { 163 | this.enabled = enabled; 164 | } 165 | 166 | public String getValidationToken() { 167 | return validationToken; 168 | } 169 | 170 | public void setValidationToken(String validationToken) { 171 | this.validationToken = validationToken; 172 | } 173 | 174 | public String getResetPasswordToken() { 175 | return resetPasswordToken; 176 | } 177 | 178 | public void setResetPasswordToken(String resetPasswordToken) { 179 | this.resetPasswordToken = resetPasswordToken; 180 | } 181 | 182 | 183 | public String getPhoneNumber() { 184 | return phoneNumber; 185 | } 186 | 187 | public void setPhoneNumber(String phoneNumber) { 188 | this.phoneNumber = phoneNumber; 189 | } 190 | 191 | 192 | public List getTransactionList() { 193 | return transactionList; 194 | } 195 | 196 | public void setTransactionList(List transactionList) { 197 | this.transactionList = transactionList; 198 | } 199 | 200 | public List getUserAccountsList() { 201 | return userAccountsList; 202 | } 203 | 204 | public void setUserAccountsList(List userAccountsList) { 205 | this.userAccountsList = userAccountsList; 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/model/audit/DateAudit.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.model.audit; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import org.springframework.data.annotation.CreatedDate; 5 | import org.springframework.data.annotation.LastModifiedDate; 6 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; 7 | 8 | import javax.persistence.EntityListeners; 9 | import javax.persistence.MappedSuperclass; 10 | import java.io.Serializable; 11 | import java.time.Instant; 12 | 13 | @MappedSuperclass 14 | @EntityListeners(AuditingEntityListener.class) 15 | @JsonIgnoreProperties( 16 | value = {"createdAt", "updatedAt"}, 17 | allowGetters = true 18 | ) 19 | public abstract class DateAudit implements Serializable { 20 | 21 | @CreatedDate 22 | private Instant createdAt; 23 | 24 | @LastModifiedDate 25 | private Instant updatedAt; 26 | 27 | public Instant getCreatedAt() { 28 | return createdAt; 29 | } 30 | 31 | public void setCreatedAt(Instant createdAt) { 32 | this.createdAt = createdAt; 33 | } 34 | 35 | public Instant getUpdatedAt() { 36 | return updatedAt; 37 | } 38 | 39 | public void setUpdatedAt(Instant updatedAt) { 40 | this.updatedAt = updatedAt; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/model/audit/UserDateAudit.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.model.audit; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import org.springframework.data.annotation.CreatedBy; 5 | import org.springframework.data.annotation.LastModifiedBy; 6 | 7 | import javax.persistence.MappedSuperclass; 8 | 9 | 10 | 11 | @MappedSuperclass 12 | @JsonIgnoreProperties( 13 | value = {"createdBy", "updatedBy"}, 14 | allowGetters = true 15 | ) 16 | public abstract class UserDateAudit extends DateAudit { 17 | 18 | @CreatedBy 19 | private Long createdBy; 20 | 21 | @LastModifiedBy 22 | private Long updatedBy; 23 | 24 | public Long getCreatedBy() { 25 | return createdBy; 26 | } 27 | 28 | public void setCreatedBy(Long createdBy) { 29 | this.createdBy = createdBy; 30 | } 31 | 32 | public Long getUpdatedBy() { 33 | return updatedBy; 34 | } 35 | 36 | public void setUpdatedBy(Long updatedBy) { 37 | this.updatedBy = updatedBy; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/payload/CreateAccountDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.payload; 2 | 3 | import javax.validation.constraints.NotBlank; 4 | import java.util.Objects; 5 | 6 | public class CreateAccountDto { 7 | 8 | @NotBlank(message = "Bank name is mandatory") 9 | private String bankName; 10 | 11 | @NotBlank(message = "Owner name is mandatory") 12 | private String ownerName; 13 | 14 | 15 | public CreateAccountDto() {} 16 | 17 | public String getBankName() { 18 | return bankName; 19 | } 20 | 21 | public void setBankName(String bankName) { 22 | this.bankName = bankName; 23 | } 24 | 25 | public String getOwnerName() { 26 | return ownerName; 27 | } 28 | 29 | public void setOwnerName(String ownerName) { 30 | this.ownerName = ownerName; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return "CreateAccountInput{" + 36 | "bankName='" + bankName + '\'' + 37 | ", ownerName='" + ownerName + '\'' + 38 | '}'; 39 | } 40 | 41 | @Override 42 | public boolean equals(Object o) { 43 | if (this == o) return true; 44 | if (o == null || getClass() != o.getClass()) return false; 45 | CreateAccountDto that = (CreateAccountDto) o; 46 | return Objects.equals(bankName, that.bankName) && 47 | Objects.equals(ownerName, that.ownerName); 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | return Objects.hash(bankName, ownerName); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/payload/TransferDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.payload; 2 | 3 | import javax.validation.constraints.Max; 4 | import javax.validation.constraints.Min; 5 | import javax.validation.constraints.Positive; 6 | 7 | public class TransferDto { 8 | 9 | private UserAccountDto sourceAccount; 10 | 11 | private UserAccountDto targetAccount; 12 | 13 | @Positive(message = "Transfer amount must be positive") 14 | // Prevent fraudulent transfers attempting to abuse currency conversion errors 15 | @Min(value = 1, message = "Amount must be larger than 1") 16 | private double amount; 17 | 18 | private String reference; 19 | 20 | public TransferDto() {} 21 | 22 | public UserAccountDto getSourceAccount() { 23 | return sourceAccount; 24 | } 25 | 26 | public void setSourceAccount(UserAccountDto sourceAccount) { 27 | this.sourceAccount = sourceAccount; 28 | } 29 | 30 | public UserAccountDto getTargetAccount() { 31 | return targetAccount; 32 | } 33 | 34 | public void setTargetAccount(UserAccountDto targetAccount) { 35 | this.targetAccount = targetAccount; 36 | } 37 | 38 | public double getAmount() { 39 | return amount; 40 | } 41 | 42 | public void setAmount(double amount) { 43 | this.amount = amount; 44 | } 45 | 46 | public String getReference() { 47 | return reference; 48 | } 49 | 50 | public void setReference(String reference) { 51 | this.reference = reference; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "TransactionInput{" + 57 | "sourceAccount=" + sourceAccount + 58 | ", targetAccount=" + targetAccount + 59 | ", amount=" + amount + 60 | ", reference='" + reference + '\'' + 61 | '}'; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/payload/UserAccountDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.payload; 2 | 3 | import javax.validation.constraints.NotBlank; 4 | import java.util.Objects; 5 | 6 | public class UserAccountDto { 7 | 8 | @NotBlank(message = "Sort code is mandatory") 9 | private String sortCode; 10 | 11 | @NotBlank(message = "Account number is mandatory") 12 | private String accountNumber; 13 | 14 | public UserAccountDto() {} 15 | 16 | public String getSortCode() { 17 | return sortCode; 18 | } 19 | 20 | public void setSortCode(String sortCode) { 21 | this.sortCode = sortCode; 22 | } 23 | 24 | public String getAccountNumber() { 25 | return accountNumber; 26 | } 27 | 28 | public void setAccountNumber(String accountNumber) { 29 | this.accountNumber = accountNumber; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "AccountInput{" + 35 | "sortCode='" + sortCode + '\'' + 36 | ", accountNumber='" + accountNumber + '\'' + 37 | '}'; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object o) { 42 | if (this == o) return true; 43 | if (o == null || getClass() != o.getClass()) return false; 44 | UserAccountDto that = (UserAccountDto) o; 45 | return Objects.equals(sortCode, that.sortCode) && 46 | Objects.equals(accountNumber, that.accountNumber); 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | return Objects.hash(sortCode, accountNumber); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/payload/UserAccountGeneratorDto.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.payload; 2 | 3 | import com.mifmif.common.regex.Generex; 4 | 5 | import static koredebank.example.bank.util.constants.ACCOUNT_NUMBER_PATTERN_STRING; 6 | import static koredebank.example.bank.util.constants.SORT_CODE_PATTERN_STRING; 7 | 8 | 9 | public class UserAccountGeneratorDto { 10 | Generex sortCodeGenerex = new Generex(SORT_CODE_PATTERN_STRING); 11 | Generex accountNumberGenerex = new Generex(ACCOUNT_NUMBER_PATTERN_STRING); 12 | 13 | public UserAccountGeneratorDto(){ 14 | 15 | } 16 | 17 | public String generateSortCode() { 18 | return sortCodeGenerex.random(); 19 | } 20 | 21 | public String generateAccountNumber() { 22 | return accountNumberGenerex.random(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/payload/Validator.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.payload; 2 | 3 | 4 | import koredebank.example.bank.dto.UserCreateAccountRequestDto; 5 | import koredebank.example.bank.dto.UserTransferFundsRequestDto; 6 | import koredebank.example.bank.util.constants; 7 | 8 | public class Validator { 9 | 10 | public static boolean isSearchCriteriaValid(UserAccountDto userAccountDto) { 11 | return constants.SORT_CODE_PATTERN.matcher(userAccountDto.getSortCode()).find() && 12 | constants.ACCOUNT_NUMBER_PATTERN.matcher(userAccountDto.getAccountNumber()).find(); 13 | } 14 | 15 | 16 | public static boolean isAccountNoValid(String accountNo) { 17 | return constants.ACCOUNT_NUMBER_PATTERN.matcher(accountNo).find(); 18 | } 19 | 20 | public static boolean isCreateAccountCriteriaValid(UserCreateAccountRequestDto userCreateAccountRequestDto) { 21 | return (!userCreateAccountRequestDto.getBankName().isBlank() && !userCreateAccountRequestDto.getOwnerName().isBlank()); 22 | } 23 | 24 | // public static boolean isSearchCriteriaValid(AccountInput accountInput) { 25 | // return constants.SORT_CODE_PATTERN.matcher(accountInput.getSortCode()).find() && 26 | // constants.ACCOUNT_NUMBER_PATTERN.matcher(accountInput.getAccountNumber()).find(); 27 | // } 28 | 29 | public static boolean isSearchTransactionValid(TransferDto transferDto) { 30 | if (!isSearchCriteriaValid(transferDto.getSourceAccount())) 31 | return false; 32 | 33 | if (!isSearchCriteriaValid(transferDto.getTargetAccount())) 34 | return false; 35 | 36 | if (transferDto.getSourceAccount().equals(transferDto.getTargetAccount())) 37 | return false; 38 | 39 | return true; 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/repository/AccountManagerRepository.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.repository; 2 | 3 | import koredebank.example.bank.model.AccountManager; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.Optional; 8 | 9 | @Repository 10 | public interface AccountManagerRepository extends JpaRepository { 11 | 12 | Optional findAdminByEmail(String email); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/repository/CustomerCompliantFormRepository.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.repository; 2 | 3 | import koredebank.example.bank.model.CustomerCompliantForm; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public interface CustomerCompliantFormRepository extends JpaRepository { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/repository/TransactionRepository.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.repository; 2 | 3 | import koredebank.example.bank.model.Transaction; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.List; 7 | 8 | 9 | public interface TransactionRepository extends JpaRepository { 10 | 11 | // Limit to recent transactions and implement separate endpoint to view old transactions 12 | List findBySourceAccountIdOrderByInitiationDate(long id); 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/repository/UserAccountRepository.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.repository; 2 | 3 | import koredebank.example.bank.model.UserAccount; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | 7 | import java.util.Optional; 8 | 9 | public interface UserAccountRepository extends JpaRepository { 10 | 11 | Optional findBySortCodeAndAccountNumber(String sortCode, String accountNumber); 12 | 13 | Optional findByAccountNumber(String accountNumber); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.repository; 2 | 3 | import koredebank.example.bank.model.UserEntity; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.Optional; 8 | 9 | @Repository 10 | public interface UserRepository extends JpaRepository { 11 | 12 | Optional findUserByEmail(String email); 13 | 14 | 15 | Optional findUserEntitiesByEmail(String email); 16 | 17 | // Optional findUserByUsername(String username); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security; 2 | 3 | import lombok.AllArgsConstructor; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 8 | 9 | @Configuration 10 | @AllArgsConstructor 11 | @EnableWebSecurity 12 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 13 | 14 | @Override 15 | protected void configure(HttpSecurity http) throws Exception { 16 | 17 | http 18 | .csrf().disable() 19 | .authorizeRequests() 20 | .antMatchers("/api/v1/bank","/api/v1/bank/***","/api/v1/bank/***","/api/v1/bank/user/***","/api/v1/bank/user/***/***","/api/v1/transaction","/api/v1/transaction/***","/api/v1/transaction/***") 21 | .permitAll() 22 | .antMatchers("/swagger-ui/","/swagger-ui","/api/**", "/swagger-ui.html", "/swagger-ui/index.html","/swagger-ui/**","/webjars/**", "/v2/**", "/swagger-resources/**").permitAll() 23 | .anyRequest().permitAll(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/config/PasswordConfig.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 6 | import org.springframework.security.crypto.password.PasswordEncoder; 7 | 8 | @Configuration 9 | public class PasswordConfig { 10 | 11 | @Bean 12 | public PasswordEncoder passwordEncoder(){ 13 | return new BCryptPasswordEncoder(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/exceptions/AccountCreationException.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.exceptions; 2 | 3 | public class AccountCreationException extends Exception { 4 | public AccountCreationException() { 5 | } 6 | 7 | public AccountCreationException(String message) { 8 | super(message); 9 | } 10 | 11 | public AccountCreationException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | 15 | public AccountCreationException(Throwable cause) { 16 | super(cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/exceptions/AuthorizationException.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.exceptions; 2 | 3 | public class AuthorizationException extends Exception { 4 | public AuthorizationException() { 5 | } 6 | 7 | public AuthorizationException(String message) { 8 | super(message); 9 | } 10 | 11 | public AuthorizationException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | 15 | public AuthorizationException(Throwable cause) { 16 | super(cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/exceptions/GeneralServiceException.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.exceptions; 2 | 3 | public class GeneralServiceException extends Exception{ 4 | public GeneralServiceException() { 5 | } 6 | 7 | public GeneralServiceException(String message) { 8 | super(message); 9 | } 10 | 11 | public GeneralServiceException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | 15 | public GeneralServiceException(Throwable cause) { 16 | super(cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/exceptions/ImageUploadException.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.exceptions; 2 | 3 | import java.io.IOException; 4 | 5 | public class ImageUploadException extends IOException { 6 | 7 | public ImageUploadException() { 8 | super(); 9 | } 10 | 11 | public ImageUploadException(String message) { 12 | super(message); 13 | } 14 | 15 | public ImageUploadException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public ImageUploadException(Throwable cause) { 20 | super(cause); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/exceptions/IncorrectPasswordException.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.exceptions; 2 | 3 | public class IncorrectPasswordException extends Exception { 4 | public IncorrectPasswordException() { 5 | } 6 | 7 | public IncorrectPasswordException(String message) { 8 | super(message); 9 | } 10 | 11 | public IncorrectPasswordException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | 15 | public IncorrectPasswordException(Throwable cause) { 16 | super(cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/securityServices/AppAuthenticationProvider.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.securityServices; 2 | 3 | 4 | 5 | import koredebank.example.bank.model.Roles; 6 | import koredebank.example.bank.model.UserEntity; 7 | import koredebank.example.bank.repository.UserRepository; 8 | import koredebank.example.bank.security.exceptions.AuthorizationException; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.context.annotation.Primary; 12 | import org.springframework.security.authentication.AuthenticationManager; 13 | import org.springframework.security.authentication.BadCredentialsException; 14 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 15 | import org.springframework.security.core.Authentication; 16 | import org.springframework.security.core.AuthenticationException; 17 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 18 | import org.springframework.stereotype.Service; 19 | 20 | import java.util.Collections; 21 | import java.util.List; 22 | import java.util.Optional; 23 | import java.util.stream.Collectors; 24 | 25 | @Slf4j 26 | @Service 27 | @Primary 28 | public class AppAuthenticationProvider implements AuthenticationManager { 29 | 30 | @Autowired 31 | UserRepository userRepository; 32 | 33 | @Override 34 | public Authentication authenticate(Authentication authentication) throws AuthenticationException { 35 | UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication; 36 | //String username = token.getName(); 37 | String firstname = token.getName(); 38 | String password = (String) token.getCredentials(); 39 | 40 | 41 | 42 | Optional user = userRepository.findUserByEmail(firstname); 43 | 44 | if (!user.isPresent()) { 45 | throw new BadCredentialsException("There is not account with given credentials"); 46 | } 47 | // if (!passwordEncoder.matches(passwordEncoder.encode(password),passwordEncoder.encode( user.get().getPassword()))) { 48 | // throw new BadCredentialsException("Invalid username or password"); 49 | // } 50 | 51 | UserEntity usersEntity=user.get(); 52 | List authorities = Collections.singletonList(usersEntity.getRoles()); 53 | if(usersEntity.getRoles() == null) { 54 | try { 55 | throw new AuthorizationException("User has no authority"); 56 | } catch (AuthorizationException e) { 57 | e.printStackTrace(); 58 | } 59 | } 60 | return new UsernamePasswordAuthenticationToken(firstname, password, authorities.stream().map(authority 61 | -> new SimpleGrantedAuthority(authority.name())).collect(Collectors.toList())); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/securityServices/ApplicationUser.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.securityServices; 2 | 3 | 4 | 5 | import com.fasterxml.jackson.annotation.JsonIgnore; 6 | import koredebank.example.bank.model.UserEntity; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.security.core.GrantedAuthority; 11 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 12 | import org.springframework.security.core.userdetails.UserDetails; 13 | 14 | import java.util.ArrayList; 15 | import java.util.Collection; 16 | import java.util.List; 17 | 18 | @Slf4j 19 | @Data 20 | @NoArgsConstructor 21 | public class ApplicationUser implements UserDetails { 22 | private String id; 23 | 24 | private String name; 25 | 26 | @JsonIgnore 27 | private String email; 28 | 29 | //email == username 30 | // @JsonIgnore 31 | // private String username; 32 | 33 | @JsonIgnore 34 | private String password; 35 | 36 | private Collection authorities; 37 | 38 | 39 | 40 | public static ApplicationUser create(UserEntity userEntity) { 41 | //user entity has no role. if you need a role, add field role 42 | 43 | List authorities = new ArrayList<>(); 44 | authorities.add(new SimpleGrantedAuthority(userEntity.getRoles().toString())); //user entity does not have role. create one 45 | return new ApplicationUser( 46 | String.valueOf( userEntity.getId()), 47 | userEntity.getFirstname() + " " + userEntity.getLastname(), 48 | userEntity.getEmail(), 49 | userEntity.getPassword(), 50 | authorities 51 | ); 52 | } 53 | 54 | public ApplicationUser(String id, String name, String email, String password, Collection authorities) { 55 | this.id = id; 56 | this.name = name; 57 | this.email = email; 58 | this.password = password; 59 | this.authorities = authorities; 60 | } 61 | 62 | @Override 63 | public Collection getAuthorities() { 64 | return null; 65 | } 66 | 67 | @Override 68 | public String getPassword() { 69 | return password; 70 | } 71 | 72 | @Override 73 | public String getUsername() { 74 | return email; 75 | } 76 | 77 | @Override 78 | public boolean isAccountNonExpired() { 79 | return true; 80 | } 81 | 82 | @Override 83 | public boolean isAccountNonLocked() { 84 | return true; 85 | } 86 | 87 | @Override 88 | public boolean isCredentialsNonExpired() { 89 | return true; 90 | } 91 | 92 | @Override 93 | public boolean isEnabled() { 94 | return true; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/securityServices/TokenProviderService.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.securityServices; 2 | 3 | 4 | 5 | import io.jsonwebtoken.Claims; 6 | import koredebank.example.bank.model.UserEntity; 7 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 8 | import org.springframework.security.core.Authentication; 9 | import org.springframework.security.core.userdetails.UserDetails; 10 | 11 | import java.util.function.Function; 12 | 13 | 14 | public interface TokenProviderService { 15 | String generateLoginToken(Authentication authentication, UserEntity userEntity); 16 | 17 | String getEmailFromToken(String token); 18 | 19 | T getClaimFromToken(String token, Function claimsResolver); 20 | 21 | public UsernamePasswordAuthenticationToken getAuthentication(final String authenticationToken, final Authentication authentication, final UserDetails userDetails); 22 | 23 | boolean validateToken(String token, UserDetails userDetails); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/securityServices/TokenProviderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.securityServices; 2 | 3 | 4 | import io.jsonwebtoken.*; 5 | import io.jsonwebtoken.SignatureException; 6 | import koredebank.example.bank.model.UserEntity; 7 | import lombok.Data; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 12 | import org.springframework.security.core.Authentication; 13 | import org.springframework.security.core.GrantedAuthority; 14 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 15 | import org.springframework.security.core.userdetails.UserDetails; 16 | import org.springframework.stereotype.Service; 17 | 18 | import java.io.Serializable; 19 | import java.util.Arrays; 20 | import java.util.Base64; 21 | import java.util.Collection; 22 | import java.util.Date; 23 | import java.util.function.Function; 24 | import java.util.stream.Collectors; 25 | 26 | import static koredebank.example.bank.security.securityUtils.SecurityConstants.*; 27 | 28 | 29 | @Data 30 | @Service 31 | @Configuration 32 | public class TokenProviderServiceImpl implements Serializable, TokenProviderService { 33 | @Override 34 | public String generateLoginToken(Authentication authentication, UserEntity userEntity) { 35 | 36 | final String authorities = authentication.getAuthorities().stream() 37 | .map(GrantedAuthority::getAuthority) 38 | .collect(Collectors.joining(",")); 39 | 40 | 41 | String jwts = Jwts.builder() 42 | .setSubject(authentication.getName()) 43 | .claim(AUTHORITIES_KEY, authorities) 44 | //this error is being thrown because "where is AUTHORITIES_KEY" coming from?? it should be a variable that holds something. 45 | //create a security constants class and declare it there then import the class here 46 | // .claim("id", user.getId()) 47 | .setIssuer("AUTOX") 48 | .signWith(SignatureAlgorithm.HS512, getEncryptedSigningKey()) 49 | //this should go away once above is solved 50 | .setIssuedAt(new Date(System.currentTimeMillis())) 51 | .setExpiration(new Date(System.currentTimeMillis() 52 | + EXPIRATION_DATE)) //same issue with AUTHORITIES_KEY above 53 | .compact(); 54 | return jwts; 55 | 56 | } 57 | private String getEncryptedSigningKey(){ 58 | 59 | String encryptedSigningKey = Base64.getEncoder().encodeToString(SIGNING_KEY_STRING.getBytes()); 60 | //same issue with above 61 | 62 | return encryptedSigningKey; 63 | } 64 | Logger logger = LoggerFactory.getLogger(TokenProviderServiceImpl.class); 65 | 66 | @Override 67 | public String getEmailFromToken(String token) { 68 | return getClaimFromToken(token, Claims::getSubject); 69 | } 70 | 71 | @Override 72 | public T getClaimFromToken(String token, Function claimsResolver) { 73 | final Claims claims = getAllClaimsFromToken(token); 74 | return claimsResolver.apply(claims); 75 | } 76 | 77 | private Claims getAllClaimsFromToken(String token) { 78 | 79 | var split = token.split(" "); 80 | String t = split[split.length-1]; 81 | 82 | 83 | Claims claims; 84 | try{ 85 | claims = Jwts.parser() 86 | .setSigningKey(getEncryptedSigningKey()) 87 | .parseClaimsJws(t) 88 | .getBody(); 89 | return claims; 90 | } 91 | catch (SignatureException ex){ 92 | logger.error("untrusted token detected and invalidated"); 93 | throw new SecurityException("token untrusted"); 94 | 95 | } 96 | 97 | } 98 | 99 | @Override 100 | public boolean validateToken(String token, UserDetails userDetails){ 101 | final String email = getEmailFromToken(token); 102 | boolean tokenStatus = email.equals(userDetails.getUsername()) && (!isTokenExpired(token)); 103 | return tokenStatus; 104 | 105 | } 106 | 107 | private boolean isTokenExpired(String token) { 108 | final Date expiration = getExpirationDateFromToken(token); 109 | return expiration.before(new Date()); 110 | } 111 | 112 | private Date getExpirationDateFromToken(String token) { 113 | return getClaimFromToken(token, Claims::getExpiration); 114 | } 115 | 116 | 117 | @Override 118 | public UsernamePasswordAuthenticationToken getAuthentication(final String authenticationToken, final Authentication authentication, final UserDetails userDetails) { 119 | final JwtParser jwtParser = Jwts.parser().setSigningKey(getEncryptedSigningKey()); 120 | 121 | final Jws claimsJws = jwtParser.parseClaimsJws(authenticationToken); 122 | 123 | final Claims claims = claimsJws.getBody(); 124 | 125 | final Collection authorities = 126 | Arrays.stream(claims.get(AUTHORITIES_KEY).toString().split(",")) 127 | .map(SimpleGrantedAuthority::new) 128 | .collect(Collectors.toList()); 129 | 130 | return new UsernamePasswordAuthenticationToken(userDetails, "", authorities); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/securityServices/UserPrincipalService.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.securityServices; 2 | 3 | 4 | import koredebank.example.bank.dto.UserLoginDto; 5 | import koredebank.example.bank.model.UserEntity; 6 | import koredebank.example.bank.repository.UserRepository; 7 | import koredebank.example.bank.security.exceptions.AuthorizationException; 8 | import koredebank.example.bank.security.exceptions.GeneralServiceException; 9 | import koredebank.example.bank.security.exceptions.IncorrectPasswordException; 10 | import koredebank.example.bank.security.securityUtils.JWTToken; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 13 | import org.springframework.security.core.Authentication; 14 | import org.springframework.security.core.context.SecurityContextHolder; 15 | import org.springframework.security.core.userdetails.UserDetails; 16 | import org.springframework.security.core.userdetails.UserDetailsService; 17 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 18 | import org.springframework.security.crypto.password.PasswordEncoder; 19 | import org.springframework.stereotype.Service; 20 | 21 | import java.util.Optional; 22 | import java.util.UUID; 23 | 24 | @Service 25 | public class UserPrincipalService implements UserDetailsService { 26 | @Autowired 27 | UserRepository userRepository; 28 | @Autowired 29 | PasswordEncoder passwordEncoder; 30 | @Autowired 31 | private AppAuthenticationProvider authenticationManager; 32 | 33 | @Autowired 34 | TokenProviderServiceImpl tokenProviderService; 35 | 36 | 37 | 38 | @Override 39 | public UserDetails loadUserByUsername(String firstname) throws UsernameNotFoundException { 40 | 41 | Optional optionalUser = userRepository.findUserByEmail(firstname); 42 | if(optionalUser.isEmpty()){ 43 | throw new UsernameNotFoundException("User with given email not found"); 44 | } 45 | else{ 46 | UserEntity userEntity = optionalUser.get(); 47 | return ApplicationUser.create(userEntity); 48 | } 49 | } 50 | 51 | public JWTToken loginUser(UserLoginDto userLoginDto) throws UsernameNotFoundException, IncorrectPasswordException, GeneralServiceException { 52 | Optional users = userRepository.findUserByEmail(userLoginDto.getEmail()); 53 | 54 | 55 | if(users.isPresent()){ 56 | if(!users.get().getEnabled()){ 57 | throw new GeneralServiceException("Account has not been enabled"); 58 | } 59 | boolean matchingResult=passwordEncoder.matches(userLoginDto.getPassword(), users.get().getPassword()); 60 | 61 | if(!matchingResult){ 62 | throw new IncorrectPasswordException("The password is Incorrect"); 63 | } 64 | final Authentication authentication = authenticationManager.authenticate( 65 | new UsernamePasswordAuthenticationToken( 66 | userLoginDto.getEmail(), userLoginDto.getPassword() 67 | ) 68 | ); 69 | 70 | SecurityContextHolder.getContext().setAuthentication(authentication); 71 | users = userRepository.findUserByEmail(userLoginDto.getEmail()); 72 | 73 | JWTToken jwtToken = new JWTToken(tokenProviderService.generateLoginToken(authentication, users.get())); 74 | 75 | 76 | return jwtToken; 77 | } 78 | throw new UsernameNotFoundException("User Not Found"); 79 | 80 | } 81 | 82 | public String signUpUser(UserEntity users) { 83 | StringBuilder stringBuilder= new StringBuilder("Validates "); 84 | boolean userExists=userRepository.findUserByEmail(users.getEmail()).isPresent(); 85 | if(userExists){ 86 | throw new IllegalStateException("user with this email already exists"); 87 | } 88 | userRepository.save(users); 89 | String encodedPassword=passwordEncoder.encode(users.getPassword()); 90 | users.setPassword(encodedPassword); 91 | String token= UUID.randomUUID().toString(); 92 | 93 | stringBuilder.append(token); 94 | return stringBuilder.toString(); 95 | } 96 | 97 | public String sendRegistrationToken(UserEntity usersEntity){ 98 | //mailsender 99 | String token= UUID.randomUUID().toString().replace("-","").substring(0,6); 100 | return token; 101 | } 102 | 103 | public String sendRecoveryToken(UserEntity users){ 104 | //mailsender 105 | String token= UUID.randomUUID().toString().replace("-","").substring(0,6); 106 | return token; 107 | } 108 | 109 | public String getUserEmailAddressFromToken(String token) throws AuthorizationException { 110 | return tokenProviderService.getEmailFromToken(token); 111 | } 112 | public boolean passwordMatches(String password,String password2){ 113 | return passwordEncoder.matches(password, password2); 114 | 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/securityUtils/JWTToken.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.securityUtils; 2 | 3 | public class JWTToken { 4 | private String accessToken; 5 | private TokenType tokenType = TokenType.BEARER_TOKEN; 6 | 7 | 8 | public JWTToken(String loginToken) { 9 | accessToken = loginToken; 10 | } 11 | 12 | public void setAccessToken(String accessToken) { 13 | this.accessToken = accessToken; 14 | } 15 | 16 | public String getAccessToken() { 17 | return accessToken; 18 | } 19 | 20 | public void setTokenType(TokenType tokenType) { 21 | this.tokenType = tokenType; 22 | } 23 | 24 | public TokenType getTokenType() { 25 | return tokenType; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/securityUtils/SecurityConstants.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.securityUtils; 2 | 3 | public class SecurityConstants { 4 | 5 | public static final String AUTHORITIES_KEY = "roles"; 6 | 7 | public static final String SIGNING_KEY_STRING = "appsecret"; 8 | 9 | public static final long EXPIRATION_DATE = 864_000_00; 10 | 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/security/securityUtils/TokenType.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.security.securityUtils; 2 | 3 | public enum TokenType { 4 | 5 | BEARER_TOKEN; 6 | 7 | @Override 8 | public String toString() { 9 | switch (this){ 10 | case BEARER_TOKEN:return "Bearer"; 11 | default: return null; 12 | } 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/service/accountManagerService/AccountManagerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.service.accountManagerService; 2 | 3 | import koredebank.example.bank.Email.EmailService; 4 | import koredebank.example.bank.dto.*; 5 | import koredebank.example.bank.model.*; 6 | import koredebank.example.bank.repository.*; 7 | import koredebank.example.bank.security.exceptions.AccountCreationException; 8 | import koredebank.example.bank.security.exceptions.AuthorizationException; 9 | import koredebank.example.bank.security.exceptions.GeneralServiceException; 10 | import koredebank.example.bank.security.securityServices.UserPrincipalService; 11 | import koredebank.example.bank.serviceUtil.IdGenerator; 12 | import koredebank.example.bank.serviceUtil.StringUtil; 13 | import org.modelmapper.ModelMapper; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.data.domain.Page; 16 | import org.springframework.data.domain.PageRequest; 17 | import org.springframework.data.domain.Pageable; 18 | import org.springframework.security.crypto.password.PasswordEncoder; 19 | import org.springframework.stereotype.Service; 20 | 21 | import javax.mail.MessagingException; 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | import java.util.Optional; 25 | 26 | @Service 27 | public class AccountManagerServiceImpl implements AccountManagerServices { 28 | 29 | @Autowired 30 | private UserRepository userRepository; 31 | 32 | @Autowired 33 | private AccountManagerRepository accountManagerRepository; 34 | 35 | @Autowired 36 | CustomerCompliantFormRepository customerCompliantFormRepository; 37 | 38 | @Autowired 39 | TransactionRepository transactionRepository; 40 | 41 | @Autowired 42 | EmailService emailService; 43 | 44 | @Autowired 45 | UserAccountRepository userAccountRepository; 46 | 47 | @Autowired 48 | private ModelMapper modelMapper; 49 | 50 | @Autowired 51 | private PasswordEncoder passwordEncoder; 52 | 53 | @Autowired 54 | private UserPrincipalService userPrincipalService; 55 | 56 | 57 | 58 | @Override 59 | public AccountManagerSignUpResponseDto registerAccountManager(AccountManagerSignUpRequestDto accountManagerSignUpRequestDto) throws AccountCreationException { 60 | 61 | checkAllParameters(accountManagerSignUpRequestDto); 62 | 63 | userWithEmailExists(accountManagerSignUpRequestDto); 64 | 65 | AccountManager accountManager = createAccountMangerDetails(accountManagerSignUpRequestDto); 66 | 67 | accountManagerRepository.save(accountManager); 68 | 69 | return generateRegistrationResponse(accountManagerSignUpRequestDto, accountManager.getId()); 70 | } 71 | 72 | @Override 73 | public boolean changeAccountManagerPassword(AccountManagerChangePassword accountManagerChangePassword, String id) throws AuthorizationException, GeneralServiceException { 74 | 75 | if(!accountManagerChangePassword.getNewPassword().equals(accountManagerChangePassword.getConfirmPassword())){ 76 | throw new GeneralServiceException("New Passwords do not match"); 77 | } 78 | 79 | Optional accountManager = accountManagerRepository.findById(id); 80 | if(accountManager.isEmpty()){ 81 | throw new GeneralServiceException("User not found"); 82 | } 83 | 84 | boolean matches = userPrincipalService.passwordMatches( 85 | accountManagerChangePassword.getOldPassword(),accountManager.get().getPassword()); 86 | 87 | if (!matches) { 88 | throw new GeneralServiceException("old password is incorrect"); 89 | }else 90 | 91 | accountManager.get().setPassword(passwordEncoder.encode(accountManagerChangePassword.getNewPassword())); 92 | accountManagerRepository.save(accountManager.get()); 93 | return true; 94 | } 95 | 96 | @Override 97 | public boolean forgotAccountManagerPassword(AccountManagerForgotPassword accountManagerForgotPassword) throws GeneralServiceException { 98 | 99 | //check if email is not empty 100 | if(accountManagerForgotPassword.getEmail().isEmpty()){ 101 | throw new GeneralServiceException("User email is empty"); 102 | } 103 | if(accountManagerForgotPassword.getNewPassword().isEmpty()){ 104 | throw new GeneralServiceException("Password is empty"); 105 | } 106 | //find user by email 107 | Optional accountManager=accountManagerRepository.findAdminByEmail(accountManagerForgotPassword.getEmail()); 108 | if(accountManager.isEmpty()){ 109 | throw new GeneralServiceException("User not found"); 110 | } 111 | 112 | accountManager.get().setPassword(passwordEncoder.encode(accountManagerForgotPassword.getNewPassword())); 113 | 114 | accountManagerRepository.save(accountManager.get()); 115 | return true; 116 | } 117 | 118 | @Override 119 | public boolean blockAccountUser(AccountManagerBlockUserRequestDto accountManagerBlockUserRequestDto) throws GeneralServiceException, MessagingException { 120 | if (accountManagerBlockUserRequestDto.getAccountNumber().isEmpty()){ 121 | throw new GeneralServiceException("Kindly input the acc number of the user"); 122 | } 123 | 124 | Optional user = userAccountRepository.findByAccountNumber(accountManagerBlockUserRequestDto.getAccountNumber()); 125 | 126 | if(user.isEmpty()){ 127 | throw new GeneralServiceException("User cannot be found"); 128 | } 129 | user.get().getUserEntity().setEnabled(false); 130 | 131 | userAccountRepository.save(user.get()); 132 | 133 | emailService.sendAccountSuspendedNotification(user.get().getUserEntity()); 134 | 135 | return true; 136 | } 137 | 138 | @Override 139 | public boolean unblockAccountUser(AccountManagerUnblockUserRequestDto accountManagerUnblockUserRequestDto) throws GeneralServiceException, MessagingException { 140 | 141 | if (accountManagerUnblockUserRequestDto.getAccountNumber().isEmpty()){ 142 | throw new GeneralServiceException("Kindly input the acc number of the user"); 143 | } 144 | 145 | Optional user = userAccountRepository.findByAccountNumber(accountManagerUnblockUserRequestDto.getAccountNumber()); 146 | 147 | if(user.isEmpty()){ 148 | throw new GeneralServiceException("User cannot be found"); 149 | } 150 | user.get().getUserEntity().setEnabled(true); 151 | 152 | userAccountRepository.save(user.get()); 153 | 154 | emailService.sendAccountSuspendedRevertNotification(user.get().getUserEntity()); 155 | 156 | return true; 157 | } 158 | 159 | private AccountManagerSignUpResponseDto generateRegistrationResponse( 160 | AccountManagerSignUpRequestDto accountManagerSignUpRequestDto, String id){ 161 | 162 | AccountManagerSignUpResponseDto accountManagerSignUpResponseDto = new AccountManagerSignUpResponseDto(); 163 | 164 | modelMapper.map(accountManagerSignUpRequestDto,accountManagerSignUpResponseDto); 165 | 166 | accountManagerSignUpResponseDto.setId(id); 167 | accountManagerSignUpResponseDto.setRole(Roles.ACCOUNT_MANAGER); 168 | 169 | return accountManagerSignUpResponseDto; 170 | } 171 | 172 | private AccountManager createAccountMangerDetails(AccountManagerSignUpRequestDto accountManagerSignUpRequestDto){ 173 | AccountManager accountManager = new AccountManager(); 174 | modelMapper.map(accountManagerSignUpRequestDto,accountManager); 175 | String password=passwordEncoder.encode(accountManagerSignUpRequestDto.getPassword()); 176 | accountManager.setPassword(password); 177 | accountManager.setId(IdGenerator.generateId()); 178 | accountManager.setRoles(Roles.ACCOUNT_MANAGER); 179 | return accountManager; 180 | } 181 | 182 | private void userWithEmailExists(AccountManagerSignUpRequestDto accountManagerSignUpRequestDto) throws AccountCreationException { 183 | Optional accountManager =accountManagerRepository.findAdminByEmail(accountManagerSignUpRequestDto.getEmail()); 184 | if(accountManager.isPresent()){ 185 | throw new AccountCreationException("Account Manager with this email already exists"); 186 | } 187 | } 188 | 189 | private void checkAllParameters(AccountManagerSignUpRequestDto accountManagerSignUpRequestDto) throws AccountCreationException { 190 | if (StringUtil.isBlank(accountManagerSignUpRequestDto.getEmail())) { 191 | throw new AccountCreationException("Email Cannot be empty"); 192 | } 193 | if (StringUtil.isBlank(accountManagerSignUpRequestDto.getPassword())) { 194 | throw new AccountCreationException("Password Cannot be empty"); 195 | } 196 | if (StringUtil.isBlank(accountManagerSignUpRequestDto.getConfirmPassword())) { 197 | throw new AccountCreationException("Confirm Password Cannot be empty"); 198 | } 199 | if (!(accountManagerSignUpRequestDto.getConfirmPassword().equals(accountManagerSignUpRequestDto.getPassword()))) { 200 | throw new AccountCreationException("Passwords do not match"); 201 | } 202 | } 203 | 204 | 205 | @Override 206 | public TransactionListResponseDto listTransactions( int page, int size) throws AuthorizationException { 207 | 208 | //create pageable 209 | Pageable pageable= PageRequest.of((page-1),size); 210 | //find all return page 211 | Page transactions = transactionRepository.findAll(pageable); 212 | //get total size of list 213 | int totalSizeOfList=transactionRepository.findAll().size(); 214 | //get the contents from page 215 | List transactionList= transactions.getContent(); 216 | //create a dto list for contents 217 | List transactionResponseDtoList= new ArrayList<>(); 218 | 219 | for (Transaction transaction: transactionList){ 220 | 221 | TransactionResponseDto transactionResponseDto = new TransactionResponseDto(); 222 | //map content to dtos 223 | modelMapper.map(transaction,transactionResponseDto); 224 | //add dto to dto list 225 | transactionResponseDtoList.add(transactionResponseDto); 226 | } 227 | //create response object 228 | TransactionListResponseDto transactionListResponseDto = new TransactionListResponseDto(); 229 | //set data into response object 230 | transactionListResponseDto.setTransactionResponseDtoList(transactionResponseDtoList); 231 | //set data into response object 232 | transactionListResponseDto.setSizeOfList(totalSizeOfList); 233 | //return response object 234 | return transactionListResponseDto; 235 | } 236 | 237 | @Override 238 | public AccountListResponseDto listUsersAccounts( int page, int size) throws AuthorizationException { 239 | 240 | Pageable pageable= PageRequest.of((page-1),size); 241 | 242 | Page userAccounts = userAccountRepository.findAll(pageable); 243 | 244 | int totalSizeOfList=userAccountRepository.findAll().size(); 245 | 246 | List userAccountList= userAccounts.getContent(); 247 | 248 | List accountResponseDtoList= new ArrayList<>(); 249 | 250 | for (UserAccount userAccount: userAccountList){ 251 | 252 | AccountResponseDto accountResponseDto = new AccountResponseDto(); 253 | 254 | modelMapper.map(userAccount,accountResponseDto); 255 | 256 | accountResponseDtoList.add(accountResponseDto); 257 | } 258 | 259 | AccountListResponseDto accountListResponseDto = new AccountListResponseDto(); 260 | 261 | accountListResponseDto.setAccountResponseDtoList(accountResponseDtoList); 262 | 263 | accountListResponseDto.setSizeOfList(totalSizeOfList); 264 | 265 | return accountListResponseDto; 266 | } 267 | 268 | @Override 269 | public UserCompliantListResponseDto listUserCompliantAndSchedules(int page, int size) throws AuthorizationException { 270 | 271 | Pageable pageable= PageRequest.of((page-1),size); 272 | 273 | Page customerCompliantForms = customerCompliantFormRepository.findAll(pageable); 274 | 275 | int totalSizeOfList=customerCompliantFormRepository.findAll().size(); 276 | 277 | List customerCompliantFormList= customerCompliantForms.getContent(); 278 | 279 | List userCompliantFormResponseDtoList= new ArrayList<>(); 280 | 281 | for (CustomerCompliantForm customerCompliantForm: customerCompliantFormList){ 282 | 283 | UserCompliantFormResponseDto userCompliantFormResponseDto = new UserCompliantFormResponseDto(); 284 | 285 | modelMapper.map(customerCompliantForm,userCompliantFormResponseDto); 286 | 287 | userCompliantFormResponseDtoList.add(userCompliantFormResponseDto); 288 | } 289 | 290 | UserCompliantListResponseDto userCompliantListResponseDto = new UserCompliantListResponseDto(); 291 | 292 | userCompliantListResponseDto.setUserCompliantFormResponseDtoList(userCompliantFormResponseDtoList); 293 | 294 | userCompliantListResponseDto.setSizeOfList(totalSizeOfList); 295 | 296 | return userCompliantListResponseDto; 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/service/accountManagerService/AccountManagerServices.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.service.accountManagerService; 2 | 3 | import koredebank.example.bank.dto.*; 4 | import koredebank.example.bank.security.exceptions.AccountCreationException; 5 | import koredebank.example.bank.security.exceptions.AuthorizationException; 6 | import koredebank.example.bank.security.exceptions.GeneralServiceException; 7 | 8 | import javax.mail.MessagingException; 9 | 10 | public interface AccountManagerServices { 11 | 12 | AccountManagerSignUpResponseDto registerAccountManager(AccountManagerSignUpRequestDto accountManagerSignUpRequestDto) throws AccountCreationException; 13 | 14 | boolean changeAccountManagerPassword(AccountManagerChangePassword accountManagerChangePassword,String id) throws AuthorizationException, GeneralServiceException; 15 | 16 | boolean forgotAccountManagerPassword(AccountManagerForgotPassword accountManagerForgotPassword) throws GeneralServiceException; 17 | 18 | boolean blockAccountUser(AccountManagerBlockUserRequestDto accountManagerBlockUserRequestDto) throws GeneralServiceException, MessagingException; 19 | 20 | boolean unblockAccountUser(AccountManagerUnblockUserRequestDto accountManagerUnblockUserRequestDto) throws GeneralServiceException, MessagingException; 21 | 22 | TransactionListResponseDto listTransactions( int page, int size) throws AuthorizationException; 23 | 24 | AccountListResponseDto listUsersAccounts( int page, int size) throws AuthorizationException; 25 | 26 | UserCompliantListResponseDto listUserCompliantAndSchedules(int page, int size) throws AuthorizationException; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/service/transactionService/TransactionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.service.transactionService; 2 | 3 | import koredebank.example.bank.Email.EmailService; 4 | import koredebank.example.bank.cloudinaryService.CloudStorageService; 5 | import koredebank.example.bank.dto.*; 6 | import koredebank.example.bank.model.*; 7 | import koredebank.example.bank.payload.UserAccountGeneratorDto; 8 | import koredebank.example.bank.repository.CustomerCompliantFormRepository; 9 | import koredebank.example.bank.repository.TransactionRepository; 10 | import koredebank.example.bank.repository.UserAccountRepository; 11 | import koredebank.example.bank.repository.UserRepository; 12 | import koredebank.example.bank.security.exceptions.AccountCreationException; 13 | import koredebank.example.bank.security.exceptions.AuthorizationException; 14 | import koredebank.example.bank.security.exceptions.GeneralServiceException; 15 | import koredebank.example.bank.security.exceptions.ImageUploadException; 16 | import koredebank.example.bank.security.securityServices.UserPrincipalService; 17 | import koredebank.example.bank.serviceUtil.IdGenerator; 18 | import koredebank.example.bank.serviceUtil.StringUtil; 19 | import lombok.extern.slf4j.Slf4j; 20 | import org.modelmapper.ModelMapper; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.data.domain.Page; 23 | import org.springframework.data.domain.PageRequest; 24 | import org.springframework.data.domain.Pageable; 25 | import org.springframework.security.crypto.password.PasswordEncoder; 26 | import org.springframework.stereotype.Service; 27 | import org.springframework.web.multipart.MultipartFile; 28 | 29 | import javax.mail.MessagingException; 30 | import java.io.IOException; 31 | import java.time.*; 32 | import java.util.*; 33 | 34 | 35 | @Service 36 | @Slf4j 37 | public class TransactionServiceImpl implements TransactionServices{ 38 | 39 | 40 | @Autowired 41 | private UserRepository userRepository; 42 | 43 | @Autowired 44 | UserAccountRepository userAccountRepository; 45 | 46 | @Autowired 47 | TransactionRepository transactionRepository; 48 | 49 | @Autowired 50 | CustomerCompliantFormRepository compliantFormRepository; 51 | 52 | @Autowired 53 | private ModelMapper modelMapper; 54 | 55 | @Autowired 56 | CloudStorageService cloudStorageService; 57 | 58 | @Autowired 59 | private PasswordEncoder passwordEncoder; 60 | 61 | @Autowired 62 | EmailService emailService; 63 | 64 | @Autowired 65 | UserPrincipalService userPrincipalService; 66 | 67 | 68 | 69 | private static final String USER_NOT_FOUND = "User not found"; 70 | 71 | @Override 72 | public UserCreateAccountResponseDto createAccounts(UserCreateAccountRequestDto userCreateAccountRequestDto, String authentication) throws AccountCreationException, AuthorizationException, MessagingException { 73 | 74 | String userEmail = userPrincipalService.getUserEmailAddressFromToken(authentication); 75 | 76 | Optional user = userRepository.findUserByEmail(userEmail); 77 | if (user.isEmpty()) { 78 | throw new AccountCreationException(USER_NOT_FOUND); 79 | } 80 | 81 | if (userCreateAccountRequestDto.getBankName() == null && userCreateAccountRequestDto.getOwnerName() == null) { 82 | throw new AccountCreationException("Account cannot be empty"); 83 | } 84 | 85 | UserAccount userAccount = createAccounts(userCreateAccountRequestDto.getBankName(),userCreateAccountRequestDto.getOwnerName()); 86 | userAccount.setUserEntity(user.get()); 87 | 88 | modelMapper.map(userCreateAccountRequestDto,userAccount); 89 | 90 | emailService.sendAccountCreationSuccessfulEmail(userAccount); 91 | 92 | userAccountRepository.save(userAccount); 93 | 94 | log.info(userAccount.toString()); 95 | UserCreateAccountResponseDto userCreateAccountResponseDto = new UserCreateAccountResponseDto(); 96 | 97 | modelMapper.map(userCreateAccountRequestDto,userCreateAccountResponseDto); 98 | return userCreateAccountResponseDto; 99 | } 100 | 101 | 102 | private UserSignUpResponseDto generateRegistrationResponse(UserSignUpRequestDto userSignUpRequestDto, String id){ 103 | UserSignUpResponseDto userSignUpResponseDto=new UserSignUpResponseDto(); 104 | 105 | modelMapper.map(userSignUpRequestDto,userSignUpResponseDto); 106 | 107 | userSignUpResponseDto.setId(id); 108 | userSignUpResponseDto.setRole(Roles.BASE_USER); 109 | 110 | return userSignUpResponseDto; 111 | } 112 | 113 | 114 | @Override 115 | public UserCheckAccountBalanceResponseDto checkAccBalance(UserCheckAccountBalanceRequestDto userCheckAccountBalanceRequestDto, String authentication) throws AccountCreationException, AuthorizationException, MessagingException, GeneralServiceException { 116 | 117 | String userEmail = userPrincipalService.getUserEmailAddressFromToken(authentication); 118 | 119 | Optional user = userRepository.findUserByEmail(userEmail); 120 | if (user.isEmpty()) { 121 | throw new AccountCreationException(USER_NOT_FOUND); 122 | } 123 | 124 | UserAccount userAccount = getAccountByDate(userCheckAccountBalanceRequestDto.getSortCode(),userCheckAccountBalanceRequestDto.getAccountNumber()); 125 | 126 | 127 | if (userAccount == null){ 128 | throw new AccountCreationException("Kindly fill in all the required details to create account"); 129 | } 130 | 131 | modelMapper.map(userAccount, userCheckAccountBalanceRequestDto); 132 | 133 | userAccountRepository.save(userAccount); 134 | 135 | UserCheckAccountBalanceResponseDto userCheckAccountBalanceResponseDto = new UserCheckAccountBalanceResponseDto(); 136 | 137 | modelMapper.map(userCheckAccountBalanceRequestDto,userCheckAccountBalanceResponseDto); 138 | 139 | return userCheckAccountBalanceResponseDto; 140 | } 141 | 142 | @Override 143 | public boolean transferFunds(UserTransferFundsRequestDto userTransferFundsRequestDto, String authentication) throws AuthorizationException, GeneralServiceException, MessagingException { 144 | 145 | String userEmail = userPrincipalService.getUserEmailAddressFromToken(authentication); 146 | 147 | Optional user = userRepository.findUserByEmail(userEmail); 148 | if (user.isEmpty()) { 149 | throw new AuthorizationException(USER_NOT_FOUND); 150 | } 151 | 152 | Optional sourceAccountNumberAndSortCode = userAccountRepository. 153 | findBySortCodeAndAccountNumber(userTransferFundsRequestDto.getSourceAccount().getSortCode(), 154 | userTransferFundsRequestDto.getSourceAccount().getAccountNumber()); 155 | 156 | Optional targetAccountNumberAndSortCode = userAccountRepository. 157 | findBySortCodeAndAccountNumber(userTransferFundsRequestDto.getTargetAccount().getSortCode(), 158 | userTransferFundsRequestDto.getTargetAccount().getAccountNumber()); 159 | 160 | if (sourceAccountNumberAndSortCode.isPresent() || !sourceAccountNumberAndSortCode.isEmpty() 161 | && targetAccountNumberAndSortCode.isPresent() || !targetAccountNumberAndSortCode.isEmpty()){ 162 | throw new GeneralServiceException("source and target account number does not exist"); 163 | } 164 | 165 | UserAccount accountSourceNumAndCode = sourceAccountNumberAndSortCode.get(); 166 | UserAccount accountTargetNumAndCode = targetAccountNumberAndSortCode.get(); 167 | 168 | isAmountAvailable(userTransferFundsRequestDto.getAmount(), accountSourceNumAndCode.getCurrentBalance()); 169 | 170 | Transaction transaction = new Transaction(); 171 | 172 | transaction.setAmount(userTransferFundsRequestDto.getAmount()); 173 | transaction.setSourceAccountId(accountSourceNumAndCode.getId()); 174 | transaction.setTargetAccountId(accountTargetNumAndCode.getId()); 175 | transaction.setTargetOwnerName(accountTargetNumAndCode.getOwnerName()); 176 | transaction.setInitiationDate(LocalDateTime.now()); 177 | transaction.setCompletionDate(LocalDateTime.now()); 178 | transaction.setReference(userTransferFundsRequestDto.getReference()); 179 | transaction.setTargetEmail(userTransferFundsRequestDto.getTargetEmail()); 180 | transaction.setUserEntity(user.get()); 181 | 182 | updateAccountBalance(sourceAccountNumberAndSortCode.get(),userTransferFundsRequestDto.getAmount(), 183 | Usage.TRANSFER); 184 | 185 | updateAccountBalance(targetAccountNumberAndSortCode.get(),userTransferFundsRequestDto.getAmount(), 186 | Usage.DEPOSIT); 187 | 188 | emailService.sendTransactionSuccessfulMessage(transaction,user.get()); 189 | 190 | emailService.sendAlertReceivedMessage(transaction); 191 | transactionRepository.save(transaction); 192 | log.info(transaction.toString()); 193 | 194 | return true; 195 | 196 | } 197 | 198 | @Override 199 | public boolean depositFunds(UserDepositsFundsRequestDto userDepositsFundsRequestDto, String authentication) throws AuthorizationException, GeneralServiceException, MessagingException { 200 | 201 | String userEmail = userPrincipalService.getUserEmailAddressFromToken(authentication); 202 | 203 | Optional user = userRepository.findUserByEmail(userEmail); 204 | if (user.isEmpty()) { 205 | throw new AuthorizationException(USER_NOT_FOUND); 206 | } 207 | 208 | Optional account = userAccountRepository.findByAccountNumber 209 | (userDepositsFundsRequestDto.getTargetAccountNo()); 210 | 211 | if (account.isEmpty()){ 212 | throw new GeneralServiceException("Account does not exist"); 213 | } 214 | 215 | updateAccountBalance(account.get(),userDepositsFundsRequestDto.getAmount(),Usage.DEPOSIT); 216 | 217 | emailService.sendDepositSuccessfulMessage(user.get(),account.get()); 218 | 219 | return true; 220 | } 221 | 222 | @Override 223 | public boolean withdrawFunds(UserWithdrawFundsRequestDto userWithdrawFundsRequestDto, String authentication) throws AuthorizationException, GeneralServiceException, MessagingException { 224 | 225 | String userEmail = userPrincipalService.getUserEmailAddressFromToken(authentication); 226 | 227 | Optional user = userRepository.findUserByEmail(userEmail); 228 | if (user.isEmpty()) { 229 | throw new AuthorizationException(USER_NOT_FOUND); 230 | } 231 | 232 | UserAccount account = getAccountByDate(userWithdrawFundsRequestDto.getSortCode(), 233 | userWithdrawFundsRequestDto.getAccountNumber()); 234 | 235 | if (account == null){ 236 | throw new GeneralServiceException("Account does not exist"); 237 | } 238 | 239 | isAmountAvailable(userWithdrawFundsRequestDto.getAmount(),account.getCurrentBalance()); 240 | updateAccountBalance(account,userWithdrawFundsRequestDto.getAmount(), Usage.WITHDRAW); 241 | 242 | emailService.sendWithdrawSuccessfulMessage(user.get(),account); 243 | 244 | return true; 245 | } 246 | 247 | @Override 248 | public UserCompliantFormResponseDto usersCompliant(String loginToken,UserCompliantFormRequestDto userCompliantFormRequestDto) throws AuthorizationException, GeneralServiceException, MessagingException, ImageUploadException { 249 | 250 | String userEmail=userPrincipalService.getUserEmailAddressFromToken(loginToken); 251 | 252 | CustomerCompliantForm customerCompliantForm = new CustomerCompliantForm(); 253 | 254 | Optional user = userRepository.findUserByEmail(userEmail); 255 | 256 | modelMapper.map(userCompliantFormRequestDto,customerCompliantForm); 257 | 258 | if(user.isEmpty()) { 259 | throw new GeneralServiceException("Bank user must create an account before scheduling a section"); 260 | } 261 | customerCompliantForm.setUser(user.get()); 262 | 263 | customerCompliantForm.setTitle(userCompliantFormRequestDto.getTitle()); 264 | customerCompliantForm.setDescription(userCompliantFormRequestDto.getDescription()); 265 | customerCompliantForm.setModeOfMeeting(userCompliantFormRequestDto.getModeOfMeeting()); 266 | customerCompliantForm.setImage1(imageUrlFromCloudinary(userCompliantFormRequestDto.getImage1())); 267 | customerCompliantForm.setImage2(imageUrlFromCloudinary(userCompliantFormRequestDto.getImage2())); 268 | customerCompliantForm.setImage3(imageUrlFromCloudinary(userCompliantFormRequestDto.getImage3())); 269 | 270 | ZoneId zone = ZoneId.of("Africa/Lagos"); 271 | 272 | Instant now = Instant.now(Clock.system(zone)); 273 | Instant expirationTime = now.plus(Duration.ofDays(userCompliantFormRequestDto.getCustomerCompliantDaysLength().getDays())) 274 | .plus(Duration.ofHours(userCompliantFormRequestDto.getCustomerCompliantDaysLength().getHours())); 275 | 276 | customerCompliantForm.setExpirationDate(expirationTime); 277 | 278 | //email here 279 | emailService.sendCompliantNotification(customerCompliantForm); 280 | 281 | compliantFormRepository.save(customerCompliantForm); 282 | 283 | UserCompliantFormResponseDto userCompliantFormResponseDto = new UserCompliantFormResponseDto(); 284 | 285 | modelMapper.map(userCompliantFormRequestDto,userCompliantFormResponseDto); 286 | 287 | return userCompliantFormResponseDto; 288 | } 289 | 290 | @Override 291 | public TransactionListResponseDto listTransactions(String loginToken, int page, int size) throws AuthorizationException { 292 | 293 | //confirmUserToken 294 | userPrincipalService.getUserEmailAddressFromToken(loginToken); 295 | //create pageable 296 | Pageable pageable= PageRequest.of((page-1),size); 297 | //find all return page 298 | Page transactions = transactionRepository.findAll(pageable); 299 | //get total size of list 300 | int totalSizeOfList=transactionRepository.findAll().size(); 301 | //get the contents from page 302 | List transactionList= transactions.getContent(); 303 | //create a dto list for contents 304 | List transactionResponseDtoList= new ArrayList<>(); 305 | 306 | for (Transaction transaction: transactionList){ 307 | 308 | TransactionResponseDto transactionResponseDto = new TransactionResponseDto(); 309 | //map content to dtos 310 | modelMapper.map(transaction,transactionResponseDto); 311 | //add dto to dto list 312 | transactionResponseDtoList.add(transactionResponseDto); 313 | } 314 | //create response object 315 | TransactionListResponseDto transactionListResponseDto = new TransactionListResponseDto(); 316 | //set data into response object 317 | transactionListResponseDto.setTransactionResponseDtoList(transactionResponseDtoList); 318 | //set data into response object 319 | transactionListResponseDto.setSizeOfList(totalSizeOfList); 320 | //return response object 321 | return transactionListResponseDto; 322 | } 323 | 324 | private String imageUrlFromCloudinary(MultipartFile image) throws ImageUploadException { 325 | String imageUrl=""; 326 | if(image!=null && !image.isEmpty()){ 327 | Map params=new HashMap<>(); 328 | params.put("public_id","BANK/"+extractFileName(image.getName())); 329 | params.put("overwrite",true); 330 | 331 | try{ 332 | Map uploadResult = cloudStorageService.uploadImage(image,params); 333 | imageUrl= String.valueOf(uploadResult.get("url")); 334 | }catch (IOException e){ 335 | e.printStackTrace(); 336 | throw new ImageUploadException("Error uploading images,file upload failed"); 337 | } 338 | } 339 | return imageUrl; 340 | } 341 | 342 | private String extractFileName(String fileName){ 343 | return fileName.split("\\.")[0]; 344 | } 345 | 346 | public UserAccount createAccounts(String bankName, String ownerName) { 347 | UserAccountGeneratorDto codeGenerator = new UserAccountGeneratorDto(); 348 | UserAccount newAccount = new UserAccount(bankName, ownerName, codeGenerator.generateSortCode(), codeGenerator.generateAccountNumber(), 0.00); 349 | // Maybe i need to map it 350 | return newAccount; 351 | } 352 | 353 | private UserAccount getAccountByDate(String sortCode, String accountNumber) throws GeneralServiceException { 354 | Optional account = userAccountRepository 355 | .findBySortCodeAndAccountNumber(sortCode, accountNumber); 356 | 357 | account.ifPresent(value -> 358 | value.setTransactionList(transactionRepository 359 | .findBySourceAccountIdOrderByInitiationDate(value.getId()))); 360 | 361 | // return account.orElse(null); 362 | 363 | if (account.isEmpty()){ 364 | throw new GeneralServiceException("Account is null"); 365 | } 366 | return account.get(); 367 | } 368 | 369 | @Override 370 | public UserAccount getAccount(String accountNumber) { 371 | Optional account = userAccountRepository 372 | .findByAccountNumber(accountNumber); 373 | 374 | return account.orElse(null); 375 | } 376 | 377 | 378 | 379 | public void updateAccountBalance(UserAccount account, double amount, Usage action) { 380 | if (action == Usage.TRANSFER){ 381 | account.setCurrentBalance(account.getCurrentBalance() - amount - 10); 382 | //10 naira is the extra charges for the transfer 383 | } 384 | else if (action == Usage.WITHDRAW) { 385 | account.setCurrentBalance((account.getCurrentBalance() - amount)); 386 | } else if (action == Usage.DEPOSIT) { 387 | account.setCurrentBalance((account.getCurrentBalance() + amount)); 388 | } 389 | userAccountRepository.save(account); 390 | log.info(account.toString()); 391 | } 392 | 393 | public boolean isAmountAvailable(double amount, double accountBalance) { 394 | return (accountBalance - amount) > 0; 395 | } 396 | } 397 | 398 | 399 | 400 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/service/transactionService/TransactionServices.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.service.transactionService; 2 | 3 | import koredebank.example.bank.dto.*; 4 | import koredebank.example.bank.model.UserAccount; 5 | import koredebank.example.bank.security.exceptions.AccountCreationException; 6 | import koredebank.example.bank.security.exceptions.AuthorizationException; 7 | import koredebank.example.bank.security.exceptions.GeneralServiceException; 8 | import koredebank.example.bank.security.exceptions.ImageUploadException; 9 | 10 | import javax.mail.MessagingException; 11 | 12 | public interface TransactionServices { 13 | 14 | UserCreateAccountResponseDto createAccounts(UserCreateAccountRequestDto userCreateAccountRequestDto, String authentication) throws AccountCreationException, AuthorizationException, MessagingException; 15 | 16 | UserCheckAccountBalanceResponseDto checkAccBalance(UserCheckAccountBalanceRequestDto userCheckAccountBalanceRequestDto, String authentication) throws AccountCreationException, AuthorizationException, MessagingException, GeneralServiceException; 17 | 18 | boolean transferFunds(UserTransferFundsRequestDto userTransferFundsRequestDto, String authentication) throws AuthorizationException, GeneralServiceException, MessagingException; 19 | 20 | boolean depositFunds(UserDepositsFundsRequestDto userDepositsFundsRequestDto,String authentication) throws AuthorizationException, GeneralServiceException, MessagingException; 21 | 22 | boolean withdrawFunds(UserWithdrawFundsRequestDto userWithdrawFundsRequestDto,String authentication) throws AuthorizationException, GeneralServiceException, MessagingException; 23 | 24 | UserCompliantFormResponseDto usersCompliant(String loginToken, UserCompliantFormRequestDto userCompliantFormRequestDto) throws AuthorizationException, GeneralServiceException, MessagingException, ImageUploadException; 25 | 26 | TransactionListResponseDto listTransactions(String loginToken, int page, int size) throws AuthorizationException; 27 | 28 | UserAccount getAccount(String accountNumber); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/service/userService/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.service.userService; 2 | 3 | import koredebank.example.bank.Email.EmailService; 4 | import koredebank.example.bank.cloudinaryService.CloudStorageService; 5 | import koredebank.example.bank.dto.*; 6 | import koredebank.example.bank.model.*; 7 | import koredebank.example.bank.payload.UserAccountGeneratorDto; 8 | import koredebank.example.bank.repository.*; 9 | import koredebank.example.bank.security.exceptions.*; 10 | import koredebank.example.bank.security.securityServices.UserPrincipalService; 11 | import koredebank.example.bank.security.securityUtils.JWTToken; 12 | import koredebank.example.bank.serviceUtil.IdGenerator; 13 | import koredebank.example.bank.serviceUtil.StringUtil; 14 | import lombok.extern.slf4j.Slf4j; 15 | import org.modelmapper.ModelMapper; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.data.domain.Page; 18 | import org.springframework.data.domain.PageRequest; 19 | import org.springframework.data.domain.Pageable; 20 | import org.springframework.security.crypto.password.PasswordEncoder; 21 | import org.springframework.stereotype.Service; 22 | import org.springframework.transaction.annotation.Transactional; 23 | import org.springframework.web.multipart.MultipartFile; 24 | 25 | import javax.mail.MessagingException; 26 | import java.io.IOException; 27 | import java.time.*; 28 | import java.util.*; 29 | 30 | @Slf4j 31 | @Service 32 | public class UserServiceImpl implements UserServices { 33 | 34 | @Autowired 35 | private UserRepository userRepository; 36 | 37 | @Autowired 38 | UserAccountRepository userAccountRepository; 39 | 40 | @Autowired 41 | TransactionRepository transactionRepository; 42 | 43 | @Autowired 44 | CustomerCompliantFormRepository compliantFormRepository; 45 | 46 | @Autowired 47 | private ModelMapper modelMapper; 48 | 49 | @Autowired 50 | CloudStorageService cloudStorageService; 51 | 52 | @Autowired 53 | private PasswordEncoder passwordEncoder; 54 | 55 | @Autowired 56 | EmailService emailService; 57 | 58 | @Autowired 59 | UserPrincipalService userPrincipalService; 60 | 61 | 62 | private static final String USER_NOT_FOUND = "User not found"; 63 | 64 | @Override 65 | public UserLoginResponseDto login(UserLoginDto userLoginDto) throws IncorrectPasswordException, GeneralServiceException { 66 | UserLoginResponseDto userLoginResponseDto=new UserLoginResponseDto(); 67 | JWTToken jwtToken= userPrincipalService.loginUser(userLoginDto); 68 | if(jwtToken!=null){ 69 | Optional usersEntity=userRepository.findUserByEmail(userLoginDto.getEmail()); 70 | if(usersEntity.isPresent()) { 71 | if (!usersEntity.get().getEnabled()) { 72 | throw new GeneralServiceException("User account has not been activated"); 73 | } 74 | } 75 | usersEntity.ifPresent(entity -> modelMapper.map(entity, userLoginResponseDto)); 76 | userLoginResponseDto.setToken(jwtToken); 77 | } 78 | return userLoginResponseDto; 79 | 80 | } 81 | 82 | @Transactional 83 | @Override 84 | public UserSignUpResponseDto signUp(UserSignUpRequestDto userSignUpRequestDto) throws GeneralServiceException, AccountCreationException, MessagingException { 85 | checkAllParameters(userSignUpRequestDto); 86 | 87 | userWithEmailExists(userSignUpRequestDto); 88 | 89 | UserEntity users= createUserEntityFromDetails(userSignUpRequestDto); 90 | 91 | String confirmation=userPrincipalService.sendRegistrationToken(users); 92 | 93 | users.setValidationToken(confirmation); 94 | 95 | emailService.sendRegistrationSuccessfulEmail(users, confirmation); 96 | 97 | log.info(confirmation); 98 | 99 | userRepository.save(users); 100 | 101 | return generateRegistrationResponse(userSignUpRequestDto, users.getId()); 102 | } 103 | 104 | @Override 105 | public boolean validateUserAccount(UserLoginValidationRequestDto userLoginValidationRequestDto) throws AccountCreationException, GeneralServiceException, MessagingException { 106 | if(StringUtil.isBlank(userLoginValidationRequestDto.getEmail())){ 107 | throw new GeneralServiceException("Email cannot be empty"); 108 | } 109 | Optional usersEntity=userRepository.findUserByEmail(userLoginValidationRequestDto.getEmail()); 110 | if(usersEntity.isPresent()){ 111 | if(usersEntity.get().getValidationToken().equals(userLoginValidationRequestDto.getToken())){ 112 | usersEntity.get().setEnabled(true); 113 | usersEntity.get().setValidationToken(null); 114 | 115 | log.info(usersEntity.get().getPassword()); 116 | emailService.sendVerificationMessage(usersEntity); 117 | userRepository.save(usersEntity.get()); 118 | return true; 119 | }else { 120 | throw new GeneralServiceException("Invalid validation token"); 121 | } 122 | } 123 | throw new GeneralServiceException("User With this email does not exist"); 124 | } 125 | 126 | @Override 127 | public boolean userChangePassword(UserChangePasswordRequestDto userChangePasswordRequestDto, String authentication) throws AuthorizationException, GeneralServiceException, MessagingException { 128 | 129 | String userEmail = userPrincipalService.getUserEmailAddressFromToken(authentication); 130 | 131 | if (!userChangePasswordRequestDto.getNewPassword().equals(userChangePasswordRequestDto.getConfirmPassword())) { 132 | throw new GeneralServiceException("New Passwords do not match"); 133 | } 134 | 135 | Optional user = userRepository.findUserByEmail(userEmail); 136 | if (user.isEmpty()) { 137 | throw new GeneralServiceException(USER_NOT_FOUND); 138 | } 139 | 140 | boolean matches = userPrincipalService.passwordMatches( 141 | userChangePasswordRequestDto.getOldPassword(),user.get().getPassword()); 142 | 143 | if (!matches) { 144 | throw new GeneralServiceException("Old password is incorrect"); 145 | }else 146 | user.get().setPassword(passwordEncoder.encode(userChangePasswordRequestDto.getNewPassword())); 147 | 148 | emailService.sendChangePasswordMessage(Optional.of(user.get())); 149 | 150 | userRepository.save(user.get()); 151 | 152 | return true; 153 | } 154 | 155 | @Override 156 | public boolean userForgotPassword(UserForgotPasswordRequestDto userForgotPasswordRequestDto) throws GeneralServiceException, MessagingException, AuthorizationException { 157 | if(StringUtil.isBlank(userForgotPasswordRequestDto.getEmail())){ 158 | throw new GeneralServiceException("Email cannot be empty!"); 159 | } 160 | Optional optionalBaseUser = userRepository.findUserByEmail(userForgotPasswordRequestDto.getEmail()); 161 | if (optionalBaseUser.isEmpty()) { 162 | throw new GeneralServiceException("No such user exists!"); 163 | } 164 | 165 | String confirmation=userPrincipalService.sendRecoveryToken(optionalBaseUser.get()); 166 | 167 | optionalBaseUser.get().setValidationToken(confirmation); 168 | 169 | 170 | emailService.sendForgotPasswordMessage(optionalBaseUser.get(),confirmation); 171 | //persist 172 | userRepository.save(optionalBaseUser.get()); 173 | return true; 174 | } 175 | 176 | @Override 177 | public boolean validateForgotTokenAndNewForgotPassword(UserRetrieveForgotPasswordRequestDto userRetrieveForgotPasswordRequestDto) throws GeneralServiceException, MessagingException, AuthorizationException { 178 | 179 | if(StringUtil.isBlank(userRetrieveForgotPasswordRequestDto.getEmail())){ 180 | throw new GeneralServiceException("Email cannot be empty"); 181 | } 182 | if (!userRetrieveForgotPasswordRequestDto.getNewPassword().equals(userRetrieveForgotPasswordRequestDto.getConfirmPassword())) { 183 | throw new GeneralServiceException("New Passwords do not match"); 184 | } 185 | Optional users = userRepository.findUserByEmail(userRetrieveForgotPasswordRequestDto.getEmail()); 186 | if (users.isPresent()){ 187 | if (users.get().getValidationToken().equals(userRetrieveForgotPasswordRequestDto.getToken())){ 188 | users.get().setEnabled(true); 189 | users.get().setValidationToken(null); 190 | 191 | users.get().setPassword(passwordEncoder.encode(userRetrieveForgotPasswordRequestDto.getNewPassword())); 192 | 193 | emailService.sendVerificationMessage(users); 194 | userRepository.save(users.get()); 195 | return true; 196 | }else { 197 | throw new GeneralServiceException("Invalid validation token"); 198 | } 199 | } 200 | throw new GeneralServiceException("User With this email does not exist"); 201 | } 202 | 203 | 204 | private UserSignUpResponseDto generateRegistrationResponse(UserSignUpRequestDto userSignUpRequestDto,String id){ 205 | UserSignUpResponseDto userSignUpResponseDto=new UserSignUpResponseDto(); 206 | 207 | modelMapper.map(userSignUpRequestDto,userSignUpResponseDto); 208 | 209 | userSignUpResponseDto.setId(id); 210 | userSignUpResponseDto.setRole(Roles.BASE_USER); 211 | 212 | return userSignUpResponseDto; 213 | } 214 | 215 | private UserEntity createUserEntityFromDetails(UserSignUpRequestDto userSignUpRequestDto){ 216 | UserEntity userEntity = new UserEntity(); 217 | modelMapper.map(userSignUpRequestDto, userEntity); 218 | String password=passwordEncoder.encode(userSignUpRequestDto.getPassword()); 219 | userEntity.setPassword(password); 220 | userEntity.setId(IdGenerator.generateId()); 221 | userEntity.setCreatedAt(Instant.now()); 222 | userEntity.setRoles(Roles.BASE_USER); 223 | return userEntity; 224 | } 225 | 226 | private void checkAllParameters(UserSignUpRequestDto userSignUpRequestDto) throws AccountCreationException { 227 | 228 | if(StringUtil.isBlank(userSignUpRequestDto.getFirstName())){ 229 | throw new AccountCreationException("FirstName Cannot be empty"); 230 | } 231 | if(StringUtil.isBlank(userSignUpRequestDto.getLastName())){ 232 | throw new AccountCreationException("LastName Cannot be empty"); 233 | } 234 | if(StringUtil.isBlank(userSignUpRequestDto.getPhoneNumber())){ 235 | throw new AccountCreationException("Phone number Cannot be empty"); 236 | } 237 | if(StringUtil.isBlank(userSignUpRequestDto.getEmail())){ 238 | throw new AccountCreationException("Email Cannot be empty"); 239 | } 240 | if(StringUtil.isBlank(userSignUpRequestDto.getPassword())){ 241 | throw new AccountCreationException("Password Cannot be empty"); 242 | } 243 | if(StringUtil.isBlank(userSignUpRequestDto.getConfirmPassword())){ 244 | throw new AccountCreationException("Confirm Password Cannot be empty"); 245 | } 246 | if(!(userSignUpRequestDto.getConfirmPassword().equals(userSignUpRequestDto.getPassword()))){ 247 | throw new AccountCreationException("Passwords do not match"); 248 | } 249 | 250 | } 251 | private void userWithEmailExists(UserSignUpRequestDto userSignUpRequestDto) throws AccountCreationException { 252 | 253 | Optional userByEmail = userRepository.findUserByEmail(userSignUpRequestDto.getEmail()); 254 | if(userByEmail.isPresent()){ 255 | throw new AccountCreationException("Users with this email already exists"); 256 | } 257 | 258 | } 259 | 260 | 261 | private String imageUrlFromCloudinary(MultipartFile image) throws ImageUploadException { 262 | String imageUrl=""; 263 | if(image!=null && !image.isEmpty()){ 264 | Map params=new HashMap<>(); 265 | params.put("public_id","BANK/"+extractFileName(image.getName())); 266 | params.put("overwrite",true); 267 | 268 | try{ 269 | Map uploadResult = cloudStorageService.uploadImage(image,params); 270 | imageUrl= String.valueOf(uploadResult.get("url")); 271 | }catch (IOException e){ 272 | e.printStackTrace(); 273 | throw new ImageUploadException("Error uploading images,file upload failed"); 274 | } 275 | } 276 | return imageUrl; 277 | } 278 | 279 | private String extractFileName(String fileName){ 280 | return fileName.split("\\.")[0]; 281 | } 282 | 283 | } 284 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/service/userService/UserServices.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.service.userService; 2 | 3 | import koredebank.example.bank.dto.*; 4 | import koredebank.example.bank.model.Transaction; 5 | import koredebank.example.bank.model.UserAccount; 6 | import koredebank.example.bank.security.exceptions.*; 7 | 8 | import javax.mail.MessagingException; 9 | import java.util.List; 10 | import java.util.Optional; 11 | 12 | public interface UserServices { 13 | 14 | UserLoginResponseDto login(UserLoginDto userLoginDto) throws IncorrectPasswordException, GeneralServiceException; 15 | 16 | UserSignUpResponseDto signUp(UserSignUpRequestDto userSignUpRequestDto) throws GeneralServiceException, AccountCreationException, MessagingException; 17 | 18 | boolean validateUserAccount(UserLoginValidationRequestDto userLoginValidationRequestDto) throws AccountCreationException, GeneralServiceException, MessagingException; 19 | 20 | boolean userChangePassword(UserChangePasswordRequestDto userChangePasswordRequestDto, String authentication) throws AuthorizationException, GeneralServiceException, MessagingException; 21 | 22 | boolean userForgotPassword(UserForgotPasswordRequestDto userForgotPasswordRequestDto) throws GeneralServiceException, MessagingException, AuthorizationException; 23 | 24 | boolean validateForgotTokenAndNewForgotPassword(UserRetrieveForgotPasswordRequestDto userRetrieveForgotPasswordRequestDto) throws GeneralServiceException, MessagingException, AuthorizationException; 25 | 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/serviceUtil/IdGenerator.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.serviceUtil; 2 | 3 | import java.util.UUID; 4 | 5 | public class IdGenerator { 6 | public static String generateId(){ 7 | UUID id=UUID.randomUUID(); 8 | return id.toString(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/serviceUtil/StringUtil.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.serviceUtil; 2 | 3 | public class StringUtil { 4 | public static boolean isNotBlank(String value) { 5 | if(value.isBlank() || value.isEmpty()){ 6 | return false; 7 | } 8 | return true; 9 | } 10 | public static boolean isBlank(String value) { 11 | if(value.isBlank() || value.isEmpty()){ 12 | return true; 13 | } 14 | return false; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/tool/AccountGenerator.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.tool; 2 | 3 | import com.mifmif.common.regex.Generex; 4 | 5 | import static koredebank.example.bank.util.constants.ACCOUNT_NUMBER_PATTERN_STRING; 6 | import static koredebank.example.bank.util.constants.SORT_CODE_PATTERN_STRING; 7 | 8 | public class AccountGenerator { 9 | 10 | Generex sortCodeGenerex = new Generex(SORT_CODE_PATTERN_STRING); 11 | Generex accountNumberGenerex = new Generex(ACCOUNT_NUMBER_PATTERN_STRING); 12 | 13 | public AccountGenerator() { 14 | } 15 | 16 | public String generateSortCode(){ 17 | return sortCodeGenerex.random(); 18 | } 19 | 20 | public String generateAccountNumber(){ 21 | return accountNumberGenerex.random(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/util/ApiRoutes.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.util; 2 | 3 | public class ApiRoutes { 4 | public static final String BANK="/bank"; 5 | public static final String ACCOUNTMANAGER="/accountManager"; 6 | public static final String User="/user"; 7 | 8 | public static final String Transaction= "/transaction"; 9 | } 10 | 11 | 12 | //Reduce api character length -------------------------------------------------------------------------------- /src/main/java/koredebank/example/bank/util/constants.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank.util; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | public class constants { 6 | 7 | //THERE IS NOTHING LIKE SORTCODE IN MY BOOK 8 | 9 | public static final String SUCCESS = 10 | "Operation completed successfully"; 11 | public static final String NO_ACCOUNT_FOUND = 12 | "Unable to find an account matching this sort code and account number"; 13 | public static final String INVALID_SEARCH_CRITERIA = 14 | "The provided sort code or account number did not match the expected format"; 15 | 16 | public static final String INSUFFICIENT_ACCOUNT_BALANCE = 17 | "Your account does not have sufficient balance"; 18 | 19 | public static final String SORT_CODE_PATTERN_STRING = "[0-9]{2}-[0-9]{2}-[0-9]{2}"; 20 | 21 | public static final String ACCOUNT_NUMBER_PATTERN_STRING = "[0-9]{8}"; 22 | public static final Pattern SORT_CODE_PATTERN = Pattern.compile("^[0-9]{2}-[0-9]{2}-[0-9]{2}$"); 23 | public static final Pattern ACCOUNT_NUMBER_PATTERN = Pattern.compile("^[0-9]{8}$"); 24 | 25 | public static final String INVALID_TRANSACTION = "Account information is invalid or transaction " + 26 | "has been denied for your protection. Please try again."; 27 | public static final String CREATE_ACCOUNT_FAILED = "Error happened during creating new account"; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.datasource.url=jdbc:postgresql://localhost:5432/Bank 3 | spring.datasource.username=postgres 4 | spring.datasource.password=korede345 5 | spring.datasource.driver-class-name=org.postgresql.Driver 6 | spring.jpa.hibernate.ddl-auto=update 7 | spring.sql.init.mode=always 8 | 9 | #THINGS THAT I ADDED IN THE APPLICATION 10 | spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect 11 | spring.jpa.show-sql=true 12 | 13 | CLOUD_NAME=salamikehindekorede 14 | API_KEY=824596511688537 15 | API_SECRET=V_VrhWmDSiBriMyB7hzhFUzc2_Y 16 | 17 | 18 | 19 | #JAVA-MAIL--new 20 | spring.mail.host= smtp.gmail.com 21 | spring.mail.username = salamikehinde345@gmail.com 22 | spring.mail.password = mnleavpjahctykpc 23 | #spring.mail.password = salami345 24 | spring.mail.port = 587 25 | #spring.mail.properties.mail.smtp.starttls.enable = true 26 | 27 | 28 | # Other smtp properties 29 | spring.mail.properties.mail.transport.protocol=smtp 30 | spring.mail.properties.mail.smtp.auth=true 31 | spring.mail.properties.mail.smtp.connectiontimeout=5000 32 | spring.mail.properties.mail.smtp.timeout=5000 33 | spring.mail.properties.mail.smtp.writetimeout=5000 34 | 35 | # TLS port 587 36 | spring.mail.properties.mail.smtp.starttls.enable=true -------------------------------------------------------------------------------- /src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://${PROD_DB_HOST}:${PROD_DB_PORT}/${PROD_DB_NAME} 2 | spring.datasource.username=${PROD_DB_USERNAME} 3 | spring.datasource.password=${PROD_DB_PASSWORD} 4 | spring.datasource.name=spring-bank-app 5 | 6 | CLOUD_NAME=salamikehindekorede 7 | API_KEY=824596511688537 8 | API_SECRET=V_VrhWmDSiBriMyB7hzhFUzc2_Y 9 | 10 | #JAVA-MAIL--new 11 | spring.mail.host= smtp.gmail.com 12 | spring.mail.username = salamikehinde345@gmail.com 13 | spring.mail.password = mnleavpjahctykpc 14 | #spring.mail.password = salami345 15 | spring.mail.port = 587 16 | #spring.mail.properties.mail.smtp.starttls.enable = true 17 | 18 | 19 | # Other smtp properties 20 | spring.mail.properties.mail.transport.protocol=smtp 21 | spring.mail.properties.mail.smtp.auth=true 22 | spring.mail.properties.mail.smtp.connectiontimeout=5000 23 | spring.mail.properties.mail.smtp.timeout=5000 24 | spring.mail.properties.mail.smtp.writetimeout=5000 25 | 26 | # TLS port 587 27 | spring.mail.properties.mail.smtp.starttls.enable=true -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | info.application.name=spring-bank-app 2 | info.application.description=An app that replicates conventional banks 3 | info.application.author=Salami Korede 4 | info.application.version=@project.version@ 5 | spring.profiles.active=dev -------------------------------------------------------------------------------- /src/test/java/koredebank/example/bank/BankApplicationTests.java: -------------------------------------------------------------------------------- 1 | package koredebank.example.bank; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BankApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /system.properties: -------------------------------------------------------------------------------- 1 | java.runtime.version=17 --------------------------------------------------------------------------------