fix(api): align frontend API client with backend endpoints

- Fix addDocumentTags to use POST /documents/:id/tags (was using PUT)
- Add getDocumentsByTag(tag) -> GET /tags/:tag
- Add getLibraryTree(id) -> GET /libraries/:id/tree
- Add getLibraryDocuments(id) -> GET /libraries/:id/documents
- Add getProjectDocuments(id) -> GET /projects/:id/documents
- Add getFolder(id) -> GET /folders/:id
- Add getFolderDocuments(id) -> GET /folders/:id/documents
- Add getFolderTree(id) -> GET /folders/:id/tree
- Add api-endpoints.md with full API documentation
- Remove duplicate/unused dead code blocks
This commit is contained in:
Hiro
2026-03-28 17:12:38 +00:00
parent 5b234cb819
commit 007c51a98f
2 changed files with 472 additions and 12 deletions

View File

@@ -36,7 +36,7 @@ class ApiClient {
}
const response = await fetch(`${API_BASE}${path}`, options);
if (!response.ok) {
const error = await response.json().catch(() => ({ message: 'Request failed' }));
throw new Error(error.message || `HTTP ${response.status}`);
@@ -50,7 +50,7 @@ class ApiClient {
put(path, body) { return this.request('PUT', path, body); }
delete(path) { return this.request('DELETE', path); }
// Auth
// ===== Auth =====
async login(token) {
try {
this.setToken(token); // Set token BEFORE making request
@@ -62,7 +62,7 @@ class ApiClient {
}
}
// Documents
// ===== Documents =====
getDocuments(params = {}) {
const query = new URLSearchParams(params).toString();
return this.get(`/documents${query ? '?' + query : ''}`);
@@ -90,7 +90,25 @@ class ApiClient {
}).then(r => r.text());
}
// Libraries
addDocumentTags(documentId, tags) {
return this.post(`/documents/${documentId}/tags`, { tags });
}
moveDocumentToFolder(documentId, folderId) {
return this.put(`/documents/${documentId}`, { folderId });
}
// ===== Tags =====
getTags() {
return this.get('/tags');
}
// GET /tags/:tag - get documents by tag
getDocumentsByTag(tag) {
return this.get(`/tags/${encodeURIComponent(tag)}`);
}
// ===== Libraries =====
getLibraries() {
return this.get('/libraries');
}
@@ -111,12 +129,17 @@ class ApiClient {
return this.delete(`/libraries/${id}`);
}
// Tags
getTags() {
return this.get('/tags');
// GET /libraries/:id/tree
getLibraryTree(id) {
return this.get(`/libraries/${id}/tree`);
}
// ===== PROJECTS =====
// GET /libraries/:id/documents
getLibraryDocuments(id) {
return this.get(`/libraries/${id}/documents`);
}
// ===== Projects =====
getProjects() {
return this.get('/projects');
}
@@ -137,17 +160,27 @@ class ApiClient {
return this.delete(`/projects/${id}`);
}
// GET /projects/:id/tree
getProjectTree(id) {
return this.get(`/projects/${id}/tree`);
}
// ===== FOLDERS =====
// GET /projects/:id/documents
getProjectDocuments(id) {
return this.get(`/projects/${id}/documents`);
}
// ===== Folders =====
getFolders(projectId, parentId = null) {
const params = new URLSearchParams({ projectId });
if (parentId) params.append('parentId', parentId);
return this.get(`/folders?${params.toString()}`);
}
getFolder(id) {
return this.get(`/folders/${id}`);
}
createFolder(data) {
return this.post('/folders', data);
}
@@ -160,9 +193,14 @@ class ApiClient {
return this.delete(`/folders/${id}`);
}
// ===== Move document to folder =====
moveDocumentToFolder(documentId, folderId) {
return this.put(`/documents/${documentId}`, { folderId });
// GET /folders/:id/documents
getFolderDocuments(id) {
return this.get(`/folders/${id}/documents`);
}
// GET /folders/:id/tree
getFolderTree(id) {
return this.get(`/folders/${id}/tree`);
}
}