diff --git a/HELP.md b/HELP.md new file mode 100644 index 0000000..82e3db2 --- /dev/null +++ b/HELP.md @@ -0,0 +1,18 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.2.6.RELEASE/maven-plugin/) +* [Spring Web](https://docs.spring.io/spring-boot/docs/2.2.6.RELEASE/reference/htmlsingle/#boot-features-developing-web-applications) +* [Spring Data JDBC](https://docs.spring.io/spring-data/jdbc/docs/current/reference/html/) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/) +* [Using Spring Data JDBC](https://github.com/spring-projects/spring-data-examples/tree/master/jdbc/basics) + diff --git a/README.md b/README.md new file mode 100644 index 0000000..cee104b --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +### Simple Employee Management System implemented in Spring and Angular for practice. +#### Features Implemented: +1. Basic **CRUD** (Create, Read, Update and Delete) Operations on Employee and Team. +2. Addition of Multiple Members to Multiple Teams. +3. Validations diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..a16b543 --- /dev/null +++ b/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..c8d4337 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,182 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index b83e545..5f5c8f9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,38 +1,60 @@ - - 4.0.0 - com.springEMS - ems - 0.0.1-SNAPSHOT - SpringEMS - - - - org.springframework.boot - spring-boot-starter-parent - 2.2.2.RELEASE - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - mysql - mysql-connector-java - - - - - - - 1.8 - - - \ No newline at end of file + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.6.RELEASE + + + com.example + crud + 0.0.1-SNAPSHOT + demo + Demo project for Spring Boot + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + + mysql + mysql-connector-java + runtime + + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/src/main/java/com/example/crud/DemoApplication.java b/src/main/java/com/example/crud/DemoApplication.java new file mode 100644 index 0000000..14f23e3 --- /dev/null +++ b/src/main/java/com/example/crud/DemoApplication.java @@ -0,0 +1,13 @@ +package com.example.crud; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + +} diff --git a/src/main/java/com/example/crud/employee/Employee.java b/src/main/java/com/example/crud/employee/Employee.java new file mode 100644 index 0000000..9c7f431 --- /dev/null +++ b/src/main/java/com/example/crud/employee/Employee.java @@ -0,0 +1,56 @@ +package com.example.crud.employee; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "employee") +public class Employee { + + @Id + @Column(name = "emp_id") + private String emp_id; + + @Column(name = "emp_first_name") + private String emp_first_name; + + @Column(name = "emp_last_name") + private String emp_last_name; + + public Employee() { + + } + + public Employee(String emp_id, String empFirstName, String empLastName) { + this.emp_id = emp_id; + this.emp_first_name = empFirstName; + this.emp_last_name = empLastName; + } + + public String getEmp_id(){ + return this.emp_id; + } + + public String getEmp_first_name(){ + return this.emp_first_name; + } + + public String getEmp_last_name(){ + return this.emp_last_name; + } + + public void setEmp_id(String emp_id) { + this.emp_id = emp_id; + } + + public void setEmp_first_name(String empFirstName) { + this.emp_first_name = empFirstName; + } + + public void setEmp_last_name(String empLastName) { + this.emp_last_name = empLastName; + } + +} \ No newline at end of file diff --git a/src/main/java/com/example/crud/employee/EmployeeController.java b/src/main/java/com/example/crud/employee/EmployeeController.java new file mode 100644 index 0000000..279fd43 --- /dev/null +++ b/src/main/java/com/example/crud/employee/EmployeeController.java @@ -0,0 +1,73 @@ +package com.example.crud.employee; + +import java.util.ArrayList; +import java.util.List; + +import com.example.crud.handler.CustomException; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class EmployeeController { + + @Autowired + private EmployeeService employeeService; + + @RequestMapping(value = "/start") + public String start() { + return "Hello World"; + } + + @CrossOrigin(origins = "*", allowedHeaders = "*") + @RequestMapping(method = RequestMethod.POST, value = "/addEmployee", produces = "application/json") + public ResponseEntity addEmployee(@RequestBody Employee emp) { + System.out + .println("ID: " + emp.getEmp_id() + " Name: " + emp.getEmp_first_name() + " " + emp.getEmp_last_name()); + employeeService.addEmployee(emp); + return new ResponseEntity(emp, HttpStatus.OK); + } + + @CrossOrigin(origins = "*", allowedHeaders = "*") + @RequestMapping(method = RequestMethod.GET, value = "/employees", produces = "application/json") + public ResponseEntity fetchEmployees() { + // System.out.println("Fetch Employees Called"); + List list = new ArrayList(); + list = employeeService.fetchAllEmployees(); + return new ResponseEntity<>(list, HttpStatus.OK); + } + + @CrossOrigin(origins = "*", allowedHeaders = "*") + @RequestMapping(method = RequestMethod.POST, value = "/deleteEmployee", produces = "application/json") + public ResponseEntity deleteEmployee(@RequestBody Employee emp) throws CustomException { + employeeService.deleteEmployee(emp); + boolean operation = true; + return new ResponseEntity<>(operation, HttpStatus.OK); + } + + @CrossOrigin(origins = "*", allowedHeaders = "*") + @RequestMapping(method = RequestMethod.GET, value = "/employee/{id}", produces = "application/json") + public ResponseEntity fetchEmployee(@PathVariable(value="id") int id) { + Employee emp = new Employee(); + emp = this.employeeService.fetchEmployee(String.valueOf(id)); + return new ResponseEntity<>(emp, HttpStatus.OK); + } + + @CrossOrigin(origins = "*", allowedHeaders = "*") + @RequestMapping(method = RequestMethod.PUT, value = "/updateEmployee/{id}") + @ResponseBody + public ResponseEntity updateEmployee(@RequestBody Employee emp, @PathVariable(value = "id") int id) { + this.employeeService.updateEmployee(emp, String.valueOf(id)); + boolean operation = true; + return new ResponseEntity<>(operation, HttpStatus.OK); + } + +} \ No newline at end of file diff --git a/src/main/java/com/example/crud/employee/EmployeeRepository.java b/src/main/java/com/example/crud/employee/EmployeeRepository.java new file mode 100644 index 0000000..6408426 --- /dev/null +++ b/src/main/java/com/example/crud/employee/EmployeeRepository.java @@ -0,0 +1,11 @@ +package com.example.crud.employee; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import com.example.crud.employee.Employee; + +@Repository +public interface EmployeeRepository extends JpaRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/example/crud/employee/EmployeeService.java b/src/main/java/com/example/crud/employee/EmployeeService.java new file mode 100644 index 0000000..6221bdc --- /dev/null +++ b/src/main/java/com/example/crud/employee/EmployeeService.java @@ -0,0 +1,64 @@ +package com.example.crud.employee; + +import java.util.ArrayList; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.example.crud.handler.*; +import com.example.crud.team.TeamService; + +@Service +public class EmployeeService { + + @Autowired + private EmployeeRepository employeeRepository; + + @Autowired + private TeamService teamService; + + public void addEmployee(Employee emp) { + this.employeeRepository.save(emp); + System.out.println("Employee Added!"); + } + + public ArrayList fetchAllEmployees() { + ArrayList list = new ArrayList(); + this.employeeRepository.findAll().forEach(list::add); + return list; + } + + public void deleteEmployee(Employee emp) throws CustomException { + teamService.deleteTeamMemberUsingEmployeeId(emp); + this.employeeRepository.delete(emp); + } + + public Employee fetchEmployee(String emp_id) { + Employee emp = new Employee(); + emp = this.employeeRepository.findById(emp_id).get(); + return emp; + } + + public void updateEmployee(Employee emp, String emp_id) { + this.employeeRepository.save(emp); + } + + public boolean checkIfEmployeeExists(String id) { + return employeeRepository.existsById(id); + } + + public boolean validateEmployee(Employee emp) throws CustomException { + if(emp.getEmp_id() == null || emp.getEmp_id().equals("") || emp.getEmp_id().length()>20) { + throw new CustomException("Invalid Field Employee ID"); + } + + if(emp.getEmp_first_name() == null || emp.getEmp_first_name().equals("") || emp.getEmp_first_name().length()>50) { + throw new CustomException("Invalid Field First Name"); + } + if(emp.getEmp_last_name() == null || emp.getEmp_last_name().equals("") || emp.getEmp_last_name().length()>50) { + throw new CustomException("Invalid Field Last Name"); + } + return true; + } + + +} \ No newline at end of file diff --git a/src/main/java/com/springEMS/handler/CustomException.java b/src/main/java/com/example/crud/handler/CustomException.java similarity index 90% rename from src/main/java/com/springEMS/handler/CustomException.java rename to src/main/java/com/example/crud/handler/CustomException.java index 75bce18..99f66bb 100644 --- a/src/main/java/com/springEMS/handler/CustomException.java +++ b/src/main/java/com/example/crud/handler/CustomException.java @@ -1,4 +1,4 @@ -package com.springEMS.handler; +package com.example.crud.handler; public class CustomException extends Exception{ @@ -23,8 +23,4 @@ public void setMessage(String message) { } - - - - -} +} \ No newline at end of file diff --git a/src/main/java/com/springEMS/handler/MyExceptionHandler.java b/src/main/java/com/example/crud/handler/MyExceptionHandler.java similarity index 93% rename from src/main/java/com/springEMS/handler/MyExceptionHandler.java rename to src/main/java/com/example/crud/handler/MyExceptionHandler.java index 17fd839..88c8b91 100644 --- a/src/main/java/com/springEMS/handler/MyExceptionHandler.java +++ b/src/main/java/com/example/crud/handler/MyExceptionHandler.java @@ -1,4 +1,4 @@ - package com.springEMS.handler; +package com.example.crud.handler; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -15,4 +15,4 @@ public ResponseEntity handleExcpetion(CustomException c){ } -} +} \ No newline at end of file diff --git a/src/main/java/com/springEMS/team/Team.java b/src/main/java/com/example/crud/team/Team.java similarity index 93% rename from src/main/java/com/springEMS/team/Team.java rename to src/main/java/com/example/crud/team/Team.java index 0b30afb..4d1653b 100644 --- a/src/main/java/com/springEMS/team/Team.java +++ b/src/main/java/com/example/crud/team/Team.java @@ -1,4 +1,4 @@ -package com.springEMS.team; +package com.example.crud.team; import javax.persistence.Entity; import javax.persistence.Id; @@ -37,10 +37,5 @@ public String getTeam_name() { public void setTeam_name(String team_name) { this.team_name = team_name; } - - - - - -} +} \ No newline at end of file diff --git a/src/main/java/com/springEMS/team/TeamController.java b/src/main/java/com/example/crud/team/TeamController.java similarity index 91% rename from src/main/java/com/springEMS/team/TeamController.java rename to src/main/java/com/example/crud/team/TeamController.java index fbe7d86..fc7d398 100644 --- a/src/main/java/com/springEMS/team/TeamController.java +++ b/src/main/java/com/example/crud/team/TeamController.java @@ -1,10 +1,11 @@ -package com.springEMS.team; +package com.example.crud.team; import java.util.ArrayList; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -12,17 +13,16 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; -import com.springEMS.employee.Employee; -import com.springEMS.handler.CustomException; +import com.example.crud.employee.Employee; +import com.example.crud.handler.*; +@CrossOrigin(origins = "*", allowedHeaders = "*") @RestController public class TeamController { @Autowired private TeamService teamServ; - //Team Requests - @RequestMapping(method = RequestMethod.GET, value = "/teams") @ResponseBody public ResponseEntity> getTeamList(){ @@ -31,7 +31,7 @@ public ResponseEntity> getTeamList(){ return new ResponseEntity>(list, HttpStatus.OK); } - @RequestMapping(method = RequestMethod.POST, value = "/team") + @RequestMapping(method = RequestMethod.POST, value = "/addTeam") @ResponseBody public ResponseEntity addTeam(@RequestBody Team team) throws CustomException { @@ -93,4 +93,4 @@ public ResponseEntity> getEmployeeForTeam(@PathVariable Stri return new ResponseEntity>(list, HttpStatus.OK); } -} +} \ No newline at end of file diff --git a/src/main/java/com/springEMS/team/TeamMember.java b/src/main/java/com/example/crud/team/TeamMember.java similarity index 87% rename from src/main/java/com/springEMS/team/TeamMember.java rename to src/main/java/com/example/crud/team/TeamMember.java index 64fd172..7424396 100644 --- a/src/main/java/com/springEMS/team/TeamMember.java +++ b/src/main/java/com/example/crud/team/TeamMember.java @@ -1,14 +1,10 @@ -package com.springEMS.team; +package com.example.crud.team; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; import javax.persistence.Table; -import com.springEMS.employee.Employee; - @Entity @Table(name = "team_member") @IdClass(TeamMemberId.class) @@ -67,4 +63,4 @@ public void setTeam_id(String team_id) { -} +} \ No newline at end of file diff --git a/src/main/java/com/springEMS/team/TeamMemberId.java b/src/main/java/com/example/crud/team/TeamMemberId.java similarity index 89% rename from src/main/java/com/springEMS/team/TeamMemberId.java rename to src/main/java/com/example/crud/team/TeamMemberId.java index 8481dcc..6973ad3 100644 --- a/src/main/java/com/springEMS/team/TeamMemberId.java +++ b/src/main/java/com/example/crud/team/TeamMemberId.java @@ -1,10 +1,11 @@ -package com.springEMS.team; +package com.example.crud.team; import java.io.Serializable; public class TeamMemberId implements Serializable{ - private String emp_id; + private static final long serialVersionUID = 1L; + private String emp_id; private String team_id; public TeamMemberId() { @@ -53,4 +54,4 @@ public int hashCode() { } -} +} \ No newline at end of file diff --git a/src/main/java/com/springEMS/team/TeamMemberRepository.java b/src/main/java/com/example/crud/team/TeamMemberRepository.java similarity index 97% rename from src/main/java/com/springEMS/team/TeamMemberRepository.java rename to src/main/java/com/example/crud/team/TeamMemberRepository.java index 3e2aed1..794813b 100644 --- a/src/main/java/com/springEMS/team/TeamMemberRepository.java +++ b/src/main/java/com/example/crud/team/TeamMemberRepository.java @@ -1,4 +1,4 @@ -package com.springEMS.team; +package com.example.crud.team; import java.util.ArrayList; @@ -25,4 +25,4 @@ public interface TeamMemberRepository extends CrudRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/springEMS/team/TeamService.java b/src/main/java/com/example/crud/team/TeamService.java similarity index 93% rename from src/main/java/com/springEMS/team/TeamService.java rename to src/main/java/com/example/crud/team/TeamService.java index 988a33c..8c4cde5 100644 --- a/src/main/java/com/springEMS/team/TeamService.java +++ b/src/main/java/com/example/crud/team/TeamService.java @@ -1,4 +1,4 @@ -package com.springEMS.team; +package com.example.crud.team; import java.util.ArrayList; @@ -7,12 +7,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.springEMS.employee.Employee; -import com.springEMS.employee.EmployeeService; -import com.springEMS.handler.CustomException; +import com.example.crud.employee.*; +import com.example.crud.handler.*; @Service public class TeamService { + @Autowired private TeamRepository teamRepo; @@ -119,19 +119,13 @@ public ArrayList getEmployeeListForTeam(String team_id) throws Excepti for(int i=0;i addDepartment(@RequestBody Department dept) throws CustomException{ - return new ResponseEntity(deptServ.addDepartment(dept), HttpStatus.OK); - } - - - @RequestMapping(method = RequestMethod.GET, value = "/department/{dept_id}") - @ResponseBody - public ResponseEntity> getEmployeeListForDepartment(@PathVariable String dept_id) throws CustomException{ - ArrayList list = new ArrayList(); - list = deptServ.getEmployeeListForDepartment(dept_id); - return new ResponseEntity>(list,HttpStatus.OK); - } - -} diff --git a/src/main/java/com/springEMS/department/DepartmentRepository.java b/src/main/java/com/springEMS/department/DepartmentRepository.java deleted file mode 100644 index aa05137..0000000 --- a/src/main/java/com/springEMS/department/DepartmentRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.springEMS.department; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface DepartmentRepository extends CrudRepository { - - -} diff --git a/src/main/java/com/springEMS/department/DepartmentService.java b/src/main/java/com/springEMS/department/DepartmentService.java deleted file mode 100644 index 230f86b..0000000 --- a/src/main/java/com/springEMS/department/DepartmentService.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.springEMS.department; - -import java.util.ArrayList; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.springEMS.handler.CustomException; -import com.springEMS.employee.Employee; -import com.springEMS.employee.EmployeeService; - -@Service -public class DepartmentService { - - @Autowired - private DepartmentRepository deptRepo; - - @Autowired - private EmployeeService empServ; - - public boolean departmentExists(String dept_id) throws CustomException{ - if(!deptRepo.existsById(dept_id)) { - return false; - } - else { - return true; - } - } - - public boolean addDepartment(Department dept) throws CustomException { - if(!this.departmentExists(dept.getDept_id())) { - deptRepo.save(dept); - return true; - } - else { - throw new CustomException("Entity already Exists"); - } - } - - public ArrayList getEmployeeListForDepartment(String dept_id) throws CustomException{ - - ArrayList list = new ArrayList(); - if(this.departmentExists(dept_id)) { - list = empServ.getEmployeeListForDepartment(dept_id); - return list; - } - else { - throw new CustomException("Entity Not Found"); - } - } -} diff --git a/src/main/java/com/springEMS/employee/Employee.java b/src/main/java/com/springEMS/employee/Employee.java deleted file mode 100644 index 085aa65..0000000 --- a/src/main/java/com/springEMS/employee/Employee.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.springEMS.employee; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(name = "employee") -public class Employee { - - @Id - @Column(name = "empId") - private String emp_id; - - private String f_name; - private String l_name; - @Column(name = "dept_id") - private String dept_id; - private String job_title; - private String dob; - private String phone_no; - - //Constructors - public Employee(){ - } - - - public Employee(String emp_id, String f_name, String l_name, String dept_id, String job_title, String dob, - String phone_no) { - super(); - this.emp_id = emp_id; - this.f_name = f_name; - this.l_name = l_name; - this.dept_id = dept_id; - this.job_title = job_title; - this.dob = dob; - this.phone_no = phone_no; - } - - - public String getEmp_id() { - return emp_id; - } - - - public void setEmp_id(String emp_id) { - this.emp_id = emp_id; - } - - - public String getF_name() { - return f_name; - } - - - public void setF_name(String f_name) { - this.f_name = f_name; - } - - - public String getL_name() { - return l_name; - } - - - public void setL_name(String l_name) { - this.l_name = l_name; - } - - - public String getDept_id() { - return dept_id; - } - - - public void setDept_id(String dept_id) { - this.dept_id = dept_id; - } - - - public String getJob_title() { - return job_title; - } - - - public void setJob_title(String job_title) { - this.job_title = job_title; - } - - - public String getDob() { - return dob; - } - - - public void setDob(String dob) { - this.dob = dob; - } - - - public String getPhone_no() { - return phone_no; - } - - - public void setPhone_no(String phone_no) { - this.phone_no = phone_no; - } - - - - - - - -} diff --git a/src/main/java/com/springEMS/employee/EmployeeController.java b/src/main/java/com/springEMS/employee/EmployeeController.java deleted file mode 100644 index 7f7ad1a..0000000 --- a/src/main/java/com/springEMS/employee/EmployeeController.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.springEMS.employee; - -import java.util.ArrayList; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; - -import com.springEMS.handler.CustomException; - -@RestController -public class EmployeeController { - - @Autowired - private EmployeeService empServ; - - @RequestMapping(method = RequestMethod.GET, value = "/employees") - @ResponseBody - public ResponseEntity> getEmployeeList(){ - ArrayList list = new ArrayList(); - list = empServ.getEmployeeList(); - return new ResponseEntity>(list, HttpStatus.OK); - } - - @RequestMapping(method = RequestMethod.GET, value = "/employee/{id}") - @ResponseBody - public ResponseEntity getEmployeeSpecs(@PathVariable String id) throws Exception { - Employee emp = empServ.getEmployeeSpecs(id); - return new ResponseEntity(emp, HttpStatus.OK); - } - - @RequestMapping(method = RequestMethod.POST, value = "/employee") - @ResponseBody - public ResponseEntity addEmployee(@RequestBody Employee emp) throws CustomException { - return new ResponseEntity(empServ.addEmployee(emp), HttpStatus.OK); - } - - @RequestMapping(method = RequestMethod.PUT, value = "/employee/{id}") - @ResponseBody - public ResponseEntity updateEmployee(@RequestBody Employee emp, @PathVariable String id) throws CustomException { - if(empServ.validateEmployee(emp)) { - empServ.updateEmployee(id,emp); - return new ResponseEntity(true, HttpStatus.OK); - } - else { - return new ResponseEntity(false, HttpStatus.OK); - } - } - - @RequestMapping(method = RequestMethod.DELETE, value="/employee/{id}") - @ResponseBody - public ResponseEntity deleteEmployee(@PathVariable String id) throws CustomException { - empServ.deleteEmployee(id); - return new ResponseEntity(true, HttpStatus.OK); - } - -} diff --git a/src/main/java/com/springEMS/employee/EmployeeRepository.java b/src/main/java/com/springEMS/employee/EmployeeRepository.java deleted file mode 100644 index 14fcb1e..0000000 --- a/src/main/java/com/springEMS/employee/EmployeeRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.springEMS.employee; - -import java.util.ArrayList; - -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface EmployeeRepository extends CrudRepository{ - - @Query(nativeQuery = true, value="select * from employee where dept_id = ?1") - public ArrayList getEmployeelistForDepartment(String dept_id); - -} diff --git a/src/main/java/com/springEMS/employee/EmployeeService.java b/src/main/java/com/springEMS/employee/EmployeeService.java deleted file mode 100644 index 542cb4d..0000000 --- a/src/main/java/com/springEMS/employee/EmployeeService.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.springEMS.employee; - -import java.util.ArrayList; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.springEMS.department.DepartmentService; -import com.springEMS.handler.CustomException; -import com.springEMS.team.TeamService; - -@Service -public class EmployeeService { - - @Autowired - private EmployeeRepository empRepo; - - @Autowired - private TeamService teamServ; - - @Autowired - private DepartmentService deptServ; - - public ArrayList getEmployeeList(){ - ArrayList list = new ArrayList(); - empRepo.findAll().forEach(list::add); - return list; - - } - - public Employee getEmployeeSpecs(String id) throws Exception { - if(!empRepo.existsById(id)) { - throw new CustomException("Entity Not Found"); - } - else { - Employee emp = empRepo.findById(id).get(); - return emp; - } - } - - public boolean addEmployee(Employee emp) throws CustomException{ - if(this.validateEmployee(emp)) { - - if(this.checkIfEmployeeExists(emp.getEmp_id())){ - throw new CustomException("Entity Already Exists"); - } - else { - if(deptServ.departmentExists(emp.getDept_id())) { - empRepo.save(emp); - return true; - } - else { - throw new CustomException("Department Does Not Exist"); - } - - } - } - else { - return false; - } - - } - - public void updateEmployee(String id, Employee emp) { - empRepo.save(emp); - return ; - - } - - public void deleteEmployee(String id) throws CustomException { - if(!empRepo.existsById(id)) { - - throw new CustomException("Entity Not Found"); - } - else { - Employee emp = empRepo.findById(id).get(); - teamServ.deleteTeamMemberUsingEmployeeId(emp); - empRepo.deleteById(id); - } - } - - public ArrayList getEmployeeListForDepartment(String dept_id){ - ArrayList list = new ArrayList(); - list = empRepo.getEmployeelistForDepartment(dept_id); - return list; - - } - - - public boolean checkIfEmployeeExists(String id) { - return empRepo.existsById(id); - } - - public boolean validateEmployee(Employee emp) throws CustomException { - if(emp.getEmp_id() == null || emp.getEmp_id().equals("") || emp.getEmp_id().length()>20) { - throw new CustomException("Invalid Field Employee ID"); - } - - if(emp.getF_name() == null || emp.getF_name().equals("") || emp.getF_name().length()>20) { - throw new CustomException("Invalid Field First Name"); - } - if(emp.getL_name() == null || emp.getL_name().equals("") || emp.getL_name().length()>20) { - throw new CustomException("Invalid Field Last Name"); - } - if(emp.getDob() == null || emp.getDob().equals("") || emp.getDob().length()>10) { - throw new CustomException("Invalid Field DOB"); - } - if(emp.getJob_title() == null || emp.getJob_title().equals("") || emp.getJob_title().length()>20) { - throw new CustomException("Invalid Field Job Title"); - } - if(emp.getPhone_no() == null || emp.getPhone_no().equals("") || emp.getPhone_no().length()>13 || !emp.getPhone_no().matches("[0-9]+")) { - throw new CustomException("Invalid Field Phone Number"); - } - return true; - } - -} diff --git a/src/main/java/com/springEMS/team/TeamRepository.java b/src/main/java/com/springEMS/team/TeamRepository.java deleted file mode 100644 index 6ebd0a3..0000000 --- a/src/main/java/com/springEMS/team/TeamRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.springEMS.team; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface TeamRepository extends CrudRepository { - - -} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 855e664..91e37c8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,3 +1,7 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/SpringEMS -spring.datasource.username=rushil -spring.datasource.password=rushil1999 \ No newline at end of file +server.port=4501 + +#DataBase Detail +#Mysql Config Detail +spring.datasource.url=jdbc:mysql://localhost:3306/?createDatabaseIfNotExist=true +spring.datasource.username= +spring.datasource.password= diff --git a/src/test/java/com/example/crud/DemoApplicationTests.java b/src/test/java/com/example/crud/DemoApplicationTests.java new file mode 100644 index 0000000..520ddcf --- /dev/null +++ b/src/test/java/com/example/crud/DemoApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.crud; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class DemoApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/target/classes/application.properties b/target/classes/application.properties index 855e664..a5d5150 100644 --- a/target/classes/application.properties +++ b/target/classes/application.properties @@ -1,3 +1,18 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/SpringEMS -spring.datasource.username=rushil -spring.datasource.password=rushil1999 \ No newline at end of file +server.port=4501 + +#DataBase Detail +#Mysql Config Detail +spring.datasource.url=jdbc:mysql://localhost:3306/spring_test?createDatabaseIfNotExist=true +spring.datasource.username=manav +spring.datasource.password=manav +# spring.datasource.platform=mysql +# spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + +# #Hibernate Using Jpa +# spring.jpa.database=mysql +# spring.jpa.show-sql=true +# spring.jpa.hibernate.ddl-auto=update +# spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl +# spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +# spring.data.jpa.repositories.enabled=true +# spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext \ No newline at end of file diff --git a/target/classes/com/springEMS/SpringEMS.class b/target/classes/com/springEMS/SpringEMS.class deleted file mode 100644 index 551c688..0000000 Binary files a/target/classes/com/springEMS/SpringEMS.class and /dev/null differ diff --git a/target/classes/com/springEMS/employee/Employee.class b/target/classes/com/springEMS/employee/Employee.class deleted file mode 100644 index 6d05073..0000000 Binary files a/target/classes/com/springEMS/employee/Employee.class and /dev/null differ diff --git a/target/classes/com/springEMS/employee/EmployeeController.class b/target/classes/com/springEMS/employee/EmployeeController.class deleted file mode 100644 index e0798e1..0000000 Binary files a/target/classes/com/springEMS/employee/EmployeeController.class and /dev/null differ diff --git a/target/classes/com/springEMS/employee/EmployeeRepository.class b/target/classes/com/springEMS/employee/EmployeeRepository.class deleted file mode 100644 index b8cb2be..0000000 Binary files a/target/classes/com/springEMS/employee/EmployeeRepository.class and /dev/null differ diff --git a/target/classes/com/springEMS/employee/EmployeeService.class b/target/classes/com/springEMS/employee/EmployeeService.class deleted file mode 100644 index 9dc1f7c..0000000 Binary files a/target/classes/com/springEMS/employee/EmployeeService.class and /dev/null differ diff --git a/target/classes/com/springEMS/handler/CustomException.class b/target/classes/com/springEMS/handler/CustomException.class deleted file mode 100644 index 6ac6aa8..0000000 Binary files a/target/classes/com/springEMS/handler/CustomException.class and /dev/null differ diff --git a/target/classes/com/springEMS/handler/MyExceptionHandler.class b/target/classes/com/springEMS/handler/MyExceptionHandler.class deleted file mode 100644 index 0269e44..0000000 Binary files a/target/classes/com/springEMS/handler/MyExceptionHandler.class and /dev/null differ diff --git a/target/classes/com/springEMS/team/Team.class b/target/classes/com/springEMS/team/Team.class deleted file mode 100644 index bfc4341..0000000 Binary files a/target/classes/com/springEMS/team/Team.class and /dev/null differ diff --git a/target/classes/com/springEMS/team/TeamController.class b/target/classes/com/springEMS/team/TeamController.class deleted file mode 100644 index 5aead9b..0000000 Binary files a/target/classes/com/springEMS/team/TeamController.class and /dev/null differ diff --git a/target/classes/com/springEMS/team/TeamMember.class b/target/classes/com/springEMS/team/TeamMember.class deleted file mode 100644 index 490b4ee..0000000 Binary files a/target/classes/com/springEMS/team/TeamMember.class and /dev/null differ diff --git a/target/classes/com/springEMS/team/TeamMemberId.class b/target/classes/com/springEMS/team/TeamMemberId.class deleted file mode 100644 index 89b110a..0000000 Binary files a/target/classes/com/springEMS/team/TeamMemberId.class and /dev/null differ diff --git a/target/classes/com/springEMS/team/TeamMemberRepository.class b/target/classes/com/springEMS/team/TeamMemberRepository.class deleted file mode 100644 index 89bf8a2..0000000 Binary files a/target/classes/com/springEMS/team/TeamMemberRepository.class and /dev/null differ diff --git a/target/classes/com/springEMS/team/TeamRepository.class b/target/classes/com/springEMS/team/TeamRepository.class deleted file mode 100644 index 65616cc..0000000 Binary files a/target/classes/com/springEMS/team/TeamRepository.class and /dev/null differ diff --git a/target/classes/com/springEMS/team/TeamService.class b/target/classes/com/springEMS/team/TeamService.class deleted file mode 100644 index 5ac5a48..0000000 Binary files a/target/classes/com/springEMS/team/TeamService.class and /dev/null differ