wad-lab 1.1.5 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/bin/index.js +30 -3
  2. package/package.json +1 -1
  3. package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/controller/CompanyController.java +88 -74
  4. package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/model/Employee.java +73 -73
  5. package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/service/CompanyService.java +90 -60
  6. package/templates/fullstack-springboot-vue/frontend/vue-axios-basic/src/App.vue +429 -405
  7. package/templates/fullstack-springboot-vue/frontend/vue-axios-interceptor/src/App.vue +177 -159
  8. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/App.vue +441 -427
  9. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/stores/companyStore.js +126 -96
  10. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/App.vue +84 -69
  11. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
  12. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
  13. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
  14. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/App.vue +191 -167
  15. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentForm.vue +98 -98
  16. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentList.vue +92 -91
  17. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeForm.vue +128 -128
  18. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeList.vue +95 -94
  19. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/App.vue +90 -90
  20. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/AddEmployeeView.vue +247 -247
  21. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/DepartmentView.vue +296 -273
  22. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/EmployeeView.vue +219 -196
  23. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/HomeDashboardView.vue +263 -263
  24. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
  25. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
  26. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
  27. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
  28. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
  29. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
  30. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
  31. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
  32. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
  33. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
  34. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/App.vue +59 -59
  35. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/components/DataCard.vue +72 -53
  36. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
  37. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
  38. package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/controller/CompanyController.java +88 -74
  39. package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/model/Employee.java +73 -73
  40. package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/service/CompanyService.java +90 -60
  41. package/templates/springboot-course-registration/src/main/java/com/example/coursereg/controller/CourseController.java +46 -42
  42. package/templates/springboot-course-registration/src/main/java/com/example/coursereg/service/CourseService.java +70 -60
  43. package/templates/springboot-hospital-api/src/main/java/com/example/hospital/controller/HospitalController.java +54 -50
  44. package/templates/springboot-hospital-api/src/main/java/com/example/hospital/service/HospitalService.java +65 -54
  45. package/templates/springboot-library-api/src/main/java/com/example/library/controller/LibraryController.java +57 -51
  46. package/templates/springboot-library-api/src/main/java/com/example/library/service/LibraryService.java +70 -60
  47. package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/controller/ItemController.java +45 -41
  48. package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/service/ItemService.java +48 -38
  49. package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
  50. package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/service/ItemService.java +48 -38
  51. package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/controller/ItemController.java +45 -41
  52. package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/service/ItemService.java +48 -38
  53. package/templates/springboot-mongo-crud/src/main/java/com/example/crud/controller/ItemController.java +45 -41
  54. package/templates/springboot-mongo-crud/src/main/java/com/example/crud/service/ItemService.java +48 -38
  55. package/templates/vue-axios/src/App.vue +264 -243
  56. package/templates/vue-axios/src/services/ItemService.js +27 -21
  57. package/templates/vue-axios-basic/src/App.vue +429 -405
  58. package/templates/vue-axios-interceptor/src/App.vue +177 -159
  59. package/templates/vue-axios-pinia/src/App.vue +441 -427
  60. package/templates/vue-axios-pinia/src/stores/companyStore.js +126 -96
  61. package/templates/vue-axios-pinia-props/src/App.vue +84 -69
  62. package/templates/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
  63. package/templates/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
  64. package/templates/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
  65. package/templates/vue-axios-props-emits/src/App.vue +191 -167
  66. package/templates/vue-axios-props-emits/src/components/DepartmentForm.vue +98 -98
  67. package/templates/vue-axios-props-emits/src/components/DepartmentList.vue +92 -91
  68. package/templates/vue-axios-props-emits/src/components/EmployeeForm.vue +128 -128
  69. package/templates/vue-axios-props-emits/src/components/EmployeeList.vue +95 -94
  70. package/templates/vue-axios-router/src/App.vue +90 -90
  71. package/templates/vue-axios-router/src/views/AddEmployeeView.vue +247 -247
  72. package/templates/vue-axios-router/src/views/DepartmentView.vue +296 -273
  73. package/templates/vue-axios-router/src/views/EmployeeView.vue +219 -196
  74. package/templates/vue-axios-router/src/views/HomeDashboardView.vue +263 -263
  75. package/templates/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
  76. package/templates/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
  77. package/templates/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
  78. package/templates/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
  79. package/templates/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
  80. package/templates/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
  81. package/templates/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
  82. package/templates/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
  83. package/templates/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
  84. package/templates/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
  85. package/templates/vue-axios-router-props/src/App.vue +59 -59
  86. package/templates/vue-axios-router-props/src/components/DataCard.vue +72 -53
  87. package/templates/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
  88. package/templates/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
  89. package/templates/vue-fetch/src/App.vue +285 -259
  90. package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
  91. package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
  92. package/templates/vue-router-pinia-springboot/frontend/src/services/ItemService.js +24 -21
  93. package/templates/vue-router-pinia-springboot/frontend/src/stores/itemStore.js +42 -37
  94. package/templates/vue-router-pinia-springboot/frontend/src/views/ListView.vue +76 -67
  95. package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
  96. package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/service/ItemService.java +45 -35
  97. package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
  98. package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
  99. package/templates/vue-springboot-mongo-crud/frontend/src/App.vue +158 -149
  100. package/templates/vue-springboot-mongo-crud/frontend/src/services/ItemService.js +24 -21
