├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── kodlamaio │ │ └── bootcampproject │ │ ├── BootcampProjectApplication.java │ │ ├── api │ │ └── controllers │ │ │ ├── AuthController.java │ │ │ ├── applications │ │ │ ├── ApplicationsController.java │ │ │ └── BlackListsController.java │ │ │ ├── bootcamps │ │ │ └── BootcampsController.java │ │ │ └── users │ │ │ ├── ApplicantsController.java │ │ │ ├── EmployeesController.java │ │ │ └── InstructorsController.java │ │ ├── business │ │ ├── abstracts │ │ │ ├── BlackListService.java │ │ │ ├── BootcampService.java │ │ │ ├── applications │ │ │ │ └── ApplicationService.java │ │ │ └── users │ │ │ │ ├── ApplicantService.java │ │ │ │ ├── EmployeeService.java │ │ │ │ └── InstructorService.java │ │ ├── concretes │ │ │ ├── BlackListManager.java │ │ │ ├── BootcampManager.java │ │ │ ├── applications │ │ │ │ └── ApplicationManager.java │ │ │ └── users │ │ │ │ ├── ApplicantManager.java │ │ │ │ ├── EmployeeManager.java │ │ │ │ ├── InstructorManager.java │ │ │ │ └── UserDetailManager.java │ │ ├── constants │ │ │ └── Messages.java │ │ ├── requests │ │ │ ├── applications │ │ │ │ ├── CreateApplicationRequest.java │ │ │ │ └── UpdateApplicationRequest.java │ │ │ ├── blacklists │ │ │ │ ├── CreateBlackListRequest.java │ │ │ │ └── UpdateBlackListRequest.java │ │ │ ├── bootcamps │ │ │ │ ├── CreateBootcampRequest.java │ │ │ │ └── UpdateBootcampRequest.java │ │ │ └── users │ │ │ │ ├── UserLoginRequest.java │ │ │ │ ├── UserRegisterRequest.java │ │ │ │ ├── applicants │ │ │ │ ├── CreateApplicantRequest.java │ │ │ │ └── UpdateApplicantRequest.java │ │ │ │ ├── employees │ │ │ │ ├── CreateEmployeeRequest.java │ │ │ │ └── UpdateEmployeeRequest.java │ │ │ │ └── instructors │ │ │ │ ├── CreateInstructorRequest.java │ │ │ │ └── UpdateInstructorRequest.java │ │ └── responses │ │ │ ├── applications │ │ │ ├── CreateApplicationResponse.java │ │ │ ├── GetAllApplicationsResponse.java │ │ │ ├── GetApplicationResponse.java │ │ │ └── UpdateApplicationResponse.java │ │ │ ├── blacklists │ │ │ ├── CreateBlackListResponse.java │ │ │ ├── GetAllBlackListsResponse.java │ │ │ ├── GetBlackListResponse.java │ │ │ └── UpdateBlackListResponse.java │ │ │ ├── bootcamps │ │ │ ├── CreateBootcampResponse.java │ │ │ ├── GetAllBootcampResponse.java │ │ │ ├── GetBootcampResponse.java │ │ │ └── UpdateBootcampResponse.java │ │ │ └── users │ │ │ ├── applicants │ │ │ ├── CreateApplicantResponse.java │ │ │ ├── GetAllApplicantsResponse.java │ │ │ ├── GetApplicantResponse.java │ │ │ └── UpdateApplicantResponse.java │ │ │ ├── employees │ │ │ ├── CreateEmployeeResponse.java │ │ │ ├── GetAllEmployeesResponse.java │ │ │ ├── GetEmployeeResponse.java │ │ │ └── UpdateEmployeeResponse.java │ │ │ └── instructors │ │ │ ├── CreateInstructorResponse.java │ │ │ ├── GetAllInstructorsResponse.java │ │ │ ├── GetInstructorResponse.java │ │ │ └── UpdateInstructorResponse.java │ │ ├── config │ │ ├── cors │ │ │ └── CorsConfig.java │ │ ├── modelmapper │ │ │ └── ModelMapperConfig.java │ │ └── security │ │ │ └── SecurityConfig.java │ │ ├── core │ │ └── utilities │ │ │ ├── exceptions │ │ │ ├── BusinessException.java │ │ │ └── RestResponseEntityExceptionHandler.java │ │ │ ├── mapping │ │ │ ├── ModelMapperManager.java │ │ │ └── ModelMapperService.java │ │ │ └── results │ │ │ ├── DataResult.java │ │ │ ├── ErrorDataResult.java │ │ │ ├── ErrorResult.java │ │ │ ├── Result.java │ │ │ ├── SuccessDataResult.java │ │ │ └── SuccessResult.java │ │ ├── dataAccess │ │ └── abstracts │ │ │ ├── BlackListRepository.java │ │ │ ├── BootcampRepository.java │ │ │ ├── applications │ │ │ └── ApplicationRepository.java │ │ │ └── users │ │ │ ├── ApplicantRepository.java │ │ │ ├── EmployeeRepository.java │ │ │ ├── InstructorRepository.java │ │ │ └── UserRepository.java │ │ ├── entities │ │ ├── BlackList.java │ │ ├── Bootcamp.java │ │ ├── applications │ │ │ └── Application.java │ │ └── users │ │ │ ├── Applicant.java │ │ │ ├── Employee.java │ │ │ ├── Instructor.java │ │ │ ├── Role.java │ │ │ └── User.java │ │ └── security │ │ ├── ApplicationUser.java │ │ ├── JwtAuthenticationEntryPoint.java │ │ ├── JwtAuthenticationFilter.java │ │ └── JwtTokenProvider.java └── resources │ └── application.properties └── test └── java └── com └── kodlamaio └── bootcampproject └── BootcampProjectApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ozmenab/casgemJavaBackend/da10257d6fa89a87da369d62a64e5af5cf72c925/.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 | -------------------------------------------------------------------------------- /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 user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.5 9 | 10 | 11 | com.kodlamaio 12 | bootcampProject 13 | 0.0.1-SNAPSHOT 14 | bootcampProject 15 | bootcampProject 16 | 17 | 11 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-security 23 | 24 | 25 | 26 | io.jsonwebtoken 27 | jjwt 28 | 0.9.1 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-validation 33 | 34 | 35 | 36 | org.modelmapper 37 | modelmapper 38 | 3.0.0 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-data-jpa 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-web 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-devtools 52 | runtime 53 | true 54 | 55 | 56 | org.postgresql 57 | postgresql 58 | runtime 59 | 60 | 61 | org.projectlombok 62 | lombok 63 | true 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-starter-test 68 | test 69 | 70 | 71 | org.jetbrains 72 | annotations 73 | RELEASE 74 | compile 75 | 76 | 77 | 78 | 79 | 80 | 81 | org.springframework.boot 82 | spring-boot-maven-plugin 83 | 84 | 85 | 86 | org.projectlombok 87 | lombok 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/BootcampProjectApplication.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject; 2 | 3 | import com.kodlamaio.bootcampproject.core.utilities.exceptions.BusinessException; 4 | import com.kodlamaio.bootcampproject.core.utilities.results.ErrorDataResult; 5 | import org.modelmapper.ModelMapper; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.http.HttpStatus; 10 | import org.springframework.validation.FieldError; 11 | import org.springframework.web.bind.MethodArgumentNotValidException; 12 | import org.springframework.web.bind.annotation.ExceptionHandler; 13 | import org.springframework.web.bind.annotation.ResponseStatus; 14 | import org.springframework.web.bind.annotation.RestControllerAdvice; 15 | 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | @SpringBootApplication 20 | @RestControllerAdvice 21 | public class BootcampProjectApplication { 22 | public static void main(String[] args) { 23 | SpringApplication.run(BootcampProjectApplication.class, args); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/api/controllers/AuthController.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.api.controllers; 2 | 3 | import com.kodlamaio.bootcampproject.business.requests.users.UserLoginRequest; 4 | import com.kodlamaio.bootcampproject.business.requests.users.UserRegisterRequest; 5 | import com.kodlamaio.bootcampproject.dataAccess.abstracts.users.UserRepository; 6 | import com.kodlamaio.bootcampproject.entities.users.User; 7 | import com.kodlamaio.bootcampproject.security.JwtTokenProvider; 8 | import lombok.AllArgsConstructor; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.springframework.http.HttpStatus; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.security.authentication.AuthenticationManager; 13 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 14 | import org.springframework.security.core.Authentication; 15 | import org.springframework.security.core.context.SecurityContextHolder; 16 | import org.springframework.security.crypto.password.PasswordEncoder; 17 | import org.springframework.web.bind.annotation.PostMapping; 18 | import org.springframework.web.bind.annotation.RequestBody; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.RestController; 21 | 22 | @RestController 23 | @RequestMapping("api/v1/auth") 24 | @AllArgsConstructor 25 | public class AuthController { 26 | private AuthenticationManager authenticationManager; 27 | private JwtTokenProvider jwtTokenProvider; 28 | private UserRepository userRepository; 29 | private PasswordEncoder passwordEncoder; 30 | 31 | @PostMapping("/login") 32 | public String login(@RequestBody UserLoginRequest userLoginRequest){ 33 | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userLoginRequest.getEmail(),userLoginRequest.getPassword()); 34 | Authentication authentication = authenticationManager.authenticate(authenticationToken); 35 | SecurityContextHolder.getContext().setAuthentication(authentication); 36 | String jwtToken = jwtTokenProvider.generateJwtToken(authentication); 37 | return "Bearer "+jwtToken; 38 | } 39 | 40 | @PostMapping("/register") 41 | public ResponseEntity register(@RequestBody UserRegisterRequest userRegisterRequest){ 42 | User user = userRepository.findByUsername(userRegisterRequest.getEmail()); 43 | if(user != null) 44 | return ResponseEntity.badRequest().body("Username already exists"); 45 | User newUser = new User(); 46 | newUser.setEmail(userRegisterRequest.getEmail()); 47 | newUser.setPassword(passwordEncoder.encode(userRegisterRequest.getPassword())); 48 | userRepository.save(newUser); 49 | return new ResponseEntity<>("User successfully register", HttpStatus.CREATED); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/api/controllers/applications/ApplicationsController.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.api.controllers.applications; 2 | 3 | import com.kodlamaio.bootcampproject.business.abstracts.applications.ApplicationService; 4 | import com.kodlamaio.bootcampproject.business.requests.applications.CreateApplicationRequest; 5 | import com.kodlamaio.bootcampproject.business.requests.applications.UpdateApplicationRequest; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import javax.validation.Valid; 12 | 13 | @RestController 14 | @RequestMapping("/api/v1/applications") 15 | @AllArgsConstructor 16 | public class ApplicationsController { 17 | private ApplicationService applicationService; 18 | 19 | @GetMapping 20 | public ResponseEntity getAll(){ 21 | return ResponseEntity.status(HttpStatus.OK).body(applicationService.getAll()); 22 | } 23 | 24 | @GetMapping("/{id}") 25 | public ResponseEntity getById(@PathVariable int id){ 26 | return ResponseEntity.status(HttpStatus.OK).body(applicationService.getById(id)); 27 | } 28 | 29 | @PostMapping 30 | public ResponseEntity add(@RequestBody @Valid CreateApplicationRequest createApplicationRequest){ 31 | return ResponseEntity.status(HttpStatus.CREATED).body(applicationService.add(createApplicationRequest)); 32 | } 33 | 34 | @PutMapping("/{id}") 35 | public ResponseEntity update(@PathVariable int id,@RequestBody UpdateApplicationRequest updateApplicationRequest){ 36 | updateApplicationRequest.setId(id); 37 | return ResponseEntity.status(HttpStatus.ACCEPTED).body(applicationService.update(id,updateApplicationRequest)); 38 | } 39 | 40 | @DeleteMapping("/{id}") 41 | public ResponseEntity delete(@PathVariable int id){ 42 | return ResponseEntity.status(HttpStatus.OK).body(applicationService.delete(id)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/api/controllers/applications/BlackListsController.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.api.controllers.applications; 2 | 3 | import com.kodlamaio.bootcampproject.business.abstracts.BlackListService; 4 | import com.kodlamaio.bootcampproject.business.requests.blacklists.CreateBlackListRequest; 5 | import com.kodlamaio.bootcampproject.business.requests.blacklists.UpdateBlackListRequest; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import javax.validation.Valid; 12 | 13 | @RestController 14 | @RequestMapping("/api/v1/blacklists") 15 | @AllArgsConstructor 16 | public class BlackListsController { 17 | private BlackListService blackListService; 18 | 19 | @GetMapping 20 | public ResponseEntity getAll(){ 21 | return ResponseEntity.status(HttpStatus.OK).body(blackListService.getAll()); 22 | } 23 | 24 | @GetMapping("/{id}") 25 | public ResponseEntity getById(@PathVariable int id){ 26 | return ResponseEntity.status(HttpStatus.OK).body(blackListService.getById(id)); 27 | } 28 | 29 | @PostMapping 30 | public ResponseEntity add(@RequestBody @Valid CreateBlackListRequest createBlackListRequest){ 31 | return ResponseEntity.status(HttpStatus.CREATED).body(blackListService.add(createBlackListRequest)); 32 | } 33 | 34 | @PutMapping("/{id}") 35 | public ResponseEntity update(@PathVariable int id,@RequestBody @Valid UpdateBlackListRequest updateBlackListRequest){ 36 | return ResponseEntity.status(HttpStatus.ACCEPTED).body(blackListService.update(id,updateBlackListRequest)); 37 | } 38 | 39 | @DeleteMapping("/{id}") 40 | public ResponseEntity delete(@PathVariable int id){ 41 | return ResponseEntity.status(HttpStatus.OK).body(blackListService.delete(id)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/api/controllers/bootcamps/BootcampsController.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.api.controllers.bootcamps; 2 | 3 | import com.kodlamaio.bootcampproject.business.abstracts.BootcampService; 4 | import com.kodlamaio.bootcampproject.business.requests.bootcamps.CreateBootcampRequest; 5 | import com.kodlamaio.bootcampproject.business.requests.bootcamps.UpdateBootcampRequest; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import javax.validation.Valid; 12 | 13 | @RestController 14 | @RequestMapping("/api/v1/bootcamps") 15 | @AllArgsConstructor 16 | public class BootcampsController { 17 | private BootcampService bootcampService; 18 | 19 | @GetMapping 20 | public ResponseEntity getAll(){ 21 | return ResponseEntity.status(HttpStatus.OK).body(bootcampService.getAll()); 22 | } 23 | 24 | @GetMapping("/{id}") 25 | public ResponseEntity getById(@PathVariable int id){ 26 | return ResponseEntity.status(HttpStatus.OK).body(bootcampService.getById(id)); 27 | } 28 | 29 | @PostMapping 30 | public ResponseEntity add(@RequestBody @Valid CreateBootcampRequest createBootcampRequest){ 31 | return ResponseEntity.status(HttpStatus.CREATED).body(bootcampService.add(createBootcampRequest)); 32 | } 33 | 34 | @PutMapping("/{id}") 35 | public ResponseEntity update(@PathVariable int id,@RequestBody @Valid UpdateBootcampRequest updateBootcampRequest){ 36 | return ResponseEntity.status(HttpStatus.ACCEPTED).body(bootcampService.update(id,updateBootcampRequest)); 37 | } 38 | 39 | @DeleteMapping("/{id}") 40 | public ResponseEntity delete(@PathVariable int id){ 41 | return ResponseEntity.status(HttpStatus.OK).body(bootcampService.delete(id)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/api/controllers/users/ApplicantsController.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.api.controllers.users; 2 | 3 | import com.kodlamaio.bootcampproject.business.abstracts.users.ApplicantService; 4 | import com.kodlamaio.bootcampproject.business.requests.users.applicants.CreateApplicantRequest; 5 | import com.kodlamaio.bootcampproject.business.requests.users.applicants.UpdateApplicantRequest; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.security.access.annotation.Secured; 10 | import org.springframework.security.access.prepost.PreAuthorize; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import javax.validation.Valid; 14 | 15 | // http://localhost:8080/api/applicants 16 | @RestController 17 | @RequestMapping("/api/v1/applicants") 18 | @AllArgsConstructor 19 | public class ApplicantsController { 20 | private ApplicantService applicantService; 21 | 22 | // http://localhost:8080/api/v1/applicants 23 | @GetMapping 24 | public ResponseEntity getAll(){ 25 | return ResponseEntity.status(HttpStatus.OK).body(applicantService.getAll()); 26 | } 27 | 28 | @GetMapping("/{id}") 29 | public ResponseEntity getById(@PathVariable int id){ 30 | return ResponseEntity.status(HttpStatus.OK).body(applicantService.getById(id)); 31 | } 32 | 33 | @PostMapping 34 | public ResponseEntity add(@RequestBody @Valid CreateApplicantRequest createApplicantRequest){ 35 | return ResponseEntity.status(HttpStatus.CREATED).body(applicantService.add(createApplicantRequest)); 36 | } 37 | 38 | @PutMapping("/{id}") 39 | public ResponseEntity update(@PathVariable int id,@RequestBody @Valid UpdateApplicantRequest updateApplicantRequest){ 40 | updateApplicantRequest.setId(id); 41 | return ResponseEntity.status(HttpStatus.ACCEPTED).body(applicantService.update(updateApplicantRequest)); 42 | } 43 | 44 | @DeleteMapping("/{id}") 45 | public ResponseEntity delete(@PathVariable int id){ 46 | return ResponseEntity.status(HttpStatus.OK).body(applicantService.delete(id)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/api/controllers/users/EmployeesController.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.api.controllers.users; 2 | 3 | import com.kodlamaio.bootcampproject.business.abstracts.users.EmployeeService; 4 | import com.kodlamaio.bootcampproject.business.requests.users.employees.CreateEmployeeRequest; 5 | import com.kodlamaio.bootcampproject.business.requests.users.employees.UpdateEmployeeRequest; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import javax.validation.Valid; 12 | 13 | // http://localhost:8080/api/employees 14 | @RestController 15 | @RequestMapping("/api/v1/employees") 16 | @AllArgsConstructor 17 | public class EmployeesController { 18 | private EmployeeService employeeService; 19 | 20 | @GetMapping 21 | public ResponseEntity getAll(){ 22 | return ResponseEntity.status(HttpStatus.OK).body(employeeService.getAll()); 23 | } 24 | 25 | @GetMapping("/{id}") 26 | public ResponseEntity getById(@PathVariable int id){ 27 | return ResponseEntity.status(HttpStatus.OK).body(employeeService.getById(id)); 28 | } 29 | 30 | @PostMapping 31 | public ResponseEntity add(@RequestBody @Valid CreateEmployeeRequest createEmployeeRequest){ 32 | return ResponseEntity.status(HttpStatus.CREATED).body(employeeService.add(createEmployeeRequest)); 33 | } 34 | 35 | @PutMapping("/{id}") 36 | public ResponseEntity update(@PathVariable int id,@RequestBody @Valid UpdateEmployeeRequest updateEmployeeRequest){ 37 | return ResponseEntity.status(HttpStatus.ACCEPTED).body(employeeService.update(id,updateEmployeeRequest)); 38 | } 39 | 40 | @DeleteMapping("/{id}") 41 | public ResponseEntity delete(@PathVariable int id){ 42 | return ResponseEntity.status(HttpStatus.OK).body(employeeService.delete(id)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/api/controllers/users/InstructorsController.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.api.controllers.users; 2 | 3 | import com.kodlamaio.bootcampproject.business.abstracts.users.InstructorService; 4 | import com.kodlamaio.bootcampproject.business.requests.users.instructors.CreateInstructorRequest; 5 | import com.kodlamaio.bootcampproject.business.requests.users.instructors.UpdateInstructorRequest; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import javax.validation.Valid; 12 | import javax.validation.constraints.Positive; 13 | 14 | @RestController 15 | @RequestMapping("/api/v1/instructors") 16 | @AllArgsConstructor 17 | public class InstructorsController { 18 | private InstructorService instructorService; 19 | 20 | @GetMapping 21 | public ResponseEntity getAll(){ 22 | return ResponseEntity.status(HttpStatus.OK).body(instructorService.getAll()); 23 | } 24 | 25 | @GetMapping("/{id}") 26 | public ResponseEntity getById(@PathVariable int id){ 27 | return ResponseEntity.status(HttpStatus.OK).body(instructorService.getById(id)); 28 | } 29 | 30 | @PostMapping 31 | public ResponseEntity add(@RequestBody @Valid CreateInstructorRequest createInstructorRequest){ 32 | return ResponseEntity.status(HttpStatus.CREATED).body(instructorService.add(createInstructorRequest)); 33 | } 34 | 35 | @PutMapping("/{id}") 36 | public ResponseEntity update(@PathVariable @Valid @Positive int id, @RequestBody @Valid UpdateInstructorRequest updateInstructorRequest){ 37 | return ResponseEntity.status(HttpStatus.ACCEPTED).body(instructorService.update(id,updateInstructorRequest)); 38 | } 39 | 40 | @DeleteMapping("/{id}") 41 | public ResponseEntity delete(@PathVariable int id){ 42 | return ResponseEntity.status(HttpStatus.OK).body(instructorService.delete(id)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/abstracts/BlackListService.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.abstracts; 2 | 3 | import com.kodlamaio.bootcampproject.business.requests.blacklists.CreateBlackListRequest; 4 | import com.kodlamaio.bootcampproject.business.requests.blacklists.UpdateBlackListRequest; 5 | import com.kodlamaio.bootcampproject.business.responses.blacklists.CreateBlackListResponse; 6 | import com.kodlamaio.bootcampproject.business.responses.blacklists.GetAllBlackListsResponse; 7 | import com.kodlamaio.bootcampproject.business.responses.blacklists.GetBlackListResponse; 8 | import com.kodlamaio.bootcampproject.business.responses.blacklists.UpdateBlackListResponse; 9 | import com.kodlamaio.bootcampproject.core.utilities.results.DataResult; 10 | import com.kodlamaio.bootcampproject.core.utilities.results.Result; 11 | 12 | import java.util.List; 13 | 14 | public interface BlackListService { 15 | DataResult> getAll(); 16 | DataResult getById(int id); 17 | DataResult add(CreateBlackListRequest createBlackListRequest); 18 | DataResult update(int id,UpdateBlackListRequest updateBlackListRequest); 19 | Result delete(int id); 20 | void IsBlackListByApplicantId(int applicantId); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/abstracts/BootcampService.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.abstracts; 2 | 3 | import com.kodlamaio.bootcampproject.business.requests.bootcamps.CreateBootcampRequest; 4 | import com.kodlamaio.bootcampproject.business.requests.bootcamps.UpdateBootcampRequest; 5 | import com.kodlamaio.bootcampproject.business.responses.bootcamps.CreateBootcampResponse; 6 | import com.kodlamaio.bootcampproject.business.responses.bootcamps.GetAllBootcampResponse; 7 | import com.kodlamaio.bootcampproject.business.responses.bootcamps.GetBootcampResponse; 8 | import com.kodlamaio.bootcampproject.business.responses.bootcamps.UpdateBootcampResponse; 9 | import com.kodlamaio.bootcampproject.core.utilities.results.DataResult; 10 | import com.kodlamaio.bootcampproject.core.utilities.results.Result; 11 | 12 | import java.util.List; 13 | 14 | public interface BootcampService { 15 | DataResult> getAll(); 16 | DataResult getById(int id); 17 | DataResult add(CreateBootcampRequest createBootcampRequest); 18 | DataResult update(int id,UpdateBootcampRequest updateBootcampRequest); 19 | Result delete(int id); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/abstracts/applications/ApplicationService.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.abstracts.applications; 2 | 3 | import com.kodlamaio.bootcampproject.business.requests.applications.CreateApplicationRequest; 4 | import com.kodlamaio.bootcampproject.business.requests.applications.UpdateApplicationRequest; 5 | import com.kodlamaio.bootcampproject.business.responses.applications.CreateApplicationResponse; 6 | import com.kodlamaio.bootcampproject.business.responses.applications.GetAllApplicationsResponse; 7 | import com.kodlamaio.bootcampproject.business.responses.applications.GetApplicationResponse; 8 | import com.kodlamaio.bootcampproject.business.responses.applications.UpdateApplicationResponse; 9 | import com.kodlamaio.bootcampproject.core.utilities.results.DataResult; 10 | import com.kodlamaio.bootcampproject.core.utilities.results.Result; 11 | import com.kodlamaio.bootcampproject.entities.applications.Application; 12 | 13 | import java.util.List; 14 | 15 | public interface ApplicationService { 16 | DataResult> getAll(); 17 | DataResult getById(int id); 18 | DataResult add(CreateApplicationRequest createApplicationRequest); 19 | DataResult update(int id,UpdateApplicationRequest updateApplicationRequest); 20 | Result delete(int id); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/abstracts/users/ApplicantService.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.abstracts.users; 2 | 3 | import com.kodlamaio.bootcampproject.business.requests.users.applicants.CreateApplicantRequest; 4 | import com.kodlamaio.bootcampproject.business.requests.users.applicants.UpdateApplicantRequest; 5 | import com.kodlamaio.bootcampproject.business.responses.users.applicants.CreateApplicantResponse; 6 | import com.kodlamaio.bootcampproject.business.responses.users.applicants.GetAllApplicantsResponse; 7 | import com.kodlamaio.bootcampproject.business.responses.users.applicants.GetApplicantResponse; 8 | import com.kodlamaio.bootcampproject.business.responses.users.applicants.UpdateApplicantResponse; 9 | import com.kodlamaio.bootcampproject.core.utilities.results.DataResult; 10 | import com.kodlamaio.bootcampproject.core.utilities.results.Result; 11 | 12 | import java.util.List; 13 | 14 | public interface ApplicantService { 15 | DataResult> getAll(); 16 | DataResult getById(int id); 17 | DataResult add(CreateApplicantRequest createApplicantRequest); 18 | DataResult update(UpdateApplicantRequest updateApplicantRequest); 19 | Result delete(int id); 20 | 21 | boolean checkIsApplicant(int id); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/abstracts/users/EmployeeService.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.abstracts.users; 2 | 3 | import com.kodlamaio.bootcampproject.business.requests.users.employees.CreateEmployeeRequest; 4 | import com.kodlamaio.bootcampproject.business.requests.users.employees.UpdateEmployeeRequest; 5 | import com.kodlamaio.bootcampproject.business.responses.users.employees.CreateEmployeeResponse; 6 | import com.kodlamaio.bootcampproject.business.responses.users.employees.GetAllEmployeesResponse; 7 | import com.kodlamaio.bootcampproject.business.responses.users.employees.GetEmployeeResponse; 8 | import com.kodlamaio.bootcampproject.business.responses.users.employees.UpdateEmployeeResponse; 9 | import com.kodlamaio.bootcampproject.core.utilities.results.DataResult; 10 | import com.kodlamaio.bootcampproject.core.utilities.results.Result; 11 | 12 | import java.util.List; 13 | 14 | public interface EmployeeService { 15 | DataResult> getAll(); 16 | DataResult getById(int id); 17 | DataResult add(CreateEmployeeRequest createEmployeeRequest); 18 | DataResult update(int id,UpdateEmployeeRequest updateEmployeeRequest); 19 | Result delete(int id); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/abstracts/users/InstructorService.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.abstracts.users; 2 | 3 | import com.kodlamaio.bootcampproject.business.requests.users.instructors.CreateInstructorRequest; 4 | import com.kodlamaio.bootcampproject.business.requests.users.instructors.UpdateInstructorRequest; 5 | import com.kodlamaio.bootcampproject.business.responses.users.instructors.CreateInstructorResponse; 6 | import com.kodlamaio.bootcampproject.business.responses.users.instructors.GetAllInstructorsResponse; 7 | import com.kodlamaio.bootcampproject.business.responses.users.instructors.GetInstructorResponse; 8 | import com.kodlamaio.bootcampproject.business.responses.users.instructors.UpdateInstructorResponse; 9 | import com.kodlamaio.bootcampproject.core.utilities.results.DataResult; 10 | import com.kodlamaio.bootcampproject.core.utilities.results.Result; 11 | 12 | import java.util.List; 13 | 14 | public interface InstructorService { 15 | DataResult> getAll(); 16 | DataResult getById(int id); 17 | DataResult add(CreateInstructorRequest createInstructorRequest); 18 | DataResult update(int id,UpdateInstructorRequest updateInstructorRequest); 19 | Result delete(int id); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/concretes/BlackListManager.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.concretes; 2 | 3 | import com.kodlamaio.bootcampproject.business.abstracts.BlackListService; 4 | import com.kodlamaio.bootcampproject.business.constants.Messages; 5 | import com.kodlamaio.bootcampproject.business.requests.blacklists.CreateBlackListRequest; 6 | import com.kodlamaio.bootcampproject.business.requests.blacklists.UpdateBlackListRequest; 7 | import com.kodlamaio.bootcampproject.business.responses.blacklists.CreateBlackListResponse; 8 | import com.kodlamaio.bootcampproject.business.responses.blacklists.GetAllBlackListsResponse; 9 | import com.kodlamaio.bootcampproject.business.responses.blacklists.GetBlackListResponse; 10 | import com.kodlamaio.bootcampproject.business.responses.blacklists.UpdateBlackListResponse; 11 | import com.kodlamaio.bootcampproject.core.utilities.exceptions.BusinessException; 12 | import com.kodlamaio.bootcampproject.core.utilities.mapping.ModelMapperService; 13 | import com.kodlamaio.bootcampproject.core.utilities.results.DataResult; 14 | import com.kodlamaio.bootcampproject.core.utilities.results.Result; 15 | import com.kodlamaio.bootcampproject.core.utilities.results.SuccessDataResult; 16 | import com.kodlamaio.bootcampproject.core.utilities.results.SuccessResult; 17 | import com.kodlamaio.bootcampproject.dataAccess.abstracts.BlackListRepository; 18 | import com.kodlamaio.bootcampproject.entities.BlackList; 19 | import lombok.AllArgsConstructor; 20 | import org.springframework.stereotype.Service; 21 | 22 | import java.util.List; 23 | import java.util.stream.Collectors; 24 | 25 | @Service 26 | @AllArgsConstructor 27 | public class BlackListManager implements BlackListService { 28 | private BlackListRepository blackListRepository; 29 | private ModelMapperService modelMapperService; 30 | 31 | @Override 32 | public DataResult> getAll() { 33 | List blackLists = blackListRepository.findAll(); 34 | List responses = 35 | blackLists.stream() 36 | .map(blackList -> modelMapperService 37 | .forResponse() 38 | .map(blackList,GetAllBlackListsResponse.class)).collect(Collectors.toList()); 39 | return new SuccessDataResult<>(responses); 40 | } 41 | 42 | @Override 43 | public DataResult getById(int id) { 44 | BlackList blackList = checkIfBlackListExists(id); 45 | GetBlackListResponse response = modelMapperService.forResponse().map(blackList,GetBlackListResponse.class); 46 | return new SuccessDataResult<>(response); 47 | } 48 | 49 | @Override 50 | public DataResult add(CreateBlackListRequest createBlackListRequest) { 51 | checkIfBlackListExistsByApplicantId(createBlackListRequest.getApplicantId()); 52 | BlackList blackList = modelMapperService.forRequest().map(createBlackListRequest,BlackList.class); 53 | blackList.setId(0); 54 | blackListRepository.save(blackList); 55 | CreateBlackListResponse response = modelMapperService.forResponse().map(blackList,CreateBlackListResponse.class); 56 | response.setId(blackList.getId()); 57 | return new SuccessDataResult<>(response); 58 | } 59 | 60 | @Override 61 | public DataResult update(int id,UpdateBlackListRequest updateBlackListRequest) { 62 | checkIfBlackListExists(id); 63 | BlackList blackList = modelMapperService.forRequest().map(updateBlackListRequest,BlackList.class); 64 | blackListRepository.save(blackList); 65 | UpdateBlackListResponse response = modelMapperService.forResponse().map(blackList,UpdateBlackListResponse.class); 66 | return new SuccessDataResult<>(response); 67 | } 68 | 69 | @Override 70 | public Result delete(int id) { 71 | checkIfBlackListExists(id); 72 | blackListRepository.deleteById(id); 73 | return new SuccessResult(Messages.BlackListDeleted); 74 | } 75 | 76 | @Override 77 | public void IsBlackListByApplicantId(int applicantId) { 78 | checkIfBlackListExistsByApplicantId(applicantId); 79 | } 80 | 81 | private void checkIfBlackListExistsByApplicantId(int applicantId){ 82 | BlackList blackList = blackListRepository.findByApplicantId(applicantId); 83 | if(blackList != null) 84 | throw new BusinessException(Messages.BlackListExistsApplicantById); 85 | } 86 | private BlackList checkIfBlackListExists(int id){ 87 | BlackList blackList = blackListRepository.findById(id).orElse(null); 88 | if(blackList == null) 89 | throw new BusinessException(Messages.BlackListNotExists); 90 | return blackList; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/concretes/BootcampManager.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.concretes; 2 | 3 | import com.kodlamaio.bootcampproject.business.abstracts.BootcampService; 4 | import com.kodlamaio.bootcampproject.business.constants.Messages; 5 | import com.kodlamaio.bootcampproject.business.requests.bootcamps.CreateBootcampRequest; 6 | import com.kodlamaio.bootcampproject.business.requests.bootcamps.UpdateBootcampRequest; 7 | import com.kodlamaio.bootcampproject.business.responses.bootcamps.CreateBootcampResponse; 8 | import com.kodlamaio.bootcampproject.business.responses.bootcamps.GetAllBootcampResponse; 9 | import com.kodlamaio.bootcampproject.business.responses.bootcamps.GetBootcampResponse; 10 | import com.kodlamaio.bootcampproject.business.responses.bootcamps.UpdateBootcampResponse; 11 | import com.kodlamaio.bootcampproject.core.utilities.exceptions.BusinessException; 12 | import com.kodlamaio.bootcampproject.core.utilities.mapping.ModelMapperService; 13 | import com.kodlamaio.bootcampproject.core.utilities.results.DataResult; 14 | import com.kodlamaio.bootcampproject.core.utilities.results.Result; 15 | import com.kodlamaio.bootcampproject.core.utilities.results.SuccessDataResult; 16 | import com.kodlamaio.bootcampproject.core.utilities.results.SuccessResult; 17 | import com.kodlamaio.bootcampproject.dataAccess.abstracts.BootcampRepository; 18 | import com.kodlamaio.bootcampproject.entities.Bootcamp; 19 | import lombok.AllArgsConstructor; 20 | import org.springframework.stereotype.Service; 21 | 22 | import java.time.LocalDate; 23 | import java.util.List; 24 | import java.util.stream.Collectors; 25 | 26 | @Service 27 | @AllArgsConstructor 28 | public class BootcampManager implements BootcampService { 29 | private BootcampRepository bootcampRepository; 30 | private ModelMapperService modelMapperService; 31 | 32 | @Override 33 | public DataResult> getAll() { 34 | List bootcamps = bootcampRepository.findAll(); 35 | List responseList = 36 | bootcamps.stream().map(bootcamp -> 37 | modelMapperService 38 | .forResponse() 39 | .map(bootcamp,GetAllBootcampResponse.class)).collect(Collectors.toList()); 40 | return new SuccessDataResult<>(responseList); 41 | } 42 | 43 | @Override 44 | public DataResult getById(int id) { 45 | Bootcamp bootcamp = checkIfExistsBootcampById(id); 46 | GetBootcampResponse response = modelMapperService.forResponse().map(bootcamp,GetBootcampResponse.class); 47 | return new SuccessDataResult<>(response); 48 | } 49 | 50 | @Override 51 | public DataResult add(CreateBootcampRequest createBootcampRequest) { 52 | checkIfBootcampEndDateIsBeforeStartDate(createBootcampRequest.getStartDate(),createBootcampRequest.getEndDate()); 53 | Bootcamp bootcamp = modelMapperService.forRequest().map(createBootcampRequest,Bootcamp.class); 54 | bootcamp.setId(0); 55 | bootcampRepository.save(bootcamp); 56 | CreateBootcampResponse response = modelMapperService.forResponse().map(bootcamp,CreateBootcampResponse.class); 57 | return new SuccessDataResult<>(response,Messages.BootcampCreated); 58 | } 59 | 60 | @Override 61 | public DataResult update(int id, UpdateBootcampRequest updateBootcampRequest) { 62 | checkIfExistsBootcampById(id); 63 | Bootcamp bootcamp = modelMapperService.forRequest().map(updateBootcampRequest,Bootcamp.class); 64 | bootcamp.setId(id); 65 | bootcampRepository.save(bootcamp); 66 | UpdateBootcampResponse response = modelMapperService.forResponse().map(bootcamp,UpdateBootcampResponse.class); 67 | return new SuccessDataResult<>(response,Messages.BootcampUpdated); 68 | } 69 | 70 | @Override 71 | public Result delete(int id) { 72 | checkIfExistsBootcampById(id); 73 | bootcampRepository.deleteById(id); 74 | return new SuccessResult(Messages.BootcampDeleted); 75 | } 76 | 77 | private Bootcamp checkIfExistsBootcampById(int id) { 78 | Bootcamp bootcamp = bootcampRepository.findById(id).orElse(null); 79 | if(bootcamp == null) 80 | throw new BusinessException(Messages.BootcampIfNotExists); 81 | return bootcamp; 82 | } 83 | 84 | private void checkIfBootcampEndDateIsBeforeStartDate(LocalDate startDate,LocalDate endDate){ 85 | if(endDate.isBefore(startDate)) 86 | throw new BusinessException(Messages.BootcampEndDateNotBeforeStartDate); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/concretes/applications/ApplicationManager.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.concretes.applications; 2 | 3 | import com.kodlamaio.bootcampproject.business.abstracts.BlackListService; 4 | import com.kodlamaio.bootcampproject.business.abstracts.BootcampService; 5 | import com.kodlamaio.bootcampproject.business.abstracts.applications.ApplicationService; 6 | import com.kodlamaio.bootcampproject.business.abstracts.users.ApplicantService; 7 | import com.kodlamaio.bootcampproject.business.constants.Messages; 8 | import com.kodlamaio.bootcampproject.business.requests.applications.CreateApplicationRequest; 9 | import com.kodlamaio.bootcampproject.business.requests.applications.UpdateApplicationRequest; 10 | import com.kodlamaio.bootcampproject.business.responses.applications.*; 11 | import com.kodlamaio.bootcampproject.business.responses.bootcamps.GetBootcampResponse; 12 | import com.kodlamaio.bootcampproject.core.utilities.exceptions.BusinessException; 13 | import com.kodlamaio.bootcampproject.core.utilities.mapping.ModelMapperService; 14 | import com.kodlamaio.bootcampproject.core.utilities.results.DataResult; 15 | import com.kodlamaio.bootcampproject.core.utilities.results.Result; 16 | import com.kodlamaio.bootcampproject.core.utilities.results.SuccessDataResult; 17 | import com.kodlamaio.bootcampproject.core.utilities.results.SuccessResult; 18 | import com.kodlamaio.bootcampproject.dataAccess.abstracts.applications.ApplicationRepository; 19 | import com.kodlamaio.bootcampproject.entities.Bootcamp; 20 | import com.kodlamaio.bootcampproject.entities.applications.Application; 21 | import lombok.AllArgsConstructor; 22 | import org.springframework.stereotype.Service; 23 | 24 | import java.util.List; 25 | import java.util.stream.Collectors; 26 | 27 | @Service 28 | @AllArgsConstructor 29 | public class ApplicationManager implements ApplicationService { 30 | private ApplicationRepository applicationRepository; 31 | private ModelMapperService modelMapperService; 32 | private ApplicantService applicantService; 33 | private BlackListService blackListService; 34 | private BootcampService bootcampService; 35 | 36 | @Override 37 | public DataResult> getAll() { 38 | List applications = applicationRepository.findAll(); 39 | List responseList = 40 | applications.stream().map(bootcamp -> 41 | modelMapperService 42 | .forResponse() 43 | .map(bootcamp,GetAllApplicationsResponse.class)).collect(Collectors.toList()); 44 | return new SuccessDataResult<>(responseList); 45 | } 46 | 47 | @Override 48 | public DataResult getById(int id) { 49 | Application application = checkIfExistsApplicationById(id); 50 | GetApplicationResponse response = modelMapperService.forResponse().map(application,GetApplicationResponse.class); 51 | return new SuccessDataResult<>(response); 52 | } 53 | 54 | @Override 55 | public DataResult add(CreateApplicationRequest createApplicationRequest) { 56 | checkIsApplicantBlackList(createApplicationRequest.getApplicantId()); 57 | checkIsApplicant(createApplicationRequest.getApplicantId()); 58 | checkIfExistsBootcampById(createApplicationRequest.getBootcampId()); 59 | Application application = modelMapperService.forRequest().map(createApplicationRequest,Application.class); 60 | applicationRepository.save(application); 61 | CreateApplicationResponse response = modelMapperService.forResponse().map(application,CreateApplicationResponse.class); 62 | return new SuccessDataResult<>(response,Messages.ApplicationCreated); 63 | } 64 | 65 | @Override 66 | public DataResult update(int id,UpdateApplicationRequest updateApplicationRequest) { 67 | checkIfExistsApplicationById(id); 68 | checkIfExistsBootcampById(updateApplicationRequest.getBootcampId()); 69 | checkIsApplicant(updateApplicationRequest.getApplicantId()); 70 | Application application = modelMapperService.forRequest().map(updateApplicationRequest,Application.class); 71 | application.setId(id); 72 | applicationRepository.save(application); 73 | UpdateApplicationResponse response = modelMapperService.forResponse().map(application,UpdateApplicationResponse.class); 74 | return new SuccessDataResult<>(response,Messages.ApplicationUpdated); 75 | } 76 | 77 | @Override 78 | public Result delete(int id) { 79 | checkIfExistsApplicationById(id); 80 | applicationRepository.deleteById(id); 81 | return new SuccessResult(Messages.ApplicationDeleted); 82 | } 83 | 84 | private Application checkIfExistsApplicationById(int id) { 85 | Application application = applicationRepository.findById(id).orElse(null); 86 | if(application == null) 87 | throw new BusinessException(Messages.BootcampIfNotExists); 88 | return application; 89 | } 90 | 91 | private void checkIsApplicant(int id) { 92 | boolean result = applicantService.checkIsApplicant(id); 93 | if(result == false) 94 | throw new BusinessException(Messages.ApplicantIfNotExists); 95 | } 96 | private void checkIsApplicantBlackList(int applicantId) { 97 | blackListService.IsBlackListByApplicantId(applicantId); 98 | } 99 | 100 | private void checkIfExistsBootcampById(int bootcampId){ 101 | GetBootcampResponse bootcampResponse= bootcampService.getById(bootcampId).getData(); 102 | if(bootcampResponse==null) 103 | throw new BusinessException("Bootcamp no exists"); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/concretes/users/ApplicantManager.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.concretes.users; 2 | 3 | import com.kodlamaio.bootcampproject.business.abstracts.users.ApplicantService; 4 | import com.kodlamaio.bootcampproject.business.constants.Messages; 5 | import com.kodlamaio.bootcampproject.business.requests.users.applicants.CreateApplicantRequest; 6 | import com.kodlamaio.bootcampproject.business.requests.users.applicants.UpdateApplicantRequest; 7 | import com.kodlamaio.bootcampproject.business.responses.users.applicants.CreateApplicantResponse; 8 | import com.kodlamaio.bootcampproject.business.responses.users.applicants.GetAllApplicantsResponse; 9 | import com.kodlamaio.bootcampproject.business.responses.users.applicants.GetApplicantResponse; 10 | import com.kodlamaio.bootcampproject.business.responses.users.applicants.UpdateApplicantResponse; 11 | import com.kodlamaio.bootcampproject.core.utilities.exceptions.BusinessException; 12 | import com.kodlamaio.bootcampproject.core.utilities.mapping.ModelMapperService; 13 | import com.kodlamaio.bootcampproject.core.utilities.results.DataResult; 14 | import com.kodlamaio.bootcampproject.core.utilities.results.Result; 15 | import com.kodlamaio.bootcampproject.core.utilities.results.SuccessDataResult; 16 | import com.kodlamaio.bootcampproject.core.utilities.results.SuccessResult; 17 | import com.kodlamaio.bootcampproject.dataAccess.abstracts.users.ApplicantRepository; 18 | import com.kodlamaio.bootcampproject.entities.users.Applicant; 19 | import com.kodlamaio.bootcampproject.entities.users.Role; 20 | import lombok.AllArgsConstructor; 21 | import org.springframework.security.crypto.password.PasswordEncoder; 22 | import org.springframework.stereotype.Service; 23 | 24 | import java.util.List; 25 | import java.util.Set; 26 | import java.util.stream.Collectors; 27 | 28 | @Service 29 | @AllArgsConstructor 30 | public class ApplicantManager implements ApplicantService { 31 | private ModelMapperService modelMapperService; 32 | private ApplicantRepository applicantRepository; 33 | private PasswordEncoder passwordEncoder; 34 | 35 | @Override 36 | public DataResult> getAll() { 37 | List applicants = applicantRepository.findAll(); 38 | List responses =applicants.stream().map(applicant -> 39 | modelMapperService 40 | .forResponse() 41 | .map(applicant,GetAllApplicantsResponse.class)).collect(Collectors.toList()); 42 | return new SuccessDataResult<>(responses, Messages.ApplicantsListed); 43 | } 44 | 45 | @Override 46 | public DataResult getById(int id) { 47 | checkIfExistsApplicantById(id); 48 | Applicant applicant = applicantRepository.findById(id).get(); 49 | GetApplicantResponse response = modelMapperService.forResponse().map(applicant,GetApplicantResponse.class); 50 | return new SuccessDataResult<>(response); 51 | } 52 | 53 | 54 | @Override 55 | public DataResult add(CreateApplicantRequest createApplicantRequest) { 56 | checkIfExistsApplicantByNationalIdentity(createApplicantRequest.getNationalIdentity()); 57 | Applicant applicant = modelMapperService.forRequest().map(createApplicantRequest,Applicant.class); 58 | applicant.setRoles(Set.of(Role.ROLE_APPLICANT)); 59 | applicant.setPassword(passwordEncoder.encode(createApplicantRequest.getPassword())); 60 | Applicant savedApplicant = applicantRepository.save(applicant); 61 | CreateApplicantResponse response = modelMapperService.forResponse().map(savedApplicant,CreateApplicantResponse.class); 62 | return new SuccessDataResult<>(response,Messages.ApplicantCreated); 63 | } 64 | 65 | @Override 66 | public DataResult update(UpdateApplicantRequest updateApplicantRequest) { 67 | checkIfExistsApplicantById(updateApplicantRequest.getId()); 68 | Applicant applicant = modelMapperService.forRequest().map(updateApplicantRequest,Applicant.class); 69 | applicant.setId(updateApplicantRequest.getId()); 70 | applicant.setRoles(Set.of(Role.ROLE_APPLICANT)); 71 | applicant.setPassword(passwordEncoder.encode(updateApplicantRequest.getPassword())); 72 | Applicant updatedApplicant=applicantRepository.save(applicant); 73 | UpdateApplicantResponse response = modelMapperService.forResponse().map(updatedApplicant,UpdateApplicantResponse.class); 74 | return new SuccessDataResult<>(response,Messages.ApplicantUpdated); 75 | 76 | } 77 | 78 | @Override 79 | public Result delete(int id) { 80 | checkIfExistsApplicantById(id); 81 | applicantRepository.deleteById(id); 82 | return new SuccessResult(Messages.ApplicantDeleted); 83 | } 84 | 85 | @Override 86 | public boolean checkIsApplicant(int id) { 87 | Applicant applicant = applicantRepository.findById(id).orElse(null); 88 | if(applicant == null) 89 | return false; 90 | return true; 91 | } 92 | 93 | //Rules 94 | private void checkIfExistsApplicantByNationalIdentity(String nationalIdentity){ 95 | Applicant applicant = applicantRepository.findByNationalIdentity(nationalIdentity); 96 | if(applicant != null) 97 | throw new BusinessException(Messages.ApplicantExists); 98 | } 99 | 100 | private void checkIfExistsApplicantById(int id) { 101 | Applicant applicant = applicantRepository.findById(id).orElse(null); 102 | if(applicant == null) 103 | throw new BusinessException(Messages.ApplicantIfNotExists); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/concretes/users/EmployeeManager.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.concretes.users; 2 | 3 | import com.kodlamaio.bootcampproject.business.abstracts.users.EmployeeService; 4 | import com.kodlamaio.bootcampproject.business.constants.Messages; 5 | import com.kodlamaio.bootcampproject.business.requests.users.employees.CreateEmployeeRequest; 6 | import com.kodlamaio.bootcampproject.business.requests.users.employees.UpdateEmployeeRequest; 7 | import com.kodlamaio.bootcampproject.business.responses.users.employees.CreateEmployeeResponse; 8 | import com.kodlamaio.bootcampproject.business.responses.users.employees.GetAllEmployeesResponse; 9 | import com.kodlamaio.bootcampproject.business.responses.users.employees.GetEmployeeResponse; 10 | import com.kodlamaio.bootcampproject.business.responses.users.employees.UpdateEmployeeResponse; 11 | import com.kodlamaio.bootcampproject.core.utilities.exceptions.BusinessException; 12 | import com.kodlamaio.bootcampproject.core.utilities.mapping.ModelMapperService; 13 | import com.kodlamaio.bootcampproject.core.utilities.results.DataResult; 14 | import com.kodlamaio.bootcampproject.core.utilities.results.Result; 15 | import com.kodlamaio.bootcampproject.core.utilities.results.SuccessDataResult; 16 | import com.kodlamaio.bootcampproject.core.utilities.results.SuccessResult; 17 | import com.kodlamaio.bootcampproject.dataAccess.abstracts.users.EmployeeRepository; 18 | import com.kodlamaio.bootcampproject.entities.users.Employee; 19 | import com.kodlamaio.bootcampproject.entities.users.Role; 20 | import lombok.AllArgsConstructor; 21 | import org.springframework.security.crypto.password.PasswordEncoder; 22 | import org.springframework.stereotype.Service; 23 | 24 | import java.util.List; 25 | import java.util.Set; 26 | import java.util.stream.Collectors; 27 | 28 | @Service 29 | @AllArgsConstructor 30 | public class EmployeeManager implements EmployeeService { 31 | private EmployeeRepository employeeRepository; 32 | private ModelMapperService modelMapperService; 33 | private PasswordEncoder passwordEncoder; 34 | 35 | @Override 36 | public DataResult> getAll() { 37 | List employees = employeeRepository.findAll(); 38 | List responses =employees.stream() 39 | .map(employee -> modelMapperService 40 | .forResponse() 41 | .map(employee,GetAllEmployeesResponse.class)) 42 | .collect(Collectors.toList()); 43 | return new SuccessDataResult<>(responses, Messages.EmployeesListed); 44 | } 45 | 46 | @Override 47 | public DataResult getById(int id) { 48 | checkIfExistsEmployeeById(id); 49 | Employee employee = employeeRepository.findById(id).get(); 50 | GetEmployeeResponse response = modelMapperService.forResponse().map(employee, GetEmployeeResponse.class); 51 | return new SuccessDataResult<>(response); 52 | } 53 | 54 | @Override 55 | public DataResult add(CreateEmployeeRequest createEmployeeRequest) { 56 | checkIfExistsEmployeeByNationalIdentity(createEmployeeRequest.getNationalIdentity()); 57 | Employee employee = modelMapperService.forRequest().map(createEmployeeRequest,Employee.class); 58 | employee.setRoles(Set.of(Role.ROLE_EMPLOYEE)); 59 | employee.setPassword(passwordEncoder.encode(createEmployeeRequest.getPassword())); 60 | Employee savedEmployee = employeeRepository.save(employee); 61 | CreateEmployeeResponse response = modelMapperService.forResponse().map(savedEmployee,CreateEmployeeResponse.class); 62 | return new SuccessDataResult<>(response,Messages.EmployeeCreated); 63 | } 64 | 65 | @Override 66 | public DataResult update(int id,UpdateEmployeeRequest updateEmployeeRequest) { 67 | checkIfExistsEmployeeById(id); 68 | Employee employee = modelMapperService.forRequest().map(updateEmployeeRequest,Employee.class); 69 | employee.setId(id); 70 | employee.setRoles(Set.of(Role.ROLE_EMPLOYEE)); 71 | employee.setPassword(passwordEncoder.encode(updateEmployeeRequest.getPassword())); 72 | Employee updatedEmployee=employeeRepository.save(employee); 73 | UpdateEmployeeResponse response = modelMapperService.forResponse().map(updatedEmployee,UpdateEmployeeResponse.class); 74 | return new SuccessDataResult<>(response,Messages.EmployeeUpdated); 75 | } 76 | 77 | @Override 78 | public Result delete(int id) { 79 | checkIfExistsEmployeeById(id); 80 | employeeRepository.deleteById(id); 81 | return new SuccessResult(Messages.EmployeeDeleted); 82 | } 83 | 84 | private void checkIfExistsEmployeeByNationalIdentity(String nationalIdentity){ 85 | Employee employee = employeeRepository.findByNationalIdentity(nationalIdentity); 86 | if(employee != null) 87 | throw new BusinessException(Messages.EmployeeExists); 88 | } 89 | 90 | private void checkIfExistsEmployeeById(int id) { 91 | Employee employee = employeeRepository.findById(id).orElse(null); 92 | if(employee == null) 93 | throw new BusinessException(Messages.EmployeeIfNotExists); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/concretes/users/InstructorManager.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.concretes.users; 2 | 3 | import com.kodlamaio.bootcampproject.business.constants.Messages; 4 | import com.kodlamaio.bootcampproject.business.responses.users.instructors.CreateInstructorResponse; 5 | import com.kodlamaio.bootcampproject.business.abstracts.users.InstructorService; 6 | import com.kodlamaio.bootcampproject.business.requests.users.instructors.CreateInstructorRequest; 7 | import com.kodlamaio.bootcampproject.business.requests.users.instructors.UpdateInstructorRequest; 8 | import com.kodlamaio.bootcampproject.business.responses.users.instructors.GetAllInstructorsResponse; 9 | import com.kodlamaio.bootcampproject.business.responses.users.instructors.GetInstructorResponse; 10 | import com.kodlamaio.bootcampproject.business.responses.users.instructors.UpdateInstructorResponse; 11 | import com.kodlamaio.bootcampproject.core.utilities.exceptions.BusinessException; 12 | import com.kodlamaio.bootcampproject.core.utilities.mapping.ModelMapperService; 13 | import com.kodlamaio.bootcampproject.core.utilities.results.DataResult; 14 | import com.kodlamaio.bootcampproject.core.utilities.results.Result; 15 | import com.kodlamaio.bootcampproject.core.utilities.results.SuccessDataResult; 16 | import com.kodlamaio.bootcampproject.core.utilities.results.SuccessResult; 17 | import com.kodlamaio.bootcampproject.dataAccess.abstracts.users.InstructorRepository; 18 | import com.kodlamaio.bootcampproject.entities.users.Instructor; 19 | import com.kodlamaio.bootcampproject.entities.users.Role; 20 | import lombok.AllArgsConstructor; 21 | import org.springframework.security.crypto.password.PasswordEncoder; 22 | import org.springframework.stereotype.Service; 23 | 24 | import java.util.List; 25 | import java.util.Set; 26 | import java.util.stream.Collectors; 27 | 28 | @Service 29 | @AllArgsConstructor 30 | public class InstructorManager implements InstructorService { 31 | private InstructorRepository instructorRepository; 32 | private ModelMapperService modelMapperService; 33 | private PasswordEncoder passwordEncoder; 34 | @Override 35 | public DataResult> getAll() { 36 | List instructors = instructorRepository.findAll(); 37 | List responses = instructors.stream().map(instructor -> 38 | modelMapperService 39 | .forResponse() 40 | .map(instructor,GetAllInstructorsResponse.class)) 41 | .collect(Collectors.toList()); 42 | return new SuccessDataResult<>(responses,Messages.InstructorsListed); 43 | } 44 | 45 | @Override 46 | public DataResult getById(int id) { 47 | checkIfExistsInstructorById(id); 48 | Instructor instructor = instructorRepository.findById(id).get(); 49 | GetInstructorResponse response = modelMapperService.forResponse().map(instructor,GetInstructorResponse.class); 50 | DataResult result = new DataResult<>(response,true); 51 | return result; 52 | } 53 | 54 | @Override 55 | public DataResult add(CreateInstructorRequest createInstructorRequest) { 56 | checkIfExistsInstructorByNationalIdentity(createInstructorRequest.getNationalIdentity()); 57 | Instructor instructor = modelMapperService.forRequest().map(createInstructorRequest, Instructor.class); 58 | instructor.setRoles(Set.of(Role.ROLE_INSTRUCTOR)); 59 | instructor.setPassword(passwordEncoder.encode(createInstructorRequest.getPassword())); 60 | instructorRepository.save(instructor); 61 | CreateInstructorResponse createInstructorResponse = modelMapperService.forResponse().map(instructor, CreateInstructorResponse.class); 62 | return new SuccessDataResult(createInstructorResponse,Messages.InstructorCreated); 63 | } 64 | 65 | @Override 66 | public DataResult update(int id,UpdateInstructorRequest updateInstructorRequest) { 67 | checkIfExistsInstructorById(id); 68 | Instructor instructor = modelMapperService.forRequest().map(updateInstructorRequest,Instructor.class); 69 | instructor.setId(id); 70 | instructor.setRoles(Set.of(Role.ROLE_INSTRUCTOR)); 71 | instructor.setPassword(passwordEncoder.encode(updateInstructorRequest.getPassword())); 72 | Instructor updatedInstructor = instructorRepository.save(instructor); 73 | UpdateInstructorResponse response = modelMapperService.forResponse().map(updatedInstructor,UpdateInstructorResponse.class); 74 | DataResult result = new DataResult<>(response,true,Messages.InstructorUpdated); 75 | return result; 76 | } 77 | 78 | @Override 79 | public Result delete(int id) { 80 | checkIfExistsInstructorById(id); 81 | instructorRepository.deleteById(id); 82 | return new SuccessResult(Messages.InstructorDeleted); 83 | } 84 | 85 | private void checkIfExistsInstructorByNationalIdentity(String nationalIdentity){ 86 | Instructor instructor = instructorRepository.findByNationalIdentity(nationalIdentity); 87 | if(instructor != null) 88 | throw new BusinessException(Messages.EmployeeExists); 89 | } 90 | 91 | private void checkIfExistsInstructorById(int id) { 92 | Instructor instructor = instructorRepository.findById(id).orElse(null); 93 | if(instructor == null) 94 | throw new BusinessException(Messages.InstructorIfNotExists); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/concretes/users/UserDetailManager.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.concretes.users; 2 | 3 | import com.kodlamaio.bootcampproject.dataAccess.abstracts.users.UserRepository; 4 | import com.kodlamaio.bootcampproject.entities.users.User; 5 | import com.kodlamaio.bootcampproject.security.ApplicationUser; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.security.core.userdetails.UserDetails; 8 | import org.springframework.security.core.userdetails.UserDetailsService; 9 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 10 | import org.springframework.stereotype.Service; 11 | 12 | @Service 13 | @AllArgsConstructor 14 | public class UserDetailManager implements UserDetailsService { 15 | 16 | private UserRepository userRepository; 17 | 18 | @Override 19 | public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { 20 | User user = userRepository.findByEmail(email); 21 | if(user==null) 22 | throw new UsernameNotFoundException("User could not found"); 23 | return ApplicationUser.create(user); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/constants/Messages.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.constants; 2 | 3 | public class Messages { 4 | public static final String InstructorDeleted = "Instructor Deleted"; 5 | public static final String InstructorCreated = "Instructor Created"; 6 | public static final String InstructorUpdated = "Instructor Updated"; 7 | public static final String InstructorsListed = "Instructors Listed"; 8 | public static final String ApplicantsListed = "Applicants Listed"; 9 | public static final String ApplicantCreated = "Applicant Created"; 10 | public static final String ApplicantUpdated = "Applicant Updated"; 11 | public static final String ApplicantDeleted = "Applicant Deleted"; 12 | public static final String EmployeesListed = "Employees Listed"; 13 | public static final String EmployeeCreated = "Employee Created"; 14 | public static final String EmployeeUpdated = "Employee Updated"; 15 | public static final String EmployeeDeleted = "Employee Deleted"; 16 | public static final String ApplicantExists = "Applicant Exists"; 17 | public static final String ApplicantIfNotExists = "Applicant no exists"; 18 | public static final String EmployeeExists = "Employee Exists"; 19 | public static final String EmployeeIfNotExists = "Employee no exists"; 20 | public static final String BootcampIfNotExists = "Bootcamp no exists"; 21 | public static final String BootcampCreated = "Bootcamp Created"; 22 | public static final String BootcampUpdated = "Bootcamp Updated"; 23 | public static final String BootcampDeleted = "Bootcamp Deleted"; 24 | public static final String ApplicationCreated = "Application Created"; 25 | public static final String ApplicationUpdated = "Application Updated"; 26 | public static final String ApplicationDeleted = "Application Deleted"; 27 | public static final String BlackListNotExists = "BlackList no exists"; 28 | public static final String BlackListExistsApplicantById = "Applicant is BlackList"; 29 | public static final String BlackListDeleted = "BlackList Deleted"; 30 | public static final String BootcampEndDateNotBeforeStartDate = "Bootcamp end date is not before start date"; 31 | public static final String InstructorIfNotExists = "Instructor no exists"; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/applications/CreateApplicationRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.applications; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.validation.constraints.Max; 8 | import javax.validation.constraints.Min; 9 | 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | public class CreateApplicationRequest { 14 | @Min(value = 0) 15 | private int bootcampId; 16 | @Min(value = 0) 17 | private int applicantId; 18 | @Min(value = 0) 19 | private int state; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/applications/UpdateApplicationRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.applications; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.validation.constraints.Min; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class UpdateApplicationRequest { 13 | private int id; 14 | @Min(value = 1) 15 | private int bootcampId; 16 | @Min(value = 1) 17 | private int applicantId; 18 | @Min(value = 1) 19 | private int state; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/blacklists/CreateBlackListRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.blacklists; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.validation.constraints.Min; 8 | import javax.validation.constraints.NotBlank; 9 | import javax.validation.constraints.Size; 10 | import java.time.LocalDate; 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class CreateBlackListRequest { 15 | private LocalDate date; 16 | @Size(min = 3,max = 254) 17 | @NotBlank 18 | private String reason; 19 | @Min(value = 1) 20 | private int applicantId; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/blacklists/UpdateBlackListRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.blacklists; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.validation.constraints.Min; 8 | import javax.validation.constraints.NotBlank; 9 | import javax.validation.constraints.Size; 10 | import java.time.LocalDate; 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class UpdateBlackListRequest { 15 | private LocalDate date; 16 | @Size(min = 3,max = 254) 17 | @NotBlank 18 | private String reason; 19 | @Min(value = 1) 20 | private int applicantId; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/bootcamps/CreateBootcampRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.bootcamps; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.validation.constraints.Min; 8 | import javax.validation.constraints.NotBlank; 9 | import javax.validation.constraints.NotNull; 10 | import javax.validation.constraints.Size; 11 | import java.time.LocalDate; 12 | 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class CreateBootcampRequest { 17 | @Min(value = 1) 18 | private int instructorId; 19 | @NotBlank 20 | @Size(min = 3,max=254) 21 | private String name; 22 | @Min(1) 23 | private int state; 24 | @NotNull 25 | private LocalDate startDate; 26 | @NotNull 27 | private LocalDate endDate; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/bootcamps/UpdateBootcampRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.bootcamps; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.validation.constraints.Min; 8 | import javax.validation.constraints.NotBlank; 9 | import javax.validation.constraints.NotNull; 10 | import javax.validation.constraints.Size; 11 | import java.time.LocalDate; 12 | 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class UpdateBootcampRequest { 17 | @Min(value = 1) 18 | private int instructorId; 19 | @NotBlank 20 | @Size(min = 3,max=254) 21 | private String name; 22 | @Min(1) 23 | private int state; 24 | @NotNull 25 | private LocalDate startDate; 26 | @NotNull 27 | private LocalDate endDate; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/users/UserLoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.users; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class UserLoginRequest { 11 | private String email; 12 | private String password; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/users/UserRegisterRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.users; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class UserRegisterRequest { 11 | private String email; 12 | private String password; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/users/applicants/CreateApplicantRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.users.applicants; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import org.hibernate.validator.constraints.Length; 7 | 8 | import javax.validation.constraints.*; 9 | import java.time.LocalDate; 10 | 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class CreateApplicantRequest { 15 | @NotBlank 16 | @Length(min = 1, max =254 ) 17 | private String firstName; 18 | @NotBlank 19 | @Length(min = 1, max = 254) 20 | private String lastName; 21 | @NotNull 22 | private LocalDate dateOfBirth; 23 | @NotBlank 24 | @Size(min=11,max=11) 25 | private String nationalIdentity; 26 | @NotBlank 27 | @Email 28 | private String email; 29 | @NotBlank 30 | private String password; 31 | @NotBlank 32 | @Size(min = 3, max = 254) 33 | private String about; 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/users/applicants/UpdateApplicantRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.users.applicants; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import org.hibernate.validator.constraints.Length; 7 | 8 | import javax.validation.constraints.*; 9 | import java.time.LocalDate; 10 | 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class UpdateApplicantRequest { 15 | @Min(value = 0) 16 | private int id; 17 | @NotBlank 18 | @Length(min = 1, max =254 ) 19 | private String firstName; 20 | @NotBlank 21 | @Length(min = 1, max = 254) 22 | private String lastName; 23 | @NotNull 24 | private LocalDate dateOfBirth; 25 | @NotBlank 26 | @Size(min=11,max=11) 27 | private String nationalIdentity; 28 | @NotBlank 29 | @Email 30 | private String email; 31 | @NotBlank 32 | private String password; 33 | @NotBlank 34 | @Size(min = 3, max = 254) 35 | private String about; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/users/employees/CreateEmployeeRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.users.employees; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import org.hibernate.validator.constraints.Length; 7 | 8 | import javax.validation.constraints.Email; 9 | import javax.validation.constraints.NotBlank; 10 | import javax.validation.constraints.NotNull; 11 | import javax.validation.constraints.Size; 12 | import java.time.LocalDate; 13 | 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | public class CreateEmployeeRequest { 18 | @NotBlank 19 | @Length(min = 1, max =254 ) 20 | private String firstName; 21 | @NotBlank 22 | @Length(min = 1, max = 254) 23 | private String lastName; 24 | @NotNull 25 | private LocalDate dateOfBirth; 26 | @NotBlank 27 | @Size(min=11,max=11) 28 | private String nationalIdentity; 29 | @NotBlank 30 | @Email 31 | private String email; 32 | @NotBlank 33 | private String password; 34 | @Size(min=3, max = 254) 35 | @NotBlank 36 | private String position; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/users/employees/UpdateEmployeeRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.users.employees; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import org.hibernate.validator.constraints.Length; 7 | 8 | import javax.validation.constraints.*; 9 | import java.time.LocalDate; 10 | 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class UpdateEmployeeRequest { 15 | @NotBlank 16 | @Length(min = 1, max =254 ) 17 | private String firstName; 18 | @NotBlank 19 | @Length(min = 1, max = 254) 20 | private String lastName; 21 | @NotNull 22 | private LocalDate dateOfBirth; 23 | @NotBlank 24 | @Size(min=11,max=11) 25 | private String nationalIdentity; 26 | @NotBlank 27 | @Email 28 | private String email; 29 | @NotBlank 30 | private String password; 31 | @Size(min=3, max = 254) 32 | @NotBlank 33 | private String position; 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/users/instructors/CreateInstructorRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.users.instructors; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.validation.constraints.Email; 8 | import javax.validation.constraints.NotBlank; 9 | import javax.validation.constraints.NotNull; 10 | import javax.validation.constraints.Size; 11 | 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class CreateInstructorRequest { 16 | @Size(min = 3) 17 | @NotNull 18 | private String firstName; 19 | @Size(min = 3) 20 | @NotBlank 21 | private String lastName; 22 | @Email 23 | @NotBlank 24 | private String email; 25 | @NotBlank 26 | @Size(min = 3,message = "must be minimum 3 char") 27 | private String companyName; 28 | @NotBlank 29 | private String password; 30 | @Size(min = 11,max = 11) 31 | private String nationalIdentity; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/requests/users/instructors/UpdateInstructorRequest.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.requests.users.instructors; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.validation.constraints.*; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class UpdateInstructorRequest { 13 | @Size(min = 3) 14 | @NotNull 15 | private String firstName; 16 | @Size(min = 3) 17 | @NotBlank 18 | private String lastName; 19 | @Email 20 | @NotBlank 21 | private String email; 22 | @NotBlank 23 | @Size(min = 3,message = "must be minimum 3 char") 24 | private String companyName; 25 | @NotBlank 26 | private String password; 27 | @Size(min = 11,max = 11) 28 | @NotBlank 29 | private String nationalIdentity; 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/applications/CreateApplicationResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.applications; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class CreateApplicationResponse { 11 | private int id; 12 | private int bootcampId; 13 | private int applicantId; 14 | private int state; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/applications/GetAllApplicationsResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.applications; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | @Data 7 | @AllArgsConstructor 8 | @NoArgsConstructor 9 | public class GetAllApplicationsResponse { 10 | private int id; 11 | private int bootcampId; 12 | private int applicantId; 13 | private int state; 14 | private String bootcampName; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/applications/GetApplicationResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.applications; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class GetApplicationResponse { 11 | private int id; 12 | private int bootcampId; 13 | private int applicantId; 14 | private int state; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/applications/UpdateApplicationResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.applications; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class UpdateApplicationResponse { 11 | private int id; 12 | private int bootcampId; 13 | private int apicantId; 14 | private int state; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/blacklists/CreateBlackListResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.blacklists; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDate; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class CreateBlackListResponse { 13 | private int id; 14 | private LocalDate date; 15 | private String reason; 16 | private int applicantId; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/blacklists/GetAllBlackListsResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.blacklists; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDate; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class GetAllBlackListsResponse { 13 | private int id; 14 | private LocalDate date; 15 | private String reason; 16 | private int applicantId; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/blacklists/GetBlackListResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.blacklists; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDate; 8 | @Data 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | public class GetBlackListResponse { 12 | private int id; 13 | private LocalDate date; 14 | private String reason; 15 | private int applicantId; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/blacklists/UpdateBlackListResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.blacklists; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDate; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class UpdateBlackListResponse { 13 | private int id; 14 | private LocalDate date; 15 | private String reason; 16 | private int applicantId; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/bootcamps/CreateBootcampResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.bootcamps; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDate; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class CreateBootcampResponse { 13 | private int id; 14 | private int instructorId; 15 | private String name; 16 | private int state; 17 | private LocalDate startDate; 18 | private LocalDate endDate; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/bootcamps/GetAllBootcampResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.bootcamps; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDate; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class GetAllBootcampResponse { 13 | private int id; 14 | private int instructorId; 15 | private String name; 16 | private int state; 17 | private LocalDate startDate; 18 | private LocalDate endDate; 19 | private String instructorFirstName; 20 | private String instructorLastName; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/bootcamps/GetBootcampResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.bootcamps; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDate; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class GetBootcampResponse { 13 | private int id; 14 | private int instructorId; 15 | private String instructorFirstName; 16 | private String instructorLastName; 17 | private String name; 18 | private int state; 19 | private LocalDate startDate; 20 | private LocalDate endDate; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/bootcamps/UpdateBootcampResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.bootcamps; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.time.LocalDate; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class UpdateBootcampResponse { 13 | private int id; 14 | private int instructorId; 15 | private String name; 16 | private int state; 17 | private LocalDate startDate; 18 | private LocalDate endDate; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/users/applicants/CreateApplicantResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.users.applicants; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class CreateApplicantResponse { 11 | private int id; 12 | private String firstName; 13 | private String lastName; 14 | private String email; 15 | private String about; 16 | private String nationalIdentity; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/users/applicants/GetAllApplicantsResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.users.applicants; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.persistence.Column; 8 | import javax.persistence.GeneratedValue; 9 | import javax.persistence.GenerationType; 10 | import javax.persistence.Id; 11 | 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class GetAllApplicantsResponse { 16 | private int id; 17 | private String firstName; 18 | private String lastName; 19 | private String email; 20 | private String about; 21 | private String nationalIdentity; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/users/applicants/GetApplicantResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.users.applicants; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class GetApplicantResponse { 11 | private int id; 12 | private String firstName; 13 | private String lastName; 14 | private String email; 15 | private String about; 16 | private String nationalIdentity; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/users/applicants/UpdateApplicantResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.users.applicants; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class UpdateApplicantResponse { 11 | private int id; 12 | private String firstName; 13 | private String lastName; 14 | private String email; 15 | private String about; 16 | private String nationalIdentity; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/users/employees/CreateEmployeeResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.users.employees; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class CreateEmployeeResponse { 11 | private int id; 12 | private String firstName; 13 | private String lastName; 14 | private String email; 15 | private String position; 16 | private String nationalIdentity; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/users/employees/GetAllEmployeesResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.users.employees; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.persistence.Column; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class GetAllEmployeesResponse { 13 | private int id; 14 | private String firstName; 15 | private String lastName; 16 | private String email; 17 | private String position; 18 | private String nationalIdentity; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/users/employees/GetEmployeeResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.users.employees; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class GetEmployeeResponse { 11 | private int id; 12 | private String firstName; 13 | private String lastName; 14 | private String email; 15 | private String position; 16 | private String nationalIdentity; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/users/employees/UpdateEmployeeResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.users.employees; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class UpdateEmployeeResponse { 11 | private int id; 12 | private String firstName; 13 | private String lastName; 14 | private String email; 15 | private String position; 16 | private String nationalIdentity; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/users/instructors/CreateInstructorResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.users.instructors; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class CreateInstructorResponse { 11 | private int id; 12 | private String firstName; 13 | private String lastName; 14 | private String email; 15 | private String companyName; 16 | private String nationalIdentity; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/users/instructors/GetAllInstructorsResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.users.instructors; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class GetAllInstructorsResponse { 11 | private int id; 12 | private String firstName; 13 | private String lastName; 14 | private String email; 15 | private String companyName; 16 | private String nationalIdentity; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/users/instructors/GetInstructorResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.users.instructors; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class GetInstructorResponse { 11 | private int id; 12 | private String firstName; 13 | private String lastName; 14 | private String email; 15 | private String companyName; 16 | private String nationalIdentity; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/business/responses/users/instructors/UpdateInstructorResponse.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.business.responses.users.instructors; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class UpdateInstructorResponse { 11 | private int id; 12 | private String firstName; 13 | private String lastName; 14 | private String email; 15 | private String companyName; 16 | private String nationalIdentity; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/config/cors/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.config.cors; 2 | 3 | 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.cors.CorsConfiguration; 7 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 8 | import org.springframework.web.filter.CorsFilter; 9 | 10 | @Configuration 11 | public class CorsConfig { 12 | 13 | @Bean 14 | public CorsFilter corsFilter() { 15 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); 16 | source.registerCorsConfiguration("/**", buildConfig()); 17 | return new CorsFilter(source); 18 | } 19 | 20 | private CorsConfiguration buildConfig() { 21 | CorsConfiguration corsConfiguration = new CorsConfiguration(); 22 | corsConfiguration.addAllowedOrigin("*"); 23 | corsConfiguration.addAllowedHeader("*"); 24 | corsConfiguration.addAllowedMethod("*"); 25 | return corsConfiguration; 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/config/modelmapper/ModelMapperConfig.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.config.modelmapper; 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 | @Bean 10 | public ModelMapper getModelMapper(){ 11 | return new ModelMapper(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/config/security/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.config.security; 2 | 3 | import com.kodlamaio.bootcampproject.business.concretes.users.UserDetailManager; 4 | import com.kodlamaio.bootcampproject.security.JwtAuthenticationEntryPoint; 5 | import com.kodlamaio.bootcampproject.security.JwtAuthenticationFilter; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.security.authentication.AuthenticationManager; 10 | import org.springframework.security.authentication.AuthenticationProvider; 11 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider; 12 | import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; 13 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 14 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 15 | import org.springframework.security.config.http.SessionCreationPolicy; 16 | import org.springframework.security.core.userdetails.UserDetailsService; 17 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 18 | import org.springframework.security.crypto.password.PasswordEncoder; 19 | import org.springframework.security.web.SecurityFilterChain; 20 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 21 | 22 | 23 | @EnableWebSecurity 24 | @AllArgsConstructor 25 | public class SecurityConfig { 26 | private UserDetailsService userDetailsService; 27 | private JwtAuthenticationEntryPoint handler; 28 | private JwtAuthenticationFilter jwtAuthenticationFilter; 29 | 30 | 31 | 32 | @Bean 33 | public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { 34 | httpSecurity 35 | .cors() 36 | .and() 37 | .csrf().disable() 38 | .exceptionHandling().authenticationEntryPoint(handler) 39 | .and() 40 | .authenticationProvider(daoAuthenticationProvider()) 41 | .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) 42 | .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) 43 | .and() 44 | .authorizeRequests() 45 | .antMatchers("/api/v1/auth/**").permitAll() 46 | .anyRequest().authenticated(); 47 | return httpSecurity.build(); 48 | } 49 | 50 | @Bean 51 | public PasswordEncoder passwordEncoder(){ 52 | return new BCryptPasswordEncoder(); 53 | } 54 | 55 | @Bean 56 | public AuthenticationProvider daoAuthenticationProvider() { 57 | DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); 58 | provider.setPasswordEncoder(passwordEncoder()); 59 | provider.setUserDetailsService(userDetailsService); 60 | return provider; 61 | } 62 | 63 | @Bean 64 | public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception { 65 | return authenticationConfiguration.getAuthenticationManager(); 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/core/utilities/exceptions/BusinessException.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.core.utilities.exceptions; 2 | 3 | public class BusinessException extends RuntimeException{ 4 | public BusinessException(String message){ 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/core/utilities/exceptions/RestResponseEntityExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.core.utilities.exceptions; 2 | 3 | import com.kodlamaio.bootcampproject.core.utilities.results.ErrorDataResult; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.http.HttpHeaders; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.validation.FieldError; 9 | import org.springframework.web.bind.MethodArgumentNotValidException; 10 | import org.springframework.web.bind.MissingPathVariableException; 11 | import org.springframework.web.bind.annotation.ControllerAdvice; 12 | import org.springframework.web.bind.annotation.ExceptionHandler; 13 | import org.springframework.web.bind.annotation.ResponseStatus; 14 | import org.springframework.web.context.request.WebRequest; 15 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 16 | 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | @ControllerAdvice 21 | @Slf4j 22 | public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler { 23 | 24 | @ExceptionHandler 25 | public ResponseEntity handleBusinessException(BusinessException businessException){ 26 | ErrorDataResult errorDataResult = new ErrorDataResult<>(businessException.getMessage(),"BUSİNESS.EXCEPTION"); 27 | log.error(businessException.getMessage()); 28 | return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorDataResult); 29 | } 30 | 31 | @Override 32 | protected ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotValidException methodArgumentNotValidException, 33 | HttpHeaders headers, HttpStatus status, WebRequest request) { 34 | Map validationErrors = new HashMap(); 35 | for(FieldError fieldError: methodArgumentNotValidException.getBindingResult().getFieldErrors()){ 36 | validationErrors.put(fieldError.getField(),fieldError.getDefaultMessage()); 37 | } 38 | ErrorDataResult errorDataResult = new ErrorDataResult<>(validationErrors,"VALIDATION.EXCEPTION"); 39 | log.warn(errorDataResult.getData().toString()); 40 | return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorDataResult); 41 | } 42 | 43 | @Override 44 | protected ResponseEntity handleMissingPathVariable(MissingPathVariableException missingPathVariableException, 45 | HttpHeaders headers, HttpStatus status, WebRequest request) { 46 | ErrorDataResult errorDataResult = new ErrorDataResult<>(missingPathVariableException.getMessage(), "MISSING PATH VARIABLE.EXCEPTION"); 47 | log.warn(errorDataResult.getData().toString()); 48 | return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorDataResult); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/core/utilities/mapping/ModelMapperManager.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.core.utilities.mapping; 2 | 3 | import lombok.AllArgsConstructor; 4 | import org.modelmapper.ModelMapper; 5 | import org.modelmapper.convention.MatchingStrategies; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | @AllArgsConstructor 10 | public class ModelMapperManager implements ModelMapperService{ 11 | private ModelMapper modelMapper; 12 | 13 | @Override 14 | public ModelMapper forRequest() { 15 | modelMapper.getConfiguration().setAmbiguityIgnored(true).setMatchingStrategy(MatchingStrategies.STANDARD); 16 | return modelMapper; 17 | } 18 | 19 | @Override 20 | public ModelMapper forResponse() { 21 | modelMapper.getConfiguration().setAmbiguityIgnored(true).setMatchingStrategy(MatchingStrategies.LOOSE); 22 | return modelMapper; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/core/utilities/mapping/ModelMapperService.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.core.utilities.mapping; 2 | 3 | import org.modelmapper.ModelMapper; 4 | 5 | public interface ModelMapperService { 6 | ModelMapper forRequest(); 7 | ModelMapper forResponse(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/core/utilities/results/DataResult.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.core.utilities.results; 2 | 3 | 4 | public class DataResult extends Result{ 5 | private T data; 6 | public DataResult(T data, boolean success, String message) { 7 | super(success, message); 8 | this.data = data; 9 | } 10 | 11 | public DataResult(T data, boolean success) { 12 | super(success); 13 | this.data = data; 14 | } 15 | 16 | public T getData() { 17 | return this.data; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/core/utilities/results/ErrorDataResult.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.core.utilities.results; 2 | 3 | public class ErrorDataResult extends DataResult { 4 | public ErrorDataResult(T data, String message) { 5 | super(data, false ,message); 6 | } 7 | 8 | public ErrorDataResult(T data) { 9 | super(data,false); 10 | } 11 | 12 | public ErrorDataResult(String message) { 13 | super(null, false ,message); 14 | } 15 | 16 | public ErrorDataResult() { 17 | super(null, false); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/core/utilities/results/ErrorResult.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.core.utilities.results; 2 | 3 | public class ErrorResult extends Result{ 4 | public ErrorResult() { 5 | super(false); 6 | } 7 | 8 | public ErrorResult(String message) { 9 | super(false,message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/core/utilities/results/Result.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.core.utilities.results; 2 | 3 | 4 | public class Result { 5 | private boolean success; 6 | private String message; 7 | 8 | public Result(boolean success) { 9 | this.success = success; 10 | } 11 | 12 | public Result(boolean success,String message) { 13 | this(success); 14 | this.message = message; 15 | } 16 | 17 | public boolean isSuccess() { 18 | return this.success; 19 | } 20 | 21 | public String getMessage() { 22 | return this.message; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/core/utilities/results/SuccessDataResult.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.core.utilities.results; 2 | 3 | public class SuccessDataResult extends DataResult { 4 | public SuccessDataResult(T data, String message) { 5 | super(data, true ,message); 6 | } 7 | 8 | public SuccessDataResult(T data) { 9 | super(data,true); 10 | } 11 | 12 | public SuccessDataResult(String message) { 13 | super(null, true ,message); 14 | } 15 | 16 | public SuccessDataResult() { 17 | super(null, true); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/core/utilities/results/SuccessResult.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.core.utilities.results; 2 | 3 | public class SuccessResult extends Result{ 4 | public SuccessResult() { 5 | super(true); 6 | } 7 | 8 | public SuccessResult(String message) { 9 | super(true,message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/dataAccess/abstracts/BlackListRepository.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.dataAccess.abstracts; 2 | 3 | import com.kodlamaio.bootcampproject.entities.BlackList; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface BlackListRepository extends JpaRepository { 7 | BlackList findByApplicantId(int id); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/dataAccess/abstracts/BootcampRepository.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.dataAccess.abstracts; 2 | 3 | import com.kodlamaio.bootcampproject.entities.Bootcamp; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface BootcampRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/dataAccess/abstracts/applications/ApplicationRepository.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.dataAccess.abstracts.applications; 2 | 3 | import com.kodlamaio.bootcampproject.entities.applications.Application; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface ApplicationRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/dataAccess/abstracts/users/ApplicantRepository.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.dataAccess.abstracts.users; 2 | 3 | import com.kodlamaio.bootcampproject.entities.users.Applicant; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface ApplicantRepository extends JpaRepository { 7 | Applicant findByNationalIdentity(String nationalIdentity); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/dataAccess/abstracts/users/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.dataAccess.abstracts.users; 2 | 3 | import com.kodlamaio.bootcampproject.entities.users.Employee; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface EmployeeRepository extends JpaRepository { 7 | Employee findByNationalIdentity(String nationalIdentity); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/dataAccess/abstracts/users/InstructorRepository.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.dataAccess.abstracts.users; 2 | 3 | import com.kodlamaio.bootcampproject.entities.users.Instructor; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface InstructorRepository extends JpaRepository { 7 | Instructor findByNationalIdentity(String nationalIdentity); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/dataAccess/abstracts/users/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.dataAccess.abstracts.users; 2 | 3 | import com.kodlamaio.bootcampproject.entities.users.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface UserRepository extends JpaRepository { 7 | User findByUsername(String username); 8 | User findByEmail(String email); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/entities/BlackList.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.entities; 2 | 3 | import com.kodlamaio.bootcampproject.entities.users.Applicant; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import javax.persistence.*; 9 | import java.time.LocalDate; 10 | 11 | @Data 12 | @Entity 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @Table(name="blacklists") 16 | public class BlackList { 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.IDENTITY) 19 | @Column(name="id") 20 | private int id; 21 | 22 | @Column(name="date") 23 | private LocalDate date; 24 | 25 | @Column(name="reason") 26 | private String reason; 27 | 28 | @ManyToOne 29 | @JoinColumn(name = "applicant_id") 30 | private Applicant applicant; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/entities/Bootcamp.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.entities; 2 | 3 | import com.kodlamaio.bootcampproject.entities.applications.Application; 4 | import com.kodlamaio.bootcampproject.entities.users.Instructor; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.*; 10 | import java.time.LocalDate; 11 | import java.util.List; 12 | 13 | @Entity 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | @Table(name="bootcamps") 18 | public class Bootcamp { 19 | @Id 20 | @GeneratedValue(strategy = GenerationType.IDENTITY) 21 | @Column(name="id") 22 | private int id; 23 | 24 | @Column(name="name") 25 | private String name; 26 | 27 | @Column(name="dateStart") 28 | private LocalDate dateStart; 29 | 30 | @Column(name = "dateEnd") 31 | private LocalDate dateEnd; 32 | 33 | @Column(name="state") 34 | private int state; 35 | 36 | @ManyToOne() 37 | @JoinColumn(name = "instructor_id") 38 | private Instructor instructor; 39 | 40 | @OneToMany(mappedBy = "bootcamp") 41 | private List applications; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/entities/applications/Application.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.entities.applications; 2 | 3 | import com.kodlamaio.bootcampproject.entities.Bootcamp; 4 | import com.kodlamaio.bootcampproject.entities.users.Applicant; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.*; 10 | 11 | @Entity 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @Table(name="applications") 16 | public class Application { 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.IDENTITY) 19 | @Column(name="id") 20 | private int id; 21 | @Column(name="state") 22 | private int state; 23 | 24 | @ManyToOne 25 | @JoinColumn(name = "applicant_id") 26 | private Applicant applicant; 27 | @ManyToOne 28 | @JoinColumn(name = "bootcamp_id") 29 | private Bootcamp bootcamp; 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/entities/users/Applicant.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.entities.users; 2 | 3 | import com.kodlamaio.bootcampproject.entities.BlackList; 4 | import com.kodlamaio.bootcampproject.entities.applications.Application; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | import lombok.NoArgsConstructor; 9 | 10 | import javax.persistence.*; 11 | import java.util.List; 12 | 13 | @Entity 14 | @Table(name="applicants") 15 | @Data 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | public class Applicant extends User{ 19 | 20 | @Column(name="about") 21 | private String about; 22 | 23 | @OneToMany(mappedBy = "applicant") 24 | private List applications; 25 | 26 | @OneToMany(mappedBy = "applicant") 27 | private List blackLists; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/entities/users/Employee.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.entities.users; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | import lombok.NoArgsConstructor; 7 | 8 | import javax.persistence.*; 9 | 10 | @Entity 11 | @Table(name="employees") 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class Employee extends User{ 16 | @Column(name="position") 17 | private String position; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/entities/users/Instructor.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.entities.users; 2 | 3 | import com.kodlamaio.bootcampproject.entities.Bootcamp; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import javax.persistence.*; 9 | import java.util.List; 10 | 11 | @Entity 12 | @Table(name="instructors") 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class Instructor extends User{ 17 | 18 | @Column(name="companyName") 19 | private String companyName; 20 | 21 | @OneToMany(mappedBy = "instructor") 22 | private List bootcamp; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/entities/users/Role.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.entities.users; 2 | 3 | public enum Role { 4 | ROLE_EMPLOYEE, 5 | ROLE_INSTRUCTOR, 6 | ROLE_APPLICANT, 7 | ROLE_USER 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/entities/users/User.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.entities.users; 2 | 3 | import com.kodlamaio.bootcampproject.entities.applications.Application; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import javax.persistence.*; 9 | import java.time.LocalDate; 10 | import java.util.List; 11 | import java.util.Set; 12 | 13 | @Entity 14 | @Table(name="users") 15 | @Data 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | @Inheritance(strategy = InheritanceType.JOINED) 19 | public class User { 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | @Column(name="id") 23 | private int id; 24 | 25 | @Column(name="firstName") 26 | private String firstName; 27 | 28 | @Column(name="lastName") 29 | private String lastName; 30 | 31 | @Column(name="email") 32 | private String email; 33 | 34 | @Column(name="username") 35 | private String username; 36 | 37 | @Column(name="password") 38 | private String password; 39 | 40 | @Column(name="dateOfBirth") 41 | private LocalDate dateOfBirth; 42 | 43 | @Column(name="nationalIdentity") 44 | private String nationalIdentity; 45 | 46 | @Enumerated(EnumType.STRING) 47 | @Column 48 | @ElementCollection(fetch = FetchType.EAGER) 49 | private Set roles = Set.of(Role.ROLE_USER); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/security/ApplicationUser.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.security; 2 | 3 | import com.kodlamaio.bootcampproject.entities.users.Role; 4 | import com.kodlamaio.bootcampproject.entities.users.User; 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | import org.springframework.security.core.GrantedAuthority; 8 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 9 | import org.springframework.security.core.userdetails.UserDetails; 10 | 11 | import java.util.*; 12 | 13 | @Getter 14 | @Setter 15 | public class ApplicationUser implements UserDetails { 16 | private int id; 17 | private String nationalIdentity; 18 | private String username; 19 | private String email; 20 | private String password; 21 | private Set authorities; 22 | public ApplicationUser(int id ,String nationalIdentity, 23 | String username, String email, String password, Set authorities) { 24 | this.id = id; 25 | this.nationalIdentity = nationalIdentity; 26 | this.username = username; 27 | this.email = email; 28 | this.password = password; 29 | this.authorities = authorities; 30 | } 31 | 32 | public static ApplicationUser create(User user){ 33 | Set authorityList = new HashSet<>(); 34 | for(Role role: user.getRoles()){ 35 | authorityList.add(new SimpleGrantedAuthority(role.name())); 36 | } 37 | return new ApplicationUser(user.getId(), user.getNationalIdentity(), 38 | user.getUsername(), user.getEmail(), user.getPassword(), authorityList); 39 | } 40 | 41 | @Override 42 | public boolean isAccountNonExpired() { 43 | return true; 44 | } 45 | 46 | @Override 47 | public boolean isAccountNonLocked() { 48 | return true; 49 | } 50 | 51 | @Override 52 | public boolean isCredentialsNonExpired() { 53 | return true; 54 | } 55 | 56 | @Override 57 | public boolean isEnabled() { 58 | return true; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/security/JwtAuthenticationEntryPoint.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.security; 2 | 3 | import org.springframework.security.core.AuthenticationException; 4 | import org.springframework.security.web.AuthenticationEntryPoint; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | @Component 12 | public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { 13 | 14 | @Override 15 | public void commence(HttpServletRequest request, HttpServletResponse response, 16 | AuthenticationException authException) throws IOException, ServletException { 17 | response.sendError(HttpServletResponse.SC_UNAUTHORIZED,authException.getMessage()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/security/JwtAuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.security; 2 | 3 | import com.kodlamaio.bootcampproject.business.concretes.users.UserDetailManager; 4 | import lombok.AllArgsConstructor; 5 | import lombok.NoArgsConstructor; 6 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 7 | import org.springframework.security.core.context.SecurityContextHolder; 8 | import org.springframework.security.core.userdetails.UserDetails; 9 | import org.springframework.security.core.userdetails.UserDetailsService; 10 | import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; 11 | import org.springframework.stereotype.Component; 12 | import org.springframework.util.StringUtils; 13 | import org.springframework.web.filter.OncePerRequestFilter; 14 | 15 | import javax.servlet.FilterChain; 16 | import javax.servlet.ServletException; 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import java.io.IOException; 20 | 21 | @AllArgsConstructor 22 | @Component 23 | public class JwtAuthenticationFilter extends OncePerRequestFilter { 24 | 25 | private JwtTokenProvider jwtTokenProvider; 26 | private UserDetailsService userDetailsService; 27 | 28 | 29 | @Override 30 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) 31 | throws ServletException, IOException { 32 | try { 33 | String jwtToken = extractJwtFromRequest(request); 34 | if (StringUtils.hasText(jwtToken) && jwtTokenProvider.validateToken(jwtToken)) { 35 | String email = jwtTokenProvider.getEmailFromJwt(jwtToken); 36 | UserDetails user = userDetailsService.loadUserByUsername(email); 37 | if (user != null) { 38 | UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(user, null, 39 | user.getAuthorities()); 40 | auth.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); 41 | SecurityContextHolder.getContext().setAuthentication(auth); 42 | } 43 | } 44 | } catch (Exception e) { 45 | return; 46 | } 47 | filterChain.doFilter(request, response); 48 | } 49 | 50 | private String extractJwtFromRequest(HttpServletRequest request) { 51 | String bearer = request.getHeader("Authorization"); 52 | if(StringUtils.hasText(bearer) && bearer.startsWith("Bearer ")) 53 | return bearer.substring("Bearer".length()+1); 54 | return null; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/kodlamaio/bootcampproject/security/JwtTokenProvider.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject.security; 2 | 3 | import io.jsonwebtoken.*; 4 | import lombok.AllArgsConstructor; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.security.core.Authentication; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.crypto.SecretKey; 10 | import java.util.Date; 11 | 12 | @Component 13 | public class JwtTokenProvider { 14 | @Value("${application.jwt.secretKey}") 15 | private String APP_SECRET; 16 | @Value("${application.jwt.expires.in}") 17 | private int EXPIRES_IN; 18 | 19 | public String generateJwtToken(Authentication authentication) { 20 | ApplicationUser applicationUser = (ApplicationUser) authentication.getPrincipal(); 21 | return Jwts.builder() 22 | .setSubject(applicationUser.getEmail()) 23 | .claim("authorities", applicationUser.getAuthorities()) 24 | .setIssuedAt(new Date()) 25 | .setExpiration(new Date(new Date().getTime() + EXPIRES_IN)) 26 | .signWith(SignatureAlgorithm.HS512, APP_SECRET) 27 | .compact(); 28 | } 29 | 30 | String getEmailFromJwt(String token) { 31 | Claims claims = getJwtBody(token); 32 | return claims.getSubject(); 33 | } 34 | 35 | boolean validateToken(String token) { 36 | try { 37 | Jwts.parser().setSigningKey(APP_SECRET).parseClaimsJws(token); 38 | return !isTokenExpired(token); 39 | } catch (SignatureException e) { 40 | return false; 41 | } catch (MalformedJwtException e) { 42 | return false; 43 | } catch (ExpiredJwtException e) { 44 | return false; 45 | } catch (UnsupportedJwtException e) { 46 | return false; 47 | } catch (IllegalArgumentException e) { 48 | return false; 49 | } 50 | } 51 | 52 | boolean isTokenExpired(String token) { 53 | Date expiration = getJwtBody(token).getExpiration(); 54 | return expiration.before(new Date()); 55 | } 56 | 57 | private Claims getJwtBody(String token) { 58 | 59 | return Jwts.parser() 60 | .setSigningKey(APP_SECRET) 61 | .parseClaimsJws(token) 62 | .getBody(); 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect 2 | spring.jpa.hibernate.ddl-auto=update 3 | spring.jpa.hibernate.show-sql=true 4 | spring.datasource.url=jdbc:postgresql://localhost:5432/bootcampDb 5 | spring.datasource.username=postgres 6 | spring.datasource.password=1234 7 | spring.jpa.properties.javax.persistence.validation.mode = none 8 | 9 | application.jwt.secretKey=springsecurity 10 | application.jwt.expires.in=3600000 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/test/java/com/kodlamaio/bootcampproject/BootcampProjectApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.kodlamaio.bootcampproject; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BootcampProjectApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------