fix : 결과 전달시 두번 래핑되는 부분 수정

- 컨트롤러와 서비스에서 각각 래핑 후 결과 전달됨으로 이중 래핑되고 있음
  -> 서비스에서 래핑하는 부분을 컨트롤러로 옮겨서 컨트롤러에서만 한번 래핑하는 걸로 수정
This commit is contained in:
2025-08-19 12:41:17 +09:00
parent aa190bf48d
commit 43e4c507a7
18 changed files with 299 additions and 277 deletions

View File

@@ -35,7 +35,7 @@ public static function index(array $params = [])
$list = $query->orderByDesc('id')
->paginate($size, ['*'], 'page', $page);
return ApiResponse::response('result', $list);
return $list;
}
/** 생성 */
@@ -54,7 +54,7 @@ public static function store(array $params = [])
]);
if ($v->fails()) {
return ApiResponse::error($v->errors()->first(), 422);
return ['error' => $v->errors()->first(), 'code' => 422];
}
// Spatie 팀(테넌트) 컨텍스트
@@ -67,7 +67,7 @@ public static function store(array $params = [])
'description' => $params['description'] ?? null,
]);
return ApiResponse::response('result', $role);
return $role;
}
/** 단건 */
@@ -80,10 +80,10 @@ public static function show(int $id)
->find($id);
if (!$role) {
return ApiResponse::error('역할을 찾을 수 없습니다.', 404);
return ['error' => '역할을 찾을 수 없습니다.', 'code' => 404];
}
return ApiResponse::response('result', $role);
return $role;
}
/** 수정 */
@@ -96,7 +96,7 @@ public static function update(int $id, array $params = [])
->find($id);
if (!$role) {
return ApiResponse::error('역할을 찾을 수 없습니다.', 404);
return ['error' => '역할을 찾을 수 없습니다.', 'code' => 404];
}
$v = Validator::make($params, [
@@ -110,12 +110,12 @@ public static function update(int $id, array $params = [])
]);
if ($v->fails()) {
return ApiResponse::error($v->errors()->first(), 422);
return ['error' => $v->errors()->first(), 'code' => 422];
}
$role->fill($v->validated())->save();
return ApiResponse::response('result', $role->fresh());
return $role->fresh();
}
/** 삭제 (하드삭제) */
@@ -128,13 +128,13 @@ public static function destroy(int $id)
->find($id);
if (!$role) {
return ApiResponse::error('역할을 찾을 수 없습니다.', 404);
return ['error' => '역할을 찾을 수 없습니다.', 'code' => 404];
}
DB::transaction(function () use ($role) {
$role->delete(); // Spatie Role 기본: soft delete 없음
});
return ApiResponse::response('success');
return 'success';
}
}