feat: ItemMaster Phase 3 API 구현 (부가 기능 8개 엔드포인트)
- Controller 2개, Service 2개, FormRequest 3개 생성 - Routes 등록 (커스텀 탭, 단위 옵션) - Service-First, Multi-tenant, Soft Delete - 라우트 테스트 및 Pint 검사 통과 - ItemMaster API 전체 32개 엔드포인트 구현 완료 9 files changed, 467 insertions(+)
This commit is contained in:
61
app/Services/ItemMaster/UnitOptionService.php
Normal file
61
app/Services/ItemMaster/UnitOptionService.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user