fix : 결과 전달시 두번 래핑되는 부분 수정
- 컨트롤러와 서비스에서 각각 래핑 후 결과 전달됨으로 이중 래핑되고 있음 -> 서비스에서 래핑하는 부분을 컨트롤러로 옮겨서 컨트롤러에서만 한번 래핑하는 걸로 수정
This commit is contained in:
@@ -74,7 +74,7 @@ public static function list(int $userId)
|
||||
|
||||
$user = self::loadUserOrError($userId);
|
||||
if (!$user) {
|
||||
return ApiResponse::error('사용자를 찾을 수 없습니다.', 404);
|
||||
return ['error' => '사용자를 찾을 수 없습니다.', 'code' => 404];
|
||||
}
|
||||
|
||||
self::setTeam($tenantId);
|
||||
@@ -86,7 +86,7 @@ public static function list(int $userId)
|
||||
->select(['roles.id','roles.tenant_id','roles.name','roles.description','roles.guard_name','roles.created_at','roles.updated_at'])
|
||||
->orderBy('roles.id', 'desc');
|
||||
|
||||
return ApiResponse::response('get', $builder);
|
||||
return $builder->get();
|
||||
}
|
||||
|
||||
/** 부여 (중복 무시) */
|
||||
@@ -96,7 +96,7 @@ public static function grant(int $userId, array $params = [])
|
||||
|
||||
$user = self::loadUserOrError($userId);
|
||||
if (!$user) {
|
||||
return ApiResponse::error('사용자를 찾을 수 없습니다.', 404);
|
||||
return ['error' => '사용자를 찾을 수 없습니다.', 'code' => 404];
|
||||
}
|
||||
|
||||
$v = Validator::make($params, [
|
||||
@@ -106,21 +106,21 @@ public static function grant(int $userId, array $params = [])
|
||||
'role_ids.*' => 'integer|min:1',
|
||||
]);
|
||||
if ($v->fails()) {
|
||||
return ApiResponse::error($v->errors()->first(), 422);
|
||||
return ['error' => $v->errors()->first(), 'code' => 422];
|
||||
}
|
||||
if (empty($params['role_names']) && empty($params['role_ids'])) {
|
||||
return ApiResponse::error('role_names 또는 role_ids 중 하나는 필요합니다.', 422);
|
||||
return ['error' => 'role_names 또는 role_ids 중 하나는 필요합니다.', 'code' => 422];
|
||||
}
|
||||
|
||||
self::setTeam($tenantId);
|
||||
|
||||
$names = self::resolveRoleNames($tenantId, $params);
|
||||
if (empty($names)) {
|
||||
return ApiResponse::error('유효한 역할이 없습니다.', 422);
|
||||
return ['error' => '유효한 역할이 없습니다.', 'code' => 422];
|
||||
}
|
||||
|
||||
$user->assignRole($names); // teams 컨텍스트 적용됨
|
||||
return ApiResponse::response('success');
|
||||
return 'success';
|
||||
}
|
||||
|
||||
/** 회수 (없는 건 무시) */
|
||||
@@ -130,7 +130,7 @@ public static function revoke(int $userId, array $params = [])
|
||||
|
||||
$user = self::loadUserOrError($userId);
|
||||
if (!$user) {
|
||||
return ApiResponse::error('사용자를 찾을 수 없습니다.', 404);
|
||||
return ['error' => '사용자를 찾을 수 없습니다.', 'code' => 404];
|
||||
}
|
||||
|
||||
$v = Validator::make($params, [
|
||||
@@ -140,21 +140,21 @@ public static function revoke(int $userId, array $params = [])
|
||||
'role_ids.*' => 'integer|min:1',
|
||||
]);
|
||||
if ($v->fails()) {
|
||||
return ApiResponse::error($v->errors()->first(), 422);
|
||||
return ['error' => $v->errors()->first(), 'code' => 422];
|
||||
}
|
||||
if (empty($params['role_names']) && empty($params['role_ids'])) {
|
||||
return ApiResponse::error('role_names 또는 role_ids 중 하나는 필요합니다.', 422);
|
||||
return ['error' => 'role_names 또는 role_ids 중 하나는 필요합니다.', 'code' => 422];
|
||||
}
|
||||
|
||||
self::setTeam($tenantId);
|
||||
|
||||
$names = self::resolveRoleNames($tenantId, $params);
|
||||
if (empty($names)) {
|
||||
return ApiResponse::error('유효한 역할이 없습니다.', 422);
|
||||
return ['error' => '유효한 역할이 없습니다.', 'code' => 422];
|
||||
}
|
||||
|
||||
$user->removeRole($names); // 배열 허용
|
||||
return ApiResponse::response('success');
|
||||
return 'success';
|
||||
}
|
||||
|
||||
/** 동기화(완전 교체) */
|
||||
@@ -164,7 +164,7 @@ public static function sync(int $userId, array $params = [])
|
||||
|
||||
$user = self::loadUserOrError($userId);
|
||||
if (!$user) {
|
||||
return ApiResponse::error('사용자를 찾을 수 없습니다.', 404);
|
||||
return ['error' => '사용자를 찾을 수 없습니다.', 'code' => 404];
|
||||
}
|
||||
|
||||
$v = Validator::make($params, [
|
||||
@@ -174,10 +174,10 @@ public static function sync(int $userId, array $params = [])
|
||||
'role_ids.*' => 'integer|min:1',
|
||||
]);
|
||||
if ($v->fails()) {
|
||||
return ApiResponse::error($v->errors()->first(), 422);
|
||||
return ['error' => $v->errors()->first(), 'code' => 422];
|
||||
}
|
||||
if (empty($params['role_names']) && empty($params['role_ids'])) {
|
||||
return ApiResponse::error('role_names 또는 role_ids 중 하나는 필요합니다.', 422);
|
||||
return ['error' => 'role_names 또는 role_ids 중 하나는 필요합니다.', 'code' => 422];
|
||||
}
|
||||
|
||||
self::setTeam($tenantId);
|
||||
@@ -185,10 +185,10 @@ public static function sync(int $userId, array $params = [])
|
||||
$names = self::resolveRoleNames($tenantId, $params);
|
||||
if (empty($names)) {
|
||||
// 정책상 빈 목록 sync 허용 시: $user->syncRoles([]) 로 전부 제거 가능
|
||||
return ApiResponse::error('유효한 역할이 없습니다.', 422);
|
||||
return ['error' => '유효한 역할이 없습니다.', 'code' => 422];
|
||||
}
|
||||
|
||||
$user->syncRoles($names);
|
||||
return ApiResponse::response('success');
|
||||
return 'success';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user