@veristone/nuxt-v-app 0.1.0 → 0.2.0
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/app/components/V/A/Crud/Create.vue +149 -0
- package/app/components/V/A/Crud/Delete.vue +148 -0
- package/app/components/V/A/Crud/Update.vue +171 -0
- package/app/composables/useVCrud.ts +58 -35
- package/app/composables/useVFetch.ts +27 -2
- package/app/layouts/default.vue +76 -68
- package/app/pages/playground/crud.vue +936 -0
- package/app/pages/playground/index.vue +6 -0
- package/app/pages/test-api-auth.vue +223 -0
- package/package.json +1 -1
|
@@ -46,6 +46,12 @@ const categories = [
|
|
|
46
46
|
to: '/playground/base',
|
|
47
47
|
icon: 'i-lucide-box'
|
|
48
48
|
},
|
|
49
|
+
{
|
|
50
|
+
title: 'CRUD Components',
|
|
51
|
+
description: 'VACrudCreate, VACrudUpdate, and VACrudDelete for modal-based CRUD operations.',
|
|
52
|
+
to: '/playground/crud',
|
|
53
|
+
icon: 'i-lucide-database'
|
|
54
|
+
},
|
|
49
55
|
{
|
|
50
56
|
title: 'Buttons',
|
|
51
57
|
description: 'Action buttons for CRUD operations, navigation, and data export.',
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
const endpoint = 'http://localhost:3002/admin/portfolio/loans'
|
|
3
|
+
|
|
4
|
+
const crud = useVCrud(endpoint, { immediate: false })
|
|
5
|
+
|
|
6
|
+
// Store results for each method
|
|
7
|
+
const results = ref<Record<string, any>>({})
|
|
8
|
+
const loading = ref<Record<string, boolean>>({})
|
|
9
|
+
const errors = ref<Record<string, string>>({})
|
|
10
|
+
|
|
11
|
+
// Test GET (findAll)
|
|
12
|
+
const testGet = async () => {
|
|
13
|
+
loading.value.get = true
|
|
14
|
+
errors.value.get = ''
|
|
15
|
+
try {
|
|
16
|
+
const data = await crud.findAll()
|
|
17
|
+
results.value.get = data
|
|
18
|
+
} catch (err: any) {
|
|
19
|
+
errors.value.get = err.message || 'Failed'
|
|
20
|
+
} finally {
|
|
21
|
+
loading.value.get = false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Test GET single (findOne) - using first ID if available
|
|
26
|
+
const testGetOne = async () => {
|
|
27
|
+
const testId = 'test-id-123'
|
|
28
|
+
loading.value.getOne = true
|
|
29
|
+
errors.value.getOne = ''
|
|
30
|
+
try {
|
|
31
|
+
const data = await crud.findOne(testId)
|
|
32
|
+
results.value.getOne = data
|
|
33
|
+
} catch (err: any) {
|
|
34
|
+
errors.value.getOne = err.message || 'Failed'
|
|
35
|
+
} finally {
|
|
36
|
+
loading.value.getOne = false
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Test POST (create)
|
|
41
|
+
const testPost = async () => {
|
|
42
|
+
loading.value.post = true
|
|
43
|
+
errors.value.post = ''
|
|
44
|
+
try {
|
|
45
|
+
const data = await crud.create({ name: 'Test Loan', amount: 1000 })
|
|
46
|
+
results.value.post = data
|
|
47
|
+
} catch (err: any) {
|
|
48
|
+
errors.value.post = err.message || 'Failed'
|
|
49
|
+
} finally {
|
|
50
|
+
loading.value.post = false
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Test PUT (update)
|
|
55
|
+
const testPut = async () => {
|
|
56
|
+
const testId = 'test-id-123'
|
|
57
|
+
loading.value.put = true
|
|
58
|
+
errors.value.put = ''
|
|
59
|
+
try {
|
|
60
|
+
const data = await crud.update(testId, { name: 'Updated Loan', amount: 2000 })
|
|
61
|
+
results.value.put = data
|
|
62
|
+
} catch (err: any) {
|
|
63
|
+
errors.value.put = err.message || 'Failed'
|
|
64
|
+
} finally {
|
|
65
|
+
loading.value.put = false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Test PATCH
|
|
70
|
+
const testPatch = async () => {
|
|
71
|
+
const testId = 'test-id-123'
|
|
72
|
+
loading.value.patch = true
|
|
73
|
+
errors.value.patch = ''
|
|
74
|
+
try {
|
|
75
|
+
const data = await crud.patch(testId, { amount: 1500 })
|
|
76
|
+
results.value.patch = data
|
|
77
|
+
} catch (err: any) {
|
|
78
|
+
errors.value.patch = err.message || 'Failed'
|
|
79
|
+
} finally {
|
|
80
|
+
loading.value.patch = false
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Test DELETE
|
|
85
|
+
const testDelete = async () => {
|
|
86
|
+
const testId = 'test-id-123'
|
|
87
|
+
loading.value.delete = true
|
|
88
|
+
errors.value.delete = ''
|
|
89
|
+
try {
|
|
90
|
+
const data = await crud.remove(testId)
|
|
91
|
+
results.value.delete = data
|
|
92
|
+
} catch (err: any) {
|
|
93
|
+
errors.value.delete = err.message || 'Failed'
|
|
94
|
+
} finally {
|
|
95
|
+
loading.value.delete = false
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Run all tests
|
|
100
|
+
const testAll = async () => {
|
|
101
|
+
await testGet()
|
|
102
|
+
await testGetOne()
|
|
103
|
+
await testPost()
|
|
104
|
+
await testPut()
|
|
105
|
+
await testPatch()
|
|
106
|
+
await testDelete()
|
|
107
|
+
}
|
|
108
|
+
</script>
|
|
109
|
+
|
|
110
|
+
<template>
|
|
111
|
+
<div class="p-8 space-y-8">
|
|
112
|
+
<div class="flex items-center justify-between">
|
|
113
|
+
<h1 class="text-2xl font-bold">API Methods Test</h1>
|
|
114
|
+
<button
|
|
115
|
+
@click="testAll"
|
|
116
|
+
class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
|
|
117
|
+
>
|
|
118
|
+
Test All Methods
|
|
119
|
+
</button>
|
|
120
|
+
</div>
|
|
121
|
+
|
|
122
|
+
<!-- GET (findAll) -->
|
|
123
|
+
<div class="border p-4 rounded">
|
|
124
|
+
<div class="flex items-center justify-between mb-4">
|
|
125
|
+
<h2 class="text-xl font-semibold">GET (findAll)</h2>
|
|
126
|
+
<button
|
|
127
|
+
@click="testGet"
|
|
128
|
+
:disabled="loading.get"
|
|
129
|
+
class="px-3 py-1 bg-green-500 text-white rounded hover:bg-green-600 disabled:opacity-50"
|
|
130
|
+
>
|
|
131
|
+
{{ loading.get ? 'Loading...' : 'Test GET' }}
|
|
132
|
+
</button>
|
|
133
|
+
</div>
|
|
134
|
+
<div v-if="errors.get" class="text-red-500 mb-2">Error: {{ errors.get }}</div>
|
|
135
|
+
<pre v-if="results.get" class="text-sm bg-gray-100 p-4 rounded overflow-auto max-h-48">{{ JSON.stringify(results.get, null, 2) }}</pre>
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
<!-- GET One (findOne) -->
|
|
139
|
+
<div class="border p-4 rounded">
|
|
140
|
+
<div class="flex items-center justify-between mb-4">
|
|
141
|
+
<h2 class="text-xl font-semibold">GET Single (findOne)</h2>
|
|
142
|
+
<button
|
|
143
|
+
@click="testGetOne"
|
|
144
|
+
:disabled="loading.getOne"
|
|
145
|
+
class="px-3 py-1 bg-green-500 text-white rounded hover:bg-green-600 disabled:opacity-50"
|
|
146
|
+
>
|
|
147
|
+
{{ loading.getOne ? 'Loading...' : 'Test GET One' }}
|
|
148
|
+
</button>
|
|
149
|
+
</div>
|
|
150
|
+
<div class="text-sm text-gray-500 mb-2">Testing with ID: test-id-123</div>
|
|
151
|
+
<div v-if="errors.getOne" class="text-red-500 mb-2">Error: {{ errors.getOne }}</div>
|
|
152
|
+
<pre v-if="results.getOne" class="text-sm bg-gray-100 p-4 rounded overflow-auto max-h-48">{{ JSON.stringify(results.getOne, null, 2) }}</pre>
|
|
153
|
+
</div>
|
|
154
|
+
|
|
155
|
+
<!-- POST (create) -->
|
|
156
|
+
<div class="border p-4 rounded">
|
|
157
|
+
<div class="flex items-center justify-between mb-4">
|
|
158
|
+
<h2 class="text-xl font-semibold">POST (create)</h2>
|
|
159
|
+
<button
|
|
160
|
+
@click="testPost"
|
|
161
|
+
:disabled="loading.post"
|
|
162
|
+
class="px-3 py-1 bg-blue-500 text-white rounded hover:bg-blue-600 disabled:opacity-50"
|
|
163
|
+
>
|
|
164
|
+
{{ loading.post ? 'Loading...' : 'Test POST' }}
|
|
165
|
+
</button>
|
|
166
|
+
</div>
|
|
167
|
+
<div class="text-sm text-gray-500 mb-2">Payload: { name: 'Test Loan', amount: 1000 }</div>
|
|
168
|
+
<div v-if="errors.post" class="text-red-500 mb-2">Error: {{ errors.post }}</div>
|
|
169
|
+
<pre v-if="results.post" class="text-sm bg-gray-100 p-4 rounded overflow-auto max-h-48">{{ JSON.stringify(results.post, null, 2) }}</pre>
|
|
170
|
+
</div>
|
|
171
|
+
|
|
172
|
+
<!-- PUT (update) -->
|
|
173
|
+
<div class="border p-4 rounded">
|
|
174
|
+
<div class="flex items-center justify-between mb-4">
|
|
175
|
+
<h2 class="text-xl font-semibold">PUT (update)</h2>
|
|
176
|
+
<button
|
|
177
|
+
@click="testPut"
|
|
178
|
+
:disabled="loading.put"
|
|
179
|
+
class="px-3 py-1 bg-yellow-500 text-white rounded hover:bg-yellow-600 disabled:opacity-50"
|
|
180
|
+
>
|
|
181
|
+
{{ loading.put ? 'Loading...' : 'Test PUT' }}
|
|
182
|
+
</button>
|
|
183
|
+
</div>
|
|
184
|
+
<div class="text-sm text-gray-500 mb-2">Testing with ID: test-id-123 | Payload: { name: 'Updated Loan', amount: 2000 }</div>
|
|
185
|
+
<div v-if="errors.put" class="text-red-500 mb-2">Error: {{ errors.put }}</div>
|
|
186
|
+
<pre v-if="results.put" class="text-sm bg-gray-100 p-4 rounded overflow-auto max-h-48">{{ JSON.stringify(results.put, null, 2) }}</pre>
|
|
187
|
+
</div>
|
|
188
|
+
|
|
189
|
+
<!-- PATCH -->
|
|
190
|
+
<div class="border p-4 rounded">
|
|
191
|
+
<div class="flex items-center justify-between mb-4">
|
|
192
|
+
<h2 class="text-xl font-semibold">PATCH</h2>
|
|
193
|
+
<button
|
|
194
|
+
@click="testPatch"
|
|
195
|
+
:disabled="loading.patch"
|
|
196
|
+
class="px-3 py-1 bg-purple-500 text-white rounded hover:bg-purple-600 disabled:opacity-50"
|
|
197
|
+
>
|
|
198
|
+
{{ loading.patch ? 'Loading...' : 'Test PATCH' }}
|
|
199
|
+
</button>
|
|
200
|
+
</div>
|
|
201
|
+
<div class="text-sm text-gray-500 mb-2">Testing with ID: test-id-123 | Payload: { amount: 1500 }</div>
|
|
202
|
+
<div v-if="errors.patch" class="text-red-500 mb-2">Error: {{ errors.patch }}</div>
|
|
203
|
+
<pre v-if="results.patch" class="text-sm bg-gray-100 p-4 rounded overflow-auto max-h-48">{{ JSON.stringify(results.patch, null, 2) }}</pre>
|
|
204
|
+
</div>
|
|
205
|
+
|
|
206
|
+
<!-- DELETE -->
|
|
207
|
+
<div class="border p-4 rounded">
|
|
208
|
+
<div class="flex items-center justify-between mb-4">
|
|
209
|
+
<h2 class="text-xl font-semibold">DELETE (remove)</h2>
|
|
210
|
+
<button
|
|
211
|
+
@click="testDelete"
|
|
212
|
+
:disabled="loading.delete"
|
|
213
|
+
class="px-3 py-1 bg-red-500 text-white rounded hover:bg-red-600 disabled:opacity-50"
|
|
214
|
+
>
|
|
215
|
+
{{ loading.delete ? 'Loading...' : 'Test DELETE' }}
|
|
216
|
+
</button>
|
|
217
|
+
</div>
|
|
218
|
+
<div class="text-sm text-gray-500 mb-2">Testing with ID: test-id-123</div>
|
|
219
|
+
<div v-if="errors.delete" class="text-red-500 mb-2">Error: {{ errors.delete }}</div>
|
|
220
|
+
<pre v-if="results.delete" class="text-sm bg-gray-100 p-4 rounded overflow-auto max-h-48">{{ JSON.stringify(results.delete, null, 2) }}</pre>
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
223
|
+
</template>
|