Skip to content

Commit

Permalink
chore: api client 사용 방식으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
kingyong9169 committed Aug 5, 2024
1 parent 1513801 commit cfaf9c8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
5 changes: 4 additions & 1 deletion apps/web/src/apis/phrase-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ import {
ApiData,
Phrase,
PhrasePaging,
RequestConfig,
} from "@daily-phrase/api";

export class PhraseApi {
private apiClient: ApiClientInstance;
constructor(apiClient: ApiClientInstance) {
this.apiClient = apiClient;
}
getPhraseList(size: number) {
getPhraseList(size: number, requestConfig?: RequestConfig) {
return this.apiClient.get<ApiData<PhrasePaging>>(
`/api/v1/phrases?page=1&size=${size}`,
{
...requestConfig,
headers: {
...requestConfig?.headers,
"content-type": "application/json",
},
},
Expand Down
9 changes: 2 additions & 7 deletions apps/web/src/app/phrase-web/[phraseId]/phrase-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ export default function PhraseList({

const requestPhraseList = async () => {
// TODO: 백엔드 https 부착
const res = await fetch("/api/v1/phrases", {
headers: {
"content-type": "application/json",
},
});
const { data } = await res.json();
const phraseList = data.result.phraseList as Phrase[];
const res = await apis.phraseApi.getPhraseList(4, { baseURL: "" });
const phraseList = res.result.phraseList;
const filteredPhraseList = phraseList
.filter((phrase) => phrase.phraseId !== +currentPhraseId)
.slice(0, 3);
Expand Down
10 changes: 2 additions & 8 deletions apps/web/src/components/event-item-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ const EventItemList = () => {
const [eventList, setEventList] = useState<Array<Prize>>([]);

const getPrizeList = async () => {
// const res = await apis.eventApi.getPrizeList({ baseURL: "" });
const res = await fetch("/api/v1/events/prizes", {
headers: {
"content-type": "application/json",
},
});
const { data } = await res.json();
const res = await apis.eventApi.getPrizeList({ baseURL: "" });
setIsLoading(false);
setEventList(data.result.prizeList);
setEventList(res.result.prizeList);
};

// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
Expand Down
10 changes: 2 additions & 8 deletions apps/web/src/components/event-participant-floating-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ const EventParticipantFloatingButton = () => {
const [eventList, setEventList] = useState<Array<Prize>>([]);

const getPrizeList = async () => {
// const res = await apis.eventApi.getPrizeList({ baseURL: "" });
const res = await fetch("/api/v1/events/prizes", {
headers: {
"content-type": "application/json",
},
});
const { data } = await res.json();
const res = await apis.eventApi.getPrizeList({ baseURL: "" });
setIsLoading(false);
setEventList(data.result.prizeList);
setEventList(res.result.prizeList);
};

// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
Expand Down

0 comments on commit cfaf9c8

Please sign in to comment.