style: Laravel Pint 코드 포맷팅 적용
- PSR-12 스타일 가이드 준수 - 302개 파일 스타일 이슈 자동 수정 - 코드 로직 변경 없음 (포맷팅만)
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use App\Models\Commons\CategoryField; // 가정: Eloquent 모델 경로
|
||||
use App\Models\Commons\Category;
|
||||
use App\Models\Commons\CategoryField;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator; // 가정: Eloquent 모델 경로
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
class CategoryFieldService extends Service
|
||||
{
|
||||
@@ -14,7 +14,7 @@ public function index(int $categoryId, array $params)
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
$size = (int)($params['size'] ?? 20);
|
||||
$size = (int) ($params['size'] ?? 20);
|
||||
$sort = $params['sort'] ?? 'sort_order';
|
||||
$order = strtolower($params['order'] ?? 'asc') === 'desc' ? 'desc' : 'asc';
|
||||
|
||||
@@ -28,19 +28,19 @@ public function index(int $categoryId, array $params)
|
||||
public function store(int $categoryId, array $data)
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$this->assertCategoryExists($tenantId, $categoryId);
|
||||
|
||||
$v = Validator::make($data, [
|
||||
'field_key' => 'required|string|max:30|alpha_dash',
|
||||
'field_name' => 'required|string|max:100',
|
||||
'field_type' => 'required|string|max:20',
|
||||
'is_required' => 'nullable|in:Y,N',
|
||||
'sort_order' => 'nullable|integer|min:0',
|
||||
'field_key' => 'required|string|max:30|alpha_dash',
|
||||
'field_name' => 'required|string|max:100',
|
||||
'field_type' => 'required|string|max:20',
|
||||
'is_required' => 'nullable|in:Y,N',
|
||||
'sort_order' => 'nullable|integer|min:0',
|
||||
'default_value' => 'nullable|string|max:100',
|
||||
'options' => 'nullable|json',
|
||||
'description' => 'nullable|string|max:255',
|
||||
'options' => 'nullable|json',
|
||||
'description' => 'nullable|string|max:255',
|
||||
]);
|
||||
$payload = $v->validate();
|
||||
|
||||
@@ -54,11 +54,11 @@ public function store(int $categoryId, array $data)
|
||||
throw new BadRequestHttpException(__('error.duplicate_key')); // ko/error.php에 매핑
|
||||
}
|
||||
|
||||
$payload['tenant_id'] = $tenantId;
|
||||
$payload['tenant_id'] = $tenantId;
|
||||
$payload['category_id'] = $categoryId;
|
||||
$payload['is_required'] = $payload['is_required'] ?? 'N';
|
||||
$payload['sort_order'] = $payload['sort_order'] ?? 0;
|
||||
$payload['created_by'] = $userId;
|
||||
$payload['sort_order'] = $payload['sort_order'] ?? 0;
|
||||
$payload['created_by'] = $userId;
|
||||
|
||||
return CategoryField::create($payload);
|
||||
}
|
||||
@@ -71,34 +71,35 @@ public function show(int $fieldId)
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($fieldId);
|
||||
|
||||
if (!$field) {
|
||||
if (! $field) {
|
||||
throw new BadRequestHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function update(int $fieldId, array $data)
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$field = CategoryField::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($fieldId);
|
||||
|
||||
if (!$field) {
|
||||
if (! $field) {
|
||||
throw new BadRequestHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
$v = Validator::make($data, [
|
||||
'field_key' => 'sometimes|string|max:30|alpha_dash',
|
||||
'field_name' => 'sometimes|string|max:100',
|
||||
'field_type' => 'sometimes|string|max:20',
|
||||
'is_required' => 'sometimes|in:Y,N',
|
||||
'sort_order' => 'sometimes|integer|min:0',
|
||||
'field_key' => 'sometimes|string|max:30|alpha_dash',
|
||||
'field_name' => 'sometimes|string|max:100',
|
||||
'field_type' => 'sometimes|string|max:20',
|
||||
'is_required' => 'sometimes|in:Y,N',
|
||||
'sort_order' => 'sometimes|integer|min:0',
|
||||
'default_value' => 'nullable|string|max:100',
|
||||
'options' => 'nullable|json',
|
||||
'description' => 'nullable|string|max:255',
|
||||
'options' => 'nullable|json',
|
||||
'description' => 'nullable|string|max:255',
|
||||
]);
|
||||
$payload = $v->validate();
|
||||
|
||||
@@ -115,6 +116,7 @@ public function update(int $fieldId, array $data)
|
||||
|
||||
$payload['updated_by'] = $userId;
|
||||
$field->update($payload);
|
||||
|
||||
return $field->refresh();
|
||||
}
|
||||
|
||||
@@ -125,7 +127,7 @@ public function destroy(int $fieldId): void
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($fieldId);
|
||||
|
||||
if (!$field) {
|
||||
if (! $field) {
|
||||
throw new BadRequestHttpException(__('error.not_found'));
|
||||
}
|
||||
$field->delete();
|
||||
@@ -137,18 +139,20 @@ public function reorder(int $categoryId, array $items): void
|
||||
$this->assertCategoryExists($tenantId, $categoryId);
|
||||
|
||||
$rows = $items['items'] ?? $items; // 둘 다 허용
|
||||
if (!is_array($rows)) {
|
||||
if (! is_array($rows)) {
|
||||
throw new BadRequestHttpException(__('error.invalid_payload'));
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($tenantId, $categoryId, $rows) {
|
||||
foreach ($rows as $row) {
|
||||
if (!isset($row['id'], $row['sort_order'])) continue;
|
||||
if (! isset($row['id'], $row['sort_order'])) {
|
||||
continue;
|
||||
}
|
||||
CategoryField::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('category_id', $categoryId)
|
||||
->where('id', $row['id'])
|
||||
->update(['sort_order' => (int)$row['sort_order']]);
|
||||
->update(['sort_order' => (int) $row['sort_order']]);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -156,10 +160,10 @@ public function reorder(int $categoryId, array $items): void
|
||||
public function bulkUpsert(int $categoryId, array $items): array
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
$userId = $this->apiUserId();
|
||||
$this->assertCategoryExists($tenantId, $categoryId);
|
||||
|
||||
if (!is_array($items) || empty($items)) {
|
||||
if (! is_array($items) || empty($items)) {
|
||||
throw new BadRequestHttpException(__('error.empty_items'));
|
||||
}
|
||||
|
||||
@@ -168,24 +172,24 @@ public function bulkUpsert(int $categoryId, array $items): array
|
||||
DB::transaction(function () use ($tenantId, $userId, $categoryId, $items, &$result) {
|
||||
foreach ($items as $it) {
|
||||
$v = Validator::make($it, [
|
||||
'id' => 'nullable|integer',
|
||||
'field_key' => 'sometimes|required_without:id|string|max:30|alpha_dash',
|
||||
'field_name' => 'required|string|max:100',
|
||||
'field_type' => 'required|string|max:20',
|
||||
'is_required' => 'nullable|in:Y,N',
|
||||
'sort_order' => 'nullable|integer|min:0',
|
||||
'id' => 'nullable|integer',
|
||||
'field_key' => 'sometimes|required_without:id|string|max:30|alpha_dash',
|
||||
'field_name' => 'required|string|max:100',
|
||||
'field_type' => 'required|string|max:20',
|
||||
'is_required' => 'nullable|in:Y,N',
|
||||
'sort_order' => 'nullable|integer|min:0',
|
||||
'default_value' => 'nullable|string|max:100',
|
||||
'options' => 'nullable|json',
|
||||
'description' => 'nullable|string|max:255',
|
||||
'options' => 'nullable|json',
|
||||
'description' => 'nullable|string|max:255',
|
||||
]);
|
||||
$payload = $v->validate();
|
||||
|
||||
if (!empty($payload['id'])) {
|
||||
if (! empty($payload['id'])) {
|
||||
$model = CategoryField::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('category_id', $categoryId)
|
||||
->find($payload['id']);
|
||||
if (!$model) {
|
||||
if (! $model) {
|
||||
throw new BadRequestHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -218,11 +222,11 @@ public function bulkUpsert(int $categoryId, array $items): array
|
||||
throw new BadRequestHttpException(__('error.duplicate_key'));
|
||||
}
|
||||
|
||||
$payload['tenant_id'] = $tenantId;
|
||||
$payload['tenant_id'] = $tenantId;
|
||||
$payload['category_id'] = $categoryId;
|
||||
$payload['is_required'] = $payload['is_required'] ?? 'N';
|
||||
$payload['sort_order'] = $payload['sort_order'] ?? 0;
|
||||
$payload['created_by'] = $userId;
|
||||
$payload['sort_order'] = $payload['sort_order'] ?? 0;
|
||||
$payload['created_by'] = $userId;
|
||||
|
||||
CategoryField::create($payload);
|
||||
$result['created']++;
|
||||
@@ -239,7 +243,7 @@ private function assertCategoryExists(int $tenantId, int $categoryId): void
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('id', $categoryId)
|
||||
->exists();
|
||||
if (!$exists) {
|
||||
if (! $exists) {
|
||||
throw new BadRequestHttpException(__('error.category_not_found'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user