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

@@ -14,10 +14,10 @@ public function index(array $params)
{
$tenantId = $this->tenantId();
$page = (int)($params['page'] ?? 1);
$size = (int)($params['size'] ?? 20);
$q = trim((string)($params['q'] ?? ''));
$pid = $params['parent_id'] ?? null;
$page = (int) ($params['page'] ?? 1);
$size = (int) ($params['size'] ?? 20);
$q = trim((string) ($params['q'] ?? ''));
$pid = $params['parent_id'] ?? null;
$onlyActive = $params['only_active'] ?? null;
$query = Category::query()->where('tenant_id', $tenantId);
@@ -29,10 +29,10 @@ public function index(array $params)
});
}
if ($pid !== null) {
$query->where('parent_id', (int)$pid);
$query->where('parent_id', (int) $pid);
}
if ($onlyActive !== null) {
$query->where('is_active', (int)!!$onlyActive);
$query->where('is_active', (int) (bool) $onlyActive);
}
$query->orderBy('parent_id')->orderBy('sort_order')->orderBy('id');
@@ -45,7 +45,10 @@ public function show(int $id)
{
$tenantId = $this->tenantId();
$cat = Category::where('tenant_id', $tenantId)->find($id);
if (!$cat) throw new NotFoundHttpException(__('error.not_found'));
if (! $cat) {
throw new NotFoundHttpException(__('error.not_found'));
}
return $cat;
}
@@ -53,22 +56,24 @@ public function show(int $id)
public function store(array $params)
{
$tenantId = $this->tenantId();
$uid = $this->apiUserId();
$uid = $this->apiUserId();
$v = Validator::make($params, [
'parent_id' => 'nullable|integer|min:1',
'code' => 'nullable|string|max:50',
'name' => 'required|string|max:100',
'description'=> 'nullable|string|max:255',
'is_active' => 'nullable|boolean',
'parent_id' => 'nullable|integer|min:1',
'code' => 'nullable|string|max:50',
'name' => 'required|string|max:100',
'description' => 'nullable|string|max:255',
'is_active' => 'nullable|boolean',
'sort_order' => 'nullable|integer|min:0',
]);
if ($v->fails()) throw new BadRequestHttpException($v->errors()->first());
if ($v->fails()) {
throw new BadRequestHttpException($v->errors()->first());
}
$data = $v->validated();
$data['tenant_id'] = $tenantId;
$data['created_by'] = $uid;
$data['is_active'] = (int)($data['is_active'] ?? 1);
$data['is_active'] = (int) ($data['is_active'] ?? 1);
$data['sort_order'] = $data['sort_order'] ?? 0;
return Category::create($data);
@@ -78,25 +83,30 @@ public function store(array $params)
public function update(int $id, array $params)
{
$tenantId = $this->tenantId();
$uid = $this->apiUserId();
$uid = $this->apiUserId();
$cat = Category::where('tenant_id', $tenantId)->find($id);
if (!$cat) throw new NotFoundHttpException(__('error.not_found'));
if (! $cat) {
throw new NotFoundHttpException(__('error.not_found'));
}
$v = Validator::make($params, [
'parent_id' => 'nullable|integer|min:1',
'code' => 'nullable|string|max:50',
'name' => 'sometimes|required|string|max:100',
'description'=> 'nullable|string|max:255',
'is_active' => 'nullable|boolean',
'parent_id' => 'nullable|integer|min:1',
'code' => 'nullable|string|max:50',
'name' => 'sometimes|required|string|max:100',
'description' => 'nullable|string|max:255',
'is_active' => 'nullable|boolean',
'sort_order' => 'nullable|integer|min:0',
]);
if ($v->fails()) throw new BadRequestHttpException($v->errors()->first());
if ($v->fails()) {
throw new BadRequestHttpException($v->errors()->first());
}
$payload = $v->validated();
$payload['updated_by'] = $uid;
$cat->update($payload);
return $cat->refresh();
}
@@ -104,14 +114,18 @@ public function update(int $id, array $params)
public function destroy(int $id)
{
$tenantId = $this->tenantId();
$uid = $this->apiUserId();
$uid = $this->apiUserId();
$cat = Category::where('tenant_id', $tenantId)->find($id);
if (!$cat) throw new NotFoundHttpException(__('error.not_found'));
if (! $cat) {
throw new NotFoundHttpException(__('error.not_found'));
}
// (옵션) 하위 존재 검사
$hasChild = Category::where('tenant_id', $tenantId)->where('parent_id', $id)->exists();
if ($hasChild) throw new BadRequestHttpException(__('error.child_exists'));
if ($hasChild) {
throw new BadRequestHttpException(__('error.child_exists'));
}
$cat->deleted_by = $uid;
$cat->save();
@@ -125,10 +139,13 @@ public function toggle(int $id)
{
$tenantId = $this->tenantId();
$cat = Category::where('tenant_id', $tenantId)->find($id);
if (!$cat) throw new NotFoundHttpException(__('error.not_found'));
if (! $cat) {
throw new NotFoundHttpException(__('error.not_found'));
}
$cat->is_active = $cat->is_active ? 0 : 1;
$cat->save();
return $cat->refresh();
}
@@ -137,16 +154,21 @@ public function move(int $id, array $params)
{
$tenantId = $this->tenantId();
$v = Validator::make($params, [
'parent_id' => 'nullable|integer|min:1',
'parent_id' => 'nullable|integer|min:1',
'sort_order' => 'nullable|integer|min:0',
]);
if ($v->fails()) throw new BadRequestHttpException($v->errors()->first());
if ($v->fails()) {
throw new BadRequestHttpException($v->errors()->first());
}
$cat = Category::where('tenant_id', $tenantId)->find($id);
if (!$cat) throw new NotFoundHttpException(__('error.not_found'));
if (! $cat) {
throw new NotFoundHttpException(__('error.not_found'));
}
$payload = $v->validated();
$cat->update($payload);
return $cat->refresh();
}
@@ -155,15 +177,18 @@ public function reorder(array $params)
{
$tenantId = $this->tenantId();
$items = $params['items'] ?? null;
if (!is_array($items) || empty($items)) {
if (! is_array($items) || empty($items)) {
throw new BadRequestHttpException(__('validation.required', ['attribute' => 'items']));
}
foreach ($items as $row) {
if (!isset($row['id'])) continue;
if (! isset($row['id'])) {
continue;
}
Category::where('tenant_id', $tenantId)
->where('id', (int)$row['id'])
->update(['sort_order' => (int)($row['sort_order'] ?? 0)]);
->where('id', (int) $row['id'])
->update(['sort_order' => (int) ($row['sort_order'] ?? 0)]);
}
return 'success';
}
@@ -171,26 +196,29 @@ public function reorder(array $params)
public function tree(array $params)
{
$tenantId = $this->tenantId();
$onlyActive = (bool)($params['only_active'] ?? false);
$onlyActive = (bool) ($params['only_active'] ?? false);
$q = Category::where('tenant_id', $tenantId)
->when($onlyActive, fn($qq) => $qq->where('is_active', 1))
->when($onlyActive, fn ($qq) => $qq->where('is_active', 1))
->orderBy('parent_id')->orderBy('sort_order')->orderBy('id')
->get(['id','parent_id','code','name','is_active','sort_order']);
->get(['id', 'parent_id', 'code', 'name', 'is_active', 'sort_order']);
$byParent = [];
foreach ($q as $c) { $byParent[$c->parent_id ?? 0][] = $c; }
foreach ($q as $c) {
$byParent[$c->parent_id ?? 0][] = $c;
}
$build = function($pid) use (&$build, &$byParent) {
$build = function ($pid) use (&$build, &$byParent) {
$nodes = $byParent[$pid] ?? [];
return array_map(function($n) use ($build) {
return array_map(function ($n) use ($build) {
return [
'id' => $n->id,
'code' => $n->code,
'name' => $n->name,
'is_active' => (int)$n->is_active,
'sort_order' => (int)$n->sort_order,
'children' => $build($n->id),
'id' => $n->id,
'code' => $n->code,
'name' => $n->name,
'is_active' => (int) $n->is_active,
'sort_order' => (int) $n->sort_order,
'children' => $build($n->id),
];
}, $nodes);
};