<file_sep>package com.hari;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;


@EnableJpaRepositories(basePackages = "com.hari.repo")
@EntityScan(basePackages = "com.hari.model")
@ComponentScan(basePackages = { "com.hari.controller","com.hari","com.hari.service"} )
@SpringBootApplication
public class EmployeeDashboardandProjectTrackerApplication {

	public static void main(String[] args) {
		SpringApplication.run(EmployeeDashboardandProjectTrackerApplication.class, args);
	}

}
<file_sep>package com.hari.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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.RestController;

import com.hari.model.ApiResponse;
import com.hari.model.Project;
import com.hari.service.ProjectService;



@CrossOrigin
@RequestMapping("/project")
@RestController
public class ProjectController {

	
	@Autowired ProjectService projectService;
	
	@RequestMapping(path="/getprojectsbyid/{id}" , method = RequestMethod.GET,  produces=MediaType.APPLICATION_JSON_VALUE)
	public List<Project> getProjectsById(@PathVariable("id") String id)
	{
		return projectService.searchProjects(id);
	}
	
	@RequestMapping(path="/addproject" , method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces=MediaType.APPLICATION_JSON_VALUE )
	public ApiResponse addEmployee(@RequestBody Project project)
	{
		return projectService.addProject(project);
		
	}
	
	@RequestMapping(path="/updateproject/{id}/{status}/{progress}/{eid}", method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE )
	public ApiResponse updateProject(@PathVariable("id") String id,@PathVariable("status") String status,@PathVariable("progress") String progress,@PathVariable("eid") String eid)
	{

		return projectService.updateProject(id,status,progress,eid);
	}
	
	
	
	@RequestMapping(path="/deleteprojectbyid/{id}/{eid}" , method = RequestMethod.DELETE,  produces=MediaType.APPLICATION_JSON_VALUE)
	public ApiResponse deleteProjectById(@PathVariable("id") String id,@PathVariable("eid") String eid)
	{
		return projectService.deleteProjectById(id,eid);
	}
}
<file_sep>package com.hari.controller;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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.RestController;

import com.hari.model.ApiResponse;
import com.hari.model.Employee;
import com.hari.service.EmployeeService;





@CrossOrigin
@RequestMapping("/employee")
@RestController
public class EmployeeController {
	
	@Autowired EmployeeService employeeService;
	
	@RequestMapping(path="/addemployee" , method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces=MediaType.APPLICATION_JSON_VALUE )
	public ApiResponse addEmployee(@RequestBody Employee emp)
	{
		return employeeService.addEmployee(emp);
		
	}
	
	@RequestMapping(path="/getmaxemployeeid" , method = RequestMethod.GET,  produces=MediaType.APPLICATION_JSON_VALUE )
	public ApiResponse getMaxEmployeeId()
	{
		return employeeService.getMaxEmployeeId();
		
	}
	
	@RequestMapping(path="/getallemployees" , method = RequestMethod.GET,  produces=MediaType.APPLICATION_JSON_VALUE)
	public List<Employee> getAllEmployees()
	{
		return employeeService.getAllEmployees();
	}
	
	
	@RequestMapping(path="/searchemployee/{id}" , method = RequestMethod.GET,  produces=MediaType.APPLICATION_JSON_VALUE)
	public Optional<Employee> searchEmployee(@PathVariable("id") String id)
	{
		return employeeService.searchEmployee(id);
	}
	
	@RequestMapping(path="/deleteemployee/{id}", method = RequestMethod.DELETE, produces=MediaType.APPLICATION_JSON_VALUE )
	public ApiResponse deleteEmployee(@PathVariable("id") String id)
	{
		return employeeService.deleteEmployee(id);
		
	}
	
	
	
	
}<file_sep>package com.hari.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hari.model.ApiResponse;
import com.hari.model.Users;
import com.hari.repo.ValidationRepo;


@Service
public class ValidationService {

