- Controller 2개, Service 2개, FormRequest 3개 생성 - Routes 등록 (커스텀 탭, 단위 옵션) - Service-First, Multi-tenant, Soft Delete - 라우트 테스트 및 Pint 검사 통과 - ItemMaster API 전체 32개 엔드포인트 구현 완료 9 files changed, 467 insertions(+)
62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\ItemMaster;
|
|
|
|
use App\Models\ItemMaster\UnitOption;
|
|
use App\Services\Service;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
class UnitOptionService extends Service
|
|
{
|
|
/**
|
|
* 단위 옵션 목록
|
|
*/
|
|
public function index(): Collection
|
|
{
|
|
$tenantId = $this->tenantId();
|
|
|
|
return UnitOption::where('tenant_id', $tenantId)
|
|
->orderBy('label')
|
|
->get();
|
|
}
|
|
|
|
/**
|
|
* 단위 옵션 생성
|
|
*/
|
|
public function store(array $data): UnitOption
|
|
{
|
|
$tenantId = $this->tenantId();
|
|
$userId = $this->apiUserId();
|
|
|
|
$unit = UnitOption::create([
|
|
'tenant_id' => $tenantId,
|
|
'label' => $data['label'],
|
|
'value' => $data['value'],
|
|
'created_by' => $userId,
|
|
]);
|
|
|
|
return $unit;
|
|
}
|
|
|
|
/**
|
|
* 단위 옵션 삭제
|
|
*/
|
|
public function destroy(int $id): void
|
|
{
|
|
$tenantId = $this->tenantId();
|
|
$userId = $this->apiUserId();
|
|
|
|
$unit = UnitOption::where('tenant_id', $tenantId)
|
|
->where('id', $id)
|
|
->first();
|
|
|
|
if (! $unit) {
|
|
throw new NotFoundHttpException(__('error.not_found'));
|
|
}
|
|
|
|
$unit->update(['deleted_by' => $userId]);
|
|
$unit->delete();
|
|
}
|
|
}
|