|
|
import apiClient from './apiClient'; |
|
|
|
|
|
class SourceService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getAll() { |
|
|
try { |
|
|
const response = await apiClient.get('/sources'); |
|
|
|
|
|
if (import.meta.env.VITE_NODE_ENV === 'development') { |
|
|
console.log('π° [Source] Retrieved sources:', response.data); |
|
|
} |
|
|
|
|
|
return response; |
|
|
} catch (error) { |
|
|
if (import.meta.env.VITE_NODE_ENV === 'development') { |
|
|
console.error('π° [Source] Get sources error:', error.response?.data || error.message); |
|
|
} |
|
|
throw error; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async analyzeKeyword(keywordData) { |
|
|
try { |
|
|
const response = await apiClient.post('/sources/keyword-analysis', { |
|
|
keyword: keywordData.keyword, |
|
|
date_range: keywordData.date_range || 'monthly' |
|
|
}); |
|
|
|
|
|
if (import.meta.env.VITE_NODE_ENV === 'development') { |
|
|
console.log('π° [Source] Keyword analysis result:', response.data); |
|
|
} |
|
|
|
|
|
return response; |
|
|
} catch (error) { |
|
|
if (import.meta.env.VITE_NODE_ENV === 'development') { |
|
|
console.error('π° [Source] Keyword analysis error:', error.response?.data || error.message); |
|
|
} |
|
|
throw error; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async analyzeKeywordPattern(keywordData) { |
|
|
try { |
|
|
const response = await apiClient.post('/sources/keyword-frequency-pattern', { |
|
|
keyword: keywordData.keyword |
|
|
}); |
|
|
|
|
|
if (import.meta.env.VITE_NODE_ENV === 'development') { |
|
|
console.log('π° [Source] Keyword frequency pattern analysis result:', response.data); |
|
|
} |
|
|
|
|
|
return response; |
|
|
} catch (error) { |
|
|
if (import.meta.env.VITE_NODE_ENV === 'development') { |
|
|
console.error('π° [Source] Keyword frequency pattern analysis error:', error.response?.data || error.message); |
|
|
} |
|
|
throw error; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async create(sourceData) { |
|
|
try { |
|
|
const response = await apiClient.post('/sources', { |
|
|
source: sourceData.source |
|
|
}); |
|
|
|
|
|
if (import.meta.env.VITE_NODE_ENV === 'development') { |
|
|
console.log('π° [Source] Source created:', response.data); |
|
|
} |
|
|
|
|
|
return response; |
|
|
} catch (error) { |
|
|
if (import.meta.env.VITE_NODE_ENV === 'development') { |
|
|
console.error('π° [Source] Create source error:', error.response?.data || error.message); |
|
|
} |
|
|
throw error; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async delete(sourceId) { |
|
|
try { |
|
|
const response = await apiClient.delete(`/sources/${sourceId}`); |
|
|
|
|
|
if (import.meta.env.VITE_NODE_ENV === 'development') { |
|
|
console.log('π° [Source] Source deleted:', response.data); |
|
|
} |
|
|
|
|
|
return response; |
|
|
} catch (error) { |
|
|
if (import.meta.env.VITE_NODE_ENV === 'development') { |
|
|
console.error('π° [Source] Delete source error:', error.response?.data || error.message); |
|
|
} |
|
|
throw error; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
export default new SourceService(); |