package/bin/index.js CHANGED
@@ -44,7 +44,7 @@ const frontendOptions = [
44
44
  const templates = [
45
45
  { name: 'all (Unpack All 54 Templates)', value: 'all' },
46
46
  { name: 'servlet-voter-eligibility (Name & Age Voting Eligibility Check)', value: 'servlet-voter-eligibility' },
47
- { name: 'fullstack-springboot-vue (Spring Boot Backend + Selectable Vue Frontend)', value: 'fullstack-springboot-vue' },
47
+ { name: 'fullstack-springboot-vue (Spring Boot: 2 Models, 2 Repos, 1 Service, 1 Controller + Selectable Vue 3 Axios Frontend)', value: 'fullstack-springboot-vue' },
48
48
  { name: 'springboot-2model-1controller-api (Spring Boot 1 Service, 1 Controller, 2 Models, 2 Repos)', value: 'springboot-2model-1controller-api' },
49
49
  { name: 'vue-axios-basic (Vue 3 + Axios Direct CRUD)', value: 'vue-axios-basic' },
50
50
  { name: 'vue-axios-props-emits (Vue 3 + Axios + Props & Emits)', value: 'vue-axios-props-emits' },
@@ -99,6 +99,7 @@ const templates = [
99
99
  { name: 'springboot-library-api (Variant 4 — Library Catalog & Analytics API)', value: 'springboot-library-api' }
100
100
  ];
101
101
 
102
+ const PAGE_SIZE = 12;
102
103
  let selectedIndex = 0;
103
104
  const selectedValues = new Set();
104
105
  const templatesRoot = path.join(__dirname, '..', 'templates');
@@ -111,14 +112,40 @@ function renderMenu() {
111
112
  console.log('Press [SPACE] to select / deselect (multi-select supported)');
112
113
  console.log('Press [ENTER] to confirm and proceed\n');
113
114
 
114
- templates.forEach((t, i) => {
115
+ const total = templates.length;
116
+ let start = selectedIndex - Math.floor(PAGE_SIZE / 2);
117
+ if (start < 0) start = 0;
118
+ if (start + PAGE_SIZE > total) {
119
+ start = Math.max(0, total - PAGE_SIZE);
120
+ }
121
+ const end = Math.min(start + PAGE_SIZE, total);
122
+
123
+ if (start > 0) {
124
+ console.log(` ▲ (${start} more above)`);
125
+ } else {
126
+ console.log(' --- Top of list ---');
127
+ }
128
+
129
+ for (let i = start; i < end; i++) {
130
+ const t = templates[i];
115
131
  const isCursor = i === selectedIndex;
116
132
  const isChecked = selectedValues.has(t.value);
117
133
  const box = isChecked ? '[x]' : '[ ]';
118
134
  const prefix = isCursor ? '> ' : ' ';
119
135
  console.log(prefix + box + ' ' + t.name);
120
- });
136
+ }
137
+
138
+ if (end < total) {
139
+ console.log(` ▼ (${total - end} more below)`);
140
+ } else {
141
+ console.log(' --- Bottom of list ---');
142
+ }
121
143
 
144
+ const selectedDisplay = selectedValues.size === 0
145
+ ? templates[selectedIndex].name
146
+ : `${selectedValues.size} template(s) selected: ${Array.from(selectedValues).join(', ')}`;
147
+ console.log(`\n[${selectedIndex + 1}/${total}] Focused: ${templates[selectedIndex].value}`);
148
+ console.log(`Selection: ${selectedDisplay}`);
122
149
  console.log('\nPress Ctrl+C to cancel.');
123
150
  }
124
151
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wad-lab",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "Interactive CLI for WAD Lab starter templates compatible with Node 12+",
5
5
  "bin": {
6
6
  "wad-lab": "./bin/index.js"
@@ -1,74 +1,88 @@
1
- package com.example.company.controller;
2
-
3
- import com.example.company.model.Department;
4
- import com.example.company.model.Employee;
5
- import com.example.company.service.CompanyService;
6
- import org.springframework.beans.factory.annotation.Autowired;
7
- import org.springframework.http.ResponseEntity;
8
- import org.springframework.web.bind.annotation.*;
9
-
10
- import java.util.List;
11
-
12
- @RestController
13
- @RequestMapping("/api")
14
- @CrossOrigin(origins = "*")
15
- public class CompanyController {
16
-
17
- private final CompanyService companyService;
18
-
19
- @Autowired
20
- public CompanyController(CompanyService companyService) {
21
- this.companyService = companyService;
22
- }
23
-
24
- @GetMapping("/departments")
25
- public List<Department> getAllDepartments() {
26
- return companyService.getAllDepartments();
27
- }
28
-
29
- @GetMapping("/departments/{id}")
30
- public ResponseEntity<Department> getDepartmentById(@PathVariable String id) {
31
- return companyService.getDepartmentById(id)
32
- .map(ResponseEntity::ok)
33
- .orElse(ResponseEntity.notFound().build());
34
- }
35
-
36
- @PostMapping("/departments")
37
- public Department createDepartment(@RequestBody Department department) {
38
- return companyService.createDepartment(department);
39
- }
40
-
41
- @DeleteMapping("/departments/{id}")
42
- public ResponseEntity<Void> deleteDepartment(@PathVariable String id) {
43
- companyService.deleteDepartment(id);
44
- return ResponseEntity.noContent().build();
45
- }
46
-
47
- @GetMapping("/employees")
48
- public List<Employee> getAllEmployees() {
49
- return companyService.getAllEmployees();
50
- }
51
-
52
- @GetMapping("/employees/{id}")
53
- public ResponseEntity<Employee> getEmployeeById(@PathVariable String id) {
54
- return companyService.getEmployeeById(id)
55
- .map(ResponseEntity::ok)
56
- .orElse(ResponseEntity.notFound().build());
57
- }
58
-
59
- @GetMapping("/employees/dept/{deptId}")
60
- public List<Employee> getEmployeesByDepartment(@PathVariable String deptId) {
61
- return companyService.getEmployeesByDepartment(deptId);
62
- }
63
-
64
- @PostMapping("/employees")
65
- public Employee createEmployee(@RequestBody Employee employee) {
66
- return companyService.createEmployee(employee);
67
- }
68
-
69
- @DeleteMapping("/employees/{id}")
70
- public ResponseEntity<Void> deleteEmployee(@PathVariable String id) {
71
- companyService.deleteEmployee(id);
72
- return ResponseEntity.noContent().build();
73
- }
74
- }
1
+ package com.example.company.controller;
2
+
3
+ import com.example.company.model.Department;
4
+ import com.example.company.model.Employee;
5
+ import com.example.company.service.CompanyService;
6
+ import org.springframework.beans.factory.annotation.Autowired;
7
+ import org.springframework.http.ResponseEntity;
8
+ import org.springframework.web.bind.annotation.*;
9
+
10
+ import java.util.List;
11
+
12
+ @RestController
13
+ @RequestMapping("/api")
14
+ @CrossOrigin(origins = "*")
15
+ public class CompanyController {
16
+
17
+ private final CompanyService companyService;
18
+
19
+ @Autowired
20
+ public CompanyController(CompanyService companyService) {
21
+ this.companyService = companyService;
22
+ }
23
+
24
+ @GetMapping("/departments")
25
+ public List<Department> getAllDepartments() {
26
+ return companyService.getAllDepartments();
27
+ }
28
+
29
+ @GetMapping("/departments/{id}")
30
+ public ResponseEntity<Department> getDepartmentById(@PathVariable String id) {
31
+ return companyService.getDepartmentById(id)
32
+ .map(ResponseEntity::ok)
33
+ .orElse(ResponseEntity.notFound().build());
34
+ }
35
+
36
+ @PostMapping("/departments")
37
+ public Department createDepartment(@RequestBody Department department) {
38
+ return companyService.createDepartment(department);
39
+ }
40
+
41
+ @PatchMapping("/departments/{id}")
42
+ public ResponseEntity<Department> patchDepartment(@PathVariable String id, @RequestBody Department patch) {
43
+ return companyService.patchDepartment(id, patch)
44
+ .map(ResponseEntity::ok)
45
+ .orElse(ResponseEntity.notFound().build());
46
+ }
47
+
48
+ @DeleteMapping("/departments/{id}")
49
+ public ResponseEntity<Void> deleteDepartment(@PathVariable String id) {
50
+ companyService.deleteDepartment(id);
51
+ return ResponseEntity.noContent().build();
52
+ }
53
+
54
+ @GetMapping("/employees")
55
+ public List<Employee> getAllEmployees() {
56
+ return companyService.getAllEmployees();
57
+ }
58
+
59
+ @GetMapping("/employees/{id}")
60
+ public ResponseEntity<Employee> getEmployeeById(@PathVariable String id) {
61
+ return companyService.getEmployeeById(id)
62
+ .map(ResponseEntity::ok)
63
+ .orElse(ResponseEntity.notFound().build());
64
+ }
65
+
66
+ @GetMapping("/employees/dept/{deptId}")
67
+ public List<Employee> getEmployeesByDepartment(@PathVariable String deptId) {
68
+ return companyService.getEmployeesByDepartment(deptId);
69
+ }
70
+
71
+ @PostMapping("/employees")
72
+ public Employee createEmployee(@RequestBody Employee employee) {
73
+ return companyService.createEmployee(employee);
74
+ }
75
+
76
+ @PatchMapping("/employees/{id}")
77
+ public ResponseEntity<Employee> patchEmployee(@PathVariable String id, @RequestBody Employee patch) {
78
+ return companyService.patchEmployee(id, patch)
79
+ .map(ResponseEntity::ok)
80
+ .orElse(ResponseEntity.notFound().build());
81
+ }
82
+
83
+ @DeleteMapping("/employees/{id}")
84
+ public ResponseEntity<Void> deleteEmployee(@PathVariable String id) {
85
+ companyService.deleteEmployee(id);
86
+ return ResponseEntity.noContent().build();
87
+ }
88
+ }
@@ -1,73 +1,73 @@
1
- package com.example.company.model;
2
-
3
- import org.springframework.data.annotation.Id;
4
- import org.springframework.data.mongodb.core.mapping.Document;
5
-
6
- @Document(collection = "employees")
7
- public class Employee {
8
-
9
- @Id
10
- private String id;
11
- private String name;
12
- private String email;
13
- private String departmentId;
14
- private double salary;
15
-
16
- public Employee() {
17
- }
18
-
19
- public Employee(String name, String email, String departmentId, double salary) {
20
- this.name = name;
21
- this.email = email;
22
- this.departmentId = departmentId;
23
- this.salary = salary;
24
- }
25
-
26
- public Employee(String id, String name, String email, String departmentId, double salary) {
27
- this.id = id;
28
- this.name = name;
29
- this.email = email;
30
- this.departmentId = departmentId;
31
- this.salary = salary;
32
- }
33
-
34
- public String getId() {
35
- return id;
36
- }
37
-
38
- public void setId(String id) {
39
- this.id = id;
40
- }
41
-
42
- public String getName() {
43
- return name;
44
- }
45
-
46
- public void setName(String name) {
47
- this.name = name;
48
- }
49
-
50
- public String getEmail() {
51
- return email;
52
- }
53
-
54
- public void setEmail(String email) {
55
- this.email = email;
56
- }
57
-
58
- public String getDepartmentId() {
59
- return departmentId;
60
- }
61
-
62
- public void setDepartmentId(String departmentId) {
63
- this.departmentId = departmentId;
64
- }
65
-
66
- public double getSalary() {
67
- return salary;
68
- }
69
-
70
- public void setSalary(double salary) {
71
- this.salary = salary;
72
- }
73
- }
1
+ package com.example.company.model;
2
+
3
+ import org.springframework.data.annotation.Id;
4
+ import org.springframework.data.mongodb.core.mapping.Document;
5
+
6
+ @Document(collection = "employees")
7
+ public class Employee {
8
+
9
+ @Id
10
+ private String id;
11
+ private String name;
12
+ private String email;
13
+ private String departmentId;
14
+ private Double salary;
15
+
16
+ public Employee() {
17
+ }
18
+
19
+ public Employee(String name, String email, String departmentId, Double salary) {
20
+ this.name = name;
21
+ this.email = email;
22
+ this.departmentId = departmentId;
23
+ this.salary = salary;
24
+ }
25
+
26
+ public Employee(String id, String name, String email, String departmentId, Double salary) {
27
+ this.id = id;
28
+ this.name = name;
29
+ this.email = email;
30
+ this.departmentId = departmentId;
31
+ this.salary = salary;
32
+ }
33
+
34
+ public String getId() {
35
+ return id;
36
+ }
37
+
38
+ public void setId(String id) {
39
+ this.id = id;
40
+ }
41
+
42
+ public String getName() {
43
+ return name;
44
+ }
45
+
46
+ public void setName(String name) {
47
+ this.name = name;
48
+ }
49
+
50
+ public String getEmail() {
51
+ return email;
52
+ }
53
+
54
+ public void setEmail(String email) {
55
+ this.email = email;
56
+ }
57
+
58
+ public String getDepartmentId() {
59
+ return departmentId;
60
+ }
61
+
62
+ public void setDepartmentId(String departmentId) {
63
+ this.departmentId = departmentId;
64
+ }
65
+
66
+ public Double getSalary() {
67
+ return salary;
68
+ }
69
+
70
+ public void setSalary(Double salary) {
71
+ this.salary = salary;
72
+ }
73
+ }
@@ -1,60 +1,90 @@
1
- package com.example.company.service;
2
-
3
- import com.example.company.model.Department;
4
- import com.example.company.model.Employee;
5
- import com.example.company.repository.DepartmentRepository;
6
- import com.example.company.repository.EmployeeRepository;
7
- import org.springframework.beans.factory.annotation.Autowired;
8
- import org.springframework.stereotype.Service;
9
-
10
- import java.util.List;
11
- import java.util.Optional;
12
-
13
- @Service
14
- public class CompanyService {
15
-
16
- private final DepartmentRepository departmentRepository;
17
- private final EmployeeRepository employeeRepository;
18
-
19
- @Autowired
20
- public CompanyService(DepartmentRepository departmentRepository, EmployeeRepository employeeRepository) {
21
- this.departmentRepository = departmentRepository;
22
- this.employeeRepository = employeeRepository;
23
- }
24
-
25
- public List<Department> getAllDepartments() {
26
- return departmentRepository.findAll();
27
- }
28
-
29
- public Optional<Department> getDepartmentById(String id) {
30
- return departmentRepository.findById(id);
31
- }
32
-
33
- public Department createDepartment(Department department) {
34
- return departmentRepository.save(department);
35
- }
36
-
37
- public void deleteDepartment(String id) {
38
- departmentRepository.deleteById(id);
39
- }
40
-
41
- public List<Employee> getAllEmployees() {
42
- return employeeRepository.findAll();
43
- }
44
-
45
- public Optional<Employee> getEmployeeById(String id) {
46
- return employeeRepository.findById(id);
47
- }
48
-
49
- public List<Employee> getEmployeesByDepartment(String departmentId) {
50
- return employeeRepository.findByDepartmentId(departmentId);
51
- }
52
-
53
- public Employee createEmployee(Employee employee) {
54
- return employeeRepository.save(employee);
55
- }
56
-
57
- public void deleteEmployee(String id) {
58
- employeeRepository.deleteById(id);
59
- }
60
- }
1
+ package com.example.company.service;
2
+
3
+ import com.example.company.model.Department;
4
+ import com.example.company.model.Employee;
5
+ import com.example.company.repository.DepartmentRepository;
6
+ import com.example.company.repository.EmployeeRepository;
7
+ import org.springframework.beans.factory.annotation.Autowired;
8
+ import org.springframework.stereotype.Service;
9
+
10
+ import java.util.List;
11
+ import java.util.Optional;
12
+
13
+ @Service
14
+ public class CompanyService {
15
+
16
+ private final DepartmentRepository departmentRepository;
17
+ private final EmployeeRepository employeeRepository;
18
+
19
+ @Autowired
20
+ public CompanyService(DepartmentRepository departmentRepository, EmployeeRepository employeeRepository) {
21
+ this.departmentRepository = departmentRepository;
22
+ this.employeeRepository = employeeRepository;
23
+ }
24
+
25
+ public List<Department> getAllDepartments() {
26
+ return departmentRepository.findAll();
27
+ }
28
+
29
+ public Optional<Department> getDepartmentById(String id) {
30
+ return departmentRepository.findById(id);
31
+ }
32
+
33
+ public Department createDepartment(Department department) {
34
+ return departmentRepository.save(department);
35
+ }
36
+
37
+ public Optional<Department> patchDepartment(String id, Department patch) {
38
+ return departmentRepository.findById(id).map(existing -> {
39
+ if (patch.getName() != null) {
40
+ existing.setName(patch.getName());
41
+ }
42
+ if (patch.getCode() != null) {
43
+ existing.setCode(patch.getCode());
44
+ }
45
+ return departmentRepository.save(existing);
46
+ });
47
+ }
48
+
49
+ public void deleteDepartment(String id) {
50
+ departmentRepository.deleteById(id);
51
+ }
52
+
53
+ public List<Employee> getAllEmployees() {
54
+ return employeeRepository.findAll();
55
+ }
56
+
57
+ public Optional<Employee> getEmployeeById(String id) {
58
+ return employeeRepository.findById(id);
59
+ }
60
+
61
+ public List<Employee> getEmployeesByDepartment(String departmentId) {
62
+ return employeeRepository.findByDepartmentId(departmentId);
63
+ }
64
+
65
+ public Employee createEmployee(Employee employee) {
66
+ return employeeRepository.save(employee);
67
+ }
68
+
69
+ public Optional<Employee> patchEmployee(String id, Employee patch) {
70
+ return employeeRepository.findById(id).map(existing -> {
71
+ if (patch.getName() != null) {
72
+ existing.setName(patch.getName());
73
+ }
74
+ if (patch.getEmail() != null) {
75
+ existing.setEmail(patch.getEmail());
76
+ }
77
+ if (patch.getDepartmentId() != null) {
78
+ existing.setDepartmentId(patch.getDepartmentId());
79
+ }
80
+ if (patch.getSalary() != null) {
81
+ existing.setSalary(patch.getSalary());
82
+ }
83
+ return employeeRepository.save(existing);
84
+ });
85
+ }
86
+
87
+ public void deleteEmployee(String id) {
88
+ employeeRepository.deleteById(id);
89
+ }
90
+ }