[FormRequest 업데이트] - ProductStoreRequest, ProductUpdateRequest에 하이브리드 필드 추가 - 고정 필드: safety_stock, lead_time, is_variable_size, product_category, part_type - 동적 필드: attributes, attributes_archive - unit 필드 추가 - is_active → 제거 (모델과 일치) - boolean 검증 개선 (in:0,1 → boolean) [ProductService 업데이트] - store/update 메서드 중복 Validator 제거 (FormRequest가 검증) - 기본값 설정 간소화 (true/false로 통일) - is_active 관련 로직 주석처리 - index 메서드 필터 - toggle 메서드 비활성화 - search 메서드 select 컬럼 수정 - Validator import 제거 [ProductController 업데이트] - toggle 메서드 주석처리 (is_active 제거에 따름) [기능 변경] - 기존: 고정 필드 위주 - 변경: 하이브리드 구조 (최소 고정 + attributes JSON) - attributes를 통해 테넌트별 커스텀 필드 지원 [비고] - is_active는 필요시 attributes JSON이나 별도 필드로 재구현 가능 - toggle 기능도 필요시 복원 가능 (주석으로 보존)
83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Helpers\ApiResponse;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Product\ProductStoreRequest;
|
|
use App\Http\Requests\Product\ProductUpdateRequest;
|
|
use App\Services\ProductService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ProductController extends Controller
|
|
{
|
|
public function __construct(private ProductService $service) {}
|
|
|
|
public function getCategory(Request $request)
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
return $this->service->getCategory($request);
|
|
}, __('message.product.category_fetched'));
|
|
}
|
|
|
|
// GET /products
|
|
public function index(Request $request)
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
return $this->service->index($request->all());
|
|
}, __('message.product.fetched'));
|
|
}
|
|
|
|
// POST /products
|
|
public function store(ProductStoreRequest $request)
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
return $this->service->store($request->validated());
|
|
}, __('message.product.created'));
|
|
}
|
|
|
|
// GET /products/{id}
|
|
public function show(int $id)
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
return $this->service->show($id);
|
|
}, __('message.product.fetched'));
|
|
}
|
|
|
|
// PATCH /products/{id}
|
|
public function update(int $id, ProductUpdateRequest $request)
|
|
{
|
|
return ApiResponse::handle(function () use ($id, $request) {
|
|
return $this->service->update($id, $request->validated());
|
|
}, __('message.product.updated'));
|
|
}
|
|
|
|
// DELETE /products/{id}
|
|
public function destroy(int $id)
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
$this->service->destroy($id);
|
|
|
|
return 'success';
|
|
}, __('message.product.deleted'));
|
|
}
|
|
|
|
// GET /products/search
|
|
public function search(Request $request)
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
return $this->service->search($request->all());
|
|
}, __('message.product.searched'));
|
|
}
|
|
|
|
// Note: toggle 메서드는 is_active 필드 제거로 인해 비활성화됨
|
|
// 필요시 attributes JSON이나 별도 필드로 구현
|
|
// POST /products/{id}/toggle
|
|
// public function toggle(int $id)
|
|
// {
|
|
// return ApiResponse::handle(function () use ($id) {
|
|
// return $this->service->toggle($id);
|
|
// }, __('message.product.toggled'));
|
|
// }
|
|
}
|