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

@@ -180,7 +180,7 @@ public static function getTenants(array $params = [])
$paginator = $query->paginate($pageSize, ['*'], 'page', $pageNo);
return ApiResponse::response('result', $paginator);
return $paginator;
}
/**
@@ -203,7 +203,7 @@ public static function getTenant(array $params = [])
->first();
if (!$userTenant) {
return ApiResponse::error('활성(기본) 테넌트를 찾을 수 없습니다.', 404);
return ['error' => '활성(기본) 테넌트를 찾을 수 없습니다.', 'code' => 404];
}
$tenantId = $userTenant->tenant_id;
}
@@ -213,7 +213,7 @@ public static function getTenant(array $params = [])
->select('id','company_name','code','email','phone','address','business_num','corp_reg_no','ceo_name','homepage','fax','logo','admin_memo','options','created_at','updated_at')
->where('id', $tenantId);
return ApiResponse::response('first', $query);
return $query->first();
}
/**
@@ -241,7 +241,7 @@ public static function storeTenants(array $params = [])
if ($validator->fails()) {
return ApiResponse::error($validator->errors()->first(), 400);
return ['error' => $validator->errors()->first(), 'code' => 400];
}
$payload = $validator->validated();
@@ -276,7 +276,7 @@ public static function storeTenants(array $params = [])
]);
// 생성된 리소스를 그대로 반환 (목록 카드용 요약 원하면 컬럼 제한)
return ApiResponse::response('result', $tenant);
return $tenant;
}
/**
@@ -303,7 +303,7 @@ public static function updateTenant(array $params = [])
]);
if ($validator->fails()) {
return ApiResponse::error($validator->errors()->first(), 400);
return ['error' => $validator->errors()->first(), 'code' => 400];
}
$payload = $validator->validated();
@@ -311,17 +311,17 @@ public static function updateTenant(array $params = [])
unset($payload['tenant_id']);
if (empty($payload)) {
return ApiResponse::error('수정할 데이터가 없습니다.', 400);
return ['error' => '수정할 데이터가 없습니다.', 'code' => 400];
}
$tenant = Tenant::find($tenantId);
if (!$tenant) {
return ApiResponse::error('테넌트를 찾을 수 없습니다.', 404);
return ['error' => '테넌트를 찾을 수 없습니다.', 'code' => 404];
}
$tenant->update($payload);
return ApiResponse::response('result', $tenant->fresh());
return $tenant->fresh();
}
/**
@@ -333,17 +333,17 @@ public static function destroyTenant(array $params = [])
{
$tenantId = $params['tenant_id'] ?? app('tenant_id');
if (!$tenantId) {
return ApiResponse::error('tenant_id가 필요합니다.', 400);
return ['error' => 'tenant_id가 필요합니다.', 'code' => 400];
}
$tenant = Tenant::find($tenantId);
if (!$tenant) {
return ApiResponse::error('테넌트를 찾을 수 없습니다.', 404);
return ['error' => '테넌트를 찾을 수 없습니다.', 'code' => 404];
}
$tenant->delete(); // SoftDeletes 트레이트가 있으면 소프트 삭제
return ApiResponse::response('success');
return 'success';
}
/**
@@ -358,19 +358,19 @@ public static function restoreTenant(array $params = [])
// 소프트 삭제 포함 조회
$tenant = Tenant::withTrashed()->find($tenantId);
if (!$tenant) {
return ApiResponse::error('테넌트를 찾을 수 없습니다.', 404);
return ['error' => '테넌트를 찾을 수 없습니다.', 'code' => 404];
}
if (is_null($tenant->deleted_at)) {
// 이미 활성 상태
return ApiResponse::error('이미 활성화된 테넌트입니다.', 400);
return ['error' => '이미 활성화된 테넌트입니다.', 'code' => 400];
}
$tenant->restore();
// 복구 결과를 data에 담고 싶으면 fresh() 후 필요한 필드만 반환
// return ApiResponse::response('result', $tenant->fresh());
// return $tenant->fresh();
return ApiResponse::response('success');
return 'success';
}
}