Skip to content

Commit

Permalink
Merge pull request #278 from TheUpperPart/Refactor/#276
Browse files Browse the repository at this point in the history
Refactor/#276: 서버 요청하는 함수를 모듈화
  • Loading branch information
pp449 authored Jan 15, 2024
2 parents 34f3d3b + c9e249e commit b4e6d97
Show file tree
Hide file tree
Showing 35 changed files with 580 additions and 374 deletions.
34 changes: 34 additions & 0 deletions src/apis/boardContents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import authAPI from '@apis/authAPI';
import { Content } from '@pages/contents/[channelLink]/[boardId]';

export const fetchBoardContents = async (channelLink: string, boardId: string) => {
const res = await authAPI<Content>({
method: 'get',
url: `/api/channel/${channelLink}/${boardId}`,
});

return res;
};

export const updateBoardContents = async (
channelLink: string,
boardId: string,
updatedContent: Content,
) => {
const res = await authAPI({
method: 'post',
url: `/api/channel/${channelLink}/${boardId}`,
data: {
title: updatedContent.title,
content: updatedContent.content,
},
});

return res;
};

export const deleteBoardContents = async (channelLink: string, boardId: string) => {
const res = await authAPI({ method: 'delete', url: `/api/channel/${channelLink}/${boardId}` });

return res;
};
59 changes: 59 additions & 0 deletions src/apis/boards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import authAPI from '@apis/authAPI';
import { NEWBOARD } from '@constants/MakeBoard';
import { Channels } from '@type/board';
import { MainPageNoticeData } from '@type/mainPage';

interface NewBoard {
boardId: number;
boardTitle: string;
boardIndex: number;
}

interface BoardsInfo {
myMatchRound: number;
myMatchId: number;
channelBoardLoadDtoList: Channels[];
}

export const fetchGamePatchNote = async (board: string) => {
const res = await authAPI<Array<MainPageNoticeData>>({
method: 'get',
url: `/api/notice/${board}`,
});

return res;
};

export const fetchBoardLists = async (channelLink: string) => {
const res = await authAPI<BoardsInfo>({
method: 'get',
url: `/api/channel/${channelLink}/boards`,
});

return res.data;
};

export const createNewBoard = async (channelLink: string) => {
const res = await authAPI<NewBoard>({
method: 'post',
url: `/api/channel/${channelLink}/new`,
data: {
title: NEWBOARD.DEFAULT_TITLE,
content: NEWBOARD.DEFAULT_CONTENT,
},
});

return res.data;
};

export const changeBoardOrder = async (channelLink: string, customedBoards: Channels[]) => {
const res = await authAPI({
method: 'post',
url: `/api/channel/${channelLink}/order`,
data: {
channelBoardLoadDtoList: customedBoards,
},
});

return res;
};
11 changes: 11 additions & 0 deletions src/apis/bracketContents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import authAPI from '@apis/authAPI';
import { BracketContents } from '@type/bracket';

export const fetchBracketContents = async (channelLink: string, curRound: number) => {
const res = await authAPI<BracketContents>({
method: 'get',
url: `/api/match/${channelLink}/${curRound}`,
});

return res.data;
};
27 changes: 27 additions & 0 deletions src/apis/brackets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import authAPI from '@apis/authAPI';
import { BracketHeader } from '@type/bracket';

export const fetchStartBracket = async (channelLink: string) => {
const res = await authAPI({
method: 'put',
url: `/api/channel/${channelLink}?status=1`,
});

return res;
};

export const fetchAllBracket = async (channelLink: string) => {
const res = await authAPI<BracketHeader>({
method: 'get',
url: `/api/match/${channelLink}`,
});

return res.data;
};

export const assignNextRound = async (channelLink: string, round: number) => {
await authAPI({
method: 'post',
url: `/api/match/${channelLink}/${round}`,
});
};
151 changes: 151 additions & 0 deletions src/apis/channels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import { NewGameOption } from './../components/MakeChannel/SelectRule';
import authAPI from '@apis/authAPI';
import { Participant } from '@components/Modal/ParticipantLists/ParticipantUser';
import { BoardInfo } from '@type/board';
import { ChannelCircleProps } from '@type/channelCircle';

export const fetchChannelLists = async () => {
const res = await authAPI<ChannelCircleProps[]>({
method: 'get',
url: '/api/channels',
});

return res.data;
};

export const fetchChannelInfo = async (channelLink: string) => {
const res = await authAPI<BoardInfo>({ method: 'get', url: '/api/channel/' + channelLink });

return res.data;
};

