Skip to content

Commit

Permalink
[Test] make games mock api #680
Browse files Browse the repository at this point in the history
  • Loading branch information
mike2ox committed Feb 24, 2023
1 parent 1889780 commit d3ede0a
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions pages/api/admin/games/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { IGames } from 'types/admin/gameLogTypes';

interface IQuery {
page: string;
season?: string;
q?: string;
size?: string;
}

function generateGamelog(): IGames {
const intraIds = ['mosong', 'rjeong', 'sungwook', 'daijeong'];
const teamNumber = [1, 2];

const teams = [
[
{
intraId: intraIds[0],
teamId: teamNumber[0],
score: 10,
win: true,
},
],
[
{
intraId: intraIds[1],
teamId: teamNumber[1],
score: 5,
win: false,
},
],
[
{
intraId: intraIds[0],
teamId: teamNumber[0],
score: 15,
win: true,
},
{
intraId: intraIds[1],
teamId: teamNumber[0],
score: 15,
win: true,
},
],
[
{
intraId: intraIds[2],
teamId: teamNumber[1],
score: 7,
win: false,
},
{
intraId: intraIds[3],
teamId: teamNumber[1],
score: 7,
win: false,
},
],
];

const games: IGames = {
gameLog: [
{
gameId: 1,
startAt: new Date(),
playTime: '15분',
mode: 'rank',
team1: teams[0],
team2: teams[1],
},
{
gameId: 2,
startAt: new Date(),
playTime: '15분',
mode: 'rank',
team1: teams[1],
team2: teams[0],
},
{
gameId: 3,
startAt: new Date(),
playTime: '30분',
mode: 'rank',
team1: teams[2],
team2: teams[3],
},
],
currentPage: 1,
totalPage: 1,
};

return games;
}

export default function handler(req: NextApiRequest, res: NextApiResponse) {
const { method, query } = req;
const { page, season = 0, q, size = 20 } = query as Partial<IQuery>;

if (!page) return res.status(400).json({ message: 'page is required' });

switch (method) {
case 'GET':
// 특정 유저의 게임 목록 조회
if (q) {
res.status(200).json(generateGamelog());
}
// 시즌별 / 전체 게임 목록 조회
if (season) {
res.status(200).json(generateGamelog());
}
break;
default:
res.setHeader('Allow', ['GET']);
res.status(405).end(`Method ${method} Not Allowed`);
}
}

0 comments on commit d3ede0a

Please sign in to comment.