Last active
November 22, 2017 09:14
-
-
Save VladKolerts/fdafebba1979f7a5f08b453eb6b5ac88 to your computer and use it in GitHub Desktop.
example code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace NaxCrmBundle\Controller\v1\banking; | |
use NaxCrmBundle\Entity\Client; | |
use NaxCrmBundle\Entity\UserLogItem; | |
use Symfony\Component\HttpFoundation\Request; | |
use FOS\RestBundle\Controller\Annotations\Get; | |
use FOS\RestBundle\Controller\Annotations\Post; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; | |
use Nelmio\ApiDocBundle\Annotation\ApiDoc; | |
use NaxCrmBundle\Controller\v1\BaseController; | |
class OrderController extends BaseController | |
{ | |
protected $csvTitles = [ | |
'id', | |
'login', | |
'symbol', | |
'flags', | |
'price_open', | |
'binary_option', | |
'price_open1', | |
'price_close', | |
'amount', | |
'currency', | |
'time_open', | |
'time', | |
'expiration', | |
'winrate', | |
'profit', | |
'email', | |
'acc_group', | |
]; | |
protected function getOrders($params = [], $trader_group = false, $client = false) | |
{ | |
$preFilters = []; | |
if (!isset($params['filters'])) { | |
$params['filters'] = []; | |
} | |
if ($trader_group) { | |
$params['filters']['acc_group'] = $trader_group; | |
} | |
else { | |
$trader_group = ($client) ? 'client#' . $client->getId() : 'all'; | |
} | |
$params['handler'] = $this->getPlatformHandler(); | |
$this->exportFileName = "orders({$trader_group})"; | |
$this->csvTimeField = 'time_open'; | |
$res = $this->getList($params, $preFilters, 'getAllOrders'); | |
return $res; | |
} | |
/** | |
* @Get("/clients/{id}/orders", name="v1_get_client_orders") | |
* @ApiDoc( | |
* views = {"default"}, | |
* section = "banking", | |
* resource = "banking/order", | |
* authentication = true, | |
* description = "Get all selected client orders", | |
* statusCodes={ | |
* 200="Returned when successful", | |
* 403={ | |
* "Returned when the user is not authorized with JWT token", | |
* "Returned when the user have not proper acl rights", | |
* }, | |
* 404={ | |
* "Returned when client was not found", | |
* }, | |
* 500="Returned when Something went wrong", | |
* }, | |
* parameters = { | |
* {"name"="filters", "dataType"="collection", "required"=false, "format"="filters[columnName]=value", "description" = "set array of filters. You can get list of filters in response"}, | |
* {"name"="order", "dataType"="collection", "required"=false, "format"="order[column]=columnName&order[dir]=DESC", "description" = "add order column and direction for output."}, | |
* {"name"="limit", "dataType"="integer", "required"=false, "format"="\d+", "description" = "add limit for output."}, | |
* {"name"="offset", "dataType"="integer", "required"=false, "format"="\d+", "description" = "add offset shifting for output."}, | |
* {"name"="exportCsv", "dataType"="string", "required"=false, "format"="lzw encoded array", "description" = "used for export result in CSV file"}, | |
* }, | |
* requirements = { | |
* {"name"="id", "dataType"="integer", "description"="select client by id", "requirement"="\d+"}, | |
* }, | |
* ) | |
* @ParamConverter("client", class="NaxCrmBundle\Entity\Client") | |
* @Security("(has_role('ROLE_MANAGER') and is_granted('R', 'client')) || (has_role('ROLE_CLIENT') and user == client)") | |
*/ | |
public function getClientsOrdersAction(Request $request, $client = null) | |
{ | |
/* @var $client Client */ | |
if (empty($client)) { | |
return $this->getFailedJsonResponse(null, "Client was not found", 404); | |
} | |
$params = $request->query->all(); | |
if(!isset($params['filters'])){ | |
$params['filters'] = array(); | |
} | |
$params['filters']['logins'] = []; | |
$accounts = $client->getAccounts(); | |
foreach ($accounts as $acc) { | |
if(!empty($acc->getExternalId())){ | |
$params['filters']['logins'][] = $acc->getExternalId(); | |
} | |
else{ | |
\NaxCrmBundle\Debug::$messages[]='WARN: Acc '.$acc->getId().' has no external_id'; | |
} | |
} | |
$res = $this->getOrders($params, false, $client); | |
return $this->getJsonResponse($res); | |
} | |
/** | |
* @Get("/orders", name="v1_get_all_orders") | |
* @ApiDoc( | |
* views = {"default"}, | |
* section = "banking", | |
* resource = "banking/order", | |
* authentication = true, | |
* description = "Get all orders", | |
* statusCodes={ | |
* 200="Returned when successful", | |
* 403={ | |
* "Returned when the user is not authorized with JWT token", | |
* "Returned when the user have not proper acl rights", | |
* }, | |
* 500="Returned when Something went wrong", | |
* }, | |
* parameters = { | |
* {"name"="filters", "dataType"="collection", "required"=false, "format"="filters[columnName]=value", "description" = "set array of filters. You can get list of filters in response"}, | |
* {"name"="order", "dataType"="collection", "required"=false, "format"="order[column]=columnName&order[dir]=DESC", "description" = "add order column and direction for output."}, | |
* {"name"="limit", "dataType"="integer", "required"=false, "format"="\d+", "description" = "add limit for output."}, | |
* {"name"="offset", "dataType"="integer", "required"=false, "format"="\d+", "description" = "add offset shifting for output."}, | |
* {"name"="exportCsv", "dataType"="string", "required"=false, "format"="lzw encoded array", "description" = "used for export result in CSV file"}, | |
* }, | |
* ) | |
* @Security("has_role('ROLE_MANAGER')") | |
*/ | |
public function getOrdersAction(Request $request) | |
{ | |
$params = $request->query->all(); | |
$res = $this->getOrders($params); | |
return $this->getJsonResponse($res); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment