15
16// Initialize database endpoint
17app.get("/api/init", async (c) => {
18 try {
19 await runMigrations();
24});
25
26// API routes
27app.route("/api/events", eventsRouter);
28app.route("/api/todos", todosRouter);
29
30// Dashboard data endpoint
31app.get("/api/dashboard", async (c) => {
32 try {
33 // Try to initialize database if not already done
102 html = html.replace("</head>", `${dataScript}</head>`);
103 } catch (dataError) {
104 console.log("Could not load initial data, app will load it via API:", dataError.message);
105 // App will load data via API instead
106 }
107
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import type { ScheduleEvent, ApiResponse } from "../../shared/types.ts";
3import * as queries from "../database/queries.ts";
4
9 try {
10 const events = await queries.getEvents();
11 return c.json({ success: true, data: events } as ApiResponse<ScheduleEvent[]>);
12 } catch (error) {
13 return c.json({ success: false, error: error.message }, 500);
26
27 const events = await queries.getEventsByDateRange(startDate, endDate);
28 return c.json({ success: true, data: events } as ApiResponse<ScheduleEvent[]>);
29 } catch (error) {
30 return c.json({ success: false, error: error.message }, 500);
43
44 const event = await queries.createEvent(eventData);
45 return c.json({ success: true, data: event } as ApiResponse<ScheduleEvent>, 201);
46 } catch (error) {
47 return c.json({ success: false, error: error.message }, 500);
60 }
61
62 return c.json({ success: true, data: event } as ApiResponse<ScheduleEvent>);
63 } catch (error) {
64 return c.json({ success: false, error: error.message }, 500);
76 }
77
78 return c.json({ success: true } as ApiResponse<null>);
79 } catch (error) {
80 return c.json({ success: false, error: error.message }, 500);
38
39 try {
40 const url = event ? `/api/events/${event.id}` : '/api/events';
41 const method = event ? 'PUT' : 'POST';
42
24 const endDate = getViewEndDate();
25
26 const response = await fetch(`/api/events/range?start=${startDate.toISOString()}&end=${endDate.toISOString()}`);
27 const result = await response.json();
28
109
110 try {
111 const response = await fetch(`/api/events/${eventId}`, {
112 method: 'DELETE'
113 });
354 key={mode}
355 onClick={() => setViewMode(mode)}
356 className={`px-3 py-1 text-sm rounded capitalize ${
357 viewMode === mode
358 ? 'bg-blue-600 text-white'
32 try {
33 setLoading(true);
34 const response = await fetch('/api/dashboard');
35 const result = await response.json();
36 if (result.success) {
75 const toggleTodoComplete = async (todo: TodoItem) => {
76 try {
77 const response = await fetch(`/api/todos/${todo.id}/toggle`, {
78 method: 'PATCH'
79 });
300
301 try {
302 const url = editingTodo ? `/api/todos/${editingTodo.id}` : '/api/todos';
303 const method = editingTodo ? 'PUT' : 'POST';
304
20 try {
21 setLoading(true);
22 const response = await fetch('/api/symptoms/analytics/insights');
23 if (response.ok) {
24 const data = await response.json();
90 <div className="stat-label">
91 Cycle Regularity
92 <div className="text-xs mt-1 capitalize">{insights.cycle_regularity}</div>
93 </div>
94 </div>
48
49 try {
50 const response = await fetch('/api/symptoms', {
51 method: 'POST',
52 headers: { 'Content-Type': 'application/json' },
35
36 try {
37 const url = isEditing ? `/api/cycles/${isEditing}` : '/api/cycles';
38 const method = isEditing ? 'PUT' : 'POST';
39
83 setLoading(true);
84 try {
85 const response = await fetch(`/api/cycles/${id}`, { method: 'DELETE' });
86 if (response.ok) {
87 setMessage({ type: 'success', text: 'Cycle deleted successfully!' });
35});
36
37// API Routes
38app.route("/api/auth", authRoutes);
39app.route("/api/projects", projectRoutes);
40app.route("/api/tasks", taskRoutes);
41app.route("/api/templates", templateRoutes);
42app.route("/api/dashboard", dashboardRoutes);
43
44// Health check endpoint
45app.get("/api/health", (c) => {
46 return c.json({
47 status: "healthy",
25
26 try {
27 const response = await fetch("/api/users/register", {
28 method: "POST",
29 headers: {