import { SearchHistoryItem, SearchHistoryDetail } from '../types'; const API_BASE = '/api'; export const searchHistoryService = { // 検索履歴リストの取得 async getHistories(page: number = 1, limit: number = 20): Promise<{ histories: SearchHistoryItem[]; total: number; page: number; limit: number; }> { const response = await fetch(`${API_BASE}/search-history?page=${page}&limit=${limit}`, { headers: { 'Authorization': `Bearer ${localStorage.getItem('authToken')}`, }, }); if (!response.ok) throw new Error('Failed to fetch search histories'); return response.json(); }, // 検索履歴詳細の取得 async getHistoryDetail(id: string): Promise { const response = await fetch(`${API_BASE}/search-history/${id}`, { headers: { 'Authorization': `Bearer ${localStorage.getItem('authToken')}`, }, }); if (!response.ok) throw new Error('Failed to fetch search history detail'); return response.json(); }, // 検索履歴の作成 async createHistory(title: string, selectedGroups?: string[]): Promise<{ id: string }> { const response = await fetch(`${API_BASE}/search-history`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('authToken')}`, }, body: JSON.stringify({ title, selectedGroups }), }); if (!response.ok) throw new Error('Failed to create search history'); return response.json(); }, // 検索履歴の削除 async deleteHistory(id: string): Promise { const response = await fetch(`${API_BASE}/search-history/${id}`, { method: 'DELETE', headers: { 'Authorization': `Bearer ${localStorage.getItem('authToken')}`, }, }); if (!response.ok) throw new Error('Failed to delete search history'); }, };