| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import { KnowledgeGroup, CreateGroupData, UpdateGroupData } from '../types';
- const API_BASE = '/api';
- export const knowledgeGroupService = {
- // すべてのグループを取得
- async getGroups(): Promise<KnowledgeGroup[]> {
- const response = await fetch(`${API_BASE}/knowledge-groups`, {
- headers: {
- 'Authorization': `Bearer ${localStorage.getItem('authToken')}`,
- },
- });
- if (!response.ok) throw new Error('Failed to fetch groups');
- return response.json();
- },
- // グループを作成
- async createGroup(data: CreateGroupData): Promise<KnowledgeGroup> {
- const response = await fetch(`${API_BASE}/knowledge-groups`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': `Bearer ${localStorage.getItem('authToken')}`,
- },
- body: JSON.stringify(data),
- });
- if (!response.ok) throw new Error('Failed to create group');
- return response.json();
- },
- // グループを更新
- async updateGroup(id: string, data: UpdateGroupData): Promise<KnowledgeGroup> {
- const response = await fetch(`${API_BASE}/knowledge-groups/${id}`, {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': `Bearer ${localStorage.getItem('authToken')}`,
- },
- body: JSON.stringify(data),
- });
- if (!response.ok) throw new Error('Failed to update group');
- return response.json();
- },
- // グループを削除
- async deleteGroup(id: string): Promise<void> {
- const response = await fetch(`${API_BASE}/knowledge-groups/${id}`, {
- method: 'DELETE',
- headers: {
- 'Authorization': `Bearer ${localStorage.getItem('authToken')}`,
- },
- });
- if (!response.ok) throw new Error('Failed to delete group');
- },
- // グループ内のファイルを取得
- async getGroupFiles(id: string): Promise<any[]> {
- const response = await fetch(`${API_BASE}/knowledge-groups/${id}/files`, {
- headers: {
- 'Authorization': `Bearer ${localStorage.getItem('authToken')}`,
- },
- });
- if (!response.ok) throw new Error('Failed to fetch group files');
- const data = await response.json();
- return data.files;
- },
- // ファイルをグループに追加
- async addFileToGroups(fileId: string, groupIds: string[]): Promise<void> {
- const response = await fetch(`${API_BASE}/knowledge-bases/${fileId}/groups`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': `Bearer ${localStorage.getItem('authToken')}`,
- },
- body: JSON.stringify({ groupIds }),
- });
- if (!response.ok) throw new Error('Failed to add file to groups');
- },
- // グループからファイルを削除
- async removeFileFromGroup(fileId: string, groupId: string): Promise<void> {
- const response = await fetch(`${API_BASE}/knowledge-bases/${fileId}/groups/${groupId}`, {
- method: 'DELETE',
- headers: {
- 'Authorization': `Bearer ${localStorage.getItem('authToken')}`,
- },
- });
- if (!response.ok) throw new Error('Failed to remove file from group');
- },
- };
|