Skip to content

Commit

Permalink
refactor: api 메서드 재사용 코드 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
2yunseong committed May 26, 2023
1 parent efe9759 commit 8ac5fe5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
export const productsQuery = async () => {
const response = await fetch('/products');
const getResponseBody = async (response: Response) => {
if (!response.ok) throw new Error();
const data = await response.json();
return data;
};

export const productsQuery = async () => {
const response = await fetch('/products');
return getResponseBody(response);
};

export const cartQuery = async () => {
const response = await fetch('/cart-items');
if (!response.ok) throw new Error();
const data = await response.json();
return data;
return getResponseBody(response);
};

export const productQuery = async (id: number) => {
const response = await fetch(`/product/${id}`);
if (!response.ok) throw new Error();
const data = await response.json();
return data;
return getResponseBody(response);
};

export const postCartItemQuery = async (id: number) => {
Expand Down

0 comments on commit 8ac5fe5

Please sign in to comment.