Skip to content

Commit

Permalink
🔨refactor: api로 분리해서 추상화
Browse files Browse the repository at this point in the history
  • Loading branch information
100Gyeon committed Jan 19, 2022
1 parent 0e3bb1d commit 1f4d6c9
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 51 deletions.
2 changes: 2 additions & 0 deletions src/infrastructure/api/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
PostFeedbackBookmarkResponse,
TeamProfileData,
TeamIssueData,
TeamInfoData,
TeamInviteData,
} from './types/team';

Expand All @@ -11,6 +12,7 @@ export interface TeamService {
postFeedbackBookmark(feedbackID: string): Promise<PostFeedbackBookmarkResponse>;
getTeamProfile(): Promise<TeamProfileData>;
getMyTeamIssue(): Promise<TeamIssueData>;
getTeamInfo(teamID: number): Promise<TeamInfoData>;
getTeamIssue(teamID: string): Promise<TeamIssueData>;
getMyIssue(teamID:string): Promise<TeamIssueData>;
getInviteInfo(): Promise<TeamInviteData>;
Expand Down
14 changes: 10 additions & 4 deletions src/infrastructure/api/types/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@ export type TeamProfileData = {
profileListData: TeamMemberNoneId[];
};

export type TeamInfoData = {
teamID: string;
export type TeamDetail = {
teamID: number;
teamImage?: string;
teamName: string;
teamDescription: string;
teamMemberCount: number;
teamMemberList: TeamMemberNoneId[];
};

export type TeamInfoData = {
teamDetailData: {
teamDetail: TeamDetail;
teamMemberCount: number;
teamMemberList: TeamMemberNoneId[];
};
};

export type TeamInvite = {
Expand Down
54 changes: 29 additions & 25 deletions src/infrastructure/mock/team.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,32 +188,36 @@ export const TEAM_DATA: {
],
},
TEAM_DETAIL_INFO: {
teamID: '0',
teamImage: 'https://cdn.pixabay.com/photo/2021/07/13/11/34/cat-6463284_1280.jpg',
teamName: '너가소개서',
teamDescription: '대학생연합 IT벤처창업 동아리',
teamMemberCount: 4,
teamMemberList: [
{
id: 1,
profileName: '캐서린',
},
{
id: 12,
profileName: '웬디',
profileImage: 'https://cdn.pixabay.com/photo/2014/11/30/14/11/cat-551554_1280.jpg',
},
{
id: 13,
profileName: '콩콩이',
profileImage: 'https://cdn.pixabay.com/photo/2014/11/30/14/11/cat-551554_1280.jpg',
},
{
id: 14,
profileName: '크왕',
profileImage: 'https://cdn.pixabay.com/photo/2014/11/30/14/11/cat-551554_1280.jpg',
teamDetailData: {
teamDetail: {
teamID: 1,
teamImage: 'https://cdn.pixabay.com/photo/2021/07/13/11/34/cat-6463284_1280.jpg',
teamName: '너가소개서',
teamDescription: '대학생연합 IT벤처창업 동아리',
},
],
teamMemberCount: 4,
teamMemberList: [
{
id: 1,
profileName: '캐서린',
},
{
id: 12,
profileName: '웬디',
profileImage: 'https://cdn.pixabay.com/photo/2014/11/30/14/11/cat-551554_1280.jpg',
},
{
id: 13,
profileName: '콩콩이',
profileImage: 'https://cdn.pixabay.com/photo/2014/11/30/14/11/cat-551554_1280.jpg',
},
{
id: 14,
profileName: '크왕',
profileImage: 'https://cdn.pixabay.com/photo/2014/11/30/14/11/cat-551554_1280.jpg',
},
],
},
},
TEAM_INVITE_INFO: {
inviteListData: [
Expand Down
6 changes: 6 additions & 0 deletions src/infrastructure/mock/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export function teamDataMock(): TeamService {
return TEAM_DATA.TEAM_PROFILE;
};

const getTeamInfo = async () => {
await wait(2000);
return TEAM_DATA.TEAM_DETAIL_INFO;
};

const getMyTeamIssue = async () => {
await wait(2000);
return TEAM_DATA.TEAM_ISSUE_INFO;
Expand All @@ -41,6 +46,7 @@ export function teamDataMock(): TeamService {
getIssueInfo,
postFeedbackBookmark,
getTeamProfile,
getTeamInfo,
getMyTeamIssue,
getTeamIssue,
getMyIssue,
Expand Down
22 changes: 22 additions & 0 deletions src/infrastructure/remote/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ export function teamDataRemote(): TeamService {
else throw '서버 통신 실패';
};

const getTeamInfo = async (teamID: number) => {
const response = await privateAPI.get({ url: `/team/detail/${teamID}` });
if (response.status === 200)
return {
teamDetailData: {
teamDetail: {
teamID: response.data.team.id,
teamImage: response.data.team.image ?? imgEmptyProfile,
teamName: response.data.team.name,
teamDescription: response.data.team.description,
},
teamMemberCount: response.data.memberCount,
teamMemberList: response.data.member.map((memberDetail: any) => ({
id: memberDetail.id,
profileName: memberDetail.name,
profileImage: memberDetail.image ?? imgEmptyProfile,
})),
},
};
};

const getMyTeamIssue = async () => {
const response = await privateAPI.get({ url: `/team/issue` });
if (response.status === 200)
Expand Down Expand Up @@ -111,6 +132,7 @@ export function teamDataRemote(): TeamService {
return {
postFeedbackBookmark,
getTeamProfile,
getTeamInfo,
getMyTeamIssue,
getTeamIssue,
getMyIssue,
Expand Down
31 changes: 9 additions & 22 deletions src/presentation/pages/Team/Main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { api } from '@api/index';
import { TeamInfoData, TeamIssueCard } from '@api/types/team';
import { imgEmptyProfile } from '@assets/images';
import TeamMemberPopup from './MemberPopup';
import { privateAPI } from '@infrastructure/remote/base';

function TeamMain() {
const [isMemberPopupOpened, setIsMemberPopupOpened] = useState(false);
Expand All @@ -21,20 +20,8 @@ function TeamMain() {
useEffect(() => {
(async () => {
if (teamID === undefined) return;
const response = await privateAPI.get({ url: `/team/detail/${teamID}` });
if (response.status === 200)
setTeamInfoData({
teamID: response.data.team.id,
teamImage: response.data.team.image ?? imgEmptyProfile,
teamName: response.data.team.name,
teamDescription: response.data.team.description,
teamMemberCount: response.data.memberCount,
teamMemberList: response.data.member.map((memberDetail: any) => ({
id: memberDetail.id,
profileName: memberDetail.name,
profileImage: memberDetail.image ?? imgEmptyProfile,
})),
});
const teamDetailData = await api.teamService.getTeamInfo(Number(teamID));
setTeamInfoData(teamDetailData);
})();
}, []);

Expand Down Expand Up @@ -68,23 +55,23 @@ function TeamMain() {
<div>
<button onClick={() => navigate(`/team/register`)}>수정</button>
</div>
<img src={teamInfoData.teamImage ?? imgEmptyProfile} />
<img src={teamInfoData.teamDetailData.teamDetail.teamImage ?? imgEmptyProfile} />
<div>
<h1>{teamInfoData.teamName}</h1>
<h1>{teamInfoData.teamDetailData.teamDetail.teamName}</h1>
<h3>
<button onClick={() => setIsMemberPopupOpened(!isMemberPopupOpened)}>
<img src={icPerson} />
<span>{teamInfoData.teamMemberCount}</span>
{isMemberPopupOpened && <TeamMemberPopup members={teamInfoData.teamMemberList} />}
<span>{teamInfoData.teamDetailData.teamMemberCount}</span>
{isMemberPopupOpened && <TeamMemberPopup members={teamInfoData.teamDetailData.teamMemberList} />}
</button>
{teamInfoData.teamMemberList.map((member, index) => (
{teamInfoData.teamDetailData.teamMemberList.map((member, index) => (
<span key={member.id}>
{member.profileName}
{index < teamInfoData.teamMemberCount - 1 ? ',\u00a0' : ''}
{index < teamInfoData.teamDetailData.teamMemberCount - 1 ? ',\u00a0' : ''}
</span>
))}
</h3>
<h2>{teamInfoData.teamDescription}</h2>
<h2>{teamInfoData.teamDetailData.teamDetail.teamDescription}</h2>
</div>
</StTeamInfo>
)}
Expand Down

0 comments on commit 1f4d6c9

Please sign in to comment.