wad-lab 1.1.6 → 1.1.8

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 (93) hide show
  1. package/package.json +1 -1
  2. package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/controller/CompanyController.java +88 -74
  3. package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/model/Employee.java +73 -73
  4. package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/service/CompanyService.java +90 -60
  5. package/templates/fullstack-springboot-vue/frontend/vue-axios-basic/src/App.vue +429 -405
  6. package/templates/fullstack-springboot-vue/frontend/vue-axios-interceptor/src/App.vue +177 -159
  7. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/App.vue +441 -427
  8. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/stores/companyStore.js +126 -96
  9. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/App.vue +84 -69
  10. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
  11. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
  12. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
  13. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/App.vue +191 -167
  14. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentForm.vue +98 -98
  15. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentList.vue +92 -91
  16. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeForm.vue +128 -128
  17. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeList.vue +95 -94
  18. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/App.vue +90 -90
  19. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/AddEmployeeView.vue +247 -247
  20. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/DepartmentView.vue +296 -273
  21. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/EmployeeView.vue +219 -196
  22. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/HomeDashboardView.vue +263 -263
  23. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
  24. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
  25. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
  26. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
  27. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
  28. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
  29. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
  30. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
  31. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
  32. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
  33. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/App.vue +59 -59
  34. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/components/DataCard.vue +72 -53
  35. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
  36. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
  37. package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/controller/CompanyController.java +88 -74
  38. package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/model/Employee.java +73 -73
  39. package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/service/CompanyService.java +90 -60
  40. package/templates/springboot-course-registration/src/main/java/com/example/coursereg/controller/CourseController.java +46 -42
  41. package/templates/springboot-course-registration/src/main/java/com/example/coursereg/service/CourseService.java +70 -60
  42. package/templates/springboot-hospital-api/src/main/java/com/example/hospital/controller/HospitalController.java +54 -50
  43. package/templates/springboot-hospital-api/src/main/java/com/example/hospital/service/HospitalService.java +65 -54
  44. package/templates/springboot-library-api/src/main/java/com/example/library/controller/LibraryController.java +57 -51
  45. package/templates/springboot-library-api/src/main/java/com/example/library/service/LibraryService.java +70 -60
  46. package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/controller/ItemController.java +45 -41
  47. package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/service/ItemService.java +48 -38
  48. package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
  49. package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/service/ItemService.java +48 -38
  50. package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/controller/ItemController.java +45 -41
  51. package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/service/ItemService.java +48 -38
  52. package/templates/springboot-mongo-crud/src/main/java/com/example/crud/controller/ItemController.java +45 -41
  53. package/templates/springboot-mongo-crud/src/main/java/com/example/crud/service/ItemService.java +48 -38
  54. package/templates/vue-axios/src/App.vue +264 -243
  55. package/templates/vue-axios/src/services/ItemService.js +27 -21
  56. package/templates/vue-axios-basic/src/App.vue +24 -0
  57. package/templates/vue-axios-interceptor/src/App.vue +177 -159
  58. package/templates/vue-axios-pinia/src/App.vue +14 -0
  59. package/templates/vue-axios-pinia/src/stores/companyStore.js +126 -96
  60. package/templates/vue-axios-pinia-props/src/App.vue +84 -69
  61. package/templates/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
  62. package/templates/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
  63. package/templates/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
  64. package/templates/vue-axios-props-emits/src/App.vue +24 -0
  65. package/templates/vue-axios-props-emits/src/components/DepartmentList.vue +2 -1
  66. package/templates/vue-axios-props-emits/src/components/EmployeeList.vue +2 -1
  67. package/templates/vue-axios-router/src/views/DepartmentView.vue +23 -0
  68. package/templates/vue-axios-router/src/views/EmployeeView.vue +23 -0
  69. package/templates/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
  70. package/templates/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
  71. package/templates/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
  72. package/templates/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
  73. package/templates/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
  74. package/templates/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
  75. package/templates/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
  76. package/templates/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
  77. package/templates/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
  78. package/templates/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
  79. package/templates/vue-axios-router-props/src/components/DataCard.vue +72 -53
  80. package/templates/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
  81. package/templates/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
  82. package/templates/vue-fetch/src/App.vue +285 -259
  83. package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
  84. package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
  85. package/templates/vue-router-pinia-springboot/frontend/src/services/ItemService.js +24 -21
  86. package/templates/vue-router-pinia-springboot/frontend/src/stores/itemStore.js +42 -37
  87. package/templates/vue-router-pinia-springboot/frontend/src/views/ListView.vue +76 -67
  88. package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
  89. package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/service/ItemService.java +45 -35
  90. package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
  91. package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
  92. package/templates/vue-springboot-mongo-crud/frontend/src/App.vue +158 -149
  93. package/templates/vue-springboot-mongo-crud/frontend/src/services/ItemService.js +24 -21
