Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GGFE-16] Game - 게임 결과 등록과 조회 #790

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions components/modal/statChange/StatChangeModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react';
import { useSetRecoilState } from 'recoil';
import { Exp } from 'types/modalTypes';
import { GameResult } from 'types/gameTypes';
import { modalState } from 'utils/recoil/modal';
import { reloadMatchState } from 'utils/recoil/match';
import ExpStat from './ExpStat';
Expand All @@ -11,17 +12,14 @@ import useAxiosGet from 'hooks/useAxiosGet';
export default function StatChangeModal({ gameId, mode }: Exp) {
const setModal = useSetRecoilState(modalState);
const setReloadMatch = useSetRecoilState(reloadMatchState);
const [stat, setStat] = useState();

const [stat, setStat] = useState<GameResult | undefined>();
useEffect(() => {
getExpHandler();
}, []);

const getExpHandler = useAxiosGet({
url: `/pingpong/games/${gameId}/result/${mode}`,
setState: (data) => {
setStat({ ...data });
},
setState: setStat,
err: 'KP03',
type: 'setError',
});
Expand Down
4 changes: 2 additions & 2 deletions hooks/modal/aftergame/useCurrentGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const useCurrentGame = () => {
startTime: '2022-07-13 11:50',
isScoreExist: false,
matchTeamsInfo: {
myTeam: { teamScore: 0, teams: [] },
enemyTeam: { teamScore: 0, teams: [] },
myTeam: { teamScore: 0, teamId: 0, players: [] },
enemyTeam: { teamScore: 0, teamId: 0, players: [] },
},
});

Expand Down
30 changes: 28 additions & 2 deletions hooks/modal/aftergame/useSubmitModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ import { errorState } from 'utils/recoil/error';
import { AfterGame, TeamScore } from 'types/scoreTypes';
import { instance } from 'utils/axios';

type rankRequest = {
gameId: number;
myTeamId: number;
myTeamScore: number | '';
enemyTeamId: number;
enemyTeamScore: number | '';
};

type normalRequest = {
gameId: number;
myTeamId: number;
enemyTeamId: number;
};

const useSubmitModal = (currentGame: AfterGame) => {
const setError = useSetRecoilState(errorState);
const setModal = useSetRecoilState(modalState);
Expand All @@ -15,7 +29,14 @@ const useSubmitModal = (currentGame: AfterGame) => {

const submitRankHandler = async (result: TeamScore) => {
try {
const res = await instance.post(`/pingpong/games/result/rank`, result);
const requestBody: rankRequest = {
gameId: currentGame.gameId,
myTeamId: currentGame.matchTeamsInfo.myTeam.teamId,
myTeamScore: result.myTeamScore,
enemyTeamId: currentGame.matchTeamsInfo.enemyTeam.teamId,
enemyTeamScore: result.enemyTeamScore,
};
const res = await instance.post(`/pingpong/games/rank`, requestBody);
alert(rankResponse[`${res?.status}`]);
await instance.put(`/pingpong/match/current`);
} catch (e) {
Expand All @@ -26,8 +47,13 @@ const useSubmitModal = (currentGame: AfterGame) => {
};

const submitNormalHandler = async () => {
const requestBody: normalRequest = {
gameId: currentGame.gameId,
myTeamId: currentGame.matchTeamsInfo.myTeam.teamId,
enemyTeamId: currentGame.matchTeamsInfo.enemyTeam.teamId,
};
try {
await instance.post(`/pingpong/games/result/normal`);
await instance.post(`/pingpong/games/normal`, requestBody);
Copy link
Contributor

@42sungwook 42sungwook May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentGame을 반복해서 써야되면
const { gameId, matchTeamsInfo } = currentGame;
처럼 destructuring해서 쓰는 방법도 있어요
참고 사이트 : http://hacks.mozilla.or.kr/2015/09/es6-in-depth-destructuring/

Copy link
Member Author

@yoouyeon yoouyeon May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호 쓰면서도 뭔가 이상하다 생각했는데 이렇게 쓰는 방법이 있었네요......
destructing 하는 쪽이 더 읽기 좋아보이니 이렇게 수정하겠습니다 👍

await instance.put(`/pingpong/match/current`);
} catch (e) {
setError('KP04');
Expand Down
2 changes: 2 additions & 0 deletions hooks/useAxiosGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PppChart, ProfileBasic, ProfileRank } from 'types/userTypes';
import { UserInfo } from 'types/admin/adminUserTypes';
import { EditedSchedule } from 'types/admin/adminSlotTypes';
import { AfterGame } from 'types/scoreTypes';
import { GameResult } from 'types/gameTypes';

interface useAxiosGetProps {
url: string;
Expand All @@ -24,6 +25,7 @@ interface useAxiosGetProps {
| Dispatch<SetStateAction<string>>
| Dispatch<SetStateAction<EditedSchedule>>
| Dispatch<SetStateAction<AfterGame>>
| Dispatch<SetStateAction<GameResult | undefined>>
| Dispatch<SetStateAction<undefined>>
| SetterOrUpdater<User>
| SetterOrUpdater<SeasonList>
Expand Down
11 changes: 11 additions & 0 deletions types/gameTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,14 @@ export interface Game {
status: string;
time: string;
}

export type GameResult = {
beforeExp: number;
beforeMaxExp: number;
beforeLevel: number;
increasedExp: number;
increasedLevel: number;
afterMaxExp: number;
changedPpp?: number;
beforePpp?: number;
};
4 changes: 3 additions & 1 deletion types/scoreTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export interface TeamScore {
export interface Player {
intraId: string;
userImageUri: string;
level: number;
}
export interface Team {
teamScore: number;
teams: Player[];
teamId: number;
players: Player[];
}

export interface Players {
Expand Down