From 839a4b4ae2304f0448783f28a97cc0a4ab3debe2 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Mon, 9 Dec 2019 17:30:42 -0500 Subject: [PATCH 01/27] added properties --- src/main/resources/application.properties | 4 +++- src/main/resources/schema-h2.sql | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7d4dc6f..71b3415 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,3 +1,5 @@ spring.profiles.active=h2 logging.level.org.springframework.boot.context.embedded=INFO -spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect \ No newline at end of file +spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect + +server.port=8081 \ No newline at end of file diff --git a/src/main/resources/schema-h2.sql b/src/main/resources/schema-h2.sql index 030913b..15c357e 100644 --- a/src/main/resources/schema-h2.sql +++ b/src/main/resources/schema-h2.sql @@ -1,4 +1,4 @@ -DROP TABLE PERSON; +DROP TABLE IF EXISTS PERSON; CREATE TABLE PERSON ( ID NUMBER(10,0) NOT NULL AUTO_INCREMENT, @@ -8,7 +8,7 @@ CREATE TABLE PERSON ( BIRTHDAY DATE DEFAULT NULL, PRIMARY KEY (ID)); -DROP TABLE HOME; +DROP TABLE IF EXISTS HOME; CREATE TABLE HOME ( ID NUMBER(10,0) NOT NULL AUTO_INCREMENT, @@ -18,7 +18,7 @@ CREATE TABLE HOME ( ); -DROP TABLE CAR; +DROP TABLE IF EXISTS CAR; CREATE TABLE CAR ( ID NUMBER(10,0) NOT NULL AUTO_INCREMENT, @@ -28,6 +28,6 @@ CREATE TABLE CAR ( PRIMARY KEY (ID) ); -DROP SEQUENCE hibernate_sequence; +DROP IF EXISTS SEQUENCE hibernate_sequence; CREATE SEQUENCE hibernate_sequence; \ No newline at end of file From c864c8a043af66c44fa194a5608dca3d67620fa8 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Tue, 10 Dec 2019 09:20:21 -0500 Subject: [PATCH 02/27] Update schema --- src/main/resources/schema-h2.sql | 49 ++++++++++++++------------------ 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/main/resources/schema-h2.sql b/src/main/resources/schema-h2.sql index 15c357e..571709d 100644 --- a/src/main/resources/schema-h2.sql +++ b/src/main/resources/schema-h2.sql @@ -1,31 +1,24 @@ -DROP TABLE IF EXISTS PERSON; - -CREATE TABLE PERSON ( - ID NUMBER(10,0) NOT NULL AUTO_INCREMENT, - FIRST_NAME VARCHAR2(255) NOT NULL DEFAULT '', - LAST_NAME VARCHAR2(255) NOT NULL DEFAULT '', - MOBILE VARCHAR2(20) NOT NULL DEFAULT '', - BIRTHDAY DATE DEFAULT NULL, - PRIMARY KEY (ID)); - -DROP TABLE IF EXISTS HOME; - -CREATE TABLE HOME ( - ID NUMBER(10,0) NOT NULL AUTO_INCREMENT, - ADDRESS VARCHAR2(255) not null default '', - HOMENUMBER varchar2(255) NOT NULL DEFAULT '', - PRIMARY KEY (ID) -); - - -DROP TABLE IF EXISTS CAR; - -CREATE TABLE CAR ( - ID NUMBER(10,0) NOT NULL AUTO_INCREMENT, - MAKE VARCHAR2(255) not null default '', - MODEL varchar2(255) NOT NULL DEFAULT '', - YEAR VARCHAR2(5) NOT NULL DEFAULT '01907', - PRIMARY KEY (ID) +DROP TABLE IF EXISTS EMPLOYEE; + +CREATE TABLE EMPLOYEE ( + EMPLOYEE_ID NUMBER(10,0) NOT NULL AUTO_INCREMENT, + FIRST_NAME VARCHAR(255) NOT NULL DEFAULT '', + LAST_NAME VARCHAR(255) NOT NULL DEFAULT '', + TITLE VARCHAR(255) NOT NULL DEFAULT 'EMPLOYEE', + PHONE VARCHAR(20) NOT NULL DEFAULT '', + HIRE_DATE DATE DEFAULT NULL, + MANAGER BOOLEAN NOT NULL DEFAULT FALSE, + DEPARTMENT_ID NUMBER(10,0) NOT NULL, + PRIMARY KEY (EMPLOYEE_ID) + ); + +DROP TABLE IF EXISTS DEPARTMENT; + +CREATE TABLE DEPARTMENT ( + DEPARTMENT_ID NUMBER(10,0) NOT NULL AUTO_INCREMENT, + DEPARTMENT_NAME VARCHAR (255) NOT NULL DEFAULT '', + DEPARTMENT_MANAGER NUMBER (10,0), + PRIMARY KEY (DEPARTMENT_ID) ); DROP IF EXISTS SEQUENCE hibernate_sequence; From 838e86ea7c43f6d709fe4a2089d41dae63142ed1 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Wed, 11 Dec 2019 19:55:26 -0500 Subject: [PATCH 03/27] Added class stubs --- .../persistenceapp/entities/Department.java | 40 +++++++++ .../persistenceapp/entities/Employee.java | 84 +++++++++++++++++++ .../repositories/DepartmentRepository.java | 10 +++ .../repositories/EmployeeRepository.java | 9 ++ .../services/DepartmentService.java | 4 + .../services/EmployeeService.java | 4 + src/main/resources/application.properties | 3 +- .../PersistenceStarterApplicationTests.java | 3 +- 8 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/zipcoder/persistenceapp/entities/Department.java create mode 100644 src/main/java/io/zipcoder/persistenceapp/entities/Employee.java create mode 100644 src/main/java/io/zipcoder/persistenceapp/repositories/DepartmentRepository.java create mode 100644 src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java create mode 100644 src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java create mode 100644 src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java diff --git a/src/main/java/io/zipcoder/persistenceapp/entities/Department.java b/src/main/java/io/zipcoder/persistenceapp/entities/Department.java new file mode 100644 index 0000000..f12a4e3 --- /dev/null +++ b/src/main/java/io/zipcoder/persistenceapp/entities/Department.java @@ -0,0 +1,40 @@ +package io.zipcoder.persistenceapp.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.util.Date; + +@Entity +public class Department { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long DEPARTMENT_ID; + + private String DEPARTMENT_NAME; + private Long DEPARTMENT_MANAGER; + + + public Long getDEPARTMENT_ID() { + return DEPARTMENT_ID; + } + + + public String getDEPARTMENT_NAME() { + return DEPARTMENT_NAME; + } + + public void setDEPARTMENT_NAME(String DEPARTMENT_NAME) { + this.DEPARTMENT_NAME = DEPARTMENT_NAME; + } + + public Long getDEPARTMENT_MANAGER() { + return DEPARTMENT_MANAGER; + } + + public void setDEPARTMENT_MANAGER(Long DEPARTMENT_MANAGER) { + this.DEPARTMENT_MANAGER = DEPARTMENT_MANAGER; + } +} diff --git a/src/main/java/io/zipcoder/persistenceapp/entities/Employee.java b/src/main/java/io/zipcoder/persistenceapp/entities/Employee.java new file mode 100644 index 0000000..30476ac --- /dev/null +++ b/src/main/java/io/zipcoder/persistenceapp/entities/Employee.java @@ -0,0 +1,84 @@ +package io.zipcoder.persistenceapp.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.util.Date; + +@Entity +public class Employee { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long EMPLOYEE_ID; + + private String FIRST_NAME; + private String LAST_NAME; + private String TITLE; + private String PHONE; + private Date HIRE_DATE; + private Boolean MANAGER; + private Long DEPARTMENT_ID; + + + public Long getEMPLOYEE_ID() { + return EMPLOYEE_ID; + } + + public String getFIRST_NAME() { + return FIRST_NAME; + } + + public void setFIRST_NAME(String FIRST_NAME) { + this.FIRST_NAME = FIRST_NAME; + } + + public String getLAST_NAME() { + return LAST_NAME; + } + + public void setLAST_NAME(String LAST_NAME) { + this.LAST_NAME = LAST_NAME; + } + + public String getTITLE() { + return TITLE; + } + + public void setTITLE(String TITLE) { + this.TITLE = TITLE; + } + + public String getPHONE() { + return PHONE; + } + + public void setPHONE(String PHONE) { + this.PHONE = PHONE; + } + + public Date getHIRE_DATE() { + return HIRE_DATE; + } + + public void setHIRE_DATE(Date HIRE_DATE) { + this.HIRE_DATE = HIRE_DATE; + } + + public Boolean getMANAGER() { + return MANAGER; + } + + public void setMANAGER(Boolean MANAGER) { + this.MANAGER = MANAGER; + } + + public Long getDEPARTMENT_ID() { + return DEPARTMENT_ID; + } + + public void setDEPARTMENT_ID(Long DEPARTMENT_ID) { + this.DEPARTMENT_ID = DEPARTMENT_ID; + } +} diff --git a/src/main/java/io/zipcoder/persistenceapp/repositories/DepartmentRepository.java b/src/main/java/io/zipcoder/persistenceapp/repositories/DepartmentRepository.java new file mode 100644 index 0000000..843ea3e --- /dev/null +++ b/src/main/java/io/zipcoder/persistenceapp/repositories/DepartmentRepository.java @@ -0,0 +1,10 @@ +package io.zipcoder.persistenceapp.repositories; + +import io.zipcoder.persistenceapp.entities.Employee; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface DepartmentRepository extends CrudRepository { + +} diff --git a/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java b/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java new file mode 100644 index 0000000..814b8d6 --- /dev/null +++ b/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java @@ -0,0 +1,9 @@ +package io.zipcoder.persistenceapp.repositories; + +import io.zipcoder.persistenceapp.entities.Department; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface EmployeeRepository extends CrudRepository { +} diff --git a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java new file mode 100644 index 0000000..394eab1 --- /dev/null +++ b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java @@ -0,0 +1,4 @@ +package io.zipcoder.persistenceapp.services; + +public class DepartmentService { +} diff --git a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java new file mode 100644 index 0000000..b1747a2 --- /dev/null +++ b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java @@ -0,0 +1,4 @@ +package io.zipcoder.persistenceapp.services; + +public class EmployeeService { +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 71b3415..a3aa50a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,4 +2,5 @@ spring.profiles.active=h2 logging.level.org.springframework.boot.context.embedded=INFO spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect -server.port=8081 \ No newline at end of file +server.port=8081 +spring.jpa.properties.hibernate.id.new_generator_mappings=true \ No newline at end of file diff --git a/src/test/java/io/zipcoder/PersistenceStarterApplicationTests.java b/src/test/java/io/zipcoder/PersistenceStarterApplicationTests.java index 3e5dd20..0121733 100644 --- a/src/test/java/io/zipcoder/PersistenceStarterApplicationTests.java +++ b/src/test/java/io/zipcoder/PersistenceStarterApplicationTests.java @@ -1,12 +1,13 @@ package io.zipcoder; +import io.zipcoder.persistenceapp.PersistenceStarterApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) -@SpringBootTest +@SpringBootTest(classes = PersistenceStarterApplication.class) public class PersistenceStarterApplicationTests { @Test From a4ff6f1a691bfeb615a4a085890ba28f3bcf0b7c Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Thu, 12 Dec 2019 20:26:37 -0500 Subject: [PATCH 04/27] data --- .../controllers/DepartmentController.java | 33 +++++++++ .../controllers/EmployeeController.java | 47 ++++++++++++ .../persistenceapp/entities/Department.java | 1 - .../persistenceapp/entities/Employee.java | 10 +-- .../services/DepartmentService.java | 3 + .../services/EmployeeService.java | 3 + src/main/resources/data-h2.sql | 73 +++++++++++++++++++ src/main/resources/schema-h2.sql | 7 +- 8 files changed, 168 insertions(+), 9 deletions(-) create mode 100644 src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java create mode 100644 src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java create mode 100644 src/main/resources/data-h2.sql diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java new file mode 100644 index 0000000..26f6850 --- /dev/null +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java @@ -0,0 +1,33 @@ +package io.zipcoder.persistenceapp.controllers; + +import io.zipcoder.persistenceapp.entities.Department; +import io.zipcoder.persistenceapp.services.DepartmentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/department") +public class DepartmentController { + + + DepartmentService departmentService; + + @Autowired + public DepartmentController(DepartmentService departmentService){ + this.departmentService = departmentService; + } + + @GetMapping + public ResponseEntity> getAllDepartments(){ + return null; + } + + // TODO + // create a department + // update department with a new manager + // change name of a department + // get department name +} diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java new file mode 100644 index 0000000..d56701d --- /dev/null +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java @@ -0,0 +1,47 @@ +package io.zipcoder.persistenceapp.controllers; + +import io.zipcoder.persistenceapp.entities.Employee; +import io.zipcoder.persistenceapp.services.EmployeeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/employee") +public class EmployeeController { + + EmployeeService employeeService; + + @Autowired + public EmployeeController(EmployeeService employeeService){ + this.employeeService = employeeService; + } + + @GetMapping + public ResponseEntity> getAllEmployees(){ + return null; + } + + // TODO + /* + + + * create employee + * update employee to set their manager + * get a list of employees under a particular manager + * get the entire hierarchy for an employee (manager, manager's manager..) + * list of employees without a manager + * list of employees under a particular department + * remove an employee + * remove a list of employees + * remove all employees from a department + * remove all employees under a particular manager + * merge departments: given two department names eg: A and B, move the manager of B to report to the manager of A, + and update all other employees to be members of department A + * remove all direct reports to a manager. Any employees previously managed by the deleted employees + should now be managed by the next manager up the hierarchy. + + */ +} diff --git a/src/main/java/io/zipcoder/persistenceapp/entities/Department.java b/src/main/java/io/zipcoder/persistenceapp/entities/Department.java index f12a4e3..9128dd2 100644 --- a/src/main/java/io/zipcoder/persistenceapp/entities/Department.java +++ b/src/main/java/io/zipcoder/persistenceapp/entities/Department.java @@ -4,7 +4,6 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; -import java.util.Date; @Entity public class Department { diff --git a/src/main/java/io/zipcoder/persistenceapp/entities/Employee.java b/src/main/java/io/zipcoder/persistenceapp/entities/Employee.java index 30476ac..ed27438 100644 --- a/src/main/java/io/zipcoder/persistenceapp/entities/Employee.java +++ b/src/main/java/io/zipcoder/persistenceapp/entities/Employee.java @@ -18,7 +18,7 @@ public class Employee { private String TITLE; private String PHONE; private Date HIRE_DATE; - private Boolean MANAGER; + private Boolean MANAGER_ID; private Long DEPARTMENT_ID; @@ -66,12 +66,12 @@ public void setHIRE_DATE(Date HIRE_DATE) { this.HIRE_DATE = HIRE_DATE; } - public Boolean getMANAGER() { - return MANAGER; + public Boolean getMANAGER_ID() { + return MANAGER_ID; } - public void setMANAGER(Boolean MANAGER) { - this.MANAGER = MANAGER; + public void setMANAGER_ID(Boolean MANAGER_ID) { + this.MANAGER_ID = MANAGER_ID; } public Long getDEPARTMENT_ID() { diff --git a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java index 394eab1..5d2d840 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java @@ -1,4 +1,7 @@ package io.zipcoder.persistenceapp.services; +import org.springframework.stereotype.Service; + +@Service public class DepartmentService { } diff --git a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java index b1747a2..ac3cd7d 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java @@ -1,4 +1,7 @@ package io.zipcoder.persistenceapp.services; +import org.springframework.stereotype.Service; + +@Service public class EmployeeService { } diff --git a/src/main/resources/data-h2.sql b/src/main/resources/data-h2.sql new file mode 100644 index 0000000..4642e43 --- /dev/null +++ b/src/main/resources/data-h2.sql @@ -0,0 +1,73 @@ + + +INSERT INTO DEPARTMENT ( +DEPARTMENT_NAME, DEPARTMENT_MANAGER +) VALUES ( +'HUMAN RESOURCES', 14 +); + +INSERT INTO DEPARTMENT ( +DEPARTMENT_NAME, DEPARTMENT_MANAGER +) VALUES ( +'MARKETING', 10 +); + +INSERT INTO DEPARTMENT ( +DEPARTMENT_NAME, DEPARTMENT_MANAGER +) VALUES ( +'IT', 2 +); + + + + +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Ailee', 'Perin', 'Services', '63044472278349193', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Horace', 'Vaud', 'Training', '3581400352523776', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Obed', 'Fussie', 'Services', '3578495167370368', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Hale', 'Tubritt', 'Services', '5422330511208340', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Lenci', 'Robbie', 'Human Resources', '3575569624043702', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Daria', 'Vautin', 'Legal', '3585398925527439', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Sidonnie', 'Chicken', 'Sales', '5315330871050050', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Delila', 'Seary', 'Accounting', '5010126412785818', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Anita', 'McKaile', 'Engineering', '3531738714411961', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Stephanie', 'O''Gormally', 'Services', '6383020970942654', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Lorenza', 'Torrecilla', 'Accounting', '5038812450486770480', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Kingsley', 'Heeron', 'Support', '337941764817630', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Neysa', 'Klamp', 'Product Management', '6767347428924578340', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Janot', 'Nyssen', 'Marketing', '3568126995399814', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Juan', 'Wedgwood', 'Engineering', '30164735517987', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Mellie', 'Diloway', 'Marketing', '3528580342654090', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Rosamund', 'Bessell', 'Services', '5602236317462746', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Harbert', 'Rogers', 'Services', '3534565963628350', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Alix', 'McGow', 'Sales', '677179174895462979', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Seth', 'Booton', 'Product Management', '3554439537488607', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Kayne', 'Reyner', 'Research and Development', '5437821212517461', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Mauricio', 'Saiger', 'Sales', '3534321322573527', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Cymbre', 'Fairman', 'Sales', '5300792847214952', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Alex', 'Dunckley', 'Engineering', '3545061165162247', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Esta', 'Gersam', 'Sales', '374283137559688', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Hillary', 'Touson', 'Services', '3585870159235194', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Magdalene', 'Molesworth', 'Marketing', '3587868322817045', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Orren', 'Boame', 'Business Development', '3582144644434090', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Erik', 'Lipprose', 'Human Resources', '3558048262357923', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Ilyse', 'Aherne', 'Accounting', '3577886601448896', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Evyn', 'McNickle', 'Accounting', '6759809855269694332', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Kamilah', 'Avrahamof', 'Marketing', '3581655015095583', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Stanwood', 'Seniour', 'Marketing', '5038617308780259', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Rosene', 'Portress', 'Support', '3554514927841316', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Kristien', 'Enticott', 'Sales', '5602218415453959', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Noach', 'Gittins', 'Business Development', '5602250538952310', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Leda', 'Kindley', 'Services', '501801696417405621', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Norrie', 'Garrard', 'Sales', '6759369463711985', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Virgilio', 'Draisey', 'Accounting', '63040733415990171', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Jane', 'Edgeson', 'Marketing', '6763382888139223', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Jarrod', 'Murley', 'Business Development', '30309395420002', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Vallie', 'Firks', 'Engineering', '5225778667935307', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Renell', 'Okenden', 'Legal', '3553064964588132', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Jefferey', 'Yallowley', 'Engineering', '4471961936954689', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Emanuel', 'Hamblin', 'Training', '5149322589750099', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Anderson', 'Striker', 'Support', '5610650582148311', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Maryrose', 'Waring', 'Accounting', '4041370228058', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Horatia', 'Parrin', 'Sales', '3547111171013567', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Rosita', 'Egdal', 'Business Development', '3547017694930460', null, null); +insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Khalil', 'Proven', 'Marketing', '560224183261043159', null, null); diff --git a/src/main/resources/schema-h2.sql b/src/main/resources/schema-h2.sql index 571709d..dae8e93 100644 --- a/src/main/resources/schema-h2.sql +++ b/src/main/resources/schema-h2.sql @@ -5,9 +5,9 @@ CREATE TABLE EMPLOYEE ( FIRST_NAME VARCHAR(255) NOT NULL DEFAULT '', LAST_NAME VARCHAR(255) NOT NULL DEFAULT '', TITLE VARCHAR(255) NOT NULL DEFAULT 'EMPLOYEE', - PHONE VARCHAR(20) NOT NULL DEFAULT '', + PHONE VARCHAR(12) NOT NULL DEFAULT '', HIRE_DATE DATE DEFAULT NULL, - MANAGER BOOLEAN NOT NULL DEFAULT FALSE, + MANAGER_ID NUMBER(10,0) NULL, DEPARTMENT_ID NUMBER(10,0) NOT NULL, PRIMARY KEY (EMPLOYEE_ID) ); @@ -17,10 +17,11 @@ DROP TABLE IF EXISTS DEPARTMENT; CREATE TABLE DEPARTMENT ( DEPARTMENT_ID NUMBER(10,0) NOT NULL AUTO_INCREMENT, DEPARTMENT_NAME VARCHAR (255) NOT NULL DEFAULT '', - DEPARTMENT_MANAGER NUMBER (10,0), + DEPARTMENT_MANAGER NUMBER (10,0) NULL, PRIMARY KEY (DEPARTMENT_ID) ); + DROP IF EXISTS SEQUENCE hibernate_sequence; CREATE SEQUENCE hibernate_sequence; \ No newline at end of file From 43fb165fce7f9da8effabdf94d8f0afc3990f87e Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 10:23:10 -0500 Subject: [PATCH 05/27] dummy data --- src/main/resources/data-h2.sql | 100 ++++++++++++++++----------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/main/resources/data-h2.sql b/src/main/resources/data-h2.sql index 4642e43..ef15915 100644 --- a/src/main/resources/data-h2.sql +++ b/src/main/resources/data-h2.sql @@ -21,53 +21,53 @@ DEPARTMENT_NAME, DEPARTMENT_MANAGER -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Ailee', 'Perin', 'Services', '63044472278349193', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Horace', 'Vaud', 'Training', '3581400352523776', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Obed', 'Fussie', 'Services', '3578495167370368', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Hale', 'Tubritt', 'Services', '5422330511208340', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Lenci', 'Robbie', 'Human Resources', '3575569624043702', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Daria', 'Vautin', 'Legal', '3585398925527439', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Sidonnie', 'Chicken', 'Sales', '5315330871050050', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Delila', 'Seary', 'Accounting', '5010126412785818', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Anita', 'McKaile', 'Engineering', '3531738714411961', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Stephanie', 'O''Gormally', 'Services', '6383020970942654', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Lorenza', 'Torrecilla', 'Accounting', '5038812450486770480', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Kingsley', 'Heeron', 'Support', '337941764817630', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Neysa', 'Klamp', 'Product Management', '6767347428924578340', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Janot', 'Nyssen', 'Marketing', '3568126995399814', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Juan', 'Wedgwood', 'Engineering', '30164735517987', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Mellie', 'Diloway', 'Marketing', '3528580342654090', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Rosamund', 'Bessell', 'Services', '5602236317462746', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Harbert', 'Rogers', 'Services', '3534565963628350', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Alix', 'McGow', 'Sales', '677179174895462979', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Seth', 'Booton', 'Product Management', '3554439537488607', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Kayne', 'Reyner', 'Research and Development', '5437821212517461', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Mauricio', 'Saiger', 'Sales', '3534321322573527', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Cymbre', 'Fairman', 'Sales', '5300792847214952', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Alex', 'Dunckley', 'Engineering', '3545061165162247', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Esta', 'Gersam', 'Sales', '374283137559688', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Hillary', 'Touson', 'Services', '3585870159235194', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Magdalene', 'Molesworth', 'Marketing', '3587868322817045', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Orren', 'Boame', 'Business Development', '3582144644434090', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Erik', 'Lipprose', 'Human Resources', '3558048262357923', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Ilyse', 'Aherne', 'Accounting', '3577886601448896', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Evyn', 'McNickle', 'Accounting', '6759809855269694332', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Kamilah', 'Avrahamof', 'Marketing', '3581655015095583', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Stanwood', 'Seniour', 'Marketing', '5038617308780259', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Rosene', 'Portress', 'Support', '3554514927841316', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Kristien', 'Enticott', 'Sales', '5602218415453959', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Noach', 'Gittins', 'Business Development', '5602250538952310', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Leda', 'Kindley', 'Services', '501801696417405621', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Norrie', 'Garrard', 'Sales', '6759369463711985', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Virgilio', 'Draisey', 'Accounting', '63040733415990171', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Jane', 'Edgeson', 'Marketing', '6763382888139223', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Jarrod', 'Murley', 'Business Development', '30309395420002', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Vallie', 'Firks', 'Engineering', '5225778667935307', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Renell', 'Okenden', 'Legal', '3553064964588132', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Jefferey', 'Yallowley', 'Engineering', '4471961936954689', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Emanuel', 'Hamblin', 'Training', '5149322589750099', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Anderson', 'Striker', 'Support', '5610650582148311', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Maryrose', 'Waring', 'Accounting', '4041370228058', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Horatia', 'Parrin', 'Sales', '3547111171013567', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Rosita', 'Egdal', 'Business Development', '3547017694930460', null, null); -insert into EMPLOYEE_DATA (FIRST_NAME, LAST_NAME, TITLE, PHONE, MANAGER_ID, DEPARTMENT_ID) values ('Khalil', 'Proven', 'Marketing', '560224183261043159', null, null); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Ailee', 'Perin', 'Services', '215-333-4444', '2010-08-28', 14, 1); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Horace', 'Vaud', 'IT Dept Manager', '215-333-4444', '2008-08-28', null, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Obed', 'Fussie', 'Services', '215-333-4444', '2010-08-28', 14, 1); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Hale', 'Tubritt', 'Services', '215-333-4444', '2010-08-28', 14, 1); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Lenci', 'Robbie', 'IT Manager', '215-333-4444', '2010-08-28', 2, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Daria', 'Vautin', 'Legal', '215-333-4444', '2010-08-28', 14, 1); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Sidonnie', 'Chicken', 'Sales', '215-333-4444', '2010-08-28', 14, 1); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Delila', 'Seary', 'Accounting', '215-333-4444', '2010-08-28', 14, 1); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Anita', 'McKaile', 'Engineering', '215-333-4444', '2010-08-28', 14, 1); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Stephanie', 'O''Gormally', 'Marketing Dept Manager', '215-333-4444', '2007-08-28', null, 2); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Lorenza', 'Torrecilla', 'Marketing Manager', '215-333-4444', '2010-08-28', 10, 2); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Kingsley', 'Heeron', 'Support', '215-333-4444', '2010-08-28', 11, 2); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Neysa', 'Klamp', 'Product Management', '215-333-4444', '2010-08-28', 11, 2); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Janot', 'Nyssen', 'HR Dept Manager', '215-333-4444', '2008-08-28', null, 1); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Juan', 'Wedgwood', 'Engineering', '215-333-4444', '2010-08-28', 11, 2); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Mellie', 'Diloway', 'Marketing', '215-333-4444', '2010-08-28', 11, 2); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Rosamund', 'Bessell', 'Services', '215-333-4444', '2010-08-28', 11, 2); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Harbert', 'Rogers', 'IT Manager', '215-333-4444', '2010-08-28', 2, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Alix', 'McGow', 'Sales', '215-333-4444', '2010-08-28', 11, 2); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Seth', 'Booton', 'Product Management', '215-333-4444', '2010-08-28', 11, 2); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Kayne', 'Reyner', 'Research and Development', '215-333-4444', '2010-08-28', 5, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Mauricio', 'Saiger', 'Sales', '215-333-4444', '2010-08-28', 5, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Cymbre', 'Fairman', 'Sales', '215-333-4444', '2010-08-28', 5, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Alex', 'Dunckley', 'Engineering', '215-333-4444', '2010-08-28', 5, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Esta', 'Gersam', 'Sales', '215-333-4444', '2010-08-28', 5, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Hillary', 'Touson', 'Services', '215-333-4444', '2010-08-28', 5, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Magdalene', 'Molesworth', 'Marketing', '215-333-4444', '2010-08-28', 5, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Orren', 'Boame', 'Business Development', '215-333-4444', '2010-08-28', 5, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Erik', 'Lipprose', 'Human Resources', '215-333-4444', '2010-08-28', 5, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Ilyse', 'Aherne', 'Accounting', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Evyn', 'McNickle', 'Accounting', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Kamilah', 'Avrahamof', 'Marketing', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Stanwood', 'Seniour', 'Marketing', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Rosene', 'Portress', 'Support', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Kristien', 'Enticott', 'Sales', '215-333-4444', '2010-08-28', null, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Noach', 'Gittins', 'Business Development', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Leda', 'Kindley', 'Services', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Norrie', 'Garrard', 'Sales', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Virgilio', 'Draisey', 'Accounting', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Jane', 'Edgeson', 'Marketing', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Jarrod', 'Murley', 'Business Development', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Vallie', 'Firks', 'Engineering', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Renell', 'Okenden', 'Legal', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Jefferey', 'Yallowley', 'Engineering', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Emanuel', 'Hamblin', 'Training', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Anderson', 'Striker', 'Support', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Maryrose', 'Waring', 'Accounting', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Horatia', 'Parrin', 'Sales', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Rosita', 'Egdal', 'Business Development', '215-333-4444', '2010-08-28', 18, 3); +insert into EMPLOYEE (FIRST_NAME, LAST_NAME, TITLE, PHONE, HIRE_DATE, MANAGER_ID, DEPARTMENT_ID) values ('Khalil', 'Proven', 'Marketing', '215-333-4444', '2010-08-28', 18, 3); From 3890cee14ec108cbdfdb73df67b83872bcf25e31 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 10:31:36 -0500 Subject: [PATCH 06/27] add get all departments --- .../controllers/DepartmentController.java | 3 ++- .../repositories/DepartmentRepository.java | 3 ++- .../repositories/EmployeeRepository.java | 3 ++- .../persistenceapp/services/DepartmentService.java | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java index 26f6850..4a193ed 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java @@ -3,6 +3,7 @@ import io.zipcoder.persistenceapp.entities.Department; import io.zipcoder.persistenceapp.services.DepartmentService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -22,7 +23,7 @@ public DepartmentController(DepartmentService departmentService){ @GetMapping public ResponseEntity> getAllDepartments(){ - return null; + return new ResponseEntity<>(departmentService.getAllDepartments(), HttpStatus.OK); } // TODO diff --git a/src/main/java/io/zipcoder/persistenceapp/repositories/DepartmentRepository.java b/src/main/java/io/zipcoder/persistenceapp/repositories/DepartmentRepository.java index 843ea3e..a571bb7 100644 --- a/src/main/java/io/zipcoder/persistenceapp/repositories/DepartmentRepository.java +++ b/src/main/java/io/zipcoder/persistenceapp/repositories/DepartmentRepository.java @@ -1,10 +1,11 @@ package io.zipcoder.persistenceapp.repositories; +import io.zipcoder.persistenceapp.entities.Department; import io.zipcoder.persistenceapp.entities.Employee; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @Repository -public interface DepartmentRepository extends CrudRepository { +public interface DepartmentRepository extends CrudRepository { } diff --git a/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java b/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java index 814b8d6..4db1160 100644 --- a/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java +++ b/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java @@ -1,9 +1,10 @@ package io.zipcoder.persistenceapp.repositories; import io.zipcoder.persistenceapp.entities.Department; +import io.zipcoder.persistenceapp.entities.Employee; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @Repository -public interface EmployeeRepository extends CrudRepository { +public interface EmployeeRepository extends CrudRepository { } diff --git a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java index 5d2d840..22c3f9c 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java @@ -1,7 +1,21 @@ package io.zipcoder.persistenceapp.services; +import io.zipcoder.persistenceapp.entities.Department; +import io.zipcoder.persistenceapp.repositories.DepartmentRepository; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class DepartmentService { + + DepartmentRepository departmentRepository; + + @Autowired + public DepartmentService(DepartmentRepository departmentRepository){ + this.departmentRepository = departmentRepository; + } + + public Iterable getAllDepartments(){ + return departmentRepository.findAll(); + } } From f5f1b710b4acf9a660ace9d08ae4382f1be9a427 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 11:28:01 -0500 Subject: [PATCH 07/27] Add exceptions and get department by id --- .../controllers/DepartmentController.java | 16 +++++++++---- .../exceptions/ResourceNotFoundException.java | 15 ++++++++++++ .../services/DepartmentService.java | 24 +++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/main/java/io/zipcoder/persistenceapp/exceptions/ResourceNotFoundException.java diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java index 4a193ed..b2b9ee8 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java @@ -5,12 +5,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController -@RequestMapping("/api/department") +@RequestMapping("/api/department/") public class DepartmentController { @@ -26,6 +24,16 @@ public ResponseEntity> getAllDepartments(){ return new ResponseEntity<>(departmentService.getAllDepartments(), HttpStatus.OK); } + @GetMapping("{id}") + public ResponseEntity getDepartmentById(@PathVariable Long id){ + return new ResponseEntity(departmentService.getDepartmentById(id),HttpStatus.OK); + } + + @PutMapping("{id}") + public ResponseEntity updateDepartmentManager(@RequestBody Department newData, @PathVariable Long departmentId){ + return new ResponseEntity(departmentService.updateDepartmentManager(newData, departmentId),HttpStatus.OK); + } + // TODO // create a department // update department with a new manager diff --git a/src/main/java/io/zipcoder/persistenceapp/exceptions/ResourceNotFoundException.java b/src/main/java/io/zipcoder/persistenceapp/exceptions/ResourceNotFoundException.java new file mode 100644 index 0000000..eafaf21 --- /dev/null +++ b/src/main/java/io/zipcoder/persistenceapp/exceptions/ResourceNotFoundException.java @@ -0,0 +1,15 @@ +package io.zipcoder.persistenceapp.exceptions; + +public class ResourceNotFoundException extends RuntimeException{ + public ResourceNotFoundException() { + } + + public ResourceNotFoundException(String message) { + super(message); + } + + public ResourceNotFoundException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java index 22c3f9c..b971c8f 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java @@ -1,6 +1,7 @@ package io.zipcoder.persistenceapp.services; import io.zipcoder.persistenceapp.entities.Department; +import io.zipcoder.persistenceapp.exceptions.ResourceNotFoundException; import io.zipcoder.persistenceapp.repositories.DepartmentRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -18,4 +19,27 @@ public DepartmentService(DepartmentRepository departmentRepository){ public Iterable getAllDepartments(){ return departmentRepository.findAll(); } + + public Department getDepartmentById(Long id){ + verifyDepartment(id); + return departmentRepository.findOne(id); + } + + public Department updateDepartmentManager(Department newData, Long ID){ + + verifyDepartment(ID); + + Department existingData = departmentRepository.findOne(ID); + existingData.setDEPARTMENT_MANAGER(newData.getDEPARTMENT_MANAGER()); + return departmentRepository.save(existingData); + } + + private void verifyDepartment(Long departmentId){ + if (departmentRepository.exists(departmentId)){ + + } else { + throw new ResourceNotFoundException("Department not found!"); + } + } + } From 89f8ff364548728a58811294deb1076c7854ca34 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 11:39:12 -0500 Subject: [PATCH 08/27] get department name --- .../controllers/DepartmentController.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java index b2b9ee8..b0283a7 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java @@ -11,6 +11,8 @@ @RequestMapping("/api/department/") public class DepartmentController { + private String departmentName; + private Long departmentManager; DepartmentService departmentService; @@ -29,11 +31,23 @@ public ResponseEntity getDepartmentById(@PathVariable Long id){ return new ResponseEntity(departmentService.getDepartmentById(id),HttpStatus.OK); } + @GetMapping("{id}/name") + public String getDepartmentName (@PathVariable Long id){ + parseDepartmentData(getDepartmentById(id)); + return departmentName; + } + @PutMapping("{id}") public ResponseEntity updateDepartmentManager(@RequestBody Department newData, @PathVariable Long departmentId){ return new ResponseEntity(departmentService.updateDepartmentManager(newData, departmentId),HttpStatus.OK); } + private void parseDepartmentData(ResponseEntity department){ + departmentName = department.getBody().getDEPARTMENT_NAME(); + departmentManager = department.getBody().getDEPARTMENT_ID(); + } + + // TODO // create a department // update department with a new manager From ace7be05e50f28244e53de95c13460b7411a1596 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 13:29:46 -0500 Subject: [PATCH 09/27] department service get name test --- .../controllers/DepartmentController.java | 18 +++--- .../persistenceapp/entities/Department.java | 2 +- .../services/DepartmentService.java | 5 ++ .../controllers/DepartmentControllerTest.java | 55 +++++++++++++++++++ .../services/DepartmentServiceTest.java | 53 ++++++++++++++++++ 5 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java create mode 100644 src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java index b0283a7..a17358f 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java @@ -26,31 +26,27 @@ public ResponseEntity> getAllDepartments(){ return new ResponseEntity<>(departmentService.getAllDepartments(), HttpStatus.OK); } + @GetMapping("{id}/name") + public String getDepartmentName (@PathVariable Long id){ + return departmentService.getDepartmentName(id); + } + @GetMapping("{id}") public ResponseEntity getDepartmentById(@PathVariable Long id){ return new ResponseEntity(departmentService.getDepartmentById(id),HttpStatus.OK); } - @GetMapping("{id}/name") - public String getDepartmentName (@PathVariable Long id){ - parseDepartmentData(getDepartmentById(id)); - return departmentName; - } - @PutMapping("{id}") public ResponseEntity updateDepartmentManager(@RequestBody Department newData, @PathVariable Long departmentId){ return new ResponseEntity(departmentService.updateDepartmentManager(newData, departmentId),HttpStatus.OK); } - private void parseDepartmentData(ResponseEntity department){ - departmentName = department.getBody().getDEPARTMENT_NAME(); - departmentManager = department.getBody().getDEPARTMENT_ID(); - } + // TODO // create a department // update department with a new manager // change name of a department - // get department name + } diff --git a/src/main/java/io/zipcoder/persistenceapp/entities/Department.java b/src/main/java/io/zipcoder/persistenceapp/entities/Department.java index 9128dd2..49bdc27 100644 --- a/src/main/java/io/zipcoder/persistenceapp/entities/Department.java +++ b/src/main/java/io/zipcoder/persistenceapp/entities/Department.java @@ -19,7 +19,7 @@ public class Department { public Long getDEPARTMENT_ID() { return DEPARTMENT_ID; } - + public void setDEPARTMENT_ID (Long id){ this.DEPARTMENT_ID = id;} public String getDEPARTMENT_NAME() { return DEPARTMENT_NAME; diff --git a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java index b971c8f..d0f9756 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java @@ -25,6 +25,11 @@ public Department getDepartmentById(Long id){ return departmentRepository.findOne(id); } + public String getDepartmentName(Long id){ + verifyDepartment(id); + return getDepartmentById(id).getDEPARTMENT_NAME(); + } + public Department updateDepartmentManager(Department newData, Long ID){ verifyDepartment(ID); diff --git a/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java b/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java new file mode 100644 index 0000000..8356510 --- /dev/null +++ b/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java @@ -0,0 +1,55 @@ +package io.zipcoder.persistenceapp.controllers; + +import io.zipcoder.persistenceapp.entities.Department; +import io.zipcoder.persistenceapp.repositories.DepartmentRepository; +import io.zipcoder.persistenceapp.services.DepartmentService; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.BDDMockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +import java.util.Optional; + + +@SpringBootTest +@AutoConfigureMockMvc +@RunWith(SpringRunner.class) +public class DepartmentControllerTest { + + @Autowired + private MockMvc mvc; + + @MockBean + private DepartmentRepository repository; + + @Autowired + private DepartmentService service; + + @Test + public void testGetAllDepartments () throws Exception { + + } + + @Test + public void testGetDepartmentName() throws Exception{ +// +// this.mvc.perform(MockMvcRequestBuilders +// .get("/1/name") +// .content(expected) +// .accept(MediaType.ALL) +// .contentType(MediaType.ALL_VALUE)) +// .andExpect(MockMvcResultMatchers.content().string(expected)); + + + } +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java b/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java new file mode 100644 index 0000000..db5dc0a --- /dev/null +++ b/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java @@ -0,0 +1,53 @@ +package io.zipcoder.persistenceapp.services; + +import io.zipcoder.persistenceapp.entities.Department; +import io.zipcoder.persistenceapp.repositories.DepartmentRepository; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.BDDMockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBootTest +@RunWith(SpringRunner.class) +public class DepartmentServiceTest { + + @MockBean + private DepartmentRepository repository; + + @Autowired + private DepartmentService service; + + + @Test + public void getDepartmentById() { + } + + @Test + public void getDepartmentName() { + Long givenId = 1L; + String expected = "MARKETING"; + Department departmentTest = new Department(); + departmentTest.setDEPARTMENT_NAME(expected); + departmentTest.setDEPARTMENT_ID(givenId); + + BDDMockito + .given(repository.save(departmentTest)) + .willReturn(departmentTest); + + BDDMockito + .given(repository.findOne(givenId)) + .willReturn(departmentTest); + + BDDMockito + .given(repository.exists(givenId)) + .willReturn(true); + + String response = service.getDepartmentName(givenId); + + Assert.assertEquals(expected,response); + } +} \ No newline at end of file From 4b325d6bfdb9fc0550c5fab6a163656e62ef69df Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 14:08:47 -0500 Subject: [PATCH 10/27] Add test for get dept by id --- .../services/DepartmentServiceTest.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java b/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java index db5dc0a..fd7a101 100644 --- a/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java +++ b/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java @@ -24,6 +24,22 @@ public class DepartmentServiceTest { @Test public void getDepartmentById() { + Long givenId = 1L; + Department departmentTest = new Department(); + departmentTest.setDEPARTMENT_NAME("Marketing"); + departmentTest.setDEPARTMENT_ID(givenId); + + BDDMockito + .given(repository.findOne(givenId)) + .willReturn(departmentTest); + + BDDMockito + .given(repository.exists(givenId)) + .willReturn(true); + + Department response = service.getDepartmentById(givenId); + + Assert.assertEquals(departmentTest,response); } @Test @@ -34,9 +50,6 @@ public void getDepartmentName() { departmentTest.setDEPARTMENT_NAME(expected); departmentTest.setDEPARTMENT_ID(givenId); - BDDMockito - .given(repository.save(departmentTest)) - .willReturn(departmentTest); BDDMockito .given(repository.findOne(givenId)) From 363bd2218cf58799190a50d275776ce6a3dabfe9 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 14:58:45 -0500 Subject: [PATCH 11/27] test get all departments --- .../services/DepartmentServiceTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java b/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java index fd7a101..4020b10 100644 --- a/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java +++ b/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java @@ -11,6 +11,9 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit4.SpringRunner; +import java.util.ArrayList; +import java.util.List; + @SpringBootTest @RunWith(SpringRunner.class) public class DepartmentServiceTest { @@ -63,4 +66,27 @@ public void getDepartmentName() { Assert.assertEquals(expected,response); } + + @Test + public void testGetAllDepartments(){ + Department departmentTest = new Department(); + departmentTest.setDEPARTMENT_NAME("Test1"); + departmentTest.setDEPARTMENT_ID(1L); + Department departmentTest2 = new Department(); + departmentTest2.setDEPARTMENT_NAME("Test1"); + departmentTest2.setDEPARTMENT_ID(2L); + + List allDepartments = new ArrayList<>(); + allDepartments.add(departmentTest); + allDepartments.add(departmentTest2); + + BDDMockito + .given(repository.findAll()) + .willReturn(allDepartments); + + Integer expected = 2; + Integer actual = allDepartments.size(); + + Assert.assertEquals(expected,actual); + } } \ No newline at end of file From a8b2f146711417c22b9bdd888d7a3d3355b6693d Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 15:47:33 -0500 Subject: [PATCH 12/27] get all depts controller test --- .../controllers/DepartmentControllerTest.java | 38 +++++++++++-------- .../services/DepartmentServiceTest.java | 6 +-- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java b/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java index 8356510..7b4b955 100644 --- a/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java +++ b/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java @@ -2,23 +2,23 @@ import io.zipcoder.persistenceapp.entities.Department; import io.zipcoder.persistenceapp.repositories.DepartmentRepository; -import io.zipcoder.persistenceapp.services.DepartmentService; -import org.junit.Assert; + import org.junit.Test; import org.junit.runner.RunWith; + import org.mockito.BDDMockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import java.util.Optional; +import java.util.ArrayList; +import java.util.List; @SpringBootTest @@ -26,30 +26,38 @@ @RunWith(SpringRunner.class) public class DepartmentControllerTest { + @Autowired private MockMvc mvc; @MockBean private DepartmentRepository repository; - @Autowired - private DepartmentService service; @Test public void testGetAllDepartments () throws Exception { + List allDepts = new ArrayList<>(); + allDepts.add(new Department()); + allDepts.add(new Department()); + // given + BDDMockito + .given(repository.findAll()) + .willReturn(allDepts); + + // when + this.mvc.perform( MockMvcRequestBuilders + .get("/api/department/") + ) .andExpect(MockMvcResultMatchers.status().isOk()); + + + this.mvc.perform(MockMvcRequestBuilders + .get("/api/departments/") + ) .andExpect(MockMvcResultMatchers.status().is4xxClientError()); } @Test public void testGetDepartmentName() throws Exception{ -// -// this.mvc.perform(MockMvcRequestBuilders -// .get("/1/name") -// .content(expected) -// .accept(MediaType.ALL) -// .contentType(MediaType.ALL_VALUE)) -// .andExpect(MockMvcResultMatchers.content().string(expected)); - } } \ No newline at end of file diff --git a/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java b/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java index 4020b10..efbb431 100644 --- a/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java +++ b/src/test/java/io/zipcoder/persistenceapp/services/DepartmentServiceTest.java @@ -26,7 +26,7 @@ public class DepartmentServiceTest { @Test - public void getDepartmentById() { + public void getDepartmentById() throws Exception{ Long givenId = 1L; Department departmentTest = new Department(); departmentTest.setDEPARTMENT_NAME("Marketing"); @@ -46,7 +46,7 @@ public void getDepartmentById() { } @Test - public void getDepartmentName() { + public void getDepartmentName() throws Exception { Long givenId = 1L; String expected = "MARKETING"; Department departmentTest = new Department(); @@ -68,7 +68,7 @@ public void getDepartmentName() { } @Test - public void testGetAllDepartments(){ + public void testGetAllDepartments() throws Exception{ Department departmentTest = new Department(); departmentTest.setDEPARTMENT_NAME("Test1"); departmentTest.setDEPARTMENT_ID(1L); From 3aa6ec6a2baf43a9070aa9409f78625eae19cafe Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 15:55:52 -0500 Subject: [PATCH 13/27] add get dept name controller test --- .../controllers/DepartmentControllerTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java b/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java index 7b4b955..7c1024c 100644 --- a/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java +++ b/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java @@ -3,6 +3,7 @@ import io.zipcoder.persistenceapp.entities.Department; import io.zipcoder.persistenceapp.repositories.DepartmentRepository; +import io.zipcoder.persistenceapp.services.DepartmentService; import org.junit.Test; import org.junit.runner.RunWith; @@ -58,6 +59,22 @@ public void testGetAllDepartments () throws Exception { @Test public void testGetDepartmentName() throws Exception{ + Department dept = new Department(); + dept.setDEPARTMENT_ID(5L); + dept.setDEPARTMENT_NAME("Test"); + BDDMockito + .given(repository.findOne(5L)) + .willReturn(dept); + + BDDMockito + .given(repository.exists(5L)) + .willReturn(true); + + + this.mvc.perform(MockMvcRequestBuilders + .get("/api/department/5/name") + ) .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().string("Test")); } } \ No newline at end of file From b334f4894d03e2e5abc72e063904baec4a571a7a Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 16:21:54 -0500 Subject: [PATCH 14/27] Add test get department by id controller --- .../controllers/DepartmentControllerTest.java | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java b/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java index 7c1024c..11c808c 100644 --- a/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java +++ b/src/test/java/io/zipcoder/persistenceapp/controllers/DepartmentControllerTest.java @@ -3,16 +3,15 @@ import io.zipcoder.persistenceapp.entities.Department; import io.zipcoder.persistenceapp.repositories.DepartmentRepository; -import io.zipcoder.persistenceapp.services.DepartmentService; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.BDDMockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @@ -36,29 +35,29 @@ public class DepartmentControllerTest { @Test - public void testGetAllDepartments () throws Exception { + public void testGetAllDepartments() throws Exception { List allDepts = new ArrayList<>(); allDepts.add(new Department()); allDepts.add(new Department()); // given BDDMockito - .given(repository.findAll()) - .willReturn(allDepts); + .given(repository.findAll()) + .willReturn(allDepts); // when - this.mvc.perform( MockMvcRequestBuilders + this.mvc.perform(MockMvcRequestBuilders .get("/api/department/") - ) .andExpect(MockMvcResultMatchers.status().isOk()); + ).andExpect(MockMvcResultMatchers.status().isOk()); this.mvc.perform(MockMvcRequestBuilders - .get("/api/departments/") - ) .andExpect(MockMvcResultMatchers.status().is4xxClientError()); + .get("/api/departments/") + ).andExpect(MockMvcResultMatchers.status().is4xxClientError()); } @Test - public void testGetDepartmentName() throws Exception{ + public void testGetDepartmentName() throws Exception { Department dept = new Department(); dept.setDEPARTMENT_ID(5L); dept.setDEPARTMENT_NAME("Test"); @@ -73,8 +72,31 @@ public void testGetDepartmentName() throws Exception{ this.mvc.perform(MockMvcRequestBuilders - .get("/api/department/5/name") - ) .andExpect(MockMvcResultMatchers.status().isOk()) + .get("/api/department/5/name") + ).andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Test")); } + + @Test + public void testGetDepartmentById() throws Exception { + Department dept = new Department(); + dept.setDEPARTMENT_ID(5L); + dept.setDEPARTMENT_NAME("Test"); + dept.setDEPARTMENT_MANAGER(10L); + + BDDMockito + .given(repository.findOne(5L)) + .willReturn(dept); + + BDDMockito + .given(repository.exists(5L)) + .willReturn(true); + + String expected = "{\"department_NAME\":\"Test\",\"department_MANAGER\":10,\"department_ID\":5}"; + this.mvc.perform(MockMvcRequestBuilders + .get("/api/department/5") + .contentType(MediaType.APPLICATION_JSON) + ).andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().string(expected)); + } } \ No newline at end of file From 283a44f9da29bcb365a6ecfa4c6043139a71931a Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 16:33:04 -0500 Subject: [PATCH 15/27] update dep manager --- .../persistenceapp/controllers/DepartmentController.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java index a17358f..4a64757 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java @@ -11,9 +11,6 @@ @RequestMapping("/api/department/") public class DepartmentController { - private String departmentName; - private Long departmentManager; - DepartmentService departmentService; @Autowired @@ -37,8 +34,8 @@ public ResponseEntity getDepartmentById(@PathVariable Long id){ } @PutMapping("{id}") - public ResponseEntity updateDepartmentManager(@RequestBody Department newData, @PathVariable Long departmentId){ - return new ResponseEntity(departmentService.updateDepartmentManager(newData, departmentId),HttpStatus.OK); + public ResponseEntity updateDepartmentManager(@RequestBody Department newData, @PathVariable Long id){ + return new ResponseEntity(departmentService.updateDepartmentManager(newData, id),HttpStatus.OK); } From b9d2ffb965ecbce9ebd0cf01b3031feee5ba6d69 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 16:50:15 -0500 Subject: [PATCH 16/27] add update dept name --- .../persistenceapp/controllers/DepartmentController.java | 7 ++++--- .../persistenceapp/services/DepartmentService.java | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java index 4a64757..0a4aa79 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java @@ -38,12 +38,13 @@ public ResponseEntity updateDepartmentManager(@RequestBody Departmen return new ResponseEntity(departmentService.updateDepartmentManager(newData, id),HttpStatus.OK); } - + @PutMapping("{id}/name") + public ResponseEntity updateDepartmentName(@RequestBody Department newData, @PathVariable Long id){ + return new ResponseEntity(departmentService.updateDepartmentName(newData, id),HttpStatus.OK); + } // TODO // create a department - // update department with a new manager - // change name of a department } diff --git a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java index d0f9756..e5e11d0 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java @@ -39,6 +39,15 @@ public Department updateDepartmentManager(Department newData, Long ID){ return departmentRepository.save(existingData); } + public Department updateDepartmentName(Department newData, Long id){ + + verifyDepartment(id); + + Department existingData = departmentRepository.findOne(id); + existingData.setDEPARTMENT_NAME(newData.getDEPARTMENT_NAME()); + return departmentRepository.save(existingData); + } + private void verifyDepartment(Long departmentId){ if (departmentRepository.exists(departmentId)){ From b9cda3f5a2feb769c35705b7d81aadeb246befee Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 17:32:52 -0500 Subject: [PATCH 17/27] create department --- .../persistenceapp/controllers/DepartmentController.java | 5 +++++ .../zipcoder/persistenceapp/services/DepartmentService.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java index 0a4aa79..8c66e10 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java @@ -43,6 +43,11 @@ public ResponseEntity updateDepartmentName(@RequestBody Department n return new ResponseEntity(departmentService.updateDepartmentName(newData, id),HttpStatus.OK); } + @PostMapping + public ResponseEntity createDepartment(@RequestBody Department newDepartment){ + return new ResponseEntity(departmentService.createDepartment(newDepartment),HttpStatus.CREATED); + } + // TODO // create a department diff --git a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java index e5e11d0..1f283a2 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/DepartmentService.java @@ -48,6 +48,10 @@ public Department updateDepartmentName(Department newData, Long id){ return departmentRepository.save(existingData); } + public Department createDepartment (Department newDepartment){ + return departmentRepository.save(newDepartment); + } + private void verifyDepartment(Long departmentId){ if (departmentRepository.exists(departmentId)){ From ee8be40cae87c0716767dab994b44e32971275f0 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 18:53:48 -0500 Subject: [PATCH 18/27] get employees under a manager --- .../controllers/DepartmentController.java | 3 -- .../controllers/EmployeeController.java | 11 +++--- .../persistenceapp/entities/Employee.java | 6 ++-- .../repositories/EmployeeRepository.java | 2 +- .../services/EmployeeService.java | 34 +++++++++++++++++++ 5 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java index 8c66e10..523a5f5 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/DepartmentController.java @@ -49,7 +49,4 @@ public ResponseEntity createDepartment(@RequestBody Department newDe } - // TODO - // create a department - } diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java index d56701d..82260f8 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java @@ -3,13 +3,15 @@ import io.zipcoder.persistenceapp.entities.Employee; import io.zipcoder.persistenceapp.services.EmployeeService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController -@RequestMapping("/api/employee") +@RequestMapping("/api/employee/") public class EmployeeController { EmployeeService employeeService; @@ -19,9 +21,9 @@ public EmployeeController(EmployeeService employeeService){ this.employeeService = employeeService; } - @GetMapping - public ResponseEntity> getAllEmployees(){ - return null; + @GetMapping("{id}") + public ResponseEntity> getAllEmployeesUnderManager(@PathVariable Long id){ + return new ResponseEntity<>(employeeService.getAllEmployeesUnderManager(id), HttpStatus.OK); } // TODO @@ -30,7 +32,6 @@ public ResponseEntity> getAllEmployees(){ * create employee * update employee to set their manager - * get a list of employees under a particular manager * get the entire hierarchy for an employee (manager, manager's manager..) * list of employees without a manager * list of employees under a particular department diff --git a/src/main/java/io/zipcoder/persistenceapp/entities/Employee.java b/src/main/java/io/zipcoder/persistenceapp/entities/Employee.java index ed27438..cb1e9d0 100644 --- a/src/main/java/io/zipcoder/persistenceapp/entities/Employee.java +++ b/src/main/java/io/zipcoder/persistenceapp/entities/Employee.java @@ -18,7 +18,7 @@ public class Employee { private String TITLE; private String PHONE; private Date HIRE_DATE; - private Boolean MANAGER_ID; + private Long MANAGER_ID; private Long DEPARTMENT_ID; @@ -66,11 +66,11 @@ public void setHIRE_DATE(Date HIRE_DATE) { this.HIRE_DATE = HIRE_DATE; } - public Boolean getMANAGER_ID() { + public Long getMANAGER_ID() { return MANAGER_ID; } - public void setMANAGER_ID(Boolean MANAGER_ID) { + public void setMANAGER_ID(Long MANAGER_ID) { this.MANAGER_ID = MANAGER_ID; } diff --git a/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java b/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java index 4db1160..75f6d98 100644 --- a/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java +++ b/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java @@ -1,10 +1,10 @@ package io.zipcoder.persistenceapp.repositories; -import io.zipcoder.persistenceapp.entities.Department; import io.zipcoder.persistenceapp.entities.Employee; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; @Repository public interface EmployeeRepository extends CrudRepository { + } diff --git a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java index ac3cd7d..c6e96d0 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java @@ -1,7 +1,41 @@ package io.zipcoder.persistenceapp.services; +import io.zipcoder.persistenceapp.entities.Employee; +import io.zipcoder.persistenceapp.exceptions.ResourceNotFoundException; +import io.zipcoder.persistenceapp.repositories.EmployeeRepository; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + @Service public class EmployeeService { + + EmployeeRepository employeeRepository; + + @Autowired + public EmployeeService (EmployeeRepository employeeRepository){ + this.employeeRepository = employeeRepository; + } + + public Iterable getAllEmployeesUnderManager (Long id){ + verifyEmployeeExists(id); + List allEmployees = new ArrayList<>(); + for (Employee each : employeeRepository.findAll()){ + if (each.getMANAGER_ID()==id){ + allEmployees.add(each); + } + } + return allEmployees; + } + + private void verifyEmployeeExists(Long id){ + if (employeeRepository.exists(id)){ + + }else + { + throw new ResourceNotFoundException("Employee not found!"); + } + } } From 0ace3812a9572e78ef1a4a9da299d75bd69f95bb Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 19:00:55 -0500 Subject: [PATCH 19/27] get all employees in a department --- .../controllers/EmployeeController.java | 10 +++++++--- .../persistenceapp/services/EmployeeService.java | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java index 82260f8..df0319e 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java @@ -21,20 +21,24 @@ public EmployeeController(EmployeeService employeeService){ this.employeeService = employeeService; } - @GetMapping("{id}") + @GetMapping("allundermanager/{id}") public ResponseEntity> getAllEmployeesUnderManager(@PathVariable Long id){ return new ResponseEntity<>(employeeService.getAllEmployeesUnderManager(id), HttpStatus.OK); } + @GetMapping("allindepartment/{id}") + public ResponseEntity> getAllEmployeesInDepartment(@PathVariable Long id){ + return new ResponseEntity<>(employeeService.getAllEmployeesInDepartment(id), HttpStatus.OK); + } + // TODO /* - * create employee * update employee to set their manager * get the entire hierarchy for an employee (manager, manager's manager..) * list of employees without a manager - * list of employees under a particular department + * remove an employee * remove a list of employees * remove all employees from a department diff --git a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java index c6e96d0..e46f93d 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java @@ -30,6 +30,17 @@ public Iterable getAllEmployeesUnderManager (Long id){ return allEmployees; } + public Iterable getAllEmployeesInDepartment (Long id){ + verifyEmployeeExists(id); + List allEmployees = new ArrayList<>(); + for (Employee each : employeeRepository.findAll()){ + if (each.getDEPARTMENT_ID()==id){ + allEmployees.add(each); + } + } + return allEmployees; + } + private void verifyEmployeeExists(Long id){ if (employeeRepository.exists(id)){ From 0f68f02aca5315cf6c4f0bfe81b2ebe8de68f15b Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 19:05:35 -0500 Subject: [PATCH 20/27] get all employees without a manager --- .../controllers/EmployeeController.java | 36 +++++++++++-------- .../services/EmployeeService.java | 11 ++++++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java index df0319e..cbf819e 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java @@ -14,37 +14,45 @@ @RequestMapping("/api/employee/") public class EmployeeController { - EmployeeService employeeService; + EmployeeService employeeService; - @Autowired - public EmployeeController(EmployeeService employeeService){ - this.employeeService = employeeService; - } + @Autowired + public EmployeeController(EmployeeService employeeService) { + this.employeeService = employeeService; + } - @GetMapping("allundermanager/{id}") - public ResponseEntity> getAllEmployeesUnderManager(@PathVariable Long id){ - return new ResponseEntity<>(employeeService.getAllEmployeesUnderManager(id), HttpStatus.OK); - } + @GetMapping("allundermanager/{id}") + public ResponseEntity> getAllEmployeesUnderManager(@PathVariable Long id) { + return new ResponseEntity<>(employeeService.getAllEmployeesUnderManager(id), HttpStatus.OK); + } - @GetMapping("allindepartment/{id}") - public ResponseEntity> getAllEmployeesInDepartment(@PathVariable Long id){ - return new ResponseEntity<>(employeeService.getAllEmployeesInDepartment(id), HttpStatus.OK); - } + @GetMapping("allindepartment/{id}") + public ResponseEntity> getAllEmployeesInDepartment(@PathVariable Long id) { + return new ResponseEntity<>(employeeService.getAllEmployeesInDepartment(id), HttpStatus.OK); + } + + @GetMapping("allnomanager") + public ResponseEntity> getAllEmployeesNoManager() { + return new ResponseEntity<>(employeeService.getAllEmployeesNoManager(), HttpStatus.OK); + } // TODO /* + * create employee * update employee to set their manager * get the entire hierarchy for an employee (manager, manager's manager..) - * list of employees without a manager + * remove an employee * remove a list of employees * remove all employees from a department * remove all employees under a particular manager + * merge departments: given two department names eg: A and B, move the manager of B to report to the manager of A, and update all other employees to be members of department A + * remove all direct reports to a manager. Any employees previously managed by the deleted employees should now be managed by the next manager up the hierarchy. diff --git a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java index e46f93d..51b07da 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java @@ -41,6 +41,17 @@ public Iterable getAllEmployeesInDepartment (Long id){ return allEmployees; } + public Iterable getAllEmployeesNoManager (){ + List allEmployees = new ArrayList<>(); + for (Employee each : employeeRepository.findAll()){ + if (each.getMANAGER_ID()==null){ + allEmployees.add(each); + } + } + return allEmployees; + } + + private void verifyEmployeeExists(Long id){ if (employeeRepository.exists(id)){ From 526c0ba4436089bd51ecca2fb2683c351ca58b8d Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 19:40:08 -0500 Subject: [PATCH 21/27] get hierarchy of employee --- .../controllers/EmployeeController.java | 11 +++- .../services/EmployeeService.java | 57 +++++++++++++------ 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java index cbf819e..83a8294 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java @@ -36,15 +36,20 @@ public ResponseEntity> getAllEmployeesNoManager() { return new ResponseEntity<>(employeeService.getAllEmployeesNoManager(), HttpStatus.OK); } + @GetMapping("hierarch/{id}") + public ResponseEntity> getHierarchy(@PathVariable Long id) { + return new ResponseEntity<>(employeeService.getHierarchy(id), HttpStatus.OK); + } + + // TODO /* - * create employee - * update employee to set their manager - * get the entire hierarchy for an employee (manager, manager's manager..) + * create employee + * update employee to set their manager * remove an employee * remove a list of employees * remove all employees from a department diff --git a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java index 51b07da..35c81d8 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java @@ -15,48 +15,69 @@ public class EmployeeService { EmployeeRepository employeeRepository; @Autowired - public EmployeeService (EmployeeRepository employeeRepository){ + public EmployeeService(EmployeeRepository employeeRepository) { this.employeeRepository = employeeRepository; } - public Iterable getAllEmployeesUnderManager (Long id){ - verifyEmployeeExists(id); + public Iterable getAllEmployeesUnderManager(Long id) { List allEmployees = new ArrayList<>(); - for (Employee each : employeeRepository.findAll()){ - if (each.getMANAGER_ID()==id){ - allEmployees.add(each); + if (verifyEmployeeExists(id)) { + for (Employee each : employeeRepository.findAll()) { + if (each.getMANAGER_ID() == id) { + allEmployees.add(each); + } } } return allEmployees; } - public Iterable getAllEmployeesInDepartment (Long id){ - verifyEmployeeExists(id); + public Iterable getAllEmployeesInDepartment(Long id) { List allEmployees = new ArrayList<>(); - for (Employee each : employeeRepository.findAll()){ - if (each.getDEPARTMENT_ID()==id){ - allEmployees.add(each); + + if (verifyEmployeeExists(id)) { + for (Employee each : employeeRepository.findAll()) { + if (each.getDEPARTMENT_ID() == id) { + allEmployees.add(each); + } } } return allEmployees; } - public Iterable getAllEmployeesNoManager (){ + public Iterable getAllEmployeesNoManager() { List allEmployees = new ArrayList<>(); - for (Employee each : employeeRepository.findAll()){ - if (each.getMANAGER_ID()==null){ + for (Employee each : employeeRepository.findAll()) { + if (each.getMANAGER_ID() == null) { allEmployees.add(each); } } return allEmployees; } + public Iterable getHierarchy (Long id){ + List result = new ArrayList<>(); + Employee one = employeeRepository.findOne(id); + result.add(one); + Boolean topManager = false; + + if (verifyEmployeeExists(id)){ + while (!topManager){ + if (one.getMANAGER_ID() == null){ + topManager = true; + } else { + one = employeeRepository.findOne(one.getMANAGER_ID()); + result.add(one); + } + } + } + return result; + } - private void verifyEmployeeExists(Long id){ - if (employeeRepository.exists(id)){ - }else - { + private Boolean verifyEmployeeExists(Long id) { + if (employeeRepository.exists(id)) { + return true; + } else { throw new ResourceNotFoundException("Employee not found!"); } } From 284dba22e900ff3b7b3521cba31d9d14fd3abeeb Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 19:57:23 -0500 Subject: [PATCH 22/27] create employee --- .../controllers/EmployeeController.java | 12 +++++++----- .../persistenceapp/services/EmployeeService.java | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java index 83a8294..15f1c31 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java @@ -5,10 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api/employee/") @@ -41,6 +38,11 @@ public ResponseEntity> getHierarchy(@PathVariable Long id) { return new ResponseEntity<>(employeeService.getHierarchy(id), HttpStatus.OK); } + @PostMapping + public ResponseEntity createEmployee (@RequestBody Employee newEmployee){ + return new ResponseEntity<>(employeeService.createEmployee(newEmployee),HttpStatus.CREATED); + } + // TODO /* @@ -48,7 +50,7 @@ public ResponseEntity> getHierarchy(@PathVariable Long id) { - * create employee + * update employee to set their manager * remove an employee * remove a list of employees diff --git a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java index 35c81d8..9d31641 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java @@ -73,6 +73,10 @@ public Iterable getHierarchy (Long id){ return result; } + public Employee createEmployee (Employee newEmployee){ + return employeeRepository.save(newEmployee); + } + private Boolean verifyEmployeeExists(Long id) { if (employeeRepository.exists(id)) { From 0f5c405675516e1f9e225a1432d5cbd1c7249ad4 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 20:10:18 -0500 Subject: [PATCH 23/27] update employee manager --- .../persistenceapp/controllers/EmployeeController.java | 7 ++++++- .../persistenceapp/services/EmployeeService.java | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java index 15f1c31..459a3d5 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java @@ -43,15 +43,20 @@ public ResponseEntity createEmployee (@RequestBody Employee newEmploye return new ResponseEntity<>(employeeService.createEmployee(newEmployee),HttpStatus.CREATED); } + @PutMapping("{id}") + public ResponseEntity updateManager (@RequestBody Employee updatedData, @PathVariable Long id){ + return new ResponseEntity<>(employeeService.updatedData(updatedData, id),HttpStatus.OK); + } + // TODO /* + * update employee to set their manager - * update employee to set their manager * remove an employee * remove a list of employees * remove all employees from a department diff --git a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java index 9d31641..c17a9a2 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java @@ -77,6 +77,16 @@ public Employee createEmployee (Employee newEmployee){ return employeeRepository.save(newEmployee); } + public Employee updatedData (Employee newData, Long id){ + Employee existingData = null; + + if (verifyEmployeeExists(id)){ + existingData = employeeRepository.findOne(id); + existingData.setMANAGER_ID(newData.getMANAGER_ID()); + } + return employeeRepository.save(existingData); + } + private Boolean verifyEmployeeExists(Long id) { if (employeeRepository.exists(id)) { From 4e2cf1238ad62d15ab068f78fadb4dfa0ff5eff2 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 20:41:10 -0500 Subject: [PATCH 24/27] remove employee --- .../controllers/EmployeeController.java | 8 +++--- .../services/EmployeeService.java | 27 +++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java index 459a3d5..da099fc 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java @@ -48,16 +48,16 @@ public ResponseEntity updateManager (@RequestBody Employee updatedData return new ResponseEntity<>(employeeService.updatedData(updatedData, id),HttpStatus.OK); } + @DeleteMapping("{id}") + public ResponseEntity deleteEmployee (@PathVariable Long id){ + return new ResponseEntity<>(employeeService.deleteEmployee(id),HttpStatus.OK); + } // TODO /* - * update employee to set their manager - - - * remove an employee * remove a list of employees * remove all employees from a department * remove all employees under a particular manager diff --git a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java index c17a9a2..fd34660 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java @@ -54,39 +54,50 @@ public Iterable getAllEmployeesNoManager() { return allEmployees; } - public Iterable getHierarchy (Long id){ + public Iterable getHierarchy(Long id) { List result = new ArrayList<>(); Employee one = employeeRepository.findOne(id); result.add(one); Boolean topManager = false; - if (verifyEmployeeExists(id)){ - while (!topManager){ - if (one.getMANAGER_ID() == null){ + if (verifyEmployeeExists(id)) { + while (!topManager) { + if (one.getMANAGER_ID() == null) { topManager = true; } else { one = employeeRepository.findOne(one.getMANAGER_ID()); - result.add(one); + if (one != null) { + result.add(one); // needs logic if we delete the dept manager + } else topManager = true; + } } } return result; } - public Employee createEmployee (Employee newEmployee){ + public Employee createEmployee(Employee newEmployee) { return employeeRepository.save(newEmployee); } - public Employee updatedData (Employee newData, Long id){ + public Employee updatedData(Employee newData, Long id) { Employee existingData = null; - if (verifyEmployeeExists(id)){ + if (verifyEmployeeExists(id)) { existingData = employeeRepository.findOne(id); existingData.setMANAGER_ID(newData.getMANAGER_ID()); } return employeeRepository.save(existingData); } + public Boolean deleteEmployee(Long id) { + if (verifyEmployeeExists(id)) { + employeeRepository.delete(id); + return true; + } + return false; + } + private Boolean verifyEmployeeExists(Long id) { if (employeeRepository.exists(id)) { From 3f810d9f210e46a8a9cb7363b5cb5f305ee60396 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Fri, 13 Dec 2019 21:08:40 -0500 Subject: [PATCH 25/27] removed employees under a manager --- .../persistenceapp/controllers/EmployeeController.java | 7 ++++++- .../persistenceapp/repositories/EmployeeRepository.java | 2 ++ .../zipcoder/persistenceapp/services/EmployeeService.java | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java index da099fc..5ee501f 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java @@ -53,6 +53,11 @@ public ResponseEntity deleteEmployee (@PathVariable Long id){ return new ResponseEntity<>(employeeService.deleteEmployee(id),HttpStatus.OK); } + @DeleteMapping("manager/{id}") + public ResponseEntity deleteEmployeeByManager(@PathVariable Long id){ + return new ResponseEntity<>(employeeService.deleteEmployeeByManager(id),HttpStatus.OK); + } + // TODO /* @@ -60,7 +65,7 @@ public ResponseEntity deleteEmployee (@PathVariable Long id){ * remove a list of employees * remove all employees from a department - * remove all employees under a particular manager + * merge departments: given two department names eg: A and B, move the manager of B to report to the manager of A, and update all other employees to be members of department A diff --git a/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java b/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java index 75f6d98..d2997bb 100644 --- a/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java +++ b/src/main/java/io/zipcoder/persistenceapp/repositories/EmployeeRepository.java @@ -1,6 +1,8 @@ package io.zipcoder.persistenceapp.repositories; import io.zipcoder.persistenceapp.entities.Employee; +import org.hibernate.annotations.SQLDelete; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java index fd34660..035663c 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java @@ -98,6 +98,12 @@ public Boolean deleteEmployee(Long id) { return false; } + public Boolean deleteEmployeeByManager (Long id){ + Iterable employees = getAllEmployeesUnderManager(id); + employeeRepository.delete(employees); + return true; + } + private Boolean verifyEmployeeExists(Long id) { if (employeeRepository.exists(id)) { From f14132c49c5f97d75c5303258bfe6c67b80f4111 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Mon, 16 Dec 2019 12:16:00 -0500 Subject: [PATCH 26/27] delete employees by department --- .../controllers/EmployeeController.java | 9 ++++++-- .../services/EmployeeService.java | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java index 5ee501f..af37d8d 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java @@ -33,7 +33,7 @@ public ResponseEntity> getAllEmployeesNoManager() { return new ResponseEntity<>(employeeService.getAllEmployeesNoManager(), HttpStatus.OK); } - @GetMapping("hierarch/{id}") + @GetMapping("hierarchy/{id}") public ResponseEntity> getHierarchy(@PathVariable Long id) { return new ResponseEntity<>(employeeService.getHierarchy(id), HttpStatus.OK); } @@ -58,13 +58,18 @@ public ResponseEntity deleteEmployeeByManager(@PathVariable Long id){ return new ResponseEntity<>(employeeService.deleteEmployeeByManager(id),HttpStatus.OK); } + @DeleteMapping("department/{id}") + public ResponseEntity deleteEmployeesByDepartment(@PathVariable Long id){ + return new ResponseEntity<>(employeeService.deleteEmployeesByDepartment(id), HttpStatus.OK); + } + // TODO /* * remove a list of employees - * remove all employees from a department + * merge departments: given two department names eg: A and B, move the manager of B to report to the manager of A, diff --git a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java index 035663c..9c947e2 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java @@ -2,6 +2,7 @@ import io.zipcoder.persistenceapp.entities.Employee; import io.zipcoder.persistenceapp.exceptions.ResourceNotFoundException; +import io.zipcoder.persistenceapp.repositories.DepartmentRepository; import io.zipcoder.persistenceapp.repositories.EmployeeRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -14,6 +15,9 @@ public class EmployeeService { EmployeeRepository employeeRepository; + @Autowired + DepartmentRepository departmentRepository; + @Autowired public EmployeeService(EmployeeRepository employeeRepository) { this.employeeRepository = employeeRepository; @@ -104,6 +108,15 @@ public Boolean deleteEmployeeByManager (Long id){ return true; } + public Boolean deleteEmployeesByDepartment (Long id){ + if (verifyDepartmentExists(id)) { + Iterable employees = getAllEmployeesInDepartment(id); + employeeRepository.delete(employees); + return true; + } + return false; + } + private Boolean verifyEmployeeExists(Long id) { if (employeeRepository.exists(id)) { @@ -112,4 +125,12 @@ private Boolean verifyEmployeeExists(Long id) { throw new ResourceNotFoundException("Employee not found!"); } } + + private Boolean verifyDepartmentExists(Long id){ + if (departmentRepository.exists(id)){ + return true; + } else { + throw new ResourceNotFoundException("Department not found"); + } + } } From 2eae01e1398249704ad8b8662c89361e29e948b7 Mon Sep 17 00:00:00 2001 From: jeanvalentin51 Date: Mon, 16 Dec 2019 14:05:08 -0500 Subject: [PATCH 27/27] merge departments --- .../controllers/EmployeeController.java | 16 +++++++--------- .../persistenceapp/services/EmployeeService.java | 13 +++++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java index af37d8d..94fe571 100644 --- a/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java +++ b/src/main/java/io/zipcoder/persistenceapp/controllers/EmployeeController.java @@ -7,6 +7,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.Map; + @RestController @RequestMapping("/api/employee/") public class EmployeeController { @@ -63,18 +65,14 @@ public ResponseEntity deleteEmployeesByDepartment(@PathVariable Long id return new ResponseEntity<>(employeeService.deleteEmployeesByDepartment(id), HttpStatus.OK); } + @PutMapping("mergedepartment/{deptfrom}/{deptto}") + public ResponseEntity> mergeDepartments(@PathVariable Long deptfrom, @PathVariable Long deptto){ + return new ResponseEntity<>(employeeService.mergeDepartments(deptfrom,deptto),HttpStatus.OK); + } + // TODO /* - - - * remove a list of employees - - - - * merge departments: given two department names eg: A and B, move the manager of B to report to the manager of A, - and update all other employees to be members of department A - * remove all direct reports to a manager. Any employees previously managed by the deleted employees should now be managed by the next manager up the hierarchy. diff --git a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java index 9c947e2..293a779 100644 --- a/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java +++ b/src/main/java/io/zipcoder/persistenceapp/services/EmployeeService.java @@ -117,6 +117,19 @@ public Boolean deleteEmployeesByDepartment (Long id){ return false; } + public Iterable mergeDepartments(Long fromDepartment, Long toDepartment){ + if (verifyDepartmentExists(fromDepartment) && verifyDepartmentExists(toDepartment)){ + Iterable fromdepartment = getAllEmployeesInDepartment(fromDepartment); + if (fromdepartment != null){ + for (Employee each : fromdepartment){ + each.setDEPARTMENT_ID(toDepartment); + } + return employeeRepository.save(fromdepartment); + } + } + return null; + } + private Boolean verifyEmployeeExists(Long id) { if (employeeRepository.exists(id)) {