wad-lab 1.1.6 → 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.
- package/package.json +1 -1
- package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/controller/CompanyController.java +88 -74
- package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/model/Employee.java +73 -73
- package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/service/CompanyService.java +90 -60
- package/templates/fullstack-springboot-vue/frontend/vue-axios-basic/src/App.vue +429 -405
- package/templates/fullstack-springboot-vue/frontend/vue-axios-interceptor/src/App.vue +177 -159
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/App.vue +441 -427
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/stores/companyStore.js +126 -96
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/App.vue +84 -69
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/App.vue +191 -167
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentForm.vue +98 -98
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentList.vue +92 -91
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeForm.vue +128 -128
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeList.vue +95 -94
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/App.vue +90 -90
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/AddEmployeeView.vue +247 -247
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/DepartmentView.vue +296 -273
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/EmployeeView.vue +219 -196
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/HomeDashboardView.vue +263 -263
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/App.vue +59 -59
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/components/DataCard.vue +72 -53
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
- package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/controller/CompanyController.java +88 -74
- package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/model/Employee.java +73 -73
- package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/service/CompanyService.java +90 -60
- package/templates/springboot-course-registration/src/main/java/com/example/coursereg/controller/CourseController.java +46 -42
- package/templates/springboot-course-registration/src/main/java/com/example/coursereg/service/CourseService.java +70 -60
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/controller/HospitalController.java +54 -50
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/service/HospitalService.java +65 -54
- package/templates/springboot-library-api/src/main/java/com/example/library/controller/LibraryController.java +57 -51
- package/templates/springboot-library-api/src/main/java/com/example/library/service/LibraryService.java +70 -60
- package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/controller/ItemController.java +45 -41
- package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/service/ItemService.java +48 -38
- package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
- package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/service/ItemService.java +48 -38
- package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/controller/ItemController.java +45 -41
- package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/service/ItemService.java +48 -38
- package/templates/springboot-mongo-crud/src/main/java/com/example/crud/controller/ItemController.java +45 -41
- package/templates/springboot-mongo-crud/src/main/java/com/example/crud/service/ItemService.java +48 -38
- package/templates/vue-axios/src/App.vue +264 -243
- package/templates/vue-axios/src/services/ItemService.js +27 -21
- package/templates/vue-axios-basic/src/App.vue +24 -0
- package/templates/vue-axios-interceptor/src/App.vue +177 -159
- package/templates/vue-axios-pinia/src/App.vue +14 -0
- package/templates/vue-axios-pinia/src/stores/companyStore.js +126 -96
- package/templates/vue-axios-pinia-props/src/App.vue +84 -69
- package/templates/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
- package/templates/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
- package/templates/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
- package/templates/vue-axios-props-emits/src/App.vue +24 -0
- package/templates/vue-axios-props-emits/src/components/DepartmentList.vue +2 -1
- package/templates/vue-axios-props-emits/src/components/EmployeeList.vue +2 -1
- package/templates/vue-axios-router/src/views/DepartmentView.vue +23 -0
- package/templates/vue-axios-router/src/views/EmployeeView.vue +23 -0
- package/templates/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
- package/templates/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
- package/templates/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
- package/templates/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
- package/templates/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
- package/templates/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
- package/templates/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
- package/templates/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
- package/templates/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
- package/templates/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
- package/templates/vue-axios-router-props/src/components/DataCard.vue +72 -53
- package/templates/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
- package/templates/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
- package/templates/vue-fetch/src/App.vue +285 -259
- package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
- package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
- package/templates/vue-router-pinia-springboot/frontend/src/services/ItemService.js +24 -21
- package/templates/vue-router-pinia-springboot/frontend/src/stores/itemStore.js +42 -37
- package/templates/vue-router-pinia-springboot/frontend/src/views/ListView.vue +76 -67
- package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
- package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/service/ItemService.java +45 -35
- package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
- package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
- package/templates/vue-springboot-mongo-crud/frontend/src/App.vue +158 -149
- package/templates/vue-springboot-mongo-crud/frontend/src/services/ItemService.js +24 -21
|
@@ -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
|
|
38
|
-
departmentRepository.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public Employee
|
|
54
|
-
return employeeRepository.
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public
|
|
58
|
-
employeeRepository.
|
|
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
|
+
}
|
|
@@ -1,42 +1,46 @@
|
|
|
1
|
-
package com.example.coursereg.controller;
|
|
2
|
-
|
|
3
|
-
import com.example.coursereg.model.Course;
|
|
4
|
-
import com.example.coursereg.service.CourseService;
|
|
5
|
-
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
-
import org.springframework.web.bind.annotation.*;
|
|
7
|
-
|
|
8
|
-
import java.util.List;
|
|
9
|
-
|
|
10
|
-
@RestController
|
|
11
|
-
@RequestMapping("/api/courses")
|
|
12
|
-
@CrossOrigin(origins = "*")
|
|
13
|
-
public class CourseController {
|
|
14
|
-
|
|
15
|
-
@Autowired
|
|
16
|
-
private CourseService courseService;
|
|
17
|
-
|
|
18
|
-
@GetMapping
|
|
19
|
-
public List<Course> getAllCourses() {
|
|
20
|
-
return courseService.getAllCourses();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@GetMapping("/{id}")
|
|
24
|
-
public Course getCourseById(@PathVariable String id) {
|
|
25
|
-
return courseService.getCourseById(id);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@PostMapping
|
|
29
|
-
public Course createCourse(@RequestBody Course course) {
|
|
30
|
-
return courseService.createCourse(course);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@DeleteMapping("/{id}")
|
|
34
|
-
public void deleteCourse(@PathVariable String id) {
|
|
35
|
-
courseService.deleteCourse(id);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@PostMapping("/{id}/register")
|
|
39
|
-
public Course registerStudent(@PathVariable String id, @RequestParam String studentName) {
|
|
40
|
-
return courseService.registerStudent(id, studentName);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
1
|
+
package com.example.coursereg.controller;
|
|
2
|
+
|
|
3
|
+
import com.example.coursereg.model.Course;
|
|
4
|
+
import com.example.coursereg.service.CourseService;
|
|
5
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
+
import org.springframework.web.bind.annotation.*;
|
|
7
|
+
|
|
8
|
+
import java.util.List;
|
|
9
|
+
|
|
10
|
+
@RestController
|
|
11
|
+
@RequestMapping("/api/courses")
|
|
12
|
+
@CrossOrigin(origins = "*")
|
|
13
|
+
public class CourseController {
|
|
14
|
+
|
|
15
|
+
@Autowired
|
|
16
|
+
private CourseService courseService;
|
|
17
|
+
|
|
18
|
+
@GetMapping
|
|
19
|
+
public List<Course> getAllCourses() {
|
|
20
|
+
return courseService.getAllCourses();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@GetMapping("/{id}")
|
|
24
|
+
public Course getCourseById(@PathVariable String id) {
|
|
25
|
+
return courseService.getCourseById(id);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@PostMapping
|
|
29
|
+
public Course createCourse(@RequestBody Course course) {
|
|
30
|
+
return courseService.createCourse(course);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@DeleteMapping("/{id}")
|
|
34
|
+
public void deleteCourse(@PathVariable String id) {
|
|
35
|
+
courseService.deleteCourse(id);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@PostMapping("/{id}/register")
|
|
39
|
+
public Course registerStudent(@PathVariable String id, @RequestParam String studentName) {
|
|
40
|
+
return courseService.registerStudent(id, studentName);
|
|
41
|
+
}
|
|
42
|
+
@PatchMapping("/{id}")
|
|
43
|
+
public Course patchCourse(@PathVariable String id, @RequestBody Course course) {
|
|
44
|
+
return courseService.patchCourse(id, course);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -1,60 +1,70 @@
|
|
|
1
|
-
package com.example.coursereg.service;
|
|
2
|
-
|
|
3
|
-
import com.example.coursereg.model.Course;
|
|
4
|
-
import com.example.coursereg.repository.CourseRepository;
|
|
5
|
-
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
-
import org.springframework.stereotype.Service;
|
|
7
|
-
|
|
8
|
-
import java.util.ArrayList;
|
|
9
|
-
import java.util.List;
|
|
10
|
-
|
|
11
|
-
@Service
|
|
12
|
-
public class CourseService {
|
|
13
|
-
|
|
14
|
-
@Autowired
|
|
15
|
-
private CourseRepository courseRepository;
|
|
16
|
-
|
|
17
|
-
public List<Course> getAllCourses() {
|
|
18
|
-
return courseRepository.findAll();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public Course getCourseById(String id) {
|
|
22
|
-
return courseRepository.findById(id).orElse(null);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public Course createCourse(Course course) {
|
|
26
|
-
if (course.getId() != null && course.getId().trim().isEmpty()) {
|
|
27
|
-
course.setId(null);
|
|
28
|
-
}
|
|
29
|
-
if (course.getEnrolledStudents() == null) {
|
|
30
|
-
course.setEnrolledStudents(new ArrayList<>());
|
|
31
|
-
}
|
|
32
|
-
return courseRepository.save(course);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public void deleteCourse(String id) {
|
|
36
|
-
courseRepository.deleteById(id);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public Course registerStudent(String courseId, String studentName) {
|
|
40
|
-
Course course = courseRepository.findById(courseId).orElse(null);
|
|
41
|
-
if (course != null) {
|
|
42
|
-
if (course.getEnrolledStudents() == null) {
|
|
43
|
-
course.setEnrolledStudents(new ArrayList<>());
|
|
44
|
-
}
|
|
45
|
-
if (course.getEnrolledStudents().size() < course.getCapacity()) {
|
|
46
|
-
course.getEnrolledStudents().add(studentName);
|
|
47
|
-
return courseRepository.save(course);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public Course getCourseByCourseCode(String courseCode) {
|
|
54
|
-
return courseRepository.findByCourseCode(courseCode).orElse(null);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public List<Course> getCoursesByDepartment(String department) {
|
|
58
|
-
return courseRepository.findByDepartment(department);
|
|
59
|
-
}
|
|
60
|
-
|
|
1
|
+
package com.example.coursereg.service;
|
|
2
|
+
|
|
3
|
+
import com.example.coursereg.model.Course;
|
|
4
|
+
import com.example.coursereg.repository.CourseRepository;
|
|
5
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
+
import org.springframework.stereotype.Service;
|
|
7
|
+
|
|
8
|
+
import java.util.ArrayList;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
|
|
11
|
+
@Service
|
|
12
|
+
public class CourseService {
|
|
13
|
+
|
|
14
|
+
@Autowired
|
|
15
|
+
private CourseRepository courseRepository;
|
|
16
|
+
|
|
17
|
+
public List<Course> getAllCourses() {
|
|
18
|
+
return courseRepository.findAll();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public Course getCourseById(String id) {
|
|
22
|
+
return courseRepository.findById(id).orElse(null);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public Course createCourse(Course course) {
|
|
26
|
+
if (course.getId() != null && course.getId().trim().isEmpty()) {
|
|
27
|
+
course.setId(null);
|
|
28
|
+
}
|
|
29
|
+
if (course.getEnrolledStudents() == null) {
|
|
30
|
+
course.setEnrolledStudents(new ArrayList<>());
|
|
31
|
+
}
|
|
32
|
+
return courseRepository.save(course);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public void deleteCourse(String id) {
|
|
36
|
+
courseRepository.deleteById(id);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public Course registerStudent(String courseId, String studentName) {
|
|
40
|
+
Course course = courseRepository.findById(courseId).orElse(null);
|
|
41
|
+
if (course != null) {
|
|
42
|
+
if (course.getEnrolledStudents() == null) {
|
|
43
|
+
course.setEnrolledStudents(new ArrayList<>());
|
|
44
|
+
}
|
|
45
|
+
if (course.getEnrolledStudents().size() < course.getCapacity()) {
|
|
46
|
+
course.getEnrolledStudents().add(studentName);
|
|
47
|
+
return courseRepository.save(course);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public Course getCourseByCourseCode(String courseCode) {
|
|
54
|
+
return courseRepository.findByCourseCode(courseCode).orElse(null);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public List<Course> getCoursesByDepartment(String department) {
|
|
58
|
+
return courseRepository.findByDepartment(department);
|
|
59
|
+
}
|
|
60
|
+
public Course patchCourse(String id, Course patch) {
|
|
61
|
+
Course existing = getCourseById(id);
|
|
62
|
+
if (existing != null) {
|
|
63
|
+
if (patch.getTitle() != null) existing.setTitle(patch.getTitle());
|
|
64
|
+
if (patch.getInstructor() != null) existing.setInstructor(patch.getInstructor());
|
|
65
|
+
if (patch.getCapacity() > 0) existing.setCapacity(patch.getCapacity());
|
|
66
|
+
return courseRepository.save(existing);
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,50 +1,54 @@
|
|
|
1
|
-
package com.example.hospital.controller;
|
|
2
|
-
|
|
3
|
-
import com.example.hospital.model.Appointment;
|
|
4
|
-
import com.example.hospital.service.HospitalService;
|
|
5
|
-
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
-
import org.springframework.web.bind.annotation.*;
|
|
7
|
-
|
|
8
|
-
import java.util.List;
|
|
9
|
-
|
|
10
|
-
@RestController
|
|
11
|
-
@RequestMapping("/api/appointments")
|
|
12
|
-
@CrossOrigin(origins = "*")
|
|
13
|
-
public class HospitalController {
|
|
14
|
-
|
|
15
|
-
@Autowired
|
|
16
|
-
private HospitalService hospitalService;
|
|
17
|
-
|
|
18
|
-
@GetMapping
|
|
19
|
-
public List<Appointment> getAllAppointments(
|
|
20
|
-
@RequestParam(required = false) String doctorName,
|
|
21
|
-
@RequestParam(required = false) String status) {
|
|
22
|
-
if (doctorName != null && !doctorName.trim().isEmpty()) {
|
|
23
|
-
return hospitalService.getAppointmentsByDoctorName(doctorName);
|
|
24
|
-
}
|
|
25
|
-
if (status != null && !status.trim().isEmpty()) {
|
|
26
|
-
return hospitalService.getAppointmentsByStatus(status);
|
|
27
|
-
}
|
|
28
|
-
return hospitalService.getAllAppointments();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@GetMapping("/{id}")
|
|
32
|
-
public Appointment getAppointmentById(@PathVariable String id) {
|
|
33
|
-
return hospitalService.getAppointmentById(id);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@PostMapping
|
|
37
|
-
public Appointment bookAppointment(@RequestBody Appointment appointment) {
|
|
38
|
-
return hospitalService.bookAppointment(appointment);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@PutMapping("/{id}/status")
|
|
42
|
-
public Appointment updateStatus(@PathVariable String id, @RequestParam String status) {
|
|
43
|
-
return hospitalService.updateStatus(id, status);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@DeleteMapping("/{id}")
|
|
47
|
-
public void cancelAppointment(@PathVariable String id) {
|
|
48
|
-
hospitalService.cancelAppointment(id);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
package com.example.hospital.controller;
|
|
2
|
+
|
|
3
|
+
import com.example.hospital.model.Appointment;
|
|
4
|
+
import com.example.hospital.service.HospitalService;
|
|
5
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
+
import org.springframework.web.bind.annotation.*;
|
|
7
|
+
|
|
8
|
+
import java.util.List;
|
|
9
|
+
|
|
10
|
+
@RestController
|
|
11
|
+
@RequestMapping("/api/appointments")
|
|
12
|
+
@CrossOrigin(origins = "*")
|
|
13
|
+
public class HospitalController {
|
|
14
|
+
|
|
15
|
+
@Autowired
|
|
16
|
+
private HospitalService hospitalService;
|
|
17
|
+
|
|
18
|
+
@GetMapping
|
|
19
|
+
public List<Appointment> getAllAppointments(
|
|
20
|
+
@RequestParam(required = false) String doctorName,
|
|
21
|
+
@RequestParam(required = false) String status) {
|
|
22
|
+
if (doctorName != null && !doctorName.trim().isEmpty()) {
|
|
23
|
+
return hospitalService.getAppointmentsByDoctorName(doctorName);
|
|
24
|
+
}
|
|
25
|
+
if (status != null && !status.trim().isEmpty()) {
|
|
26
|
+
return hospitalService.getAppointmentsByStatus(status);
|
|
27
|
+
}
|
|
28
|
+
return hospitalService.getAllAppointments();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@GetMapping("/{id}")
|
|
32
|
+
public Appointment getAppointmentById(@PathVariable String id) {
|
|
33
|
+
return hospitalService.getAppointmentById(id);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@PostMapping
|
|
37
|
+
public Appointment bookAppointment(@RequestBody Appointment appointment) {
|
|
38
|
+
return hospitalService.bookAppointment(appointment);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@PutMapping("/{id}/status")
|
|
42
|
+
public Appointment updateStatus(@PathVariable String id, @RequestParam String status) {
|
|
43
|
+
return hospitalService.updateStatus(id, status);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@DeleteMapping("/{id}")
|
|
47
|
+
public void cancelAppointment(@PathVariable String id) {
|
|
48
|
+
hospitalService.cancelAppointment(id);
|
|
49
|
+
}
|
|
50
|
+
@PatchMapping("/{id}")
|
|
51
|
+
public Appointment patchAppointment(@PathVariable String id, @RequestBody Appointment appointment) {
|
|
52
|
+
return hospitalService.patchAppointment(id, appointment);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,54 +1,65 @@
|
|
|
1
|
-
package com.example.hospital.service;
|
|
2
|
-
|
|
3
|
-
import com.example.hospital.model.Appointment;
|
|
4
|
-
import com.example.hospital.repository.AppointmentRepository;
|
|
5
|
-
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
-
import org.springframework.stereotype.Service;
|
|
7
|
-
|
|
8
|
-
import java.util.List;
|
|
9
|
-
|
|
10
|
-
@Service
|
|
11
|
-
public class HospitalService {
|
|
12
|
-
|
|
13
|
-
@Autowired
|
|
14
|
-
private AppointmentRepository appointmentRepository;
|
|
15
|
-
|
|
16
|
-
public List<Appointment> getAllAppointments() {
|
|
17
|
-
return appointmentRepository.findAll();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public Appointment getAppointmentById(String id) {
|
|
21
|
-
return appointmentRepository.findById(id).orElse(null);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public Appointment bookAppointment(Appointment appointment) {
|
|
25
|
-
if (appointment.getId() != null && appointment.getId().trim().isEmpty()) {
|
|
26
|
-
appointment.setId(null);
|
|
27
|
-
}
|
|
28
|
-
if (appointment.getStatus() == null || appointment.getStatus().trim().isEmpty()) {
|
|
29
|
-
appointment.setStatus("PENDING");
|
|
30
|
-
}
|
|
31
|
-
return appointmentRepository.save(appointment);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public Appointment updateStatus(String id, String status) {
|
|
35
|
-
Appointment appointment = appointmentRepository.findById(id).orElse(null);
|
|
36
|
-
if (appointment != null) {
|
|
37
|
-
appointment.setStatus(status);
|
|
38
|
-
return appointmentRepository.save(appointment);
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public void cancelAppointment(String id) {
|
|
44
|
-
appointmentRepository.deleteById(id);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public List<Appointment> getAppointmentsByDoctorName(String doctorName) {
|
|
48
|
-
return appointmentRepository.findByDoctorName(doctorName);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public List<Appointment> getAppointmentsByStatus(String status) {
|
|
52
|
-
return appointmentRepository.findByStatus(status);
|
|
53
|
-
}
|
|
54
|
-
|
|
1
|
+
package com.example.hospital.service;
|
|
2
|
+
|
|
3
|
+
import com.example.hospital.model.Appointment;
|
|
4
|
+
import com.example.hospital.repository.AppointmentRepository;
|
|
5
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
+
import org.springframework.stereotype.Service;
|
|
7
|
+
|
|
8
|
+
import java.util.List;
|
|
9
|
+
|
|
10
|
+
@Service
|
|
11
|
+
public class HospitalService {
|
|
12
|
+
|
|
13
|
+
@Autowired
|
|
14
|
+
private AppointmentRepository appointmentRepository;
|
|
15
|
+
|
|
16
|
+
public List<Appointment> getAllAppointments() {
|
|
17
|
+
return appointmentRepository.findAll();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public Appointment getAppointmentById(String id) {
|
|
21
|
+
return appointmentRepository.findById(id).orElse(null);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public Appointment bookAppointment(Appointment appointment) {
|
|
25
|
+
if (appointment.getId() != null && appointment.getId().trim().isEmpty()) {
|
|
26
|
+
appointment.setId(null);
|
|
27
|
+
}
|
|
28
|
+
if (appointment.getStatus() == null || appointment.getStatus().trim().isEmpty()) {
|
|
29
|
+
appointment.setStatus("PENDING");
|
|
30
|
+
}
|
|
31
|
+
return appointmentRepository.save(appointment);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public Appointment updateStatus(String id, String status) {
|
|
35
|
+
Appointment appointment = appointmentRepository.findById(id).orElse(null);
|
|
36
|
+
if (appointment != null) {
|
|
37
|
+
appointment.setStatus(status);
|
|
38
|
+
return appointmentRepository.save(appointment);
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public void cancelAppointment(String id) {
|
|
44
|
+
appointmentRepository.deleteById(id);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public List<Appointment> getAppointmentsByDoctorName(String doctorName) {
|
|
48
|
+
return appointmentRepository.findByDoctorName(doctorName);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public List<Appointment> getAppointmentsByStatus(String status) {
|
|
52
|
+
return appointmentRepository.findByStatus(status);
|
|
53
|
+
}
|
|
54
|
+
public Appointment patchAppointment(String id, Appointment patch) {
|
|
55
|
+
Appointment existing = getAppointmentById(id);
|
|
56
|
+
if (existing != null) {
|
|
57
|
+
if (patch.getPatientName() != null) existing.setPatientName(patch.getPatientName());
|
|
58
|
+
if (patch.getDoctorName() != null) existing.setDoctorName(patch.getDoctorName());
|
|
59
|
+
if (patch.getAppointmentDate() != null) existing.setAppointmentDate(patch.getAppointmentDate());
|
|
60
|
+
if (patch.getStatus() != null) existing.setStatus(patch.getStatus());
|
|
61
|
+
return appointmentRepository.save(existing);
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|