feat: [approval] 전자결재 모듈 API 구현

- 마이그레이션 4개 (approval_forms, approval_lines, approvals, approval_steps)
- 모델 4개 (ApprovalForm, ApprovalLine, Approval, ApprovalStep)
- ApprovalService 비즈니스 로직 (양식/결재선 CRUD, 기안함/결재함/참조함, 결재 액션)
- 컨트롤러 3개 (ApprovalFormController, ApprovalLineController, ApprovalController)
- FormRequest 13개 (양식/결재선/문서 검증)
- Swagger 문서 3개 (26개 엔드포인트)
- i18n 메시지/에러 키 추가
- 라우트 26개 등록
This commit is contained in:
2025-12-17 23:23:20 +09:00
parent 77914da7b7
commit b43796a558
33 changed files with 4067 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Http\Requests\Approval;
use App\Models\Tenants\ApprovalForm;
use Illuminate\Foundation\Http\FormRequest;
class FormIndexRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$categories = implode(',', ApprovalForm::CATEGORIES);
return [
'category' => "nullable|string|in:{$categories}",
'is_active' => 'nullable|boolean',
'search' => 'nullable|string|max:100',
'sort_by' => 'nullable|string|in:created_at,name,code,category',
'sort_dir' => 'nullable|string|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:100',
'page' => 'nullable|integer|min:1',
];
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Http\Requests\Approval;
use App\Models\Tenants\ApprovalForm;
use Illuminate\Foundation\Http\FormRequest;
class FormStoreRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$categories = implode(',', ApprovalForm::CATEGORIES);
return [
'name' => 'required|string|max:100',
'code' => 'required|string|max:50|regex:/^[a-zA-Z0-9_-]+$/',
'category' => "nullable|string|in:{$categories}",
'template' => 'required|array',
'template.fields' => 'required|array',
'template.fields.*.name' => 'required|string|max:50',
'template.fields.*.type' => 'required|string|in:text,textarea,number,date,select,checkbox,file',
'template.fields.*.label' => 'required|string|max:100',
'template.fields.*.required' => 'nullable|boolean',
'template.fields.*.options' => 'nullable|array',
'is_active' => 'nullable|boolean',
];
}
public function messages(): array
{
return [
'name.required' => __('validation.required', ['attribute' => '양식명']),
'code.required' => __('validation.required', ['attribute' => '양식코드']),
'code.regex' => __('validation.regex', ['attribute' => '양식코드']),
'template.required' => __('validation.required', ['attribute' => '템플릿']),
'template.fields.required' => __('validation.required', ['attribute' => '필드']),
];
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Requests\Approval;
use App\Models\Tenants\ApprovalForm;
use Illuminate\Foundation\Http\FormRequest;
class FormUpdateRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$categories = implode(',', ApprovalForm::CATEGORIES);
return [
'name' => 'nullable|string|max:100',
'code' => 'nullable|string|max:50|regex:/^[a-zA-Z0-9_-]+$/',
'category' => "nullable|string|in:{$categories}",
'template' => 'nullable|array',
'template.fields' => 'required_with:template|array',
'template.fields.*.name' => 'required_with:template.fields|string|max:50',
'template.fields.*.type' => 'required_with:template.fields|string|in:text,textarea,number,date,select,checkbox,file',
'template.fields.*.label' => 'required_with:template.fields|string|max:100',
'template.fields.*.required' => 'nullable|boolean',
'template.fields.*.options' => 'nullable|array',
'is_active' => 'nullable|boolean',
];
}
public function messages(): array
{
return [
'code.regex' => __('validation.regex', ['attribute' => '양식코드']),
];
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Requests\Approval;
use Illuminate\Foundation\Http\FormRequest;
class InboxIndexRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'status' => 'nullable|string|in:requested,scheduled,completed,rejected',
'sort_by' => 'nullable|string|in:created_at,drafted_at,completed_at,title',
'sort_dir' => 'nullable|string|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:100',
'page' => 'nullable|integer|min:1',
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests\Approval;
use App\Models\Tenants\Approval;
use Illuminate\Foundation\Http\FormRequest;
class IndexRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$statuses = implode(',', Approval::STATUSES);
return [
'status' => "nullable|string|in:{$statuses}",
'search' => 'nullable|string|max:100',
'sort_by' => 'nullable|string|in:created_at,drafted_at,completed_at,title,status',
'sort_dir' => 'nullable|string|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:100',
'page' => 'nullable|integer|min:1',
];
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Requests\Approval;
use Illuminate\Foundation\Http\FormRequest;
class LineIndexRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'search' => 'nullable|string|max:100',
'sort_by' => 'nullable|string|in:created_at,name,is_default',
'sort_dir' => 'nullable|string|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:100',
'page' => 'nullable|integer|min:1',
];
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Requests\Approval;
use App\Models\Tenants\ApprovalLine;
use Illuminate\Foundation\Http\FormRequest;
class LineStoreRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$stepTypes = implode(',', ApprovalLine::STEP_TYPES);
return [
'name' => 'required|string|max:100',
'steps' => 'required|array|min:1',
'steps.*.type' => "required|string|in:{$stepTypes}",
'steps.*.user_id' => 'required|integer|exists:users,id',
'is_default' => 'nullable|boolean',
];
}
public function messages(): array
{
return [
'name.required' => __('validation.required', ['attribute' => '결재선명']),
'steps.required' => __('validation.required', ['attribute' => '결재단계']),
'steps.min' => __('validation.min.array', ['attribute' => '결재단계', 'min' => 1]),
'steps.*.type.required' => __('validation.required', ['attribute' => '단계유형']),
'steps.*.type.in' => __('validation.in', ['attribute' => '단계유형']),
'steps.*.user_id.required' => __('validation.required', ['attribute' => '결재자']),
'steps.*.user_id.exists' => __('validation.exists', ['attribute' => '결재자']),
];
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Http\Requests\Approval;
use App\Models\Tenants\ApprovalLine;
use Illuminate\Foundation\Http\FormRequest;
class LineUpdateRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$stepTypes = implode(',', ApprovalLine::STEP_TYPES);
return [
'name' => 'nullable|string|max:100',
'steps' => 'nullable|array|min:1',
'steps.*.type' => "required_with:steps|string|in:{$stepTypes}",
'steps.*.user_id' => 'required_with:steps|integer|exists:users,id',
'is_default' => 'nullable|boolean',
];
}
public function messages(): array
{
return [
'steps.min' => __('validation.min.array', ['attribute' => '결재단계', 'min' => 1]),
'steps.*.type.in' => __('validation.in', ['attribute' => '단계유형']),
'steps.*.user_id.exists' => __('validation.exists', ['attribute' => '결재자']),
];
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Requests\Approval;
use Illuminate\Foundation\Http\FormRequest;
class ReferenceIndexRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'is_read' => 'nullable|boolean',
'sort_by' => 'nullable|string|in:created_at,drafted_at,completed_at,title',
'sort_dir' => 'nullable|string|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:100',
'page' => 'nullable|integer|min:1',
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Requests\Approval;
use Illuminate\Foundation\Http\FormRequest;
class RejectRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'comment' => 'required|string|max:1000',
];
}
public function messages(): array
{
return [
'comment.required' => __('error.approval.reject_comment_required'),
];
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Http\Requests\Approval;
use App\Models\Tenants\ApprovalLine;
use Illuminate\Foundation\Http\FormRequest;
class StoreRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$stepTypes = implode(',', ApprovalLine::STEP_TYPES);
return [
'form_id' => 'required|integer|exists:approval_forms,id',
'title' => 'required|string|max:200',
'content' => 'required|array',
'attachments' => 'nullable|array',
'attachments.*' => 'integer|exists:files,id',
'submit' => 'nullable|boolean',
'steps' => 'required_if:submit,true|array|min:1',
'steps.*.type' => "required_with:steps|string|in:{$stepTypes}",
'steps.*.user_id' => 'required_with:steps|integer|exists:users,id',
];
}
public function messages(): array
{
return [
'form_id.required' => __('validation.required', ['attribute' => '결재양식']),
'form_id.exists' => __('validation.exists', ['attribute' => '결재양식']),
'title.required' => __('validation.required', ['attribute' => '제목']),
'content.required' => __('validation.required', ['attribute' => '내용']),
'steps.required_if' => __('error.approval.steps_required'),
'steps.min' => __('validation.min.array', ['attribute' => '결재단계', 'min' => 1]),
];
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Http\Requests\Approval;
use App\Models\Tenants\ApprovalLine;
use Illuminate\Foundation\Http\FormRequest;
class SubmitRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$stepTypes = implode(',', ApprovalLine::STEP_TYPES);
return [
'steps' => 'required|array|min:1',
'steps.*.type' => "required|string|in:{$stepTypes}",
'steps.*.user_id' => 'required|integer|exists:users,id',
];
}
public function messages(): array
{
return [
'steps.required' => __('error.approval.steps_required'),
'steps.min' => __('validation.min.array', ['attribute' => '결재단계', 'min' => 1]),
'steps.*.type.required' => __('validation.required', ['attribute' => '단계유형']),
'steps.*.type.in' => __('validation.in', ['attribute' => '단계유형']),
'steps.*.user_id.required' => __('validation.required', ['attribute' => '결재자']),
'steps.*.user_id.exists' => __('validation.exists', ['attribute' => '결재자']),
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Requests\Approval;
use Illuminate\Foundation\Http\FormRequest;
class UpdateRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'form_id' => 'nullable|integer|exists:approval_forms,id',
'title' => 'nullable|string|max:200',
'content' => 'nullable|array',
'attachments' => 'nullable|array',
'attachments.*' => 'integer|exists:files,id',
];
}
public function messages(): array
{
return [
'form_id.exists' => __('validation.exists', ['attribute' => '결재양식']),
];
}
}