feat(v1): unify API response, validation, exception handling and tests

This commit is contained in:
likingcode
2026-03-08 14:40:30 +00:00
parent 539dc41868
commit 6a4c6a369a
10 changed files with 216 additions and 73 deletions

View File

@@ -143,7 +143,8 @@ public class UserController {
// 加载用户列表
async function loadUsers() {
const res = await fetch('/api/users');
const users = await res.json();
const payload = await res.json();
const users = payload.data || [];
const tbody = document.querySelector('#userTable tbody');
tbody.innerHTML = users.map(u => `
<tr>
@@ -196,7 +197,7 @@ public class UserController {
await fetch(`/api/users/${id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ...user, id: parseInt(id) })
body: JSON.stringify(user)
});
} else {
await fetch('/api/users', {