Skip to content

Commit

Permalink
Merge pull request #219 from Neogasogaeseo/feat/#217
Browse files Browse the repository at this point in the history
  • Loading branch information
SeojinSeojin authored Mar 11, 2022
2 parents af88d0b + 06337ae commit 4191f62
Show file tree
Hide file tree
Showing 22 changed files with 505 additions and 354 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"lottie-web": "^5.8.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-error-boundary": "3.1.4",
"react-ga": "^3.3.0",
"react-query": "3.34.16",
"react-router-dom": "^6.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { NeososeoFormService } from './neososeo-form';
import { TeamService } from './team';
import { UserService } from './user';
import { loginUserRemote } from '@infrastructure/remote/login-user';
import { NeososeoFormRemote } from '@infrastructure/remote/neososeo-form';
import { userDataRemote } from '@infrastructure/remote/user';
import { NeososeoFormRemote } from '@infrastructure/remote/neososeo-form';

export const api: APIService = getAPIMethod();

Expand Down
8 changes: 4 additions & 4 deletions src/infrastructure/api/neoga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import {
NeogaMainCardItem,
NeogaCardItem,
NeogaResultCardItem,
ResultFormList,
CreateFormInfo,
ResultDetail,
ResultFeedback,
} from './types/neoga';
import { Keyword } from './types/user';

export interface NeogaService {
getBannerTemplate(): Promise<NeogaBannerItem | null>;
getMainTemplate(): Promise<NeogaMainCardItem[]>;
getAllTemplates(viewMode: 'recent' | 'popular'): Promise<NeogaCardItem[]>;
getMainResultCard(): Promise<NeogaResultCardItem>;
getFormResultCard(): Promise<NeogaResultCardItem>;
getResultKeywords(formID: number): Promise<Keyword[]>;
getAllResultListTemplates(formID: number): Promise<ResultFormList[]>;
postAnswerBookmark(answerID: number): Promise<{ isSuccess: boolean }>;
postCreateForm(formID: number): Promise<{ isCreated: boolean; q: string }>;
getCreateFormInfo(formID: number): Promise<CreateFormInfo>;
getNeososeoInfo(formID: number): Promise<ResultDetail>;
getNeososeoFeedback(formID: number): Promise<ResultFeedback>;
}
27 changes: 27 additions & 0 deletions src/infrastructure/api/types/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface CustomError extends Error {
code: number;
}

export class NotFoundError implements CustomError {
code: 404;
name: 'Not Found Error';
message: string;

constructor(message: string) {
this.code = 404;
this.name = 'Not Found Error';
this.message = message;
}
}

export class UnauthorizedError implements CustomError {
code: 401;
name: 'Unauthorized Error';
message: string;

constructor(message: string) {
this.code = 401;
this.name = 'Unauthorized Error';
this.message = message;
}
}
31 changes: 19 additions & 12 deletions src/infrastructure/mock/neoga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ export function neogaDataMock(): NeogaService {
return NEOGA_DATA.RESULT_CARD_TEMPLATE;
};

const getResultKeywords = async () => {
await wait(2000);
return NEOGA_DATA.KEYWORD_LISTS;
};

const getAllResultListTemplates = async () => {
await wait(2000);
return NEOGA_DATA.NEOGA_RESULT;
};

const postAnswerBookmark = async () => {
await wait(1000);
return { isSuccess: true };
Expand All @@ -52,17 +42,34 @@ export function neogaDataMock(): NeogaService {
return { id: 0, title: '', subtitle: '', image: '' };
};

const getNeososeoInfo = async () => {
return {
id: 1,
title: 'aa',
subtitle: 'aaa',
darkIconImage:
'https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/240/apple/285/smiling-face-with-hearts_1f970.png',
createdAt: '2222-22-22',
q: 'aafagara',
keywordList: [],
};
};

const getNeososeoFeedback = async () => {
return { answerCount: 0, answerList: [] };
};

return {
getBannerTemplate,
getMainTemplate,
getAllTemplates,
getMainResultCard,
getFormResultCard,
getResultKeywords,
getAllResultListTemplates,
postAnswerBookmark,
postCreateForm,
getCreateFormInfo,
getNeososeoInfo,
getNeososeoFeedback,
};
}

Expand Down
5 changes: 1 addition & 4 deletions src/infrastructure/remote/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { isProduction } from '@utils/constant';
import axios from 'axios';

const BASEURL = isProduction
? 'https://asia-northeast3-neogasogaeseo-9aaf5.cloudfunctions.net/api'
: 'http://127.0.0.1:5000/neogasogaeseo-9aaf5/asia-northeast3/api';
const BASEURL = 'https://asia-northeast3-neogasogaeseo-9aaf5.cloudfunctions.net/api';
const getAccessToken = () => localStorage.getItem('token') ?? '';