@@ -1,67 +1,76 @@
1
- <script setup>
2
- import { onMounted } from 'vue'
3
- import { useCompanyStore } from '../stores/companyStore'
4
- import EntityTable from '../components/EntityTable.vue'
5
- import EntityForm from '../components/EntityForm.vue'
6
-
7
- const store = useCompanyStore()
8
-
9
- const employeeFields = [
10
- { key: 'name', label: 'Employee Name', type: 'text', placeholder: 'e.g. Jane Doe' },
11
- { key: 'email', label: 'Email Address', type: 'email', placeholder: 'e.g. jane@example.com' },
12
- { key: 'role', label: 'Job Role', type: 'text', placeholder: 'e.g. Developer' },
13
- { key: 'department', label: 'Department', type: 'text', placeholder: 'e.g. Engineering' }
14
- ]
15
-
16
- const employeeColumns = [
17
- { key: 'id', label: 'ID' },
18
- { key: 'name', label: 'Name' },
19
- { key: 'email', label: 'Email' },
20
- { key: 'role', label: 'Role' },
21
- { key: 'department', label: 'Department' }
22
- ]
23
-
24
- const handleAddEmployee = (formData) => {
25
- store.addEmployee({
26
- name: formData.name,
27
- email: formData.email,
28
- role: formData.role,
29
- department: formData.department
30
- })
31
- }
32
-
33
- const handleDeleteEmployee = (id) => {
34
- store.removeEmployee(id)
35
- }
36
-
37
- onMounted(() => {
38
- store.fetchEmployees()
39
- })
40
- </script>
41
-
42
- <template>
43
- <div class="manage-employees-view">
44
- <h2>Manage Employees</h2>
45
- <EntityForm
46
- :fields="employeeFields"
47
- title="Add New Employee"
48
- @submit-form="handleAddEmployee"
49
- />
50
- <EntityTable
51
- :items="store.employees"
52
- :columns="employeeColumns"
53
- title="All Employees"
54
- @delete-item="handleDeleteEmployee"
55
- />
56
- </div>
57
- </template>
58
-
59
- <style scoped>
60
- .manage-employees-view {
61
- padding: 16px 0;
62
- }
63
- .manage-employees-view h2 {
64
- font-size: 1.5rem;
65
- margin-bottom: 20px;
66
- }
67
- </style>
1
+ <script setup>
2
+ import { onMounted } from 'vue'
3
+ import { useCompanyStore } from '../stores/companyStore'
4
+ import EntityTable from '../components/EntityTable.vue'
5
+ import EntityForm from '../components/EntityForm.vue'
6
+
7
+ const companyStore = useCompanyStore()
8
+ const store = companyStore
9
+
10
+ const employeeFields = [
11
+ { key: 'name', label: 'Employee Name', type: 'text', placeholder: 'e.g. Jane Doe' },
12
+ { key: 'email', label: 'Email Address', type: 'email', placeholder: 'e.g. jane@example.com' },
13
+ { key: 'role', label: 'Job Role', type: 'text', placeholder: 'e.g. Developer' },
14
+ { key: 'department', label: 'Department', type: 'text', placeholder: 'e.g. Engineering' }
15
+ ]
16
+
17
+ const employeeColumns = [
18
+ { key: 'id', label: 'ID' },
19
+ { key: 'name', label: 'Name' },
20
+ { key: 'email', label: 'Email' },
21
+ { key: 'role', label: 'Role' },
22
+ { key: 'department', label: 'Department' }
23
+ ]
24
+
25
+ const handleAddEmployee = (formData) => {
26
+ store.addEmployee({
27
+ name: formData.name,
28
+ email: formData.email,
29
+ role: formData.role,
30
+ department: formData.department
31
+ })
32
+ }
33
+
34
+ const handleDeleteEmployee = (id) => {
35
+ store.removeEmployee(id)
36
+ }
37
+
38
+ const handlePatch = (item) => {
39
+ const salary = prompt('New salary:', item.salary)
40
+ if (salary !== null && salary !== '') {
41
+ companyStore.patchEmployee(item.id, { salary: Number(salary) })
42
+ }
43
+ }
44
+
45
+ onMounted(() => {
46
+ store.fetchEmployees()
47
+ })
48
+ </script>
49
+
50
+ <template>
51
+ <div class="manage-employees-view">
52
+ <h2>Manage Employees</h2>
53
+ <EntityForm
54
+ :fields="employeeFields"
55
+ title="Add New Employee"
56
+ @submit-form="handleAddEmployee"
57
+ />
58
+ <EntityTable
59
+ :items="store.employees"
60
+ :columns="employeeColumns"
61
+ title="All Employees"
62
+ @delete-item="handleDeleteEmployee"
63
+ @patch-item="handlePatch"
64
+ />
65
+ </div>
66
+ </template>
67
+
68
+ <style scoped>
69
+ .manage-employees-view {
70
+ padding: 16px 0;
71
+ }
72
+ .manage-employees-view h2 {
73
+ font-size: 1.5rem;
74
+ margin-bottom: 20px;
75
+ }
76
+ </style>
@@ -1,59 +1,59 @@
1
- <script setup>
2
- </script>
3
-
4
- <template>
5
- <div class="app-container">
6
- <header class="navbar">
7
- <h2>Company Management</h2>
8
- <nav class="nav-links">
9
- <router-link to="/">Departments</router-link>
10
- <router-link to="/employees">Employees</router-link>
11
- </nav>
12
- </header>
13
- <main class="content">
14
- <router-view />
15
- </main>
16
- </div>
17
- </template>
18
-
19
- <style scoped>
20
- .app-container {
21
- max-width: 800px;
22
- margin: 0 auto;
23
- padding: 24px 16px;
24
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
25
- color: #2d3748;
26
- }
27
- .navbar {
28
- display: flex;
29
- justify-content: space-between;
30
- align-items: center;
31
- border-bottom: 2px solid #e2e8f0;
32
- padding-bottom: 16px;
33
- margin-bottom: 24px;
34
- }
35
- .navbar h2 {
36
- margin: 0;
37
- font-size: 22px;
38
- }
39
- .nav-links {
40
- display: flex;
41
- gap: 12px;
42
- }
43
- .nav-links a {
44
- text-decoration: none;
45
- color: #4a5568;
46
- font-weight: 500;
47
- padding: 6px 14px;
48
- border-radius: 4px;
49
- border: 1px solid #cbd5e0;
50
- }
51
- .nav-links a.router-link-active {
52
- background-color: #3182ce;
53
- border-color: #3182ce;
54
- color: #fff;
55
- }
56
- .content {
57
- margin-top: 10px;
58
- }
59
- </style>
1
+ <script setup>
2
+ </script>
3
+
4
+ <template>
5
+ <div class="app-container">
6
+ <header class="navbar">
7
+ <h2>Company Management</h2>
8
+ <nav class="nav-links">
9
+ <router-link to="/">Departments</router-link>
10
+ <router-link to="/employees">Employees</router-link>
11
+ </nav>
12
+ </header>
13
+ <main class="content">
14
+ <router-view />
15
+ </main>
16
+ </div>
17
+ </template>
18
+
19
+ <style scoped>
20
+ .app-container {
21
+ max-width: 800px;
22
+ margin: 0 auto;
23
+ padding: 24px 16px;
24
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
25
+ color: #2d3748;
26
+ }
27
+ .navbar {
28
+ display: flex;
29
+ justify-content: space-between;
30
+ align-items: center;
31
+ border-bottom: 2px solid #e2e8f0;
32
+ padding-bottom: 16px;
33
+ margin-bottom: 24px;
34
+ }
35
+ .navbar h2 {
36
+ margin: 0;
37
+ font-size: 22px;
38
+ }
39
+ .nav-links {
40
+ display: flex;
41
+ gap: 12px;
42
+ }
43
+ .nav-links a {
44
+ text-decoration: none;
45
+ color: #4a5568;
46
+ font-weight: 500;
47
+ padding: 6px 14px;
48
+ border-radius: 4px;
49
+ border: 1px solid #cbd5e0;
50
+ }
51
+ .nav-links a.router-link-active {
52
+ background-color: #3182ce;
53
+ border-color: #3182ce;
54
+ color: #fff;
55
+ }
56
+ .content {
57
+ margin-top: 10px;
58
+ }
59
+ </style>
@@ -1,53 +1,72 @@
1
- <script setup>
2
- const props = defineProps(['title', 'subtitle', 'id'])
3
- const emit = defineEmits(['remove'])
4
-
5
- const handleRemove = () => {
6
- emit('remove', props.id)
7
- }
8
- </script>
9
-
10
- <template>
11
- <div class="data-card">
12
- <div class="card-info">
13
- <h4>{{ title }}</h4>
14
- <p>{{ subtitle }}</p>
15
- </div>
16
- <button class="btn-remove" @click="handleRemove">Delete</button>
17
- </div>
18
- </template>
19
-
20
- <style scoped>
21
- .data-card {
22
- display: flex;
23
- justify-content: space-between;
24
- align-items: center;
25
- border: 1px solid #e2e8f0;
26
- border-radius: 6px;
27
- padding: 12px 16px;
28
- margin-bottom: 10px;
29
- background-color: #fff;
30
- }
31
- .card-info h4 {
32
- margin: 0 0 4px 0;
33
- font-size: 16px;
34
- color: #2d3748;
35
- }
36
- .card-info p {
37
- margin: 0;
38
- font-size: 14px;
39
- color: #718096;
40
- }
41
- .btn-remove {
42
- background-color: #e53e3e;
43
- color: white;
44
- border: none;
45
- border-radius: 4px;
46
- padding: 6px 12px;
47
- cursor: pointer;
48
- font-size: 13px;
49
- }
50
- .btn-remove:hover {
51
- background-color: #c53030;
52
- }
53
- </style>
1
+ <script setup>
2
+ const props = defineProps(['title', 'subtitle', 'id'])
3
+ const emit = defineEmits(['remove', 'patch'])
4
+
5
+ const handleRemove = () => {
6
+ emit('remove', props.id)
7
+ }
8
+ </script>
9
+
10
+ <template>
11
+ <div class="data-card">
12
+ <div class="card-info">
13
+ <h4>{{ title }}</h4>
14
+ <p>{{ subtitle }}</p>
15
+ </div>
16
+ <div class="card-actions">
17
+ <button class="btn-patch" @click="$emit('patch', id)">Patch</button>
18
+ <button class="btn-remove" @click="handleRemove">Delete</button>
19
+ </div>
20
+ </div>
21
+ </template>
22
+
23
+ <style scoped>
24
+ .data-card {
25
+ display: flex;
26
+ justify-content: space-between;
27
+ align-items: center;
28
+ border: 1px solid #e2e8f0;
29
+ border-radius: 6px;
30
+ padding: 12px 16px;
31
+ margin-bottom: 10px;
32
+ background-color: #fff;
33
+ }
34
+ .card-info h4 {
35
+ margin: 0 0 4px 0;
36
+ font-size: 16px;
37
+ color: #2d3748;
38
+ }
39
+ .card-info p {
40
+ margin: 0;
41
+ font-size: 14px;
42
+ color: #718096;
43
+ }
44
+ .card-actions {
45
+ display: flex;
46
+ gap: 8px;
47
+ }
48
+ .btn-patch {
49
+ background-color: #3182ce;
50
+ color: white;
51
+ border: none;
52
+ border-radius: 4px;
53
+ padding: 6px 12px;
54
+ cursor: pointer;
55
+ font-size: 13px;
56
+ }
57
+ .btn-patch:hover {
58
+ background-color: #2b6cb0;
59
+ }
60
+ .btn-remove {
61
+ background-color: #e53e3e;
62
+ color: white;
63
+ border: none;
64
+ border-radius: 4px;
65
+ padding: 6px 12px;
66
+ cursor: pointer;
67
+ font-size: 13px;
68
+ }
69
+ .btn-remove:hover {
70
+ background-color: #c53030;
71
+ }
72
+ </style>
@@ -1,77 +1,89 @@
1
- <script setup>
2
- import { ref, onMounted } from 'vue'
3
- import api from '../services/api'
4
- import EntryForm from '../components/EntryForm.vue'
5
- import DataCard from '../components/DataCard.vue'
6
-
7
- const departments = ref([])
8
-
9
- const deptFields = [
10
- { key: 'name', label: 'Department Name', placeholder: 'e.g. Engineering' },
11
- { key: 'code', label: 'Department Code', placeholder: 'e.g. ENG' }
12
- ]
13
-
14
- const fetchDepartments = async () => {
15
- try {
16
- const res = await api.get('/departments')
17
- departments.value = res.data
18
- } catch (error) {
19
- console.error(error)
20
- }
21
- }
22
-
23
- const handleCreateDepartment = async (formData) => {
24
- try {
25
- const res = await api.post('/departments', formData)
26
- departments.value.push(res.data)
27
- } catch (error) {
28
- console.error(error)
29
- }
30
- }
31
-
32
- const handleRemoveDepartment = async (id) => {
33
- try {
34
- await api.delete(`/departments/${id}`)
35
- departments.value = departments.value.filter(dept => dept.id !== id)
36
- } catch (error) {
37
- console.error(error)
38
- }
39
- }
40
-
41
- onMounted(() => {
42
- fetchDepartments()
43
- })
44
- </script>
45
-
46
- <template>
47
- <div class="page-container">
48
- <h2>Departments</h2>
49
- <EntryForm :fields="deptFields" @submit-data="handleCreateDepartment" />
50
- <div class="card-list">
51
- <p v-if="departments.length === 0" class="empty-state">No departments available.</p>
52
- <DataCard
53
- v-for="dept in departments"
54
- :key="dept.id"
55
- :id="dept.id"
56
- :title="dept.name"
57
- :subtitle="dept.code"
58
- @remove="handleRemoveDepartment"
59
- />
60
- </div>
61
- </div>
62
- </template>
63
-
64
- <style scoped>
65
- .page-container {
66
- display: flex;
67
- flex-direction: column;
68
- }
69
- .empty-state {
70
- color: #a0aec0;
71
- font-style: italic;
72
- }
73
- .card-list {
74
- display: flex;
75
- flex-direction: column;
76
- }
77
- </style>
1
+ <script setup>
2
+ import { ref, onMounted } from 'vue'
3
+ import api from '../services/api'
4
+ import EntryForm from '../components/EntryForm.vue'
5
+ import DataCard from '../components/DataCard.vue'
6
+
7
+ const departments = ref([])
8
+
9
+ const deptFields = [
10
+ { key: 'name', label: 'Department Name', placeholder: 'e.g. Engineering' },
11
+ { key: 'code', label: 'Department Code', placeholder: 'e.g. ENG' }
12
+ ]
13
+
14
+ const fetchDepartments = async () => {
15
+ try {
16
+ const res = await api.get('/departments')
17
+ departments.value = res.data
18
+ } catch (error) {
19
+ console.error(error)
20
+ }
21
+ }
22
+
23
+ const handleCreateDepartment = async (formData) => {
24
+ try {
25
+ const res = await api.post('/departments', formData)
26
+ departments.value.push(res.data)
27
+ } catch (error) {
28
+ console.error(error)
29
+ }
30
+ }
31
+
32
+ const handleRemoveDepartment = async (id) => {
33
+ try {
34
+ await api.delete(`/departments/${id}`)
35
+ departments.value = departments.value.filter(dept => dept.id !== id)
36
+ } catch (error) {
37
+ console.error(error)
38
+ }
39
+ }
40
+
41
+ const handlePatch = async (id, code) => {
42
+ const newCode = prompt('New code:', code)
43
+ if (!newCode || newCode === code) return
44
+ try {
45
+ await api.patch(`/departments/${id}`, { code: newCode })
46
+ await fetchDepartments()
47
+ } catch (error) {
48
+ console.error(error)
49
+ }
50
+ }
51
+
52
+ onMounted(() => {
53
+ fetchDepartments()
54
+ })
55
+ </script>
56
+
57
+ <template>
58
+ <div class="page-container">
59
+ <h2>Departments</h2>
60
+ <EntryForm :fields="deptFields" @submit-data="handleCreateDepartment" />
61
+ <div class="card-list">
62
+ <p v-if="departments.length === 0" class="empty-state">No departments available.</p>
63
+ <DataCard
64
+ v-for="dept in departments"
65
+ :key="dept.id"
66
+ :id="dept.id"
67
+ :title="dept.name"
68
+ :subtitle="dept.code"
69
+ @remove="handleRemoveDepartment"
70
+ @patch="handlePatch(dept.id, dept.code)"
71
+ />
72
+ </div>
73
+ </div>
74
+ </template>
75
+
76
+ <style scoped>
77
+ .page-container {
78
+ display: flex;
79
+ flex-direction: column;
80
+ }
81
+ .empty-state {
82
+ color: #a0aec0;
83
+ font-style: italic;
84
+ }
85
+ .card-list {
86
+ display: flex;
87
+ flex-direction: column;
88
+ }
89
+ </style>