├── README.md
├── README.txt
├── Screenshots-Postman
├── GetAllDepartments.png
├── GetAllEmployees.png
├── GetDepartmentByID.png
├── GetEmployeeByID.png
├── PostDepartment.png
├── PostEmployee.png
└── PutEmployeeByID.png
├── employee-management
├── .classpath
├── .project
├── .settings
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.jdt.core.prefs
│ └── org.eclipse.m2e.core.prefs
├── pom.xml
├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── employee
│ │ │ └── management
│ │ │ ├── Application.java
│ │ │ ├── controller
│ │ │ ├── DepartmentController.java
│ │ │ └── EmployeeController.java
│ │ │ ├── model
│ │ │ ├── Department.java
│ │ │ └── Employee.java
│ │ │ ├── repository
│ │ │ ├── DepartmentRepository.java
│ │ │ └── EmployeeRepository.java
│ │ │ └── service
│ │ │ ├── DepartmentService.java
│ │ │ └── EmployeeService.java
│ │ └── resources
│ │ └── application.properties
└── target
│ └── classes
│ ├── application.properties
│ └── com
│ └── employee
│ └── management
│ ├── Application.class
│ ├── controller
│ ├── DepartmentController.class
│ └── EmployeeController.class
│ ├── model
│ ├── Department.class
│ └── Employee.class
│ ├── repository
│ ├── DepartmentRepository.class
│ └── EmployeeRepository.class
│ └── service
│ ├── DepartmentService.class
│ └── EmployeeService.class
└── employeemanagementsystemDB.sql
/README.md:
--------------------------------------------------------------------------------
1 | #Employee Management System
2 |
3 | #HOW TO RUN THIS PROJECT?#
4 | ###FROM THE IDE:###
5 | 1. Open the project in an IDE like Eclipse.
6 | 2. You can run the DBScript provided in MySQL to create database and tables with basic values.
7 | (Creating database is necessary since hibernate- update option is used : "spring.jpa.hibernate.ddl-auto = update")
8 | 3. In case you do not want to run file, you can change the line "spring.jpa.hibernate.ddl-auto = update" to "spring.jpa.hibernate.ddl-auto = create-drop"
9 | in src/main/resources/application.properties file.
10 | 4. Check your database connection in src/main/resources/application.properties file and change if needed.
11 | 5. Go to com.employee.management
12 | 6. Right Click on class Application.
13 | 7. Hit "Run As Java Application" in the IDE.
14 | 8. Check if localhost server has started.
15 | 9. Open Postman client service on Google chrome.
16 | 10. Hit url : "http://localhost:8080/employees" and url : "http://localhost:8080/departments"
17 | 11. Accordingly select the request method and the url as follows:
18 | Department:
19 | GET - "http://localhost:8080/departments" - gets list of all departments
20 | GET - "http://localhost:8080/departments/{id}" - gets department with selected id
21 | POST - "http://localhost:8080/departments" - inserts into department
22 | PUT - "http://localhost:8080/departments/{id}" - updates departments with selected id
23 | DELETE - "http://localhost:8080/departments" - deletes all departments
24 | DELETE - "http://localhost:8080/departments/{id}" - deletes departments with selected id
25 | PATCH - "http://localhost:8080/departments/{id}" - patches/updates departments with selected id
26 |
27 | Employee:
28 | GET - "http://localhost:8080/employees" - gets list of all employees
29 | GET - "http://localhost:8080/employees/{id}" - gets employees with selected id
30 | POST - "http://localhost:8080/employees" - inserts into employees
31 | PUT - "http://localhost:8080/employees/{id}" - updates employees with selected id
32 | DELETE - "http://localhost:8080/employees" - deletes all employees
33 | DELETE - "http://localhost:8080/employees/{id}" - deletes employees with selected id
34 | PATCH - "http://localhost:8080/employees/{id}" - patches/updates employees with selected id
35 |
36 |
37 | #ASSUMPTIONS#
38 | 1. DATABASE and TABLES are created in MySQL
39 | 2. DepartmentID is a foreign key in Employee table.
40 | 3. Make sure department table is populated with the department you refer for in employee.
41 | 4. While inserting employee detail through postman service: give a department id for department.
42 | Eg: {
43 | "employeeID": 2,
44 | "firstName": "Tim",
45 | "lastName": "Cook",
46 | "department": 3
47 | }
48 |
49 |
50 | #TECHNOLOGY STACK#
51 | 1. Java
52 | 2. Eclipse Neon 4.6.0
53 | 3. MySQL Workbench
54 | 4. Postman for Chrome: Version 4.10.5
55 |
56 |
57 | #DESIGN DISCUSSION#
58 | 1. The employee table has a department id foreign key.
59 | 2. Department table needs to have a value existing to be referred by the employee table.
60 | 3. Get mapping will fetch the results, Post mapping will insert results, Put mapping and Patch mapping will update results, Delete mapping will delete results.
61 | 4. You will need to create database if not, change in the application.properties file.
62 |
63 |
64 | ### Ease of extending the program ###
65 | 1. You can add useraccount table and assign username and password details for the employee.
66 | 2. You can also create a system account who handles all the creation and deleting of employee and department.
67 |
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 | #Employee Management System
2 |
3 | #HOW TO RUN THIS PROJECT?#
4 | ###FROM THE IDE:###
5 | 1. Open the project in an IDE like Eclipse.
6 | 2. You can run the DBScript provided in MySQL to create database and tables with basic values.
7 | (Creating database is necessary since hibernate- update option is used : "spring.jpa.hibernate.ddl-auto = update")
8 | 3. In case you do not want to run file, you can change the line "spring.jpa.hibernate.ddl-auto = update" to "spring.jpa.hibernate.ddl-auto = create-drop"
9 | in src/main/resources/application.properties file.
10 | 4. Check your database connection in src/main/resources/application.properties file and change if needed.
11 | 5. Go to com.employee.management
12 | 6. Right Click on class Application.
13 | 7. Hit "Run As Java Application" in the IDE.
14 | 8. Check if localhost server has started.
15 | 9. Open Postman client service on Google chrome.
16 | 10. Hit url : "http://localhost:8080/employees" and url : "http://localhost:8080/departments"
17 | 11. Accordingly select the request method and the url as follows:
18 | Department:
19 | GET - "http://localhost:8080/departments" - gets list of all departments
20 | GET - "http://localhost:8080/departments/{id}" - gets department with selected id
21 | POST - "http://localhost:8080/departments" - inserts into department
22 | PUT - "http://localhost:8080/departments/{id}" - updates departments with selected id
23 | DELETE - "http://localhost:8080/departments" - deletes all departments
24 | DELETE - "http://localhost:8080/departments/{id}" - deletes departments with selected id
25 | PATCH - "http://localhost:8080/departments/{id}" - patches/updates departments with selected id
26 |
27 | Employee:
28 | GET - "http://localhost:8080/employees" - gets list of all employees
29 | GET - "http://localhost:8080/employees/{id}" - gets employees with selected id
30 | POST - "http://localhost:8080/employees" - inserts into employees
31 | PUT - "http://localhost:8080/employees/{id}" - updates employees with selected id
32 | DELETE - "http://localhost:8080/employees" - deletes all employees
33 | DELETE - "http://localhost:8080/employees/{id}" - deletes employees with selected id
34 | PATCH - "http://localhost:8080/employees/{id}" - patches/updates employees with selected id
35 |
36 |
37 | #ASSUMPTIONS#
38 | 1. DATABASE and TABLES are created in MySQL
39 | 2. DepartmentID is a foreign key in Employee table.
40 | 3. Make sure department table is populated with the department you refer for in employee.
41 | 4. While inserting employee detail through postman service: give a department id for department.
42 | Eg: {
43 | "employeeID": 2,
44 | "firstName": "Tim",
45 | "lastName": "Cook",
46 | "department": 3
47 | }
48 |
49 |
50 | #TECHNOLOGY STACK#
51 | 1. Java
52 | 2. Eclipse Neon 4.6.0
53 | 3. MySQL Workbench
54 | 4. Postman for Chrome: Version 4.10.5
55 |
56 |
57 | #DESIGN DISCUSSION#
58 | 1. The employee table has a department id foreign key.
59 | 2. Department table needs to have a value existing to be referred by the employee table.
60 | 3. Get mapping will fetch the results, Post mapping will insert results, Put mapping and Patch mapping will update results, Delete mapping will delete results.
61 | 4. You will need to create database if not, change in the application.properties file.
62 |
63 |
64 | ### Ease of extending the program ###
65 | 1. You can add useraccount table and assign username and password details for the employee.
66 | 2. You can also create a system account who handles all the creation and deleting of employee and department.
67 |
--------------------------------------------------------------------------------
/Screenshots-Postman/GetAllDepartments.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/Screenshots-Postman/GetAllDepartments.png
--------------------------------------------------------------------------------
/Screenshots-Postman/GetAllEmployees.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/Screenshots-Postman/GetAllEmployees.png
--------------------------------------------------------------------------------
/Screenshots-Postman/GetDepartmentByID.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/Screenshots-Postman/GetDepartmentByID.png
--------------------------------------------------------------------------------
/Screenshots-Postman/GetEmployeeByID.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/Screenshots-Postman/GetEmployeeByID.png
--------------------------------------------------------------------------------
/Screenshots-Postman/PostDepartment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/Screenshots-Postman/PostDepartment.png
--------------------------------------------------------------------------------
/Screenshots-Postman/PostEmployee.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/Screenshots-Postman/PostEmployee.png
--------------------------------------------------------------------------------
/Screenshots-Postman/PutEmployeeByID.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/Screenshots-Postman/PutEmployeeByID.png
--------------------------------------------------------------------------------
/employee-management/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/employee-management/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | employee-management
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/employee-management/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/main/resources=UTF-8
4 | encoding//src/test/java=UTF-8
5 | encoding//src/test/resources=UTF-8
6 | encoding/=UTF-8
7 |
--------------------------------------------------------------------------------
/employee-management/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.6
6 |
--------------------------------------------------------------------------------
/employee-management/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/employee-management/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | com.employee.management
4 | employee-management
5 | 0.0.1-SNAPSHOT
6 | Employee Management
7 |
8 |
9 | org.springframework.boot
10 | spring-boot-starter-parent
11 | 1.4.4.RELEASE
12 |
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-maven-plugin
19 |
20 |
21 |
22 |
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-logging
32 |
33 |
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-starter-ws
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-starter-web
42 |
43 |
44 |
45 |
46 | org.springframework.boot
47 | spring-boot-starter-data-jpa
48 |
49 |
50 | mysql
51 | mysql-connector-java
52 |
53 |
54 |
55 |
56 | org.springframework.boot
57 | spring-boot-starter-log4j2
58 |
59 |
60 |
--------------------------------------------------------------------------------
/employee-management/src/main/java/com/employee/management/Application.java:
--------------------------------------------------------------------------------
1 | package com.employee.management;
2 |
3 | import org.apache.logging.log4j.LogManager;
4 | import org.apache.logging.log4j.Logger;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.context.annotation.ComponentScan;
8 |
9 | @SpringBootApplication
10 | @ComponentScan(basePackages ="com.employee.management")
11 | public class Application {
12 |
13 | //logging
14 | static final Logger logger = LogManager.getLogger(Application.class.getName());
15 |
16 | public static void main(String[] args) {
17 | logger.info("entered application");
18 | SpringApplication.run(Application.class, args);
19 |
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/employee-management/src/main/java/com/employee/management/controller/DepartmentController.java:
--------------------------------------------------------------------------------
1 | package com.employee.management.controller;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.logging.log4j.LogManager;
6 | import org.apache.logging.log4j.Logger;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.web.bind.annotation.DeleteMapping;
9 | import org.springframework.web.bind.annotation.GetMapping;
10 | import org.springframework.web.bind.annotation.PatchMapping;
11 | import org.springframework.web.bind.annotation.PathVariable;
12 | import org.springframework.web.bind.annotation.PostMapping;
13 | import org.springframework.web.bind.annotation.PutMapping;
14 | import org.springframework.web.bind.annotation.RequestBody;
15 | import org.springframework.web.bind.annotation.RestController;
16 |
17 | import com.employee.management.model.Department;
18 | import com.employee.management.service.DepartmentService;
19 |
20 | @RestController
21 | public class DepartmentController {
22 |
23 | static final Logger logger = LogManager.getLogger(DepartmentController.class.getName());
24 |
25 | @Autowired
26 | private DepartmentService departmentService;
27 |
28 | // displaying list of all department
29 | @GetMapping("/departments")
30 | public List getAllDepartment(){
31 | return departmentService.getAllDepartments();
32 | }
33 |
34 | // displaying department by id
35 | @GetMapping("/departments/{id}")
36 | public Department getDepartment(@PathVariable int id){
37 | return departmentService.getDepartment(id);
38 | }
39 |
40 | // inserting department
41 | @PostMapping("/departments")
42 | public void addDepartment(@RequestBody Department department){
43 | departmentService.addDepartment(department);
44 | }
45 |
46 | //updating department by id
47 | @PutMapping("/departments/{id}")
48 | public void updateDepartment(@RequestBody Department d, @PathVariable int id){
49 | departmentService.updateDepartment(d, id);
50 | }
51 |
52 | // deleting all department
53 | @DeleteMapping("/departments")
54 | public void deleteAllDepartments(){
55 | departmentService.deleteAllDepartment();
56 | }
57 |
58 | // deleting department by id
59 | @DeleteMapping("departments/{id}")
60 | public void deleteDepartmentByID(@RequestBody Department d, @PathVariable int id){
61 | departmentService.deleteDepartmentByID(id);
62 | }
63 |
64 | // updating/ patching department by id
65 | @PatchMapping("departments/{id}")
66 | public void patchDepartmentByID(@RequestBody Department d, @PathVariable int id) {
67 | departmentService.patchDepartment(d, id);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/employee-management/src/main/java/com/employee/management/controller/EmployeeController.java:
--------------------------------------------------------------------------------
1 | package com.employee.management.controller;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.logging.log4j.LogManager;
6 | import org.apache.logging.log4j.Logger;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.web.bind.annotation.DeleteMapping;
9 | import org.springframework.web.bind.annotation.GetMapping;
10 | import org.springframework.web.bind.annotation.PatchMapping;
11 | import org.springframework.web.bind.annotation.PathVariable;
12 | import org.springframework.web.bind.annotation.PostMapping;
13 | import org.springframework.web.bind.annotation.PutMapping;
14 | import org.springframework.web.bind.annotation.RequestBody;
15 | import org.springframework.web.bind.annotation.RestController;
16 |
17 | import com.employee.management.model.Employee;
18 | import com.employee.management.service.EmployeeService;
19 |
20 | @RestController
21 | public class EmployeeController {
22 |
23 | static final Logger logger = LogManager.getLogger(EmployeeController.class.getName());
24 |
25 | @Autowired
26 | private EmployeeService employeeService;
27 |
28 | // displaying list of all employees
29 | @GetMapping("/employees")
30 | public List getAllEmployee(){
31 | return employeeService.getAllEmployees();
32 | }
33 |
34 | // displaying employee by id
35 | @GetMapping("/employees/{id}")
36 | public Employee getEmployee(@PathVariable int id){
37 | return employeeService.getEmployee(id);
38 | }
39 |
40 | // inserting employee
41 | @PostMapping("/employees")
42 | public void addEmployees(@RequestBody Employee employee){
43 | employeeService.addEmployee(employee);
44 | }
45 |
46 | //updating employee by id
47 | @PutMapping("/employees/{id}")
48 | public void updateEmployee(@RequestBody Employee e, @PathVariable int id){
49 | employeeService.updateEmployee(e, id);
50 | }
51 |
52 | // deleting all employees
53 | @DeleteMapping("/employees")
54 | public void deleteAllEmployees(){
55 | employeeService.deleteAllEmployees();
56 | }
57 |
58 | // deleting employee by id
59 | @DeleteMapping("employees/{id}")
60 | public void deleteEmployeeByID(@RequestBody Employee e, @PathVariable int id){
61 | employeeService.deleteEmployeeByID(id);
62 | }
63 |
64 | // updating/ patching employee by id
65 | @PatchMapping("employees/{id}")
66 | public void patchEmployeeByID(@RequestBody Employee e, @PathVariable int id) {
67 | employeeService.patchEmployee(e, id);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/employee-management/src/main/java/com/employee/management/model/Department.java:
--------------------------------------------------------------------------------
1 | package com.employee.management.model;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.GenerationType;
7 | import javax.persistence.Id;
8 | import javax.persistence.Table;
9 |
10 | @Entity
11 | @Table(name="department")
12 | public class Department {
13 |
14 | @Id
15 | @Column(name="department_id")
16 | @GeneratedValue(strategy = GenerationType.AUTO)
17 | private int department_ID;
18 | private String short_Name;
19 | private String department_Name;
20 |
21 | public Department() {
22 |
23 | }
24 |
25 | public Department(int departmentID){
26 | super();
27 | this.department_ID = departmentID;
28 | }
29 |
30 | public Department(int departmentID, String short_Name, String department_Name) {
31 | super();
32 | this.department_ID = departmentID;
33 | this.short_Name = short_Name;
34 | this.department_Name = department_Name;
35 | }
36 |
37 | public int getDepartment_ID() {
38 | return department_ID;
39 | }
40 |
41 | public void setDepartment_ID(int department_ID) {
42 | this.department_ID = department_ID;
43 | }
44 |
45 | public String getShort_Name() {
46 | return short_Name;
47 | }
48 |
49 | public void setShort_Name(String short_Name) {
50 | this.short_Name = short_Name;
51 | }
52 |
53 | public String getDepartment_Name() {
54 | return department_Name;
55 | }
56 |
57 | public void setDepartment_Name(String department_Name) {
58 | this.department_Name = department_Name;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/employee-management/src/main/java/com/employee/management/model/Employee.java:
--------------------------------------------------------------------------------
1 | package com.employee.management.model;
2 |
3 | import javax.persistence.Column;
4 | import javax.persistence.Entity;
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.GenerationType;
7 | import javax.persistence.Id;
8 | import javax.persistence.JoinColumn;
9 | import javax.persistence.ManyToOne;
10 | import javax.persistence.Table;
11 | import javax.validation.constraints.NotNull;
12 |
13 | @Entity
14 | @Table (name = "employee")
15 | public class Employee {
16 |
17 | @Id
18 | @Column(name="employee_id")
19 | @GeneratedValue(strategy = GenerationType.AUTO)
20 | private int employeeID;
21 |
22 | @Column(name="first_name")
23 | private String firstName;
24 |
25 | @Column(name="last_name")
26 | private String lastName;
27 |
28 | @NotNull
29 | @ManyToOne
30 | @JoinColumn(name="department_id")
31 | private Department department;
32 |
33 | public Employee(){
34 |
35 | }
36 |
37 | public Employee(String firstName, String lastName, Department department) {
38 | super();
39 | this.firstName = firstName;
40 | this.lastName = lastName;
41 | this.department = department;
42 | }
43 |
44 | public int getEmployeeID() {
45 | return employeeID;
46 | }
47 |
48 | public void setEmployeeID(int employeeID) {
49 | this.employeeID = employeeID;
50 | }
51 |
52 | public String getFirstName() {
53 | return firstName;
54 | }
55 |
56 | public void setFirstName(String firstName) {
57 | this.firstName = firstName;
58 | }
59 |
60 | public String getLastName() {
61 | return lastName;
62 | }
63 |
64 | public void setLastName(String lastName) {
65 | this.lastName = lastName;
66 | }
67 |
68 | @Override
69 | public String toString(){
70 | return String.format("Employee [employeeID = %d, firstName = %s, lastName = %s, department_ID= %d", employeeID, firstName, lastName, department.getDepartment_ID());
71 | }
72 |
73 | public Department getDepartment() {
74 | return department;
75 | }
76 |
77 | public void setDepartment(Department department) {
78 | this.department = department;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/employee-management/src/main/java/com/employee/management/repository/DepartmentRepository.java:
--------------------------------------------------------------------------------
1 | package com.employee.management.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 | import com.employee.management.model.Department;
5 |
6 | public interface DepartmentRepository extends CrudRepository{
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/employee-management/src/main/java/com/employee/management/repository/EmployeeRepository.java:
--------------------------------------------------------------------------------
1 | package com.employee.management.repository;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 |
5 | import com.employee.management.model.Employee;
6 |
7 | // interface extending crud repository
8 | public interface EmployeeRepository extends CrudRepository{
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/employee-management/src/main/java/com/employee/management/service/DepartmentService.java:
--------------------------------------------------------------------------------
1 | package com.employee.management.service;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Service;
7 |
8 | import com.employee.management.model.Department;
9 | import com.employee.management.repository.DepartmentRepository;
10 |
11 | @Service
12 | public class DepartmentService {
13 |
14 | @Autowired
15 | private DepartmentRepository departmentRepository;
16 |
17 |
18 | // fetching all department
19 | public List getAllDepartments(){
20 | List depts = (List)departmentRepository.findAll();
21 | return depts;
22 | }
23 |
24 | // fetching department by id
25 | public Department getDepartment(int id){
26 | return departmentRepository.findOne(id);
27 | }
28 |
29 | // inserting department
30 | public void addDepartment(Department d) {
31 | departmentRepository.save(d);
32 | }
33 |
34 | // updating department by id
35 | public void updateDepartment(Department d, int id){
36 | if(id == d.getDepartment_ID()) {
37 | departmentRepository.save(d);
38 | }
39 | }
40 |
41 | // deleting all departments
42 | public void deleteAllDepartment(){
43 | departmentRepository.deleteAll();
44 | }
45 |
46 | // deleting department by id
47 | public void deleteDepartmentByID(int id){
48 | departmentRepository.delete(id);
49 | }
50 |
51 | //patching/updating department by id
52 | public void patchDepartment(Department d, int id) {
53 | if(id == d.getDepartment_ID()) {
54 | departmentRepository.save(d);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/employee-management/src/main/java/com/employee/management/service/EmployeeService.java:
--------------------------------------------------------------------------------
1 | package com.employee.management.service;
2 |
3 | import java.util.List;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.stereotype.Service;
6 | import com.employee.management.model.Employee;
7 | import com.employee.management.repository.EmployeeRepository;
8 |
9 | // employee service class
10 | @Service
11 | public class EmployeeService {
12 |
13 | @Autowired
14 | private EmployeeRepository employeeRepository;
15 |
16 | // fetching all employees
17 | public List getAllEmployees(){
18 | List emps = (List)employeeRepository.findAll();
19 | return emps;
20 | }
21 |
22 | // fetching employee by id
23 | public Employee getEmployee(int id){
24 | return employeeRepository.findOne(id);
25 | }
26 |
27 | // inserting employee
28 | public void addEmployee(Employee e) {
29 | employeeRepository.save(e);
30 | }
31 |
32 | // updating employee by id
33 | public void updateEmployee(Employee emp, int id){
34 | if(id == emp.getEmployeeID()) {
35 | employeeRepository.save(emp);
36 | }
37 | }
38 |
39 | // deleting all employees
40 | public void deleteAllEmployees(){
41 | employeeRepository.deleteAll();
42 | }
43 |
44 | // deleting employee by id
45 | public void deleteEmployeeByID(int id){
46 | employeeRepository.delete(id);
47 | }
48 |
49 | //patching/updating employee by id
50 | public void patchEmployee(Employee emp, int id) {
51 | if(id == emp.getEmployeeID()) {
52 | employeeRepository.save(emp);
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/employee-management/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url = jdbc:mysql://localhost:3306/employeemanagementsystem
2 | spring.datasource.username = root
3 | spring.datasource.password = root
4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver
5 | spring.data.jpa.repositories.enabled=true
6 |
7 | # Keep the connection alive if idle for a long time (needed in production)
8 | spring.datasource.testWhileIdle = true
9 | spring.datasource.validationQuery = SELECT 1
10 |
11 | # Show or not log for each sql query
12 | spring.jpa.show-sql = true
13 |
14 | # Hibernate ddl auto (create, create-drop, update)
15 | #set to create-drop instead of update
16 | spring.jpa.hibernate.ddl-auto = update
17 |
18 | # Naming strategy
19 | spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
20 |
21 | # Use spring.jpa.properties.* for Hibernate native properties (the prefix is
22 | # stripped before adding them to the entity manager)
23 |
24 | # The SQL dialect makes Hibernate generate better SQL for the chosen database
25 | spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
26 |
27 |
28 | logging.level.org.springframework.web=INFO
29 | logging.level.guru.springframework.controllers=DEBUG
30 | logging.level.org.hibernate=ERROR
31 | logging.file=logs/spring-boot-logging.log
--------------------------------------------------------------------------------
/employee-management/target/classes/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url = jdbc:mysql://localhost:3306/employeemanagementsystem
2 | spring.datasource.username = root
3 | spring.datasource.password = root
4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver
5 | spring.data.jpa.repositories.enabled=true
6 |
7 | # Keep the connection alive if idle for a long time (needed in production)
8 | spring.datasource.testWhileIdle = true
9 | spring.datasource.validationQuery = SELECT 1
10 |
11 | # Show or not log for each sql query
12 | spring.jpa.show-sql = true
13 |
14 | # Hibernate ddl auto (create, create-drop, update)
15 | #set to create-drop instead of update
16 | spring.jpa.hibernate.ddl-auto = update
17 |
18 | # Naming strategy
19 | spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
20 |
21 | # Use spring.jpa.properties.* for Hibernate native properties (the prefix is
22 | # stripped before adding them to the entity manager)
23 |
24 | # The SQL dialect makes Hibernate generate better SQL for the chosen database
25 | spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
26 |
27 |
28 | logging.level.org.springframework.web=INFO
29 | logging.level.guru.springframework.controllers=DEBUG
30 | logging.level.org.hibernate=ERROR
31 | logging.file=logs/spring-boot-logging.log
--------------------------------------------------------------------------------
/employee-management/target/classes/com/employee/management/Application.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/employee-management/target/classes/com/employee/management/Application.class
--------------------------------------------------------------------------------
/employee-management/target/classes/com/employee/management/controller/DepartmentController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/employee-management/target/classes/com/employee/management/controller/DepartmentController.class
--------------------------------------------------------------------------------
/employee-management/target/classes/com/employee/management/controller/EmployeeController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/employee-management/target/classes/com/employee/management/controller/EmployeeController.class
--------------------------------------------------------------------------------
/employee-management/target/classes/com/employee/management/model/Department.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/employee-management/target/classes/com/employee/management/model/Department.class
--------------------------------------------------------------------------------
/employee-management/target/classes/com/employee/management/model/Employee.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/employee-management/target/classes/com/employee/management/model/Employee.class
--------------------------------------------------------------------------------
/employee-management/target/classes/com/employee/management/repository/DepartmentRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/employee-management/target/classes/com/employee/management/repository/DepartmentRepository.class
--------------------------------------------------------------------------------
/employee-management/target/classes/com/employee/management/repository/EmployeeRepository.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/employee-management/target/classes/com/employee/management/repository/EmployeeRepository.class
--------------------------------------------------------------------------------
/employee-management/target/classes/com/employee/management/service/DepartmentService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/employee-management/target/classes/com/employee/management/service/DepartmentService.class
--------------------------------------------------------------------------------
/employee-management/target/classes/com/employee/management/service/EmployeeService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apoorva-joshi/EmployeeManagement/c361ac50e5c074307952c604550a3c360eaf8ed5/employee-management/target/classes/com/employee/management/service/EmployeeService.class
--------------------------------------------------------------------------------
/employeemanagementsystemDB.sql:
--------------------------------------------------------------------------------
1 | -- MySQL dump 10.13 Distrib 5.6.17, for Win64 (x86_64)
2 | --
3 | -- Host: 127.0.0.1 Database: employeemanagementsystem
4 | -- ------------------------------------------------------
5 | -- Server version 5.6.20
6 |
7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10 | /*!40101 SET NAMES utf8 */;
11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12 | /*!40103 SET TIME_ZONE='+00:00' */;
13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17 |
18 | --
19 | -- Table structure for table `department`
20 | --
21 |
22 | DROP TABLE IF EXISTS `department`;
23 | /*!40101 SET @saved_cs_client = @@character_set_client */;
24 | /*!40101 SET character_set_client = utf8 */;
25 | CREATE TABLE `department` (
26 | `DEPARTMENT_ID` int(11) NOT NULL AUTO_INCREMENT,
27 | `SHORT_NAME` varchar(10) DEFAULT NULL,
28 | `DEPARTMENT_NAME` varchar(100) DEFAULT NULL,
29 | PRIMARY KEY (`DEPARTMENT_ID`)
30 | ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;
31 | /*!40101 SET character_set_client = @saved_cs_client */;
32 |
33 | --
34 | -- Dumping data for table `department`
35 | --
36 |
37 | LOCK TABLES `department` WRITE;
38 | /*!40000 ALTER TABLE `department` DISABLE KEYS */;
39 | INSERT INTO `department` VALUES (1,'HR','Human Resources Management'),(2,'IT','Information Technology'),(3,'ENGG','Engineering'),(4,'R&D','Research and Development'),(5,'MK','Marketing'),(6,'ACNT','Accounting');
40 | /*!40000 ALTER TABLE `department` ENABLE KEYS */;
41 | UNLOCK TABLES;
42 |
43 | --
44 | -- Table structure for table `employee`
45 | --
46 |
47 | DROP TABLE IF EXISTS `employee`;
48 | /*!40101 SET @saved_cs_client = @@character_set_client */;
49 | /*!40101 SET character_set_client = utf8 */;
50 | CREATE TABLE `employee` (
51 | `EMPLOYEE_ID` int(11) NOT NULL AUTO_INCREMENT,
52 | `FIRST_NAME` varchar(50) DEFAULT NULL,
53 | `LAST_NAME` varchar(50) DEFAULT NULL,
54 | `department_id` int(11) NOT NULL,
55 | PRIMARY KEY (`EMPLOYEE_ID`),
56 | KEY `FKbejtwvg9bxus2mffsm3swj3u9` (`department_id`),
57 | CONSTRAINT `FKbejtwvg9bxus2mffsm3swj3u9` FOREIGN KEY (`department_id`) REFERENCES `department` (`DEPARTMENT_ID`)
58 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
59 | /*!40101 SET character_set_client = @saved_cs_client */;
60 |
61 | --
62 | -- Dumping data for table `employee`
63 | --
64 |
65 | LOCK TABLES `employee` WRITE;
66 | /*!40000 ALTER TABLE `employee` DISABLE KEYS */;
67 | INSERT INTO `employee` VALUES (1,'Apoorva','Joshi',4),(2,'Tim','Cook',3);
68 | /*!40000 ALTER TABLE `employee` ENABLE KEYS */;
69 | UNLOCK TABLES;
70 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
71 |
72 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
73 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
74 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
75 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
76 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
77 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
78 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
79 |
80 | -- Dump completed on 2017-04-07 17:12:40
81 |
--------------------------------------------------------------------------------