refactor(pagination): size 초과 시 오류 대신 자동 조정으로 변경
- config/pagination.php 추가 (기본값 중앙 관리) - HasPagination Trait 추가 (prepareForValidation에서 자동 조정) - 22개 IndexRequest에 Trait 적용, max 규칙 제거 - 특수 케이스: Employee($maxSize=500), Audit($maxSize=200) size/per_page가 최대값 초과 시 422 오류 대신 최대값으로 자동 조정되어 리스트가 빈 화면으로 표시되는 문제 해결 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace App\Http\Requests\Quote;
|
||||
|
||||
use App\Http\Requests\Traits\HasPagination;
|
||||
use App\Models\Quote\Quote;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class QuoteIndexRequest extends FormRequest
|
||||
{
|
||||
use HasPagination;
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
@@ -15,9 +18,16 @@ public function authorize(): bool
|
||||
/**
|
||||
* 검증 전 데이터 전처리
|
||||
* - 쿼리 스트링의 "true"/"false" 문자열을 boolean으로 변환
|
||||
* - size/per_page 최대값 제한
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
// HasPagination Trait의 페이지네이션 처리
|
||||
$maxSize = $this->maxSize ?? config('pagination.max_size', 100);
|
||||
if ($this->has('size') && $this->input('size') > $maxSize) {
|
||||
$this->merge(['size' => $maxSize]);
|
||||
}
|
||||
|
||||
if ($this->has('with_items')) {
|
||||
$this->merge([
|
||||
'with_items' => filter_var($this->with_items, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
|
||||
@@ -29,7 +39,7 @@ public function rules(): array
|
||||
{
|
||||
return [
|
||||
'page' => 'nullable|integer|min:1',
|
||||
'size' => 'nullable|integer|min:1|max:100',
|
||||
'size' => 'nullable|integer|min:1',
|
||||
'q' => 'nullable|string|max:100',
|
||||
'quote_type' => 'nullable|in:'.implode(',', Quote::TYPES),
|
||||
'status' => 'nullable|in:'.implode(',', [
|
||||
@@ -50,4 +60,4 @@ public function rules(): array
|
||||
'with_items' => 'nullable|boolean', // 수주 전환용 품목 포함 여부
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user