api
This commit is contained in:
80
frontend/modules/api/controllers/ApiController.php
Normal file
80
frontend/modules/api/controllers/ApiController.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\behaviors\GsCors;
|
||||
use yii\filters\auth\CompositeAuth;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\filters\ContentNegotiator;
|
||||
use yii\rest\Controller;
|
||||
use yii\web\Response;
|
||||
|
||||
|
||||
/**
|
||||
* @OA\Info(
|
||||
* version="1.0.0",
|
||||
* title="Документация Сервис для создания чеков",
|
||||
* description="Документация для работы с API",
|
||||
*
|
||||
* ),
|
||||
* @OA\PathItem(
|
||||
* path="/api"
|
||||
* ),
|
||||
* @OA\Server(
|
||||
* url="https://check.itguild.info/api",
|
||||
* description="Основной сервер",
|
||||
* ),
|
||||
*
|
||||
* @OA\Server(
|
||||
* url="http://check-back.loc/api",
|
||||
* description="Локальный сервер",
|
||||
* ),
|
||||
*
|
||||
* @OA\SecurityScheme(
|
||||
* securityScheme="bearerAuth",
|
||||
* in="header",
|
||||
* name="Authorization",
|
||||
* type="http",
|
||||
* scheme="bearer",
|
||||
* bearerFormat="JWT",
|
||||
* ),
|
||||
*/
|
||||
class ApiController extends Controller
|
||||
{
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'corsFilter' => [
|
||||
'class' => GsCors::class,
|
||||
'cors' => [
|
||||
'Origin' => ['*'],
|
||||
//'Access-Control-Allow-Credentials' => true,
|
||||
'Access-Control-Allow-Headers' => [
|
||||
'Access-Control-Allow-Origin',
|
||||
'Access-Control-Allow-Methods',
|
||||
'Content-Type',
|
||||
'Access-Control-Allow-Headers',
|
||||
'Authorization',
|
||||
'X-Requested-With'
|
||||
],
|
||||
'Access-Control-Allow-Methods' => ['POST', 'GET', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
|
||||
'Access-Control-Request-Method' => ['POST', 'GET', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
|
||||
]
|
||||
],
|
||||
'authenticator' => [
|
||||
'class' => CompositeAuth::class,
|
||||
'authMethods' => [
|
||||
HttpBearerAuth::class,
|
||||
],
|
||||
],
|
||||
[
|
||||
'class' => ContentNegotiator::className(),
|
||||
'formats' => [
|
||||
'application/json' => Response::FORMAT_JSON,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
82
frontend/modules/api/controllers/CategoryController.php
Normal file
82
frontend/modules/api/controllers/CategoryController.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\classes\Debug;
|
||||
use common\services\CompanyService;
|
||||
|
||||
class CategoryController extends ApiController
|
||||
{
|
||||
public CompanyService $companyService;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->companyService = new CompanyService();
|
||||
}
|
||||
|
||||
public function behaviors(): array
|
||||
{
|
||||
$behaviors = parent::behaviors();
|
||||
unset($behaviors['authenticator']);
|
||||
return $behaviors;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @OA\Get(path="/category",
|
||||
* summary="Список категорий компании",
|
||||
* description="Получить список всех категорий компании",
|
||||
* tags={"Category"},
|
||||
* @OA\Parameter(
|
||||
* name="company_id",
|
||||
* in="query",
|
||||
* required=true,
|
||||
* @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="parent_id",
|
||||
* type="integer",
|
||||
* example="33",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="company_id",
|
||||
* type="integer",
|
||||
* example="23",
|
||||
* ),
|
||||
* )
|
||||
* ),
|
||||
* ),
|
||||
*
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function actionIndex(int $company_id): array
|
||||
{
|
||||
return $this->companyService->getCategoryByCompanyId($company_id);
|
||||
}
|
||||
|
||||
}
|
20
frontend/modules/api/controllers/DefaultController.php
Normal file
20
frontend/modules/api/controllers/DefaultController.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use yii\web\Controller;
|
||||
|
||||
/**
|
||||
* Default controller for the `api` module
|
||||
*/
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/**
|
||||
* Renders the index view for the module
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
}
|
114
frontend/modules/api/controllers/ProductController.php
Normal file
114
frontend/modules/api/controllers/ProductController.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user