릴리스: v0.1.6 MariaDB 개발 환경 및 저장소 설정 정리
This commit is contained in:
31
backend/src/routes/games.js
Normal file
31
backend/src/routes/games.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const express = require('express')
|
||||
const { z } = require('zod')
|
||||
const { nanoid } = require('nanoid')
|
||||
const { listGames, getGameDetail, createGameSuggestion } = require('../db')
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
const games = await listGames()
|
||||
res.json({ games })
|
||||
})
|
||||
|
||||
router.get('/:gameId', async (req, res) => {
|
||||
const detail = await getGameDetail(req.params.gameId)
|
||||
if (!detail) return res.status(404).json({ error: 'not_found' })
|
||||
res.json({ game: detail.game, items: detail.items })
|
||||
})
|
||||
|
||||
router.post('/suggest', async (req, res) => {
|
||||
const schema = z.object({ name: z.string().min(1).max(60) })
|
||||
const parsed = schema.safeParse(req.body)
|
||||
if (!parsed.success) return res.status(400).json({ error: 'bad_request' })
|
||||
|
||||
const suggestion = await createGameSuggestion({
|
||||
id: nanoid(),
|
||||
name: parsed.data.name,
|
||||
})
|
||||
res.json({ suggestion })
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
Reference in New Issue
Block a user