style: Laravel Pint 코드 포맷팅 적용

- PSR-12 스타일 가이드 준수
- 302개 파일 스타일 이슈 자동 수정
- 코드 로직 변경 없음 (포맷팅만)
This commit is contained in:
2025-11-06 17:45:49 +09:00
parent 48e76432ee
commit cc206fdbed
294 changed files with 4476 additions and 2561 deletions

View File

@@ -2,15 +2,14 @@
namespace App\Services;
use App\Models\Commons\Category;
use App\Models\Products\CommonCode;
use App\Models\Products\Product;
use App\Models\Commons\Category;
use Illuminate\Support\Facades\Validator;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class ProductService extends Service
{
/**
* 카테고리 트리 전체 조회 (parent_id = null 기준)
*/
@@ -33,11 +32,11 @@ protected function fetchCategoryTree(?int $parentId = null)
$tenantId = $this->tenantId(); // Base Service에서 상속받은 메서드
$query = Category::query()
->when($tenantId, fn($q) => $q->where('tenant_id', $tenantId))
->when($tenantId, fn ($q) => $q->where('tenant_id', $tenantId))
->when(
is_null($parentId),
fn($q) => $q->whereNull('parent_id'),
fn($q) => $q->where('parent_id', $parentId)
fn ($q) => $q->whereNull('parent_id'),
fn ($q) => $q->where('parent_id', $parentId)
)
->where('is_active', 1)
->orderBy('sort_order');
@@ -57,7 +56,8 @@ protected function fetchCategoryTree(?int $parentId = null)
*/
public static function getCategoryFlat($group = 'category')
{
$query = CommonCode::where('code_group',$group)->whereNull('parent_id');
$query = CommonCode::where('code_group', $group)->whereNull('parent_id');
return $query->get();
}
@@ -66,11 +66,11 @@ public function index(array $params)
{
$tenantId = $this->tenantId();
$size = (int)($params['size'] ?? 20);
$q = trim((string)($params['q'] ?? ''));
$categoryId = $params['category_id'] ?? null;
$size = (int) ($params['size'] ?? 20);
$q = trim((string) ($params['q'] ?? ''));
$categoryId = $params['category_id'] ?? null;
$productType = $params['product_type'] ?? null; // PRODUCT|PART|SUBASSEMBLY...
$active = $params['active'] ?? null; // 1/0
$active = $params['active'] ?? null; // 1/0
$query = Product::query()
->with('category:id,name') // 필요한 컬럼만 가져오기
@@ -83,9 +83,15 @@ public function index(array $params)
->orWhere('description', 'like', "%{$q}%");
});
}
if ($categoryId) $query->where('category_id', (int)$categoryId);
if ($productType) $query->where('product_type', $productType);
if ($active !== null && $active !== '') $query->where('is_active', (int)$active);
if ($categoryId) {
$query->where('category_id', (int) $categoryId);
}
if ($productType) {
$query->where('product_type', $productType);
}
if ($active !== null && $active !== '') {
$query->where('is_active', (int) $active);
}
$paginator = $query->orderBy('id')->paginate($size);
@@ -96,6 +102,7 @@ public function index(array $params)
$arr['created_at'] = $item->created_at
? $item->created_at->format('Y-m-d')
: null;
return $arr;
})
);
@@ -107,19 +114,19 @@ public function index(array $params)
public function store(array $data)
{
$tenantId = $this->tenantId();
$userId = $this->apiUserId();
$userId = $this->apiUserId();
$v = Validator::make($data, [
'code' => 'required|string|max:30',
'name' => 'required|string|max:100',
'category_id' => 'required|integer',
'product_type' => 'required|string|max:30',
'attributes' => 'nullable|array',
'description' => 'nullable|string|max:255',
'is_sellable' => 'nullable|in:0,1',
'code' => 'required|string|max:30',
'name' => 'required|string|max:100',
'category_id' => 'required|integer',
'product_type' => 'required|string|max:30',
'attributes' => 'nullable|array',
'description' => 'nullable|string|max:255',
'is_sellable' => 'nullable|in:0,1',
'is_purchasable' => 'nullable|in:0,1',
'is_producible' => 'nullable|in:0,1',
'is_active' => 'nullable|in:0,1',
'is_producible' => 'nullable|in:0,1',
'is_active' => 'nullable|in:0,1',
]);
$payload = $v->validate();
@@ -128,14 +135,16 @@ public function store(array $data)
->where('tenant_id', $tenantId)
->where('code', $payload['code'])
->exists();
if ($dup) throw new BadRequestHttpException(__('error.duplicate_key'));
if ($dup) {
throw new BadRequestHttpException(__('error.duplicate_key'));
}
$payload['tenant_id'] = $tenantId;
$payload['created_by'] = $userId;
$payload['is_sellable'] = $payload['is_sellable'] ?? 1;
$payload['tenant_id'] = $tenantId;
$payload['created_by'] = $userId;
$payload['is_sellable'] = $payload['is_sellable'] ?? 1;
$payload['is_purchasable'] = $payload['is_purchasable'] ?? 0;
$payload['is_producible'] = $payload['is_producible'] ?? 1;
$payload['is_active'] = $payload['is_active'] ?? 1;
$payload['is_producible'] = $payload['is_producible'] ?? 1;
$payload['is_active'] = $payload['is_active'] ?? 1;
// attributes array → json 저장 (Eloquent casts가 array면 그대로 가능)
return Product::create($payload);
@@ -146,7 +155,10 @@ public function show(int $id)
{
$tenantId = $this->tenantId();
$p = Product::query()->where('tenant_id', $tenantId)->find($id);
if (!$p) throw new BadRequestHttpException(__('error.not_found'));
if (! $p) {
throw new BadRequestHttpException(__('error.not_found'));
}
return $p;
}
@@ -154,22 +166,24 @@ public function show(int $id)
public function update(int $id, array $data)
{
$tenantId = $this->tenantId();
$userId = $this->apiUserId();
$userId = $this->apiUserId();
$p = Product::query()->where('tenant_id', $tenantId)->find($id);
if (!$p) throw new BadRequestHttpException(__('error.not_found'));
if (! $p) {
throw new BadRequestHttpException(__('error.not_found'));
}
$v = Validator::make($data, [
'code' => 'sometimes|string|max:30',
'name' => 'sometimes|string|max:100',
'category_id' => 'sometimes|integer',
'product_type' => 'sometimes|string|max:30',
'attributes' => 'nullable|array',
'description' => 'nullable|string|max:255',
'is_sellable' => 'nullable|in:0,1',
'code' => 'sometimes|string|max:30',
'name' => 'sometimes|string|max:100',
'category_id' => 'sometimes|integer',
'product_type' => 'sometimes|string|max:30',
'attributes' => 'nullable|array',
'description' => 'nullable|string|max:255',
'is_sellable' => 'nullable|in:0,1',
'is_purchasable' => 'nullable|in:0,1',
'is_producible' => 'nullable|in:0,1',
'is_active' => 'nullable|in:0,1',
'is_producible' => 'nullable|in:0,1',
'is_active' => 'nullable|in:0,1',
]);
$payload = $v->validate();
@@ -178,11 +192,14 @@ public function update(int $id, array $data)
->where('tenant_id', $tenantId)
->where('code', $payload['code'])
->exists();
if ($dup) throw new BadRequestHttpException(__('error.duplicate_key'));
if ($dup) {
throw new BadRequestHttpException(__('error.duplicate_key'));
}
}
$payload['updated_by'] = $userId;
$p->update($payload);
return $p->refresh();
}
@@ -191,7 +208,9 @@ public function destroy(int $id): void
{
$tenantId = $this->tenantId();
$p = Product::query()->where('tenant_id', $tenantId)->find($id);
if (!$p) throw new BadRequestHttpException(__('error.not_found'));
if (! $p) {
throw new BadRequestHttpException(__('error.not_found'));
}
$p->delete();
}
@@ -199,8 +218,8 @@ public function destroy(int $id): void
public function search(array $params)
{
$tenantId = $this->tenantId();
$q = trim((string)($params['q'] ?? ''));
$lim = (int)($params['limit'] ?? 20);
$q = trim((string) ($params['q'] ?? ''));
$lim = (int) ($params['limit'] ?? 20);
$qr = Product::query()->where('tenant_id', $tenantId);
if ($q !== '') {
@@ -209,24 +228,25 @@ public function search(array $params)
->orWhere('code', 'like', "%{$q}%");
});
}
return $qr->orderBy('name')->limit($lim)->get(['id','code','name','product_type','category_id','is_active']);
return $qr->orderBy('name')->limit($lim)->get(['id', 'code', 'name', 'product_type', 'category_id', 'is_active']);
}
// 활성 토글
public function toggle(int $id)
{
$tenantId = $this->tenantId();
$userId = $this->apiUserId();
$userId = $this->apiUserId();
$p = Product::query()->where('tenant_id', $tenantId)->find($id);
if (!$p) throw new BadRequestHttpException(__('error.not_found'));
if (! $p) {
throw new BadRequestHttpException(__('error.not_found'));
}
$p->is_active = $p->is_active ? 0 : 1;
$p->updated_by = $userId;
$p->save();
return ['id' => $p->id, 'is_active' => (int)$p->is_active];
return ['id' => $p->id, 'is_active' => (int) $p->is_active];
}
}