diff --git a/src/api/shopApi.ts b/src/api/shopApi.ts index 43213375..afdcf53c 100644 --- a/src/api/shopApi.ts +++ b/src/api/shopApi.ts @@ -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; @@ -43,3 +49,51 @@ export interface ShopResponse { }; links: LinkInfo[]; } + +// POST /shops - 가게 등록 +export const postShop = async (body: ShopRequest): Promise => { + try { + const response = await api.post('/shops', body); + return response.data; + } catch (error) { + const axiosError = error as AxiosError; // 에러 타입 명시 + 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 => { + try { + const response = await api.get(`/shops/${shopId}`); + return response.data; + } catch (error) { + const axiosError = error as AxiosError; // 에러 타입 명시 + 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 => { + try { + const response = await api.put(`/shops/${shopId}`, body); + return response.data; + } catch (error) { + const axiosError = error as AxiosError; // 에러 타입 명시 + if (axiosError.response) { + throw new Error(axiosError.response.data.message); + } else { + throw new Error('서버에 연결할 수 없습니다. 인터넷 연결을 확인해주세요.'); + } + } +};