Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/api/shopApi.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import api from './api';
import { AxiosError } from 'axios';
import type {
ADDRESS_OPTIONS,
CATEGORY_OPTIONS,
} from '@/constants/dropdownOptions';
import type { UserProfileItem } from './userApi';

interface ErrorMessage {
message: string;
}

export interface LinkInfo {
rel: string;
description: string;
Expand Down Expand Up @@ -43,3 +49,51 @@ export interface ShopResponse {
};
links: LinkInfo[];
}

// POST /shops - 가게 등록
export const postShop = async (body: ShopRequest): Promise<ShopResponse> => {
try {
const response = await api.post<ShopResponse>('/shops', body);
return response.data;
} catch (error) {
const axiosError = error as AxiosError<ErrorMessage>; // 에러 타입 명시
if (axiosError.response) {
throw new Error(axiosError.response.data.message);
} else {
throw new Error('서버에 연결할 수 없습니다. 인터넷 연결을 확인해주세요.');
}
}
};

// GET /shops/{shop_id} - 가게 정보 조회
export const getShop = async (shopId: string): Promise<ShopResponse> => {
try {
const response = await api.get<ShopResponse>(`/shops/${shopId}`);
return response.data;
} catch (error) {
const axiosError = error as AxiosError<ErrorMessage>; // 에러 타입 명시
if (axiosError.response) {
throw new Error(axiosError.response.data.message);
} else {
throw new Error('서버에 연결할 수 없습니다. 인터넷 연결을 확인해주세요.');
}
}
};

// PUT /shops/{shop_id} - 가게 정보 수정
export const putShop = async (
shopId: string,
body: ShopRequest,
): Promise<ShopResponse> => {
try {
const response = await api.put<ShopResponse>(`/shops/${shopId}`, body);
return response.data;
} catch (error) {
const axiosError = error as AxiosError<ErrorMessage>; // 에러 타입 명시
if (axiosError.response) {
throw new Error(axiosError.response.data.message);
} else {
throw new Error('서버에 연결할 수 없습니다. 인터넷 연결을 확인해주세요.');
}
}
};