fix : 결과 전달시 두번 래핑되는 부분 수정
- 컨트롤러와 서비스에서 각각 래핑 후 결과 전달됨으로 이중 래핑되고 있음 -> 서비스에서 래핑하는 부분을 컨트롤러로 옮겨서 컨트롤러에서만 한번 래핑하는 걸로 수정
This commit is contained in:
@@ -42,7 +42,7 @@ public static function index(array $params = [])
|
||||
{
|
||||
$tenantId = self::tenantId();
|
||||
if (!$tenantId) {
|
||||
return ApiResponse::error('활성 테넌트가 없습니다.', 400);
|
||||
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
|
||||
}
|
||||
|
||||
$per = (int)($params['per_page'] ?? $params['size'] ?? 20);
|
||||
@@ -60,7 +60,7 @@ public static function index(array $params = [])
|
||||
$page = isset($params['page']) ? (int)$params['page'] : null;
|
||||
$data = $q->orderByDesc('id')->paginate($per, ['*'], 'page', $page);
|
||||
|
||||
return ApiResponse::response('result', $data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,10 +70,10 @@ public static function show(int $userId)
|
||||
{
|
||||
$tenantId = self::tenantId();
|
||||
if (!$tenantId) {
|
||||
return ApiResponse::error('활성 테넌트가 없습니다.', 400);
|
||||
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
|
||||
}
|
||||
if (!$userId) {
|
||||
return ApiResponse::error('userId가 올바르지 않습니다.', 422);
|
||||
return ['error' => 'userId가 올바르지 않습니다.', 'code' => 422];
|
||||
}
|
||||
|
||||
$item = TenantUserProfile::where('tenant_id', $tenantId)
|
||||
@@ -82,10 +82,10 @@ public static function show(int $userId)
|
||||
->first();
|
||||
|
||||
if (!$item) {
|
||||
return ApiResponse::error('프로필을 찾을 수 없습니다.', 404);
|
||||
return ['error' => '프로필을 찾을 수 없습니다.', 'code' => 404];
|
||||
}
|
||||
|
||||
return ApiResponse::response('result', $item->toArray());
|
||||
return $item->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,15 +96,15 @@ public static function update(int $userId, array $params = [])
|
||||
{
|
||||
$tenantId = self::tenantId();
|
||||
if (!$tenantId) {
|
||||
return ApiResponse::error('활성 테넌트가 없습니다.', 400);
|
||||
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
|
||||
}
|
||||
if (!$userId) {
|
||||
return ApiResponse::error('userId가 올바르지 않습니다.', 422);
|
||||
return ['error' => 'userId가 올바르지 않습니다.', 'code' => 422];
|
||||
}
|
||||
|
||||
// (선택) 간단 유효성: 최소 1개 키 존재
|
||||
if (empty($params) || !is_array($params)) {
|
||||
return ApiResponse::error('수정할 항목이 없습니다.', 422);
|
||||
return ['error' => '수정할 항목이 없습니다.', 'code' => 422];
|
||||
}
|
||||
|
||||
$fields = self::effectiveFieldMap($tenantId);
|
||||
@@ -141,7 +141,7 @@ public static function update(int $userId, array $params = [])
|
||||
$profile->save();
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
return ApiResponse::error('프로필 저장 중 오류가 발생했습니다.', 500);
|
||||
return ['error' => '프로필 저장 중 오류가 발생했습니다.', 'code' => 500];
|
||||
}
|
||||
|
||||
$fresh = TenantUserProfile::where('tenant_id', $tenantId)
|
||||
@@ -149,7 +149,7 @@ public static function update(int $userId, array $params = [])
|
||||
->with(['user:id,name,email'])
|
||||
->first();
|
||||
|
||||
return ApiResponse::response('result', $fresh ? $fresh->toArray() : null);
|
||||
return $fresh ? $fresh->toArray() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,11 +159,11 @@ public static function me(array $params = [])
|
||||
{
|
||||
$tenantId = self::tenantId();
|
||||
if (!$tenantId) {
|
||||
return ApiResponse::error('활성 테넌트가 없습니다.', 400);
|
||||
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
|
||||
}
|
||||
$userId = auth()->id();
|
||||
if (!$userId) {
|
||||
return ApiResponse::error('인증 정보가 없습니다.', 401);
|
||||
return ['error' => '인증 정보가 없습니다.', 'code' => 401];
|
||||
}
|
||||
|
||||
$item = TenantUserProfile::where('tenant_id', $tenantId)
|
||||
@@ -172,7 +172,7 @@ public static function me(array $params = [])
|
||||
->first();
|
||||
|
||||
// 없으면 null 반환(스펙에 따라 404로 바꾸려면 위와 동일 처리)
|
||||
return ApiResponse::response('result', $item ? $item->toArray() : null);
|
||||
return $item ? $item->toArray() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,11 +183,11 @@ public static function updateMe(array $params = [])
|
||||
{
|
||||
$tenantId = self::tenantId();
|
||||
if (!$tenantId) {
|
||||
return ApiResponse::error('활성 테넌트가 없습니다.', 400);
|
||||
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
|
||||
}
|
||||
$userId = auth()->id();
|
||||
if (!$userId) {
|
||||
return ApiResponse::error('인증 정보가 없습니다.', 401);
|
||||
return ['error' => '인증 정보가 없습니다.', 'code' => 401];
|
||||
}
|
||||
return self::update($userId, $params);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user