feat: Implement client payment history endpoint and add type filtering to product category API.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Service;
|
||||
|
||||
use App\Enums\Product\ProductTypeEnums;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Api\Service\ProductCategoryResource;
|
||||
use App\Http\Resources\Api\Service\ServiceResource;
|
||||
@@ -23,7 +24,14 @@ class ProductCategoryController extends Controller
|
||||
* operationId="getProductCategoryList",
|
||||
* tags={"Product Categories"},
|
||||
* summary="Get list of product categories",
|
||||
* description="Returns a list of active product categories with their children",
|
||||
* description="Returns a list of active product categories filtered by type. The `type` parameter is required.",
|
||||
* @OA\Parameter(
|
||||
* name="type",
|
||||
* in="query",
|
||||
* description="Product type filter (e.g. vps, hosting, cloud, email, ssl, domain, web design, addon)",
|
||||
* required=true,
|
||||
* @OA\Schema(type="string")
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Successful operation",
|
||||
@@ -47,12 +55,35 @@ class ProductCategoryController extends Controller
|
||||
* ))
|
||||
* ))
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Missing or invalid type filter"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function getCategories(Request $request)
|
||||
{
|
||||
$type = $request->query('type');
|
||||
|
||||
if (!$type) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Vui lòng chọn Phân loại sản phẩm',
|
||||
'data' => [],
|
||||
], 422);
|
||||
}
|
||||
|
||||
if (!ProductTypeEnums::tryFrom($type)) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Phân loại sản phẩm không hợp lệ',
|
||||
'data' => [],
|
||||
], 422);
|
||||
}
|
||||
|
||||
$categories = ProductCategories::where('is_active', true)
|
||||
->where('type', $type)
|
||||
->whereNull('parent_id')
|
||||
->with(['children' => function($query) {
|
||||
$query->where('is_active', true)
|
||||
|
||||
Reference in New Issue
Block a user