add sqllite

This commit is contained in:
2026-02-06 15:35:54 +09:00
parent e7b7414d73
commit 921455749e
9 changed files with 2745 additions and 26 deletions

47
services/api.ts Normal file
View 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);
}
}
};