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,243 +1,264 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { ref, reactive, onMounted } from 'vue'
|
|
3
|
-
import ItemService from './services/ItemService'
|
|
4
|
-
|
|
5
|
-
const items = ref([])
|
|
6
|
-
const loading = ref(false)
|
|
7
|
-
const errorMessage = ref('')
|
|
8
|
-
|
|
9
|
-
const searchId = ref('')
|
|
10
|
-
const selectedItem = ref(null)
|
|
11
|
-
|
|
12
|
-
const createForm = reactive({
|
|
13
|
-
name: '',
|
|
14
|
-
description: '',
|
|
15
|
-
price: 0
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
const editForm = reactive({
|
|
19
|
-
id: '',
|
|
20
|
-
name: '',
|
|
21
|
-
description: '',
|
|
22
|
-
price: 0
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
async function fetchAll() {
|
|
26
|
-
loading.value = true
|
|
27
|
-
errorMessage.value = ''
|
|
28
|
-
try {
|
|
29
|
-
const res = await ItemService.getAll()
|
|
30
|
-
items.value = res.data
|
|
31
|
-
} catch (err) {
|
|
32
|
-
errorMessage.value = err.message
|
|
33
|
-
} finally {
|
|
34
|
-
loading.value = false
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function fetchById(id) {
|
|
39
|
-
if (!id) return
|
|
40
|
-
loading.value = true
|
|
41
|
-
errorMessage.value = ''
|
|
42
|
-
try {
|
|
43
|
-
const res = await ItemService.getOne(id)
|
|
44
|
-
selectedItem.value = res.data
|
|
45
|
-
} catch (err) {
|
|
46
|
-
errorMessage.value = err.message
|
|
47
|
-
} finally {
|
|
48
|
-
loading.value = false
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function createItem() {
|
|
53
|
-
if (!createForm.name) return
|
|
54
|
-
loading.value = true
|
|
55
|
-
errorMessage.value = ''
|
|
56
|
-
try {
|
|
57
|
-
await ItemService.create({
|
|
58
|
-
name: createForm.name,
|
|
59
|
-
description: createForm.description,
|
|
60
|
-
describtion: createForm.description,
|
|
61
|
-
price: Number(createForm.price)
|
|
62
|
-
})
|
|
63
|
-
createForm.name = ''
|
|
64
|
-
createForm.description = ''
|
|
65
|
-
createForm.price = 0
|
|
66
|
-
await fetchAll()
|
|
67
|
-
} catch (err) {
|
|
68
|
-
errorMessage.value = err.message
|
|
69
|
-
} finally {
|
|
70
|
-
loading.value = false
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async function updateItem() {
|
|
75
|
-
if (!editForm.id) return
|
|
76
|
-
loading.value = true
|
|
77
|
-
errorMessage.value = ''
|
|
78
|
-
try {
|
|
79
|
-
await ItemService.update(editForm.id, {
|
|
80
|
-
id: editForm.id,
|
|
81
|
-
name: editForm.name,
|
|
82
|
-
description: editForm.description,
|
|
83
|
-
describtion: editForm.description,
|
|
84
|
-
price: Number(editForm.price)
|
|
85
|
-
})
|
|
86
|
-
editForm.id = ''
|
|
87
|
-
editForm.name = ''
|
|
88
|
-
editForm.description = ''
|
|
89
|
-
editForm.price = 0
|
|
90
|
-
await fetchAll()
|
|
91
|
-
} catch (err) {
|
|
92
|
-
errorMessage.value = err.message
|
|
93
|
-
} finally {
|
|
94
|
-
loading.value = false
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async function deleteItem(id) {
|
|
99
|
-
loading.value = true
|
|
100
|
-
errorMessage.value = ''
|
|
101
|
-
try {
|
|
102
|
-
await ItemService.delete(id)
|
|
103
|
-
if (selectedItem.value && selectedItem.value.id === id) {
|
|
104
|
-
selectedItem.value = null
|
|
105
|
-
}
|
|
106
|
-
await fetchAll()
|
|
107
|
-
} catch (err) {
|
|
108
|
-
errorMessage.value = err.message
|
|
109
|
-
} finally {
|
|
110
|
-
loading.value = false
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
<br>
|
|
170
|
-
<
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
<label for="
|
|
177
|
-
<br>
|
|
178
|
-
<input id="
|
|
179
|
-
<br><br>
|
|
180
|
-
|
|
181
|
-
<label for="
|
|
182
|
-
<br>
|
|
183
|
-
<input id="
|
|
184
|
-
<br><br>
|
|
185
|
-
|
|
186
|
-
<
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
<
|
|
197
|
-
<
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
<
|
|
213
|
-
<
|
|
214
|
-
<br>
|
|
215
|
-
|
|
216
|
-
<
|
|
217
|
-
<
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
<
|
|
225
|
-
<
|
|
226
|
-
<
|
|
227
|
-
|
|
228
|
-
<
|
|
229
|
-
<br>
|
|
230
|
-
|
|
231
|
-
<
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
<
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
</
|
|
242
|
-
</
|
|
243
|
-
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref, reactive, onMounted } from 'vue'
|
|
3
|
+
import ItemService from './services/ItemService'
|
|
4
|
+
|
|
5
|
+
const items = ref([])
|
|
6
|
+
const loading = ref(false)
|
|
7
|
+
const errorMessage = ref('')
|
|
8
|
+
|
|
9
|
+
const searchId = ref('')
|
|
10
|
+
const selectedItem = ref(null)
|
|
11
|
+
|
|
12
|
+
const createForm = reactive({
|
|
13
|
+
name: '',
|
|
14
|
+
description: '',
|
|
15
|
+
price: 0
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const editForm = reactive({
|
|
19
|
+
id: '',
|
|
20
|
+
name: '',
|
|
21
|
+
description: '',
|
|
22
|
+
price: 0
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
async function fetchAll() {
|
|
26
|
+
loading.value = true
|
|
27
|
+
errorMessage.value = ''
|
|
28
|
+
try {
|
|
29
|
+
const res = await ItemService.getAll()
|
|
30
|
+
items.value = res.data
|
|
31
|
+
} catch (err) {
|
|
32
|
+
errorMessage.value = err.message
|
|
33
|
+
} finally {
|
|
34
|
+
loading.value = false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function fetchById(id) {
|
|
39
|
+
if (!id) return
|
|
40
|
+
loading.value = true
|
|
41
|
+
errorMessage.value = ''
|
|
42
|
+
try {
|
|
43
|
+
const res = await ItemService.getOne(id)
|
|
44
|
+
selectedItem.value = res.data
|
|
45
|
+
} catch (err) {
|
|
46
|
+
errorMessage.value = err.message
|
|
47
|
+
} finally {
|
|
48
|
+
loading.value = false
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function createItem() {
|
|
53
|
+
if (!createForm.name) return
|
|
54
|
+
loading.value = true
|
|
55
|
+
errorMessage.value = ''
|
|
56
|
+
try {
|
|
57
|
+
await ItemService.create({
|
|
58
|
+
name: createForm.name,
|
|
59
|
+
description: createForm.description,
|
|
60
|
+
describtion: createForm.description,
|
|
61
|
+
price: Number(createForm.price)
|
|
62
|
+
})
|
|
63
|
+
createForm.name = ''
|
|
64
|
+
createForm.description = ''
|
|
65
|
+
createForm.price = 0
|
|
66
|
+
await fetchAll()
|
|
67
|
+
} catch (err) {
|
|
68
|
+
errorMessage.value = err.message
|
|
69
|
+
} finally {
|
|
70
|
+
loading.value = false
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function updateItem() {
|
|
75
|
+
if (!editForm.id) return
|
|
76
|
+
loading.value = true
|
|
77
|
+
errorMessage.value = ''
|
|
78
|
+
try {
|
|
79
|
+
await ItemService.update(editForm.id, {
|
|
80
|
+
id: editForm.id,
|
|
81
|
+
name: editForm.name,
|
|
82
|
+
description: editForm.description,
|
|
83
|
+
describtion: editForm.description,
|
|
84
|
+
price: Number(editForm.price)
|
|
85
|
+
})
|
|
86
|
+
editForm.id = ''
|
|
87
|
+
editForm.name = ''
|
|
88
|
+
editForm.description = ''
|
|
89
|
+
editForm.price = 0
|
|
90
|
+
await fetchAll()
|
|
91
|
+
} catch (err) {
|
|
92
|
+
errorMessage.value = err.message
|
|
93
|
+
} finally {
|
|
94
|
+
loading.value = false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function deleteItem(id) {
|
|
99
|
+
loading.value = true
|
|
100
|
+
errorMessage.value = ''
|
|
101
|
+
try {
|
|
102
|
+
await ItemService.delete(id)
|
|
103
|
+
if (selectedItem.value && selectedItem.value.id === id) {
|
|
104
|
+
selectedItem.value = null
|
|
105
|
+
}
|
|
106
|
+
await fetchAll()
|
|
107
|
+
} catch (err) {
|
|
108
|
+
errorMessage.value = err.message
|
|
109
|
+
} finally {
|
|
110
|
+
loading.value = false
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function patchItem(id, partial) {
|
|
115
|
+
loading.value = true
|
|
116
|
+
errorMessage.value = ''
|
|
117
|
+
try {
|
|
118
|
+
await ItemService.patch(id, partial)
|
|
119
|
+
await fetchAll()
|
|
120
|
+
} catch (err) {
|
|
121
|
+
errorMessage.value = err.message
|
|
122
|
+
} finally {
|
|
123
|
+
loading.value = false
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function promptPatch(item) {
|
|
128
|
+
const newPrice = prompt('Enter new price:')
|
|
129
|
+
if (newPrice !== null && newPrice !== '') {
|
|
130
|
+
patchItem(item.id, { price: Number(newPrice) })
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function startEdit(item) {
|
|
135
|
+
editForm.id = item.id
|
|
136
|
+
editForm.name = item.name
|
|
137
|
+
editForm.description = item.description || item.describtion || ''
|
|
138
|
+
editForm.price = item.price
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function cancelEdit() {
|
|
142
|
+
editForm.id = ''
|
|
143
|
+
editForm.name = ''
|
|
144
|
+
editForm.description = ''
|
|
145
|
+
editForm.price = 0
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
onMounted(() => {
|
|
149
|
+
fetchAll()
|
|
150
|
+
})
|
|
151
|
+
</script>
|
|
152
|
+
|
|
153
|
+
<template>
|
|
154
|
+
<h2>Vue Axios CRUD</h2>
|
|
155
|
+
<br>
|
|
156
|
+
|
|
157
|
+
<p v-if="loading">Loading...</p>
|
|
158
|
+
<br v-if="loading">
|
|
159
|
+
|
|
160
|
+
<p v-if="errorMessage">{{ errorMessage }}</p>
|
|
161
|
+
<br v-if="errorMessage">
|
|
162
|
+
|
|
163
|
+
<button @click="fetchAll">Refresh All (GET /api/items)</button>
|
|
164
|
+
<br><br>
|
|
165
|
+
<hr>
|
|
166
|
+
<br>
|
|
167
|
+
|
|
168
|
+
<h3>Create Item (POST /api/items)</h3>
|
|
169
|
+
<br>
|
|
170
|
+
<form @submit.prevent="createItem">
|
|
171
|
+
<label for="create-name">Name:</label>
|
|
172
|
+
<br>
|
|
173
|
+
<input id="create-name" v-model="createForm.name" placeholder="Item Name" required>
|
|
174
|
+
<br><br>
|
|
175
|
+
|
|
176
|
+
<label for="create-desc">Description:</label>
|
|
177
|
+
<br>
|
|
178
|
+
<input id="create-desc" v-model="createForm.description" placeholder="Item Description" required>
|
|
179
|
+
<br><br>
|
|
180
|
+
|
|
181
|
+
<label for="create-price">Price:</label>
|
|
182
|
+
<br>
|
|
183
|
+
<input id="create-price" v-model.number="createForm.price" type="number" placeholder="Item Price" required>
|
|
184
|
+
<br><br>
|
|
185
|
+
|
|
186
|
+
<button type="submit">Create Item</button>
|
|
187
|
+
</form>
|
|
188
|
+
|
|
189
|
+
<br>
|
|
190
|
+
<hr>
|
|
191
|
+
<br>
|
|
192
|
+
|
|
193
|
+
<h3>Update Item (PUT /api/items/:id)</h3>
|
|
194
|
+
<br>
|
|
195
|
+
<form @submit.prevent="updateItem">
|
|
196
|
+
<label for="edit-id">Item ID:</label>
|
|
197
|
+
<br>
|
|
198
|
+
<input id="edit-id" v-model="editForm.id" placeholder="Item ID" required>
|
|
199
|
+
<br><br>
|
|
200
|
+
|
|
201
|
+
<label for="edit-name">Name:</label>
|
|
202
|
+
<br>
|
|
203
|
+
<input id="edit-name" v-model="editForm.name" placeholder="Item Name" required>
|
|
204
|
+
<br><br>
|
|
205
|
+
|
|
206
|
+
<label for="edit-desc">Description:</label>
|
|
207
|
+
<br>
|
|
208
|
+
<input id="edit-desc" v-model="editForm.description" placeholder="Item Description" required>
|
|
209
|
+
<br><br>
|
|
210
|
+
|
|
211
|
+
<label for="edit-price">Price:</label>
|
|
212
|
+
<br>
|
|
213
|
+
<input id="edit-price" v-model.number="editForm.price" type="number" placeholder="Item Price" required>
|
|
214
|
+
<br><br>
|
|
215
|
+
|
|
216
|
+
<button type="submit">Update Item</button>
|
|
217
|
+
<button type="button" @click="cancelEdit">Clear</button>
|
|
218
|
+
</form>
|
|
219
|
+
|
|
220
|
+
<br>
|
|
221
|
+
<hr>
|
|
222
|
+
<br>
|
|
223
|
+
|
|
224
|
+
<h3>Get Item By ID (GET /api/items/:id)</h3>
|
|
225
|
+
<br>
|
|
226
|
+
<input v-model="searchId" placeholder="Enter Item ID">
|
|
227
|
+
<br><br>
|
|
228
|
+
<button @click="fetchById(searchId)">Fetch By ID</button>
|
|
229
|
+
<br><br>
|
|
230
|
+
|
|
231
|
+
<div v-if="selectedItem">
|
|
232
|
+
<h4>Item Details</h4>
|
|
233
|
+
<p>ID: {{ selectedItem.id }}</p>
|
|
234
|
+
<br>
|
|
235
|
+
<p>Name: {{ selectedItem.name }}</p>
|
|
236
|
+
<br>
|
|
237
|
+
<p>Description: {{ selectedItem.description || selectedItem.describtion }}</p>
|
|
238
|
+
<br>
|
|
239
|
+
<p>Price: ${{ selectedItem.price }}</p>
|
|
240
|
+
<br>
|
|
241
|
+
<button @click="selectedItem = null">Close Details</button>
|
|
242
|
+
</div>
|
|
243
|
+
|
|
244
|
+
<br>
|
|
245
|
+
<hr>
|
|
246
|
+
<br>
|
|
247
|
+
|
|
248
|
+
<h3>Items List (GET /api/items)</h3>
|
|
249
|
+
<br>
|
|
250
|
+
|
|
251
|
+
<p v-if="items.length === 0">No items loaded.</p>
|
|
252
|
+
|
|
253
|
+
<ul v-if="items.length > 0">
|
|
254
|
+
<li v-for="item in items" :key="item.id">
|
|
255
|
+
<span>{{ item.name }} - {{ item.description || item.describtion }} - ${{ item.price }} (ID: {{ item.id }})</span>
|
|
256
|
+
<br><br>
|
|
257
|
+
<button @click="fetchById(item.id)">View Details</button>
|
|
258
|
+
<button @click="startEdit(item)">Edit</button>
|
|
259
|
+
<button @click="deleteItem(item.id)">Delete</button>
|
|
260
|
+
<button @click="promptPatch(item)">Patch</button>
|
|
261
|
+
<br><br>
|
|
262
|
+
</li>
|
|
263
|
+
</ul>
|
|
264
|
+
</template>
|
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
import axios from 'axios'
|
|
2
|
-
|
|
3
|
-
const API_URL = 'http://localhost:8080/api/items'
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
getAll() {
|
|
7
|
-
return axios.get(API_URL)
|
|
8
|
-
},
|
|
9
|
-
getOne(id) {
|
|
10
|
-
return axios.get(API_URL + '/' + id)
|
|
11
|
-
},
|
|
12
|
-
create(data) {
|
|
13
|
-
return axios.post(API_URL, data)
|
|
14
|
-
},
|
|
15
|
-
update(id, data) {
|
|
16
|
-
return axios.put(API_URL + '/' + id, data)
|
|
17
|
-
},
|
|
18
|
-
delete(id) {
|
|
19
|
-
return axios.delete(API_URL + '/' + id)
|
|
20
|
-
}
|
|
21
|
-
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
|
|
3
|
+
const API_URL = 'http://localhost:8080/api/items'
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
getAll() {
|
|
7
|
+
return axios.get(API_URL)
|
|
8
|
+
},
|
|
9
|
+
getOne(id) {
|
|
10
|
+
return axios.get(API_URL + '/' + id)
|
|
11
|
+
},
|
|
12
|
+
create(data) {
|
|
13
|
+
return axios.post(API_URL, data)
|
|
14
|
+
},
|
|
15
|
+
update(id, data) {
|
|
16
|
+
return axios.put(API_URL + '/' + id, data)
|
|
17
|
+
},
|
|
18
|
+
delete(id) {
|
|
19
|
+
return axios.delete(API_URL + '/' + id)
|
|
20
|
+
},
|
|
21
|
+
patch(id, data) {
|
|
22
|
+
return axios.patch(API_URL + '/' + id, data)
|
|
23
|
+
},
|
|
24
|
+
patchItem(id, partial) {
|
|
25
|
+
return axios.patch(API_URL + '/' + id, partial)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
<td>{{ dept.name }}</td>
|
|
53
53
|
<td><code>{{ dept.code }}</code></td>
|
|
54
54
|
<td>
|
|
55
|
+
<button @click="patchDepartment(dept.id, dept.code)" class="btn">Patch</button>
|
|
55
56
|
<button @click="deleteDepartment(dept.id)" class="btn btn-danger">Delete</button>
|
|
56
57
|
</td>
|
|
57
58
|
</tr>
|
|
@@ -131,6 +132,7 @@
|
|
|
131
132
|
<td>{{ getDepartmentName(emp.departmentId) }}</td>
|
|
132
133
|
<td>${{ Number(emp.salary).toLocaleString() }}</td>
|
|
133
134
|
<td>
|
|
135
|
+
<button @click="patchEmployeeSalary(emp.id, emp.salary)" class="btn">Patch</button>
|
|
134
136
|
<button @click="deleteEmployee(emp.id)" class="btn btn-danger">Delete</button>
|
|
135
137
|
</td>
|
|
136
138
|
</tr>
|
|
@@ -230,6 +232,28 @@ const deleteEmployee = async (id) => {
|
|
|
230
232
|
}
|
|
231
233
|
}
|
|
232
234
|
|
|
235
|
+
const patchDepartment = async (id, currentCode) => {
|
|
236
|
+
const code = prompt('Enter new department code:', currentCode)
|
|
237
|
+
if (!code || code === currentCode) return
|
|
238
|
+
try {
|
|
239
|
+
await api.patch(`/departments/${id}`, { code })
|
|
240
|
+
await fetchDepartments()
|
|
241
|
+
} catch (error) {
|
|
242
|
+
console.error(error)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const patchEmployeeSalary = async (id, currentSalary) => {
|
|
247
|
+
const salary = prompt('Enter new salary:', currentSalary)
|
|
248
|
+
if (!salary || Number(salary) === Number(currentSalary)) return
|
|
249
|
+
try {
|
|
250
|
+
await api.patch(`/employees/${id}`, { salary: Number(salary) })
|
|
251
|
+
await fetchEmployees()
|
|
252
|
+
} catch (error) {
|
|
253
|
+
console.error(error)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
233
257
|
const getDepartmentName = (deptId) => {
|
|
234
258
|
const dept = departments.value.find((d) => d.id === deptId)
|
|
235
259
|
return dept ? dept.name : `Dept #${deptId}`
|