const getBasePrivateHeaders = () => ({
Expand Down
47 changes: 0 additions & 47 deletions src/infrastructure/remote/neoga-result.ts

This file was deleted.

60 changes: 45 additions & 15 deletions src/infrastructure/remote/neoga.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NeogaService } from '@api/neoga';
import { NotFoundError } from '@api/types/errors';
import { AxiosError } from 'axios';
import { NEOGA_DATA } from '../mock/neoga.data';
import { privateAPI } from './base';

export function NeogaDataRemote(): NeogaService {
Expand Down Expand Up @@ -128,16 +128,6 @@ export function NeogaDataRemote(): NeogaService {
else throw '서버 통신 실패';
};

const getResultKeywords = async () => {
await wait(2000);
return NEOGA_DATA.KEYWORD_LISTS;
};

const getAllResultListTemplates = async () => {
await wait(2000);
return NEOGA_DATA.NEOGA_RESULT;
};

const postAnswerBookmark = async (answerID: number) => {
const response = await privateAPI.put({ url: `/form/detail/answer/${answerID}/pin` });
return { isSuccess: response.success };
Expand Down Expand Up @@ -170,18 +160,58 @@ export function NeogaDataRemote(): NeogaService {
} else throw '서버 통신 실패';
};

const getNeososeoInfo = async (formID: number) => {
const response = await privateAPI.get({ url: `/form/detail/${formID}` });
if (!response.data) throw new NotFoundError('해당 유저와 폼 아이디로 생성된 폼이 없습니다.');
return {
id: response.data.id,
title: response.data.title,
subtitle: response.data.subtitle.replace('\\n', '\n'),
darkIconImage: response.data.darkIconImage,
createdAt: response.data.createdAt,
q: response.data.q,
keywordList: response.data.keyword.map((keyword: any) => ({
id: keyword.id,
content: keyword.name,
color: keyword.colorcode,
})),
};
};

const getNeososeoFeedback = async (formID: number) => {
const response = await privateAPI.get({ url: `/form/detail/${formID}/answer` });
return {
answerCount: response.data.answerCount,
answerList: response.data.answer
? response.data.answer.map((feedback: any) => ({
formID: feedback.formID,
id: feedback.id,
name: feedback.name,
relationship: feedback.relationship,
content: feedback.content,
isPinned: feedback.isPinned,
createdAt: feedback.createdAt,
keywordList: feedback.keywords.map((keyword: any) => ({
id: keyword.id,
content: keyword.name,
color: keyword.colorcode,
answerId: keyword.answerId,
})),
}))
: [],
};
};

return {
getBannerTemplate,
getMainTemplate,
getAllTemplates,
getMainResultCard,
getFormResultCard,
getResultKeywords,
getAllResultListTemplates,
postAnswerBookmark,
postCreateForm,
getCreateFormInfo,
getNeososeoInfo,
getNeososeoFeedback,
};
}

const wait = (milliSeconds: number) => new Promise((resolve) => setTimeout(resolve, milliSeconds));
10 changes: 7 additions & 3 deletions src/infrastructure/remote/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { NotFoundError } from '@api/types/errors';
import { UserService } from '@api/user';
import { KEYWORD_PAGE } from '@utils/constant';
import { AxiosError } from 'axios';
import { publicAPI } from './base';

export function userDataRemote(): UserService {
Expand All @@ -24,7 +26,9 @@ export function userDataRemote(): UserService {
};

const getMyPageInfo = async (userID: string) => {
const response = await publicAPI.get({ url: `/user/${userID}` });
const response = await publicAPI.get({ url: `/user/${userID}` }).catch((error: AxiosError) => {
if (error.response?.status === 404) throw new NotFoundError('사용자를 찾을 수 없습니다.');
});
return {
username: response.data.user.name,
userID: response.data.user.profileId,
Expand Down Expand Up @@ -58,7 +62,7 @@ export function userDataRemote(): UserService {
content: bookmark.content,
isBookmarked: bookmark.isPinned,
keywordList: bookmark.keywords.map((keyword: any) => ({
id: keyword.answerId,
id: keyword.name,
content: keyword.name,
color: keyword.colorCode,
})),
Expand Down Expand Up @@ -86,7 +90,7 @@ export function userDataRemote(): UserService {
body: feedback.content,
createdAt: feedback.createdAt,
keywordList: feedback.keywords.map((keyword: any) => ({
id: keyword.answerId,
id: keyword.name,
content: keyword.name,
color: keyword.colorCode,
})),
Expand Down
Loading

0 comments on commit 4191f62

Please sign in to comment.