Skip to content

Commit 61fb573

Browse files
committed
fix: #20
1 parent f7e49e1 commit 61fb573

File tree

12 files changed

+496
-53
lines changed

12 files changed

+496
-53
lines changed

database/api/api.function.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Context } from "hono";
2-
import type { Hono } from "hono";
2+
import { Hono } from "hono";
33
import {
44
createFunction,
55
deleteFunction,
@@ -9,13 +9,16 @@ import {
99
} from "../tables/functions.ts";
1010

1111
// Setup function API routes
12-
export function setupFunctionAPIRoutes(app: Hono) {
12+
export function setupFunctionAPIRoutes() {
13+
const app = new Hono();
1314
// Functions routes
14-
app.get("/functions", getAllFunctionsHandler);
15-
app.get("/functions/:name", getFunctionHandler);
16-
app.post("/functions", createFunctionHandler);
17-
app.put("/functions/:name", updateFunctionHandler);
18-
app.delete("/functions/:name", deleteFunctionHandler);
15+
app.get("/", getAllFunctionsHandler);
16+
app.post("/", createFunctionHandler);
17+
app.get("/:name", getFunctionHandler);
18+
app.put("/:name", updateFunctionHandler);
19+
app.delete("/:name", deleteFunctionHandler);
20+
21+
return app;
1922
}
2023

2124
// Function handlers
@@ -141,3 +144,5 @@ async function deleteFunctionHandler(c: Context): Promise<Response> {
141144
);
142145
}
143146
}
147+
148+
export type AppType = ReturnType<typeof setupFunctionAPIRoutes>;

database/api/api.service.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Context, Next } from "hono";
2-
import type { Hono } from "hono";
2+
import { Hono } from "hono";
33
import { DatabaseContext, updateConfig } from "../config.ts";
44
import {
55
createService,
@@ -25,18 +25,21 @@ export function databaseMiddleware(dbContext: DatabaseContext) {
2525
}
2626

2727
// Setup all API routes
28-
export function setupAPIRoutes(app: Hono) {
29-
// Services routes
30-
app.get("/services", getAllServicesHandler);
31-
app.get("/services/:name", getServiceHandler);
32-
app.post("/services", createServiceHandler);
33-
app.put("/services/:name", updateServiceHandler);
34-
app.delete("/services/:name", deleteServiceHandler);
35-
36-
// Config routes
28+
export function setupAPIRoutes() {
29+
const app = new Hono();
30+
// Config routes (more specific, should come first)
3731
app.get("/config", getAllConfigHandler);
3832
app.get("/config/:key", getConfigHandler);
3933
app.put("/config/:key", updateConfigHandler);
34+
35+
// Services routes (parameterized routes come after specific routes)
36+
app.get("/", getAllServicesHandler);
37+
app.post("/", createServiceHandler);
38+
app.get("/:name", getServiceHandler);
39+
app.put("/:name", updateServiceHandler);
40+
app.delete("/:name", deleteServiceHandler);
41+
42+
return app;
4043
}
4144

4245
// Services handlers
@@ -260,3 +263,4 @@ async function updateConfigHandler(c: Context): Promise<Response> {
260263
);
261264
}
262265
}
266+
export type AppType = ReturnType<typeof setupAPIRoutes>;

database/api/api.task.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Context } from "hono";
2-
import type { Hono } from "hono";
2+
import { Hono } from "hono";
33
import {
44
createTask,
55
deleteTask,
@@ -23,13 +23,16 @@ export function queueBaseMiddleware(queueBase: Kysely<QueueBase>) {
2323
}
2424

2525
// Setup task API routes
26-
export function setupTaskAPIRoutes(app: Hono) {
26+
export function setupTaskAPIRoutes() {
27+
const app = new Hono();
28+
2729
// Tasks routes
28-
app.get("/tasks", getAllTasksHandler);
29-
app.get("/tasks/:id", getTaskHandler);
30-
app.post("/tasks", createTaskHandler);
31-
app.put("/tasks/:id", updateTaskHandler);
32-
app.delete("/tasks/:id", deleteTaskHandler);
30+
app.get("/", getAllTasksHandler);
31+
app.post("/", createTaskHandler);
32+
app.get("/:id", getTaskHandler);
33+
app.put("/:id", updateTaskHandler);
34+
app.delete("/:id", deleteTaskHandler);
35+
return app;
3336
}
3437

3538
// Task handlers
@@ -193,3 +196,5 @@ async function deleteTaskHandler(c: Context): Promise<Response> {
193196
);
194197
}
195198
}
199+
200+
export type AppType = ReturnType<typeof setupTaskAPIRoutes>;

0 commit comments

Comments
 (0)