- Controller 3개, Service 3개, FormRequest 6개 생성 - Routes 등록 (BOM 항목, 섹션 템플릿, 마스터 필드) - Service-First, Multi-tenant, Soft Delete - 라우트 테스트 및 Pint 검사 통과 13 files changed, 600+ insertions(+)
91 lines
2.3 KiB
PHP
91 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\ItemMaster;
|
|
|
|
use App\Models\ItemMaster\SectionTemplate;
|
|
use App\Services\Service;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
class SectionTemplateService extends Service
|
|
{
|
|
/**
|
|
* 섹션 템플릿 목록
|
|
*/
|
|
public function index(): Collection
|
|
{
|
|
$tenantId = $this->tenantId();
|
|
|
|
return SectionTemplate::where('tenant_id', $tenantId)
|
|
->orderBy('created_at', 'desc')
|
|
->get();
|
|
}
|
|
|
|
/**
|
|
* 섹션 템플릿 생성
|
|
*/
|
|
public function store(array $data): SectionTemplate
|
|
{
|
|
$tenantId = $this->tenantId();
|
|
$userId = $this->apiUserId();
|
|
|
|
$template = SectionTemplate::create([
|
|
'tenant_id' => $tenantId,
|
|
'title' => $data['title'],
|
|
'type' => $data['type'],
|
|
'description' => $data['description'] ?? null,
|
|
'is_default' => $data['is_default'] ?? false,
|
|
'created_by' => $userId,
|
|
]);
|
|
|
|
return $template;
|
|
}
|
|
|
|
/**
|
|
* 섹션 템플릿 수정
|
|
*/
|
|
public function update(int $id, array $data): SectionTemplate
|
|
{
|
|
$tenantId = $this->tenantId();
|
|
$userId = $this->apiUserId();
|
|
|
|
$template = SectionTemplate::where('tenant_id', $tenantId)
|
|
->where('id', $id)
|
|
->first();
|
|
|
|
if (! $template) {
|
|
throw new NotFoundHttpException(__('error.not_found'));
|
|
}
|
|
|
|
$template->update([
|
|
'title' => $data['title'] ?? $template->title,
|
|
'type' => $data['type'] ?? $template->type,
|
|
'description' => $data['description'] ?? $template->description,
|
|
'is_default' => $data['is_default'] ?? $template->is_default,
|
|
'updated_by' => $userId,
|
|
]);
|
|
|
|
return $template->fresh();
|
|
}
|
|
|
|
/**
|
|
* 섹션 템플릿 삭제
|
|
*/
|
|
public function destroy(int $id): void
|
|
{
|
|
$tenantId = $this->tenantId();
|
|
$userId = $this->apiUserId();
|
|
|
|
$template = SectionTemplate::where('tenant_id', $tenantId)
|
|
->where('id', $id)
|
|
->first();
|
|
|
|
if (! $template) {
|
|
throw new NotFoundHttpException(__('error.not_found'));
|
|
}
|
|
|
|
$template->update(['deleted_by' => $userId]);
|
|
$template->delete();
|
|
}
|
|
}
|