Files
xingrin/frontend/services/engine.service.ts
yyhuni f328474404 feat(frontend): add comprehensive mock data infrastructure for services
- Add mock data modules for auth, engines, notifications, scheduled-scans, and workers
- Implement mock authentication data with user profiles and login/logout responses
- Create mock scan engine configurations with multiple predefined scanning profiles
- Add mock notification system with various severity levels and categories
- Implement mock scheduled scan data with cron expressions and run history
- Add mock worker node data with status and performance metrics
- Update service layer to integrate with new mock data infrastructure
- Provide helper functions for filtering and paginating mock data
- Enable frontend development and testing without backend API dependency
2026-01-03 07:59:20 +08:00

71 lines
1.6 KiB
TypeScript

import apiClient from '@/lib/api-client'
import type { ScanEngine } from '@/types/engine.types'
import { USE_MOCK, mockDelay, getMockEngines, getMockEngineById } from '@/mock'
/**
* Engine API service
*/
/**
* Get engine list
*/
export async function getEngines(): Promise<ScanEngine[]> {
if (USE_MOCK) {
await mockDelay()
return getMockEngines()
}
// Engines are usually not many, get all
const response = await apiClient.get('/engines/', {
params: { pageSize: 1000 }
})
// Backend returns paginated data: { results: [...], total, page, pageSize, totalPages }
return response.data.results || response.data
}
/**
* Get engine details
*/
export async function getEngine(id: number): Promise<ScanEngine> {
if (USE_MOCK) {
await mockDelay()
const engine = getMockEngineById(id)
if (!engine) throw new Error('Engine not found')
return engine
}
const response = await apiClient.get(`/engines/${id}/`)
return response.data
}
/**
* Create engine
*/
export async function createEngine(data: {
name: string
configuration: string
}): Promise<ScanEngine> {
const response = await apiClient.post('/engines/', data)
return response.data
}
/**
* Update engine
*/
export async function updateEngine(
id: number,
data: Partial<{
name: string
configuration: string
}>
): Promise<ScanEngine> {
const response = await apiClient.patch(`/engines/${id}/`, data)
return response.data
}
/**
* Delete engine
*/
export async function deleteEngine(id: number): Promise<void> {
await apiClient.delete(`/engines/${id}/`)
}