refactor: dependency injection for GameSessionStore via composition root
This commit is contained in:
parent
4f59f3bc14
commit
a4a4bfff57
6 changed files with 107 additions and 79 deletions
|
|
@ -1,11 +1,16 @@
|
|||
import express from "express";
|
||||
import { Router } from "express";
|
||||
import type { Router } from "express";
|
||||
import { healthRouter } from "./healthRouter.js";
|
||||
import { gameRouter } from "./gameRouter.js";
|
||||
import { createGameRouter } from "./gameRouter.js";
|
||||
import { lobbyRouter } from "./lobbyRouter.js";
|
||||
import type { GameSessionStore } from "../gameSessionStore/index.js";
|
||||
|
||||
export const apiRouter: Router = express.Router();
|
||||
export const createApiRouter = (store: GameSessionStore): Router => {
|
||||
const router = express.Router();
|
||||
|
||||
apiRouter.use("/health", healthRouter);
|
||||
apiRouter.use("/game", gameRouter);
|
||||
apiRouter.use("/lobbies", lobbyRouter);
|
||||
router.use("/health", healthRouter);
|
||||
router.use("/game", createGameRouter(store));
|
||||
router.use("/lobbies", lobbyRouter);
|
||||
|
||||
return router;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,13 +1,19 @@
|
|||
import express from "express";
|
||||
import type { Router } from "express";
|
||||
import { createGame, submitAnswer } from "../controllers/gameController.js";
|
||||
import { createGameController } from "../controllers/gameController.js";
|
||||
import { requireAuth } from "../middleware/authMiddleware.js";
|
||||
import { gameLimiter } from "../middleware/rateLimiters.js";
|
||||
import type { GameSessionStore } from "../gameSessionStore/index.js";
|
||||
|
||||
export const gameRouter: Router = express.Router();
|
||||
export const createGameRouter = (store: GameSessionStore): Router => {
|
||||
const router = express.Router();
|
||||
const controller = createGameController(store);
|
||||
|
||||
gameRouter.use(requireAuth);
|
||||
gameRouter.use(gameLimiter);
|
||||
router.use(requireAuth);
|
||||
router.use(gameLimiter);
|
||||
|
||||
gameRouter.post("/start", createGame);
|
||||
gameRouter.post("/answer", submitAnswer);
|
||||
router.post("/start", controller.createGame);
|
||||
router.post("/answer", controller.submitAnswer);
|
||||
|
||||
return router;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue