forked from pagers-org/Menu-Management-App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 서버 API 및 fetchAPI 래퍼 추가 pagers-org#20
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import request from '../utils/request.js'; | ||
import { Tparams } from '../types/api.js'; | ||
|
||
/* 카테고리별 메뉴리스트 조회 */ | ||
export const getMenus = (category: string) => { | ||
return request({ | ||
url: `/api/category/${category}/menu`, | ||
method: 'GET', | ||
}); | ||
}; | ||
|
||
/* 메뉴 생성 */ | ||
export const createMenu = ({ category, name }: Tparams) => { | ||
return request({ | ||
url: `/api/category/${category}/menu`, | ||
method: 'POST', | ||
data: { name }, | ||
}); | ||
}; | ||
|
||
/* 메뉴 이름 수정 */ | ||
export const modifyMenu = ({ category, menuId, name }: Tparams) => { | ||
return request({ | ||
url: `/api/category/${category}/menu/${menuId}`, | ||
method: 'PUT', | ||
data: { name }, | ||
}); | ||
}; | ||
|
||
/* 메뉴 품절 처리 */ | ||
export const soleOutMenu = ({ category, menuId }: Tparams) => { | ||
return request({ | ||
url: `/api/category/${category}/menu/${menuId}`, | ||
method: 'PUT', | ||
}); | ||
}; | ||
|
||
/* 메뉴 삭제 */ | ||
export const deleteMenu = ({ category, menuId }: Tparams) => { | ||
return request({ | ||
url: `/api/category/${category}/menu/${menuId}`, | ||
method: 'DELETE', | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type Tparams = { | ||
category: string; | ||
menuId?: string; | ||
name?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const SERVER_URL = 'http://localhost:3000' as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { SERVER_URL } from '../utils/constants/env.js'; | ||
|
||
type Tconfig = { | ||
url: string; | ||
method: string; | ||
data?: { name?: string }; | ||
}; | ||
|
||
export default async (config: Tconfig) => { | ||
const { url, method, data } = config; | ||
|
||
const requestUrl = SERVER_URL + url; | ||
|
||
const response = await fetch(requestUrl, { | ||
method, | ||
body: JSON.stringify(data), | ||
}); | ||
console.log('요청정보? >>>> ', response); | ||
const resData = await response.json(); | ||
|
||
if (response.status === 200) { | ||
return resData; | ||
} else { | ||
throw new Error('서버요청 에러!!'); | ||
} | ||
}; |