style: Laravel Pint 코드 포맷팅 적용
- PSR-12 스타일 가이드 준수 - 302개 파일 스타일 이슈 자동 수정 - 코드 로직 변경 없음 (포맷팅만)
This commit is contained in:
@@ -2,13 +2,12 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
use App\Models\Tenants\SettingFieldDef;
|
||||
use App\Models\Tenants\TenantFieldSetting;
|
||||
use App\Models\Tenants\TenantOptionGroup;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class TenantFieldSettingService
|
||||
{
|
||||
@@ -21,23 +20,24 @@ protected static function tenantId(): ?int
|
||||
/** 효과값 1개 빌드: 전역정의 + 테넌트설정 merge */
|
||||
protected static function buildEffectiveRow(SettingFieldDef $def, ?TenantFieldSetting $s): array
|
||||
{
|
||||
$enabled = $s ? (bool)$s->enabled : (bool)$def->is_core;
|
||||
$enabled = $s ? (bool) $s->enabled : (bool) $def->is_core;
|
||||
|
||||
return [
|
||||
'field_key' => $def->field_key,
|
||||
'label' => $def->label,
|
||||
'data_type' => $def->data_type,
|
||||
'input_type' => $def->input_type,
|
||||
'option_source' => $def->option_source,
|
||||
'option_payload' => $def->option_payload,
|
||||
'storage_area' => $def->storage_area,
|
||||
'storage_key' => $def->storage_key,
|
||||
'is_core' => (bool)$def->is_core,
|
||||
'field_key' => $def->field_key,
|
||||
'label' => $def->label,
|
||||
'data_type' => $def->data_type,
|
||||
'input_type' => $def->input_type,
|
||||
'option_source' => $def->option_source,
|
||||
'option_payload' => $def->option_payload,
|
||||
'storage_area' => $def->storage_area,
|
||||
'storage_key' => $def->storage_key,
|
||||
'is_core' => (bool) $def->is_core,
|
||||
// tenant overlay
|
||||
'enabled' => $enabled,
|
||||
'required' => $s ? (bool)$s->required : false,
|
||||
'sort_order' => $s ? (int)$s->sort_order : 0,
|
||||
'enabled' => $enabled,
|
||||
'required' => $s ? (bool) $s->required : false,
|
||||
'sort_order' => $s ? (int) $s->sort_order : 0,
|
||||
'option_group_id' => $s ? $s->option_group_id : null,
|
||||
'code_group' => $s ? $s->code_group : null,
|
||||
'code_group' => $s ? $s->code_group : null,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ protected static function buildEffectiveRow(SettingFieldDef $def, ?TenantFieldSe
|
||||
public static function index(array $params = [])
|
||||
{
|
||||
$tenantId = self::tenantId();
|
||||
if (!$tenantId) {
|
||||
if (! $tenantId) {
|
||||
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
|
||||
}
|
||||
|
||||
@@ -74,8 +74,7 @@ public static function index(array $params = [])
|
||||
$rows[] = $effective;
|
||||
}
|
||||
|
||||
usort($rows, fn ($a, $b) =>
|
||||
($a['sort_order'] <=> $b['sort_order']) ?: strcmp($a['field_key'], $b['field_key'])
|
||||
usort($rows, fn ($a, $b) => ($a['sort_order'] <=> $b['sort_order']) ?: strcmp($a['field_key'], $b['field_key'])
|
||||
);
|
||||
|
||||
return array_values($rows);
|
||||
@@ -89,18 +88,18 @@ public static function index(array $params = [])
|
||||
public static function bulkUpsert(array $params = [])
|
||||
{
|
||||
$tenantId = self::tenantId();
|
||||
if (!$tenantId) {
|
||||
if (! $tenantId) {
|
||||
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
|
||||
}
|
||||
|
||||
$v = Validator::make($params, [
|
||||
'items' => ['required','array','min:1'],
|
||||
'items.*.field_key' => ['required','string','max:64', Rule::exists('setting_field_defs','field_key')],
|
||||
'items.*.enabled' => ['nullable','boolean'],
|
||||
'items.*.required' => ['nullable','boolean'],
|
||||
'items.*.sort_order' => ['nullable','integer'],
|
||||
'items.*.option_group_id' => ['nullable','integer'],
|
||||
'items.*.code_group' => ['nullable','string','max:50'],
|
||||
'items' => ['required', 'array', 'min:1'],
|
||||
'items.*.field_key' => ['required', 'string', 'max:64', Rule::exists('setting_field_defs', 'field_key')],
|
||||
'items.*.enabled' => ['nullable', 'boolean'],
|
||||
'items.*.required' => ['nullable', 'boolean'],
|
||||
'items.*.sort_order' => ['nullable', 'integer'],
|
||||
'items.*.option_group_id' => ['nullable', 'integer'],
|
||||
'items.*.code_group' => ['nullable', 'string', 'max:50'],
|
||||
]);
|
||||
|
||||
if ($v->fails()) {
|
||||
@@ -113,11 +112,11 @@ public static function bulkUpsert(array $params = [])
|
||||
DB::transaction(function () use ($payload, $tenantId) {
|
||||
foreach ($payload['items'] as $row) {
|
||||
// option_group_id 유효성(해당 테넌트 소유인지)
|
||||
if (!empty($row['option_group_id'])) {
|
||||
if (! empty($row['option_group_id'])) {
|
||||
$exists = TenantOptionGroup::where('tenant_id', $tenantId)
|
||||
->where('id', $row['option_group_id'])
|
||||
->exists();
|
||||
if (!$exists) {
|
||||
if (! $exists) {
|
||||
throw new \RuntimeException('option_group_id is invalid for this tenant');
|
||||
}
|
||||
}
|
||||
@@ -125,11 +124,11 @@ public static function bulkUpsert(array $params = [])
|
||||
TenantFieldSetting::updateOrCreate(
|
||||
['tenant_id' => $tenantId, 'field_key' => $row['field_key']],
|
||||
[
|
||||
'enabled' => isset($row['enabled']) ? (int)$row['enabled'] : 0,
|
||||
'required' => isset($row['required']) ? (int)$row['required'] : 0,
|
||||
'sort_order' => isset($row['sort_order']) ? (int)$row['sort_order'] : 0,
|
||||
'enabled' => isset($row['enabled']) ? (int) $row['enabled'] : 0,
|
||||
'required' => isset($row['required']) ? (int) $row['required'] : 0,
|
||||
'sort_order' => isset($row['sort_order']) ? (int) $row['sort_order'] : 0,
|
||||
'option_group_id' => $row['option_group_id'] ?? null,
|
||||
'code_group' => $row['code_group'] ?? null,
|
||||
'code_group' => $row['code_group'] ?? null,
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -150,22 +149,22 @@ public static function bulkUpsert(array $params = [])
|
||||
public static function updateOne(string $fieldKey, array $params = [])
|
||||
{
|
||||
$tenantId = self::tenantId();
|
||||
if (!$tenantId) {
|
||||
if (! $tenantId) {
|
||||
return ['error' => '활성 테넌트가 없습니다.', 'code' => 400];
|
||||
}
|
||||
|
||||
// 전역 key 존재 확인
|
||||
$def = SettingFieldDef::where('field_key', $fieldKey)->first();
|
||||
if (!$def) {
|
||||
if (! $def) {
|
||||
return ['error' => 'field_key not found', 'code' => 404];
|
||||
}
|
||||
|
||||
$v = Validator::make($params, [
|
||||
'enabled' => ['nullable','boolean'],
|
||||
'required' => ['nullable','boolean'],
|
||||
'sort_order' => ['nullable','integer'],
|
||||
'option_group_id' => ['nullable','integer'],
|
||||
'code_group' => ['nullable','string','max:50'],
|
||||
'enabled' => ['nullable', 'boolean'],
|
||||
'required' => ['nullable', 'boolean'],
|
||||
'sort_order' => ['nullable', 'integer'],
|
||||
'option_group_id' => ['nullable', 'integer'],
|
||||
'code_group' => ['nullable', 'string', 'max:50'],
|
||||
]);
|
||||
|
||||
if ($v->fails()) {
|
||||
@@ -174,11 +173,11 @@ public static function updateOne(string $fieldKey, array $params = [])
|
||||
$data = $v->validated();
|
||||
|
||||
// option_group_id 테넌트 소유 검증
|
||||
if (!empty($data['option_group_id'])) {
|
||||
if (! empty($data['option_group_id'])) {
|
||||
$ok = TenantOptionGroup::where('tenant_id', $tenantId)
|
||||
->where('id', $data['option_group_id'])
|
||||
->exists();
|
||||
if (!$ok) {
|
||||
if (! $ok) {
|
||||
return ['error' => 'option_group_id is invalid for this tenant', 'code' => 422];
|
||||
}
|
||||
}
|
||||
@@ -190,7 +189,7 @@ public static function updateOne(string $fieldKey, array $params = [])
|
||||
]);
|
||||
|
||||
// 제공된 키만 반영
|
||||
foreach (['enabled','required','sort_order','option_group_id','code_group'] as $k) {
|
||||
foreach (['enabled', 'required', 'sort_order', 'option_group_id', 'code_group'] as $k) {
|
||||
if (array_key_exists($k, $data)) {
|
||||
$item->{$k} = $data[$k];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user