|
|
|
|
|
|
|
|
import axios from 'axios'; |
|
|
import type { |
|
|
UploadResponse, |
|
|
GenerateResponse, |
|
|
ChatResponse, |
|
|
GeoJSONFeature |
|
|
} from '../types'; |
|
|
|
|
|
const API_BASE = import.meta.env.VITE_API_URL || 'http://localhost:8000'; |
|
|
|
|
|
const api = axios.create({ |
|
|
baseURL: API_BASE, |
|
|
headers: { |
|
|
'Content-Type': 'application/json', |
|
|
}, |
|
|
}); |
|
|
|
|
|
export const apiService = { |
|
|
|
|
|
async health() { |
|
|
const response = await api.get('/api/health'); |
|
|
return response.data; |
|
|
}, |
|
|
|
|
|
|
|
|
async getSampleData(): Promise<GeoJSONFeature> { |
|
|
const response = await api.get('/api/sample-data'); |
|
|
return response.data; |
|
|
}, |
|
|
|
|
|
|
|
|
async uploadBoundary(geojson: GeoJSONFeature): Promise<UploadResponse> { |
|
|
const response = await api.post('/api/upload-boundary-json', { |
|
|
geojson: geojson, |
|
|
}); |
|
|
return response.data; |
|
|
}, |
|
|
|
|
|
|
|
|
async uploadBoundaryFile(file: File): Promise<UploadResponse> { |
|
|
const formData = new FormData(); |
|
|
formData.append('file', file); |
|
|
|
|
|
|
|
|
const filename = file.name.toLowerCase(); |
|
|
const isDxfOrDwg = filename.endsWith('.dxf') || filename.endsWith('.dwg'); |
|
|
const endpoint = isDxfOrDwg ? '/api/upload-dxf' : '/api/upload-boundary'; |
|
|
|
|
|
const response = await api.post(endpoint, formData, { |
|
|
headers: { 'Content-Type': 'multipart/form-data' }, |
|
|
}); |
|
|
return response.data; |
|
|
}, |
|
|
|
|
|
|
|
|
async generateLayouts( |
|
|
sessionId: string, |
|
|
targetPlots: number = 8, |
|
|
setback: number = 50 |
|
|
): Promise<GenerateResponse> { |
|
|
const response = await api.post('/api/generate-layouts', { |
|
|
session_id: sessionId, |
|
|
target_plots: targetPlots, |
|
|
setback: setback, |
|
|
}); |
|
|
return response.data; |
|
|
}, |
|
|
|
|
|
|
|
|
async chat(sessionId: string, message: string): Promise<ChatResponse> { |
|
|
const response = await api.post('/api/chat', { |
|
|
session_id: sessionId, |
|
|
message: message, |
|
|
}); |
|
|
return response.data; |
|
|
}, |
|
|
|
|
|
|
|
|
async exportDxf(sessionId: string, optionId: number): Promise<Blob> { |
|
|
const response = await api.post('/api/export-dxf', { |
|
|
session_id: sessionId, |
|
|
option_id: optionId, |
|
|
}, { |
|
|
responseType: 'blob', |
|
|
}); |
|
|
return response.data; |
|
|
}, |
|
|
|
|
|
|
|
|
async exportAllDxf(sessionId: string): Promise<Blob> { |
|
|
const formData = new FormData(); |
|
|
formData.append('session_id', sessionId); |
|
|
|
|
|
const response = await api.post('/api/export-all-dxf', formData, { |
|
|
responseType: 'blob', |
|
|
}); |
|
|
return response.data; |
|
|
}, |
|
|
}; |
|
|
|
|
|
export default apiService; |
|
|
|