	@Autowired ValidationRepo validationRepo;


	
	public ApiResponse validateLogin(String id, String password) {
		if(validationRepo.existsById(id))
		{
			try 
			{
				Users ruser = validationRepo.getUsersById(id);
				if(ruser.getPassword().equalsIgnoreCase(password))
					return new ApiResponse("200","User does Exists",ruser.getRole());
				else
					return new ApiResponse("201","Incorrect Credentials"," ");
			}
			catch(Exception e)
			{
				return new ApiResponse("500","Server Problem  "+e," ");
			}
		}
		else
		{
			return new ApiResponse("201","User does not Exists"," ");
		}
	}
}<file_sep>package com.hari.model;

public class ApiResponse {

	String status;
	String message;
	String value;
	
	public ApiResponse(String string, String string2) {
		this.status = string;
		this.message = string2;
	}
	
	public ApiResponse(String string, String string2,String s3) {
		this.status = string;
		this.message = string2;
		this.value = s3;
	}
	
	public ApiResponse(String string) {
		this.value = string;
	}

	public String getStatus() {
		return status;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	
}
<file_sep>server.port=8080
spring.datasource.url=jdbc:mysql://us-cdbr-iron-east-01.cleardb.net:3306/heroku_d2683617bfdda5c
spring.datasource.username=b9f6302e383cdf
spring.datasource.password=<PASSWORD>
spring.jpa.show-sql= true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
<file_sep>package com.hari.repo;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.hari.model.Employee;



public interface EmployeeRepo extends JpaRepository<Employee,String>{
		
	@Transactional
    @Modifying
    @Query(value = "delete from employee_details where id = ?1",nativeQuery = true)
	void deleteEmployee(String id);
	
	@Transactional
    @Query(value = "SELECT MAX(SUBSTRING(id, 5, length(id)-4) ) FROM employee_details;",nativeQuery = true)
	String getMaxEmployeeId();

}<file_sep>package com.hari.service;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hari.model.ApiResponse;
import com.hari.model.Employee;
import com.hari.model.Report;
import com.hari.model.Users;
import com.hari.repo.EmployeeRepo;
import com.hari.repo.ProjectRepo;
import com.hari.repo.ReportRepo;
import com.hari.repo.ValidationRepo;




@Service
public class EmployeeService {

	
	String maxId;
	
	@Autowired EmployeeRepo employeeRepo;
	
	@Autowired ProjectRepo projectRepo;
	
	@Autowired ValidationRepo validationRepo;
	
	
	@Autowired ReportRepo reportRepo;
	
	public ApiResponse addEmployee(Employee employee)
	{
		Users user = new Users(employee.getId(),"password","<PASSWORD>");
		Report report = new Report(employee.getId()," "," "," ","Trainee");
		if(employeeRepo.existsById(employee.getId()))
		{		
			return new ApiResponse("201","Error in adding the Employee ");
		}
		else
		{
			employeeRepo.save(employee);
			validationRepo.save(user);
			reportRepo.save(report);
			projectRepo.saveFirstProject("1",employee.getId(),"Induction","Kick Started","5");
			return new ApiResponse("200","Employee Saved successfully");
		}
	}
	
	public List<Employee> getAllEmployees() {	
		return  employeeRepo.findAll();
	}
	
	public ApiResponse deleteEmployee(String id) {
		try 
		{
			if(employeeRepo.existsById(id))
			{
				validationRepo.deleteById(id);
				employeeRepo.deleteEmployee(id);
				return new ApiResponse("200","Employee Deleted Successfully"," ");
			}
			else
			{
				return new ApiResponse("201","No Employee exists with id "+id," ");
			}
		}catch(Exception e)
		{
			return new ApiResponse("500","Server Problem"," ");
		}
	}

	public Optional<Employee> searchEmployee(String id) {
		
			return employeeRepo.findById(id);
	}

	public ApiResponse getMaxEmployeeId() {		
		return new ApiResponse("200","Employee Deleted Successfully","EMP-"+String.valueOf(Integer.parseInt(employeeRepo.getMaxEmployeeId())+1));
	}
}
