All files / frontend/src/services/api websdr.ts

25% Statements 8/32
100% Branches 0/0
0% Functions 0/4
25% Lines 8/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63                  1x                                                                                         1x 1x 1x 1x 1x 1x   1x  
/**
 * WebSDR API Service
 * 
 * Handles all WebSDR-related API calls:
 * - List WebSDR receivers
 * - Check WebSDR health status
 * - Get WebSDR configuration
 */
 
import api from '@/lib/api';
import type { WebSDRConfig, WebSDRHealthStatus } from './types';
 
/**
 * Get list of all configured WebSDR receivers
 */
export async function getWebSDRs(): Promise<WebSDRConfig[]> {
    console.log('📡 WebSDRService.getWebSDRs(): calling GET /api/v1/acquisition/websdrs');
    const response = await api.get<WebSDRConfig[]>('/api/v1/acquisition/websdrs');
    console.log('✅ WebSDRService.getWebSDRs(): ricevuti', response.data.length, 'WebSDRs');
    return response.data;
}
 
/**
 * Check health status of all WebSDR receivers
 */
export async function checkWebSDRHealth(): Promise<Record<number, WebSDRHealthStatus>> {
    console.log('🏥 WebSDRService.checkWebSDRHealth(): calling GET /api/v1/acquisition/websdrs/health');
    const response = await api.get<Record<number, WebSDRHealthStatus>>('/api/v1/acquisition/websdrs/health');
    console.log('✅ WebSDRService.checkWebSDRHealth(): ricevuto health status');
    return response.data;
}
 
/**
 * Get configuration for specific WebSDR
 */
export async function getWebSDRConfig(id: number): Promise<WebSDRConfig> {
    const websdrs = await getWebSDRs();
    const websdr = websdrs.find(w => w.id === id);
 
    if (!websdr) {
        throw new Error(`WebSDR with id ${id} not found`);
    }
 
    return websdr;
}
 
/**
 * Get active WebSDRs only
 */
export async function getActiveWebSDRs(): Promise<WebSDRConfig[]> {
    const websdrs = await getWebSDRs();
    return websdrs.filter(w => w.is_active);
}
 
const webSDRService = {
    getWebSDRs,
    checkWebSDRHealth,
    getWebSDRConfig,
    getActiveWebSDRs,
};
 
export default webSDRService;