diff --git a/server/src/controllers/games.controller.ts b/server/src/controllers/games.controller.ts new file mode 100644 index 0000000..1238d64 --- /dev/null +++ b/server/src/controllers/games.controller.ts @@ -0,0 +1,8 @@ +import { Request, Response } from "express"; +import { getGamesService } from "../services/games.service"; + +export const getGamesController = async (_req: Request, res: Response) => { + const games = await getGamesService(); + + res.status(200).json(games); +} \ No newline at end of file diff --git a/server/src/models/games.model.ts b/server/src/models/games.model.ts new file mode 100644 index 0000000..9a7e046 --- /dev/null +++ b/server/src/models/games.model.ts @@ -0,0 +1,20 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient({ + log: ['query'], +}) + +export const getGames = async () => { + const games = await prisma.game.findMany( + { + include: + { + _count: { + select: { + ads: true + } + } + } + }) + return games; +} diff --git a/server/src/routes/games.route.ts b/server/src/routes/games.route.ts index d1fa318..3522218 100644 --- a/server/src/routes/games.route.ts +++ b/server/src/routes/games.route.ts @@ -1,24 +1,8 @@ -// route para ads import { Router } from 'express'; -import { PrismaClient } from '@prisma/client' +import { getGamesController } from '../controllers/games.controller'; const gamesRouter = Router(); -const prisma = new PrismaClient({ - log: ['query'], -}) -gamesRouter.get('/', async (_req, res) => { - const games = await prisma.game.findMany({ include: - { - _count: { - select: { - ads: true - } - } - } - }) - - res.status(200).json(games); -}); +gamesRouter.get('/', getGamesController); export default gamesRouter; \ No newline at end of file diff --git a/server/src/services/games.service.ts b/server/src/services/games.service.ts new file mode 100644 index 0000000..e659cdc --- /dev/null +++ b/server/src/services/games.service.ts @@ -0,0 +1,5 @@ +import { getGames } from "../models/games.model"; + +export const getGamesService = async () => { + return getGames(); +} \ No newline at end of file