Skip to content

Commit

Permalink
#93 [REFACTOR] card API 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
misung-dev committed Oct 1, 2024
1 parent 2f806d6 commit a38befd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
32 changes: 16 additions & 16 deletions src/apis/cards.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { authAxios } from '../axios';

// 전체 명함 조회
export const getCards = async ({ member_id }) => {
const response = await authAxios.get(`/cards/${member_id}`);
// console.log(response.data.result);
return response;
export const getCardList = async (member_id) => {
const { data } = await authAxios.get(`/cards/${member_id}`);

return data;
};

// 명함 생성
export const postCards = async ({ member_id, data }) => {
const response = await authAxios.post(`/cards/${member_id}`, data);
// console.log(response);
return response;
export const postCard = async (member_id, body) => {
const { data } = await authAxios.post(`/cards/${member_id}`, body);

return data;
};

// 명함 삭제
export const deleteCards = async ({ card_id }) => {
const response = await authAxios.delete(`/cards/${card_id}`);
// console.log(response);
return response;
export const deleteCard = async (card_id) => {
const { data } = await authAxios.delete(`/cards/${card_id}`);

return data;
};

// 명함 수정
export const putCards = async ({ card_id, data }) => {
const response = await authAxios.put(`/cards/${card_id}`, data);
// console.log(response);
return response;
export const putCard = async (card_id, body) => {
const { data } = await authAxios.put(`/cards/${card_id}`, body);

return data;
};
4 changes: 3 additions & 1 deletion src/apis/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { getGroupList } from './group';
export * from './group';
export * from './cards';
export * from './myCard';
7 changes: 3 additions & 4 deletions src/pages/HomePage/HomePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
} from '../../components';
import { useVisibleCardsEffect } from '../../utils/HomePageUtils/homePageEffects';
import CARDS_SAMPLE_DATA from '../../constants/cardsSampleData.js';
import { getMyCard } from '../../apis/myCard.js';
import { getCards } from '../../apis/cards.js';
import { getCardList, getMyCard } from '../../apis';

const member_id = 5; // dummy data

Expand All @@ -33,8 +32,8 @@ export default function HomePage() {

async function fetchCards(member_id) {
try {
const response = await getCards({ member_id: member_id });
setCardsData(response.data.cards);
const { cards } = await getCardList(member_id);
setCardsData(cards);
} catch (error) {
console.error('카드 리스트를 불러오지 못했습니다.', error);
}
Expand Down

0 comments on commit a38befd

Please sign in to comment.