refac, feat: API 호출 구조 재작성
- api.php에서 param path 강제 - api.php에서 GET param 허용 - SammoAPI 호출자를 axios에서 fetch 기반(ky)로 변경 - SammoAPI에서 단순 POST대신 REST에 따라 지정 가능하도록 재구성 - SammoAPI에서 NumVar, StrVar를 PathParam으로 변경하도록 변경 - API CallType들을 def/API로 분리 시작 - 일부 API를 시험삼아 변경(login)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export function APIPathGen(obj, callback, path) {
|
||||
export function APIPathGen(obj, callback, path, pathParams) {
|
||||
return new Proxy(obj, {
|
||||
get(target, key) {
|
||||
let nextPath;
|
||||
@@ -9,12 +9,21 @@ export function APIPathGen(obj, callback, path) {
|
||||
nextPath = [...path, key.toString()];
|
||||
}
|
||||
|
||||
if (pathParams !== undefined) {
|
||||
pathParams = { ...pathParams };
|
||||
}
|
||||
|
||||
const varType = target.__nextVarType;
|
||||
const varKey = target.__nextVarKey;
|
||||
let next;
|
||||
if (varType !== undefined) {
|
||||
if (varType !== undefined && varKey !== undefined) {
|
||||
if (typeof key !== varType) {
|
||||
throw `${key} is not ${varType}`;
|
||||
}
|
||||
if(pathParams === undefined){
|
||||
pathParams = {}
|
||||
}
|
||||
pathParams[varKey] = key;
|
||||
next = target.next;
|
||||
}
|
||||
else if (key in target) {
|
||||
@@ -25,26 +34,28 @@ export function APIPathGen(obj, callback, path) {
|
||||
}
|
||||
|
||||
if (typeof (next) === 'function') {
|
||||
return callback(nextPath);
|
||||
return callback(nextPath, next, pathParams);
|
||||
}
|
||||
return APIPathGen(next, callback, nextPath);
|
||||
return APIPathGen(next, callback, nextPath, pathParams);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//generic 인자로 '자동'을 주려면 생략해야하므로 2단 호출
|
||||
export function StrVar() {
|
||||
export function StrVar(key) {
|
||||
return (next) => {
|
||||
return {
|
||||
__nextVarType: 'string',
|
||||
__nextVarKey: key,
|
||||
next
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function NumVar(next) {
|
||||
export function NumVar(key, next) {
|
||||
return {
|
||||
__nextVarType: 'number',
|
||||
__nextVarKey: key,
|
||||
next
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user