114 lines
3.3 KiB
PHP
114 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace frontend\modules\api\controllers;
|
|
|
|
use common\services\CompanyService;
|
|
use common\services\ProductService;
|
|
|
|
class ProductController extends ApiController
|
|
{
|
|
|
|
public CompanyService $companyService;
|
|
public ProductService $productService;
|
|
|
|
public function init()
|
|
{
|
|
parent::init();
|
|
$this->companyService = new CompanyService();
|
|
$this->productService = new ProductService();
|
|
}
|
|
|
|
public function behaviors(): array
|
|
{
|
|
$behaviors = parent::behaviors();
|
|
unset($behaviors['authenticator']);
|
|
return $behaviors;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @OA\Get(path="/product",
|
|
* summary="Список товаров компании",
|
|
* description="Получить список всех товаров компании",
|
|
* tags={"Product"},
|
|
* @OA\Parameter(
|
|
* name="company_id",
|
|
* in="query",
|
|
* required=true,
|
|
* @OA\Schema(
|
|
* type="integer",
|
|
* default=null
|
|
* )
|
|
* ),
|
|
* @OA\Parameter(
|
|
* name="category_id",
|
|
* in="query",
|
|
* required=false,
|
|
* @OA\Schema(
|
|
* type="integer",
|
|
* default=null
|
|
* )
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="Возвращает массив",
|
|
* @OA\MediaType(
|
|
* mediaType="application/json",
|
|
* @OA\Schema(
|
|
* type="array",
|
|
* @OA\Items(
|
|
* @OA\Property(
|
|
* property="id",
|
|
* type="integer",
|
|
* example="1",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="title",
|
|
* type="string",
|
|
* example="Кальянный клуб LA",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="article",
|
|
* type="string",
|
|
* example="005",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="type",
|
|
* type="integer",
|
|
* example="1",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="price",
|
|
* type="integer",
|
|
* example="250",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="status",
|
|
* type="integer",
|
|
* example="1",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="product_category_id",
|
|
* type="integer",
|
|
* example="5",
|
|
* ),
|
|
* @OA\Property(
|
|
* property="company_id",
|
|
* type="integer",
|
|
* example="23",
|
|
* ),
|
|
* )
|
|
* ),
|
|
* ),
|
|
*
|
|
* ),
|
|
* )
|
|
*
|
|
* @return array
|
|
*/
|
|
public function actionIndex(int $company_id, int $category_id = null): array
|
|
{
|
|
return $this->productService->findBy($company_id, $category_id);
|
|
}
|
|
|
|
} |