- 마이그레이션 4개 (esign_contracts, esign_signers, esign_sign_fields, esign_audit_logs) - 모델 4개 (EsignContract, EsignSigner, EsignSignField, EsignAuditLog) - 서비스 4개 (EsignContractService, EsignSignService, EsignPdfService, EsignAuditService) - 컨트롤러 2개 (EsignContractController, EsignSignController) - FormRequest 4개 (ContractStore, FieldConfigure, SignSubmit, SignReject) - Mail 1개 (EsignRequestMail + 이메일 템플릿) - API 라우트 (인증 계약 관리 + 토큰 기반 서명 프로세스) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
117 lines
3.8 KiB
PHP
117 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\ESign;
|
|
|
|
use App\Helpers\ApiResponse;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\ESign\ContractStoreRequest;
|
|
use App\Http\Requests\ESign\FieldConfigureRequest;
|
|
use App\Services\ESign\EsignContractService;
|
|
use App\Services\ESign\EsignPdfService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class EsignContractController extends Controller
|
|
{
|
|
public function __construct(
|
|
private EsignContractService $service,
|
|
private EsignPdfService $pdfService,
|
|
) {}
|
|
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
return $this->service->list($request->all());
|
|
}, __('message.fetched'));
|
|
}
|
|
|
|
public function show(int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
return $this->service->show($id);
|
|
}, __('message.fetched'));
|
|
}
|
|
|
|
public function store(ContractStoreRequest $request): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
return $this->service->create($request->validated() + ['file' => $request->file('file')]);
|
|
}, __('message.created'));
|
|
}
|
|
|
|
public function cancel(int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
return $this->service->cancel($id);
|
|
}, __('message.esign.cancelled'));
|
|
}
|
|
|
|
public function configureFields(int $id, FieldConfigureRequest $request): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($id, $request) {
|
|
return $this->service->configureFields($id, $request->validated()['fields']);
|
|
}, __('message.esign.fields_configured'));
|
|
}
|
|
|
|
public function send(int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
return $this->service->send($id);
|
|
}, __('message.esign.sent'));
|
|
}
|
|
|
|
public function remind(int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
return $this->service->remind($id);
|
|
}, __('message.esign.reminded'));
|
|
}
|
|
|
|
public function stats(): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () {
|
|
return $this->service->stats();
|
|
}, __('message.fetched'));
|
|
}
|
|
|
|
public function download(int $id): \Symfony\Component\HttpFoundation\StreamedResponse|JsonResponse
|
|
{
|
|
try {
|
|
$contract = $this->service->show($id);
|
|
$filePath = $contract->signed_file_path ?? $contract->original_file_path;
|
|
|
|
if (! $filePath || ! Storage::disk('local')->exists($filePath)) {
|
|
return ApiResponse::error(__('error.esign.file_not_found'), 404);
|
|
}
|
|
|
|
$fileName = $contract->original_file_name ?? 'contract.pdf';
|
|
|
|
return Storage::disk('local')->download($filePath, $fileName);
|
|
} catch (\Throwable $e) {
|
|
return ApiResponse::error($e->getMessage(), 500);
|
|
}
|
|
}
|
|
|
|
public function verify(int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
$contract = $this->service->show($id);
|
|
|
|
if (! $contract->original_file_path || ! $contract->original_file_hash) {
|
|
return ['verified' => false, 'message' => '파일 정보가 없습니다.'];
|
|
}
|
|
|
|
$isValid = $this->pdfService->verifyIntegrity(
|
|
$contract->original_file_path,
|
|
$contract->original_file_hash
|
|
);
|
|
|
|
return [
|
|
'verified' => $isValid,
|
|
'original_hash' => $contract->original_file_hash,
|
|
];
|
|
}, __('message.esign.verified'));
|
|
}
|
|
}
|