feat: [items] 아이템 API 기능 개선
- ItemsController, ItemsBomController, ItemsFileController 수정 - ItemBatchDeleteRequest 추가 - ItemsService 개선 - ItemsApi Swagger 문서 업데이트
This commit is contained in:
@@ -255,25 +255,24 @@ public function createItem(array $data): Product
|
||||
/**
|
||||
* 품목 수정 (Product 전용)
|
||||
*
|
||||
* @param string $code 품목 코드
|
||||
* @param int $id 품목 ID
|
||||
* @param array $data 검증된 데이터
|
||||
*/
|
||||
public function updateItem(string $code, array $data): Product
|
||||
public function updateItem(int $id, array $data): Product
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$product = Product::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('code', $code)
|
||||
->first();
|
||||
->find($id);
|
||||
|
||||
if (! $product) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
// 코드 변경 시 중복 체크
|
||||
if (isset($data['code']) && $data['code'] !== $code) {
|
||||
if (isset($data['code']) && $data['code'] !== $product->code) {
|
||||
$exists = Product::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('code', $data['code'])
|
||||
@@ -294,16 +293,15 @@ public function updateItem(string $code, array $data): Product
|
||||
/**
|
||||
* 품목 삭제 (Product 전용, Soft Delete)
|
||||
*
|
||||
* @param string $code 품목 코드
|
||||
* @param int $id 품목 ID
|
||||
*/
|
||||
public function deleteItem(string $code): void
|
||||
public function deleteItem(int $id): void
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
$product = Product::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('code', $code)
|
||||
->first();
|
||||
->find($id);
|
||||
|
||||
if (! $product) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
@@ -312,6 +310,29 @@ public function deleteItem(string $code): void
|
||||
$product->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 품목 일괄 삭제 (Product 전용, Soft Delete)
|
||||
*
|
||||
* @param array $ids 품목 ID 배열
|
||||
*/
|
||||
public function batchDeleteItems(array $ids): void
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
$products = Product::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->whereIn('id', $ids)
|
||||
->get();
|
||||
|
||||
if ($products->isEmpty()) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
foreach ($products as $product) {
|
||||
$product->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 품목 상세 조회 (code 기반, BOM 포함 옵션)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user