111 lines
2.7 KiB
PHP
111 lines
2.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\V1;
|
||
|
|
|
||
|
|
use App\Helpers\ApiResponse;
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Http\Requests\V1\Process\StoreProcessRequest;
|
||
|
|
use App\Http\Requests\V1\Process\UpdateProcessRequest;
|
||
|
|
use App\Services\ProcessService;
|
||
|
|
use Illuminate\Http\JsonResponse;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
|
||
|
|
class ProcessController extends Controller
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
private readonly ProcessService $processService
|
||
|
|
) {}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 공정 목록 조회
|
||
|
|
*/
|
||
|
|
public function index(Request $request): JsonResponse
|
||
|
|
{
|
||
|
|
$params = $request->only(['page', 'size', 'q', 'status', 'process_type']);
|
||
|
|
$result = $this->processService->index($params);
|
||
|
|
|
||
|
|
return ApiResponse::handle($result, 'message.fetched');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 공정 상세 조회
|
||
|
|
*/
|
||
|
|
public function show(int $id): JsonResponse
|
||
|
|
{
|
||
|
|
$result = $this->processService->show($id);
|
||
|
|
|
||
|
|
return ApiResponse::handle($result, 'message.fetched');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 공정 생성
|
||
|
|
*/
|
||
|
|
public function store(StoreProcessRequest $request): JsonResponse
|
||
|
|
{
|
||
|
|
$result = $this->processService->store($request->validated());
|
||
|
|
|
||
|
|
return ApiResponse::handle($result, 'message.created', 201);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 공정 수정
|
||
|
|
*/
|
||
|
|
public function update(UpdateProcessRequest $request, int $id): JsonResponse
|
||
|
|
{
|
||
|
|
$result = $this->processService->update($id, $request->validated());
|
||
|
|
|
||
|
|
return ApiResponse::handle($result, 'message.updated');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 공정 삭제
|
||
|
|
*/
|
||
|
|
public function destroy(int $id): JsonResponse
|
||
|
|
{
|
||
|
|
$this->processService->destroy($id);
|
||
|
|
|
||
|
|
return ApiResponse::handle(null, 'message.deleted');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 공정 일괄 삭제
|
||
|
|
*/
|
||
|
|
public function destroyMany(Request $request): JsonResponse
|
||
|
|
{
|
||
|
|
$ids = $request->input('ids', []);
|
||
|
|
$count = $this->processService->destroyMany($ids);
|
||
|
|
|
||
|
|
return ApiResponse::handle(['deleted_count' => $count], 'message.deleted');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 공정 상태 토글
|
||
|
|
*/
|
||
|
|
public function toggleActive(int $id): JsonResponse
|
||
|
|
{
|
||
|
|
$result = $this->processService->toggleActive($id);
|
||
|
|
|
||
|
|
return ApiResponse::handle($result, 'message.updated');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 공정 옵션 목록 (드롭다운용)
|
||
|
|
*/
|
||
|
|
public function options(): JsonResponse
|
||
|
|
{
|
||
|
|
$result = $this->processService->options();
|
||
|
|
|
||
|
|
return ApiResponse::handle($result, 'message.fetched');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 공정 통계
|
||
|
|
*/
|
||
|
|
public function stats(): JsonResponse
|
||
|
|
{
|
||
|
|
$result = $this->processService->getStats();
|
||
|
|
|
||
|
|
return ApiResponse::handle($result, 'message.fetched');
|
||
|
|
}
|
||
|
|
}
|