feat: 품목 코드 중복 시 에러 반환 및 중복 ID 제공
- DuplicateCodeException 커스텀 예외 추가 - 등록/수정 시 자동 코드 증가 기능 제거 - 중복 발견 시 duplicate_id, duplicate_code 함께 반환 - resolveUniqueCode(), resolveUniqueMaterialCode() 메서드 제거
This commit is contained in:
51
app/Exceptions/DuplicateCodeException.php
Normal file
51
app/Exceptions/DuplicateCodeException.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 품목 코드 중복 예외
|
||||
*
|
||||
* 중복된 품목 ID를 함께 반환하기 위한 커스텀 예외
|
||||
*/
|
||||
class DuplicateCodeException extends Exception
|
||||
{
|
||||
protected int $duplicateId;
|
||||
|
||||
protected string $duplicateCode;
|
||||
|
||||
public function __construct(string $code, int $duplicateId, ?string $message = null)
|
||||
{
|
||||
$this->duplicateCode = $code;
|
||||
$this->duplicateId = $duplicateId;
|
||||
|
||||
parent::__construct($message ?? __('error.item.duplicate_code'));
|
||||
}
|
||||
|
||||
public function getDuplicateId(): int
|
||||
{
|
||||
return $this->duplicateId;
|
||||
}
|
||||
|
||||
public function getDuplicateCode(): string
|
||||
{
|
||||
return $this->duplicateCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP 응답으로 변환
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $this->getMessage(),
|
||||
'error' => [
|
||||
'code' => 400,
|
||||
],
|
||||
'duplicate_id' => $this->duplicateId,
|
||||
'duplicate_code' => $this->duplicateCode,
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user