export const createNewChannel = async (newGameOption: NewGameOption) => {
const res = await authAPI<ChannelCircleProps>({
method: 'post',
url: '/api/channel',
data: {
gameCategory: newGameOption.gameCategory,
matchFormat: newGameOption.matchFormat,
title: newGameOption.title,
maxPlayer: newGameOption.maxPlayer,
tier: newGameOption.tier,
tierMax: newGameOption.tierMax,
tierMin: newGameOption.tierMin,
playCount: newGameOption.playCount,
playCountMin: newGameOption.playCountMin,
channelImageUrl: newGameOption.channelImageUrl,
},
});

return res;
};

export const updateChannelOrder = async (customedChannels: ChannelCircleProps[]) => {
await authAPI({ method: 'post', url: '/api/channels/order', data: customedChannels });
};

export const joinChannel = async (channelLink: string) => {
const res = await authAPI<ChannelCircleProps>({
method: 'post',
url: `/api/${channelLink}/participant/observer`,
});

return res;
};

export const updateChannelInfo = async (
channelLink: string,
updatedLeagueTitle: string,
updatedMaxPlayer: number,
) => {
const res = await authAPI({
method: 'post',
url: `/api/channel/${channelLink}`,
data: {
title: updatedLeagueTitle,
maxPlayer: updatedMaxPlayer,
},
});

return res;
};

export const fetchParticipantUser = async (channelLink: string) => {
const res = await authAPI<Participant[]>({
method: 'get',
url: `/api/${channelLink}/players`,
});

return res;
};

export const fetchRequestUser = async (channelLink: string) => {
const res = await authAPI<Participant[]>({
method: 'get',
url: `/api/${channelLink}/player/requests`,
});

return res;
};

export const fetchOberverUser = async (channelLink: string) => {
const res = await authAPI<Participant[]>({
method: 'get',
url: `/api/${channelLink}/observers`,
});

return res;
};

export const joinChannelParticipant = async (
channelLink: string,
gameId: string,
nickname: string,
) => {
const res = await authAPI({
method: 'post',
url: `/api/${channelLink}/participant`,
data: {
gameId,
nickname,
},
});

return res;
};

export const demoteToObserver = async (channelLink: string, participantPK: number) => {
const res = await authAPI({
method: 'post',
url: `/api/${channelLink}/${participantPK}/observer`,
});

return res;
};

export const promoteToAdmin = async (channelLink: string, participantPK: number) => {
const res = await authAPI({
method: 'post',
url: `/api/${channelLink}/${participantPK}/host`,
});

return res;
};

export const confirmParticipation = async (channelLink: string, requestPK: number) => {
const res = await authAPI({
method: 'post',
url: `/api/${channelLink}/${requestPK}/player`,
});

return res;
};

export const rejectParticipation = async (channelLink: string, requestPK: number) => {
const res = await authAPI({
method: 'post',
url: `/api/${channelLink}/${requestPK}/observer`,
});

return res;
};
33 changes: 33 additions & 0 deletions src/apis/mainContents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import authAPI from '@apis/authAPI';
import { MainContent } from '@pages/contents/[channelLink]/main';
import { useRouter } from 'next/router';

export const fetchMainContents = async (channelLink: string): Promise<MainContent | undefined> => {
const res = await authAPI<MainContent>({
method: 'get',
url: `/api/channel/${channelLink}/main`,
});

if (res.status !== 200) {
return;
}

return res.data;
};

export const updateMainContents = async (
channelLink: string,
updatedContent: MainContent,
): Promise<void> => {
const res = await authAPI({
method: 'post',
url: `/api/channel/${channelLink}/main`,
data: updatedContent,
});

if (res.status !== 200) {
const router = useRouter();
router.push('/');
return;
}
};
49 changes: 49 additions & 0 deletions src/apis/match.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import authAPI from '@apis/authAPI';
import { GetMatchPlayerScoreInfos } from '@components/RoundCheckIn';
import { MatchCountList } from '@type/channelConfig';

export const fetchInitialMatchCount = async (channelLink: string) => {
const res = await authAPI<MatchCountList>({
method: 'get',
url: `/api/match/${channelLink}/count`,
});

return res.data;
};

export const fetchMatchInfos = async (channelLink: string, matchId: string) => {
const res = await authAPI<GetMatchPlayerScoreInfos>({
method: 'get',
url: `/api/channel/${channelLink}/match/${matchId}/player/info`,
});

return res;
};

export const fetchRoundInfo = async (channelLink: string, curRound: number) => {
const res = await authAPI({
method: 'get',
url: `/api/match/${channelLink}/${curRound}`,
});

return res;
};

export const updateRoundMatch = async (channelLink: string, matchSetCountList: number[]) => {
const res = await authAPI({
method: 'post',
url: `/api/match/${channelLink}/count`,
data: {
matchSetCountList,
},
});

return res;
};

export const navigateToCheckInPage = async (channelLink: string, matchId: number) => {
authAPI({
method: 'post',
url: `/api/match/${channelLink}/${matchId}/call-off`,
});
};
Loading

0 comments on commit b4e6d97

Please sign in to comment.