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.
- package/bin/index.js +30 -3
- 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 +429 -405
- package/templates/vue-axios-interceptor/src/App.vue +177 -159
- package/templates/vue-axios-pinia/src/App.vue +441 -427
- 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 +191 -167
- package/templates/vue-axios-props-emits/src/components/DepartmentForm.vue +98 -98
- package/templates/vue-axios-props-emits/src/components/DepartmentList.vue +92 -91
- package/templates/vue-axios-props-emits/src/components/EmployeeForm.vue +128 -128
- package/templates/vue-axios-props-emits/src/components/EmployeeList.vue +95 -94
- package/templates/vue-axios-router/src/App.vue +90 -90
- package/templates/vue-axios-router/src/views/AddEmployeeView.vue +247 -247
- package/templates/vue-axios-router/src/views/DepartmentView.vue +296 -273
- package/templates/vue-axios-router/src/views/EmployeeView.vue +219 -196
- package/templates/vue-axios-router/src/views/HomeDashboardView.vue +263 -263
- 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/App.vue +59 -59
- 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,259 +1,285 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { ref, reactive, onMounted } from 'vue'
|
|
3
|
-
|
|
4
|
-
const API_URL = 'http://localhost:8080/api/items'
|
|
5
|
-
|
|
6
|
-
const items = ref([])
|
|
7
|
-
const loading = ref(false)
|
|
8
|
-
const errorMessage = ref('')
|
|
9
|
-
|
|
10
|
-
const searchId = ref('')
|
|
11
|
-
const selectedItem = ref(null)
|
|
12
|
-
|
|
13
|
-
const createForm = reactive({
|
|
14
|
-
name: '',
|
|
15
|
-
description: '',
|
|
16
|
-
price: 0
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const editForm = reactive({
|
|
20
|
-
id: '',
|
|
21
|
-
name: '',
|
|
22
|
-
description: '',
|
|
23
|
-
price: 0
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
async function fetchAll() {
|
|
27
|
-
loading.value = true
|
|
28
|
-
errorMessage.value = ''
|
|
29
|
-
try {
|
|
30
|
-
const res = await fetch(API_URL)
|
|
31
|
-
if (!res.ok) throw new Error('Failed to fetch items: ' + res.statusText)
|
|
32
|
-
items.value = await res.json()
|
|
33
|
-
} catch (err) {
|
|
34
|
-
errorMessage.value = err.message
|
|
35
|
-
} finally {
|
|
36
|
-
loading.value = false
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function fetchById(id) {
|
|
41
|
-
if (!id) return
|
|
42
|
-
loading.value = true
|
|
43
|
-
errorMessage.value = ''
|
|
44
|
-
try {
|
|
45
|
-
const res = await fetch(API_URL + '/' + id)
|
|
46
|
-
if (!res.ok) throw new Error('Failed to fetch item ' + id + ': ' + res.statusText)
|
|
47
|
-
selectedItem.value = await res.json()
|
|
48
|
-
} catch (err) {
|
|
49
|
-
errorMessage.value = err.message
|
|
50
|
-
} finally {
|
|
51
|
-
loading.value = false
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async function createItem() {
|
|
56
|
-
if (!createForm.name) return
|
|
57
|
-
loading.value = true
|
|
58
|
-
errorMessage.value = ''
|
|
59
|
-
try {
|
|
60
|
-
const res = await fetch(API_URL, {
|
|
61
|
-
method: 'POST',
|
|
62
|
-
headers: { 'Content-Type': 'application/json' },
|
|
63
|
-
body: JSON.stringify({
|
|
64
|
-
name: createForm.name,
|
|
65
|
-
description: createForm.description,
|
|
66
|
-
describtion: createForm.description,
|
|
67
|
-
price: Number(createForm.price)
|
|
68
|
-
})
|
|
69
|
-
})
|
|
70
|
-
if (!res.ok) throw new Error('Failed to create item: ' + res.statusText)
|
|
71
|
-
createForm.name = ''
|
|
72
|
-
createForm.description = ''
|
|
73
|
-
createForm.price = 0
|
|
74
|
-
await fetchAll()
|
|
75
|
-
} catch (err) {
|
|
76
|
-
errorMessage.value = err.message
|
|
77
|
-
} finally {
|
|
78
|
-
loading.value = false
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async function updateItem() {
|
|
83
|
-
if (!editForm.id) return
|
|
84
|
-
loading.value = true
|
|
85
|
-
errorMessage.value = ''
|
|
86
|
-
try {
|
|
87
|
-
const res = await fetch(API_URL + '/' + editForm.id, {
|
|
88
|
-
method: 'PUT',
|
|
89
|
-
headers: { 'Content-Type': 'application/json' },
|
|
90
|
-
body: JSON.stringify({
|
|
91
|
-
id: editForm.id,
|
|
92
|
-
name: editForm.name,
|
|
93
|
-
description: editForm.description,
|
|
94
|
-
describtion: editForm.description,
|
|
95
|
-
price: Number(editForm.price)
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
if (!res.ok) throw new Error('Failed to update item: ' + res.statusText)
|
|
99
|
-
editForm.id = ''
|
|
100
|
-
editForm.name = ''
|
|
101
|
-
editForm.description = ''
|
|
102
|
-
editForm.price = 0
|
|
103
|
-
await fetchAll()
|
|
104
|
-
} catch (err) {
|
|
105
|
-
errorMessage.value = err.message
|
|
106
|
-
} finally {
|
|
107
|
-
loading.value = false
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async function deleteItem(id) {
|
|
112
|
-
loading.value = true
|
|
113
|
-
errorMessage.value = ''
|
|
114
|
-
try {
|
|
115
|
-
const res = await fetch(API_URL + '/' + id, {
|
|
116
|
-
method: 'DELETE'
|
|
117
|
-
})
|
|
118
|
-
if (!res.ok) throw new Error('Failed to delete item: ' + res.statusText)
|
|
119
|
-
if (selectedItem.value && selectedItem.value.id === id) {
|
|
120
|
-
selectedItem.value = null
|
|
121
|
-
}
|
|
122
|
-
await fetchAll()
|
|
123
|
-
} catch (err) {
|
|
124
|
-
errorMessage.value = err.message
|
|
125
|
-
} finally {
|
|
126
|
-
loading.value = false
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
<br>
|
|
186
|
-
<hr>
|
|
187
|
-
<br>
|
|
188
|
-
|
|
189
|
-
<h3>
|
|
190
|
-
<br>
|
|
191
|
-
<form @submit.prevent="
|
|
192
|
-
<label for="
|
|
193
|
-
<br>
|
|
194
|
-
<input id="
|
|
195
|
-
<br><br>
|
|
196
|
-
|
|
197
|
-
<label for="
|
|
198
|
-
<br>
|
|
199
|
-
<input id="
|
|
200
|
-
<br><br>
|
|
201
|
-
|
|
202
|
-
<label for="
|
|
203
|
-
<br>
|
|
204
|
-
<input id="
|
|
205
|
-
<br><br>
|
|
206
|
-
|
|
207
|
-
<
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
</
|
|
215
|
-
|
|
216
|
-
<
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
<
|
|
229
|
-
<
|
|
230
|
-
<br>
|
|
231
|
-
|
|
232
|
-
<
|
|
233
|
-
<
|
|
234
|
-
<
|
|
235
|
-
<
|
|
236
|
-
|
|
237
|
-
<button
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
<
|
|
242
|
-
<
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
<
|
|
246
|
-
|
|
247
|
-
<
|
|
248
|
-
|
|
249
|
-
<
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref, reactive, onMounted } from 'vue'
|
|
3
|
+
|
|
4
|
+
const API_URL = 'http://localhost:8080/api/items'
|
|
5
|
+
|
|
6
|
+
const items = ref([])
|
|
7
|
+
const loading = ref(false)
|
|
8
|
+
const errorMessage = ref('')
|
|
9
|
+
|
|
10
|
+
const searchId = ref('')
|
|
11
|
+
const selectedItem = ref(null)
|
|
12
|
+
|
|
13
|
+
const createForm = reactive({
|
|
14
|
+
name: '',
|
|
15
|
+
description: '',
|
|
16
|
+
price: 0
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const editForm = reactive({
|
|
20
|
+
id: '',
|
|
21
|
+
name: '',
|
|
22
|
+
description: '',
|
|
23
|
+
price: 0
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
async function fetchAll() {
|
|
27
|
+
loading.value = true
|
|
28
|
+
errorMessage.value = ''
|
|
29
|
+
try {
|
|
30
|
+
const res = await fetch(API_URL)
|
|
31
|
+
if (!res.ok) throw new Error('Failed to fetch items: ' + res.statusText)
|
|
32
|
+
items.value = await res.json()
|
|
33
|
+
} catch (err) {
|
|
34
|
+
errorMessage.value = err.message
|
|
35
|
+
} finally {
|
|
36
|
+
loading.value = false
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function fetchById(id) {
|
|
41
|
+
if (!id) return
|
|
42
|
+
loading.value = true
|
|
43
|
+
errorMessage.value = ''
|
|
44
|
+
try {
|
|
45
|
+
const res = await fetch(API_URL + '/' + id)
|
|
46
|
+
if (!res.ok) throw new Error('Failed to fetch item ' + id + ': ' + res.statusText)
|
|
47
|
+
selectedItem.value = await res.json()
|
|
48
|
+
} catch (err) {
|
|
49
|
+
errorMessage.value = err.message
|
|
50
|
+
} finally {
|
|
51
|
+
loading.value = false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function createItem() {
|
|
56
|
+
if (!createForm.name) return
|
|
57
|
+
loading.value = true
|
|
58
|
+
errorMessage.value = ''
|
|
59
|
+
try {
|
|
60
|
+
const res = await fetch(API_URL, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: { 'Content-Type': 'application/json' },
|
|
63
|
+
body: JSON.stringify({
|
|
64
|
+
name: createForm.name,
|
|
65
|
+
description: createForm.description,
|
|
66
|
+
describtion: createForm.description,
|
|
67
|
+
price: Number(createForm.price)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
if (!res.ok) throw new Error('Failed to create item: ' + res.statusText)
|
|
71
|
+
createForm.name = ''
|
|
72
|
+
createForm.description = ''
|
|
73
|
+
createForm.price = 0
|
|
74
|
+
await fetchAll()
|
|
75
|
+
} catch (err) {
|
|
76
|
+
errorMessage.value = err.message
|
|
77
|
+
} finally {
|
|
78
|
+
loading.value = false
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function updateItem() {
|
|
83
|
+
if (!editForm.id) return
|
|
84
|
+
loading.value = true
|
|
85
|
+
errorMessage.value = ''
|
|
86
|
+
try {
|
|
87
|
+
const res = await fetch(API_URL + '/' + editForm.id, {
|
|
88
|
+
method: 'PUT',
|
|
89
|
+
headers: { 'Content-Type': 'application/json' },
|
|
90
|
+
body: JSON.stringify({
|
|
91
|
+
id: editForm.id,
|
|
92
|
+
name: editForm.name,
|
|
93
|
+
description: editForm.description,
|
|
94
|
+
describtion: editForm.description,
|
|
95
|
+
price: Number(editForm.price)
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
if (!res.ok) throw new Error('Failed to update item: ' + res.statusText)
|
|
99
|
+
editForm.id = ''
|
|
100
|
+
editForm.name = ''
|
|
101
|
+
editForm.description = ''
|
|
102
|
+
editForm.price = 0
|
|
103
|
+
await fetchAll()
|
|
104
|
+
} catch (err) {
|
|
105
|
+
errorMessage.value = err.message
|
|
106
|
+
} finally {
|
|
107
|
+
loading.value = false
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function deleteItem(id) {
|
|
112
|
+
loading.value = true
|
|
113
|
+
errorMessage.value = ''
|
|
114
|
+
try {
|
|
115
|
+
const res = await fetch(API_URL + '/' + id, {
|
|
116
|
+
method: 'DELETE'
|
|
117
|
+
})
|
|
118
|
+
if (!res.ok) throw new Error('Failed to delete item: ' + res.statusText)
|
|
119
|
+
if (selectedItem.value && selectedItem.value.id === id) {
|
|
120
|
+
selectedItem.value = null
|
|
121
|
+
}
|
|
122
|
+
await fetchAll()
|
|
123
|
+
} catch (err) {
|
|
124
|
+
errorMessage.value = err.message
|
|
125
|
+
} finally {
|
|
126
|
+
loading.value = false
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function patchItem(id, partial) {
|
|
131
|
+
loading.value = true
|
|
132
|
+
errorMessage.value = ''
|
|
133
|
+
try {
|
|
134
|
+
const res = await fetch(`http://localhost:8080/api/items/${id}`, {
|
|
135
|
+
method: 'PATCH',
|
|
136
|
+
headers: { 'Content-Type': 'application/json' },
|
|
137
|
+
body: JSON.stringify(partial)
|
|
138
|
+
})
|
|
139
|
+
if (!res.ok) throw new Error('Failed to patch item: ' + res.statusText)
|
|
140
|
+
await fetchAll()
|
|
141
|
+
} catch (err) {
|
|
142
|
+
errorMessage.value = err.message
|
|
143
|
+
} finally {
|
|
144
|
+
loading.value = false
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function promptPatch(item) {
|
|
149
|
+
const newPrice = prompt('Enter new price:')
|
|
150
|
+
if (newPrice !== null && newPrice !== '') {
|
|
151
|
+
patchItem(item.id, { price: Number(newPrice) })
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function startEdit(item) {
|
|
156
|
+
editForm.id = item.id
|
|
157
|
+
editForm.name = item.name
|
|
158
|
+
editForm.description = item.description || item.describtion || ''
|
|
159
|
+
editForm.price = item.price
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function cancelEdit() {
|
|
163
|
+
editForm.id = ''
|
|
164
|
+
editForm.name = ''
|
|
165
|
+
editForm.description = ''
|
|
166
|
+
editForm.price = 0
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
onMounted(() => {
|
|
170
|
+
fetchAll()
|
|
171
|
+
})
|
|
172
|
+
</script>
|
|
173
|
+
|
|
174
|
+
<template>
|
|
175
|
+
<h2>Vue Fetch CRUD</h2>
|
|
176
|
+
<br>
|
|
177
|
+
|
|
178
|
+
<p v-if="loading">Loading...</p>
|
|
179
|
+
<br v-if="loading">
|
|
180
|
+
|
|
181
|
+
<p v-if="errorMessage">{{ errorMessage }}</p>
|
|
182
|
+
<br v-if="errorMessage">
|
|
183
|
+
|
|
184
|
+
<button @click="fetchAll">Refresh All (GET /api/items)</button>
|
|
185
|
+
<br><br>
|
|
186
|
+
<hr>
|
|
187
|
+
<br>
|
|
188
|
+
|
|
189
|
+
<h3>Create Item (POST /api/items)</h3>
|
|
190
|
+
<br>
|
|
191
|
+
<form @submit.prevent="createItem">
|
|
192
|
+
<label for="create-name">Name:</label>
|
|
193
|
+
<br>
|
|
194
|
+
<input id="create-name" v-model="createForm.name" placeholder="Item Name" required>
|
|
195
|
+
<br><br>
|
|
196
|
+
|
|
197
|
+
<label for="create-desc">Description:</label>
|
|
198
|
+
<br>
|
|
199
|
+
<input id="create-desc" v-model="createForm.description" placeholder="Item Description" required>
|
|
200
|
+
<br><br>
|
|
201
|
+
|
|
202
|
+
<label for="create-price">Price:</label>
|
|
203
|
+
<br>
|
|
204
|
+
<input id="create-price" v-model.number="createForm.price" type="number" placeholder="Item Price" required>
|
|
205
|
+
<br><br>
|
|
206
|
+
|
|
207
|
+
<button type="submit">Create Item</button>
|
|
208
|
+
</form>
|
|
209
|
+
|
|
210
|
+
<br>
|
|
211
|
+
<hr>
|
|
212
|
+
<br>
|
|
213
|
+
|
|
214
|
+
<h3>Update Item (PUT /api/items/:id)</h3>
|
|
215
|
+
<br>
|
|
216
|
+
<form @submit.prevent="updateItem">
|
|
217
|
+
<label for="edit-id">Item ID:</label>
|
|
218
|
+
<br>
|
|
219
|
+
<input id="edit-id" v-model="editForm.id" placeholder="Item ID" required>
|
|
220
|
+
<br><br>
|
|
221
|
+
|
|
222
|
+
<label for="edit-name">Name:</label>
|
|
223
|
+
<br>
|
|
224
|
+
<input id="edit-name" v-model="editForm.name" placeholder="Item Name" required>
|
|
225
|
+
<br><br>
|
|
226
|
+
|
|
227
|
+
<label for="edit-desc">Description:</label>
|
|
228
|
+
<br>
|
|
229
|
+
<input id="edit-desc" v-model="editForm.description" placeholder="Item Description" required>
|
|
230
|
+
<br><br>
|
|
231
|
+
|
|
232
|
+
<label for="edit-price">Price:</label>
|
|
233
|
+
<br>
|
|
234
|
+
<input id="edit-price" v-model.number="editForm.price" type="number" placeholder="Item Price" required>
|
|
235
|
+
<br><br>
|
|
236
|
+
|
|
237
|
+
<button type="submit">Update Item</button>
|
|
238
|
+
<button type="button" @click="cancelEdit">Clear</button>
|
|
239
|
+
</form>
|
|
240
|
+
|
|
241
|
+
<br>
|
|
242
|
+
<hr>
|
|
243
|
+
<br>
|
|
244
|
+
|
|
245
|
+
<h3>Get Item By ID (GET /api/items/:id)</h3>
|
|
246
|
+
<br>
|
|
247
|
+
<input v-model="searchId" placeholder="Enter Item ID">
|
|
248
|
+
<br><br>
|
|
249
|
+
<button @click="fetchById(searchId)">Fetch By ID</button>
|
|
250
|
+
<br><br>
|
|
251
|
+
|
|
252
|
+
<div v-if="selectedItem">
|
|
253
|
+
<h4>Item Details</h4>
|
|
254
|
+
<p>ID: {{ selectedItem.id }}</p>
|
|
255
|
+
<br>
|
|
256
|
+
<p>Name: {{ selectedItem.name }}</p>
|
|
257
|
+
<br>
|
|
258
|
+
<p>Description: {{ selectedItem.description || selectedItem.describtion }}</p>
|
|
259
|
+
<br>
|
|
260
|
+
<p>Price: ${{ selectedItem.price }}</p>
|
|
261
|
+
<br>
|
|
262
|
+
<button @click="selectedItem = null">Close Details</button>
|
|
263
|
+
</div>
|
|
264
|
+
|
|
265
|
+
<br>
|
|
266
|
+
<hr>
|
|
267
|
+
<br>
|
|
268
|
+
|
|
269
|
+
<h3>Items List (GET /api/items)</h3>
|
|
270
|
+
<br>
|
|
271
|
+
|
|
272
|
+
<p v-if="items.length === 0">No items loaded.</p>
|
|
273
|
+
|
|
274
|
+
<ul v-if="items.length > 0">
|
|
275
|
+
<li v-for="item in items" :key="item.id">
|
|
276
|
+
<span>{{ item.name }} - {{ item.description || item.describtion }} - ${{ item.price }} (ID: {{ item.id }})</span>
|
|
277
|
+
<br><br>
|
|
278
|
+
<button @click="fetchById(item.id)">View Details</button>
|
|
279
|
+
<button @click="startEdit(item)">Edit</button>
|
|
280
|
+
<button @click="deleteItem(item.id)">Delete</button>
|
|
281
|
+
<button @click="promptPatch(item)">Patch</button>
|
|
282
|
+
<br><br>
|
|
283
|
+
</li>
|
|
284
|
+
</ul>
|
|
285
|
+
</template>
|
|
@@ -1,41 +1,45 @@
|
|
|
1
|
-
package com.example.crud.controller;
|
|
2
|
-
|
|
3
|
-
import com.example.crud.model.Item;
|
|
4
|
-
import com.example.crud.service.ItemService;
|
|
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/items")
|
|
12
|
-
@CrossOrigin(origins = "*")
|
|
13
|
-
public class ItemController {
|
|
14
|
-
@Autowired
|
|
15
|
-
private ItemService service;
|
|
16
|
-
|
|
17
|
-
@GetMapping
|
|
18
|
-
public List<Item> getAll() {
|
|
19
|
-
return service.getAll();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@GetMapping("/{id}")
|
|
23
|
-
public Item getById(@PathVariable String id) {
|
|
24
|
-
return service.getById(id);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@PostMapping
|
|
28
|
-
public Item create(@RequestBody Item item) {
|
|
29
|
-
return service.create(item);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@PutMapping("/{id}")
|
|
33
|
-
public Item update(@PathVariable String id, @RequestBody Item item) {
|
|
34
|
-
return service.update(id, item);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@DeleteMapping("/{id}")
|
|
38
|
-
public void delete(@PathVariable String id) {
|
|
39
|
-
service.delete(id);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
package com.example.crud.controller;
|
|
2
|
+
|
|
3
|
+
import com.example.crud.model.Item;
|
|
4
|
+
import com.example.crud.service.ItemService;
|
|
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/items")
|
|
12
|
+
@CrossOrigin(origins = "*")
|
|
13
|
+
public class ItemController {
|
|
14
|
+
@Autowired
|
|
15
|
+
private ItemService service;
|
|
16
|
+
|
|
17
|
+
@GetMapping
|
|
18
|
+
public List<Item> getAll() {
|
|
19
|
+
return service.getAll();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@GetMapping("/{id}")
|
|
23
|
+
public Item getById(@PathVariable String id) {
|
|
24
|
+
return service.getById(id);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@PostMapping
|
|
28
|
+
public Item create(@RequestBody Item item) {
|
|
29
|
+
return service.create(item);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@PutMapping("/{id}")
|
|
33
|
+
public Item update(@PathVariable String id, @RequestBody Item item) {
|
|
34
|
+
return service.update(id, item);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@DeleteMapping("/{id}")
|
|
38
|
+
public void delete(@PathVariable String id) {
|
|
39
|
+
service.delete(id);
|
|
40
|
+
}
|
|
41
|
+
@PatchMapping("/{id}")
|
|
42
|
+
public Item patch(@PathVariable String id, @RequestBody Item item) {
|
|
43
|
+
return service.patch(id, item);
|
|
44
|
+
}
|
|
45
|
+
}
|