add sqllite
This commit is contained in:
47
services/api.ts
Normal file
47
services/api.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
import { WiFiHotspot } from '../types';
|
||||
|
||||
const API_Base_URL = 'http://localhost:3000/api/markers';
|
||||
|
||||
export const apiService = {
|
||||
getHotspots: async (): Promise<WiFiHotspot[]> => {
|
||||
try {
|
||||
const response = await fetch(API_Base_URL);
|
||||
if (!response.ok) throw new Error('Failed to fetch markers');
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (e) {
|
||||
console.error("Failed to load hotspots from API", e);
|
||||
return [];
|
||||
}
|
||||
},
|
||||
|
||||
saveHotspot: async (hotspot: WiFiHotspot): Promise<void> => {
|
||||
try {
|
||||
const response = await fetch(API_Base_URL, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(hotspot),
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to save marker');
|
||||
// Trigger a storage event to refresh UI if needed (keeping compatibility)
|
||||
window.dispatchEvent(new Event('storage_updated'));
|
||||
} catch (e) {
|
||||
console.error("Failed to save hotspot", e);
|
||||
}
|
||||
},
|
||||
|
||||
deleteHotspot: async (id: string): Promise<void> => {
|
||||
try {
|
||||
const response = await fetch(`${API_Base_URL}/${id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to delete marker');
|
||||
window.dispatchEvent(new Event('storage_updated'));
|
||||
} catch (e) {
|
||||
console.error("Failed to delete hotspot", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user