diff --git a/src/api/userApi.ts b/src/api/userApi.ts index 8f60a665..7a98383d 100644 --- a/src/api/userApi.ts +++ b/src/api/userApi.ts @@ -123,3 +123,39 @@ export const postToken = async ({ } } }; + +// get /users/{user_id} - 회원 정보 조회 +export const getUser = async (userId: string): Promise => { + try { + const response = await api.get(`/users/${userId}`); + 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 /users/{user_id} - 회원 정보 수정 +export const putUser = async ( + userId: string, + body: UpdateUserRequest, +): Promise => { + try { + const response = await api.put( + `/users/${userId}`, + 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('서버에 연결할 수 없습니다. 인터넷 연결을 확인해주세요.'); + } + } +};