1
0
mirror of synced 2024-11-29 00:36:06 +03:00

Add history method for tasks

This commit is contained in:
Pavel 2024-01-17 16:32:18 +03:00 committed by GitHub
commit af8a79379b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 373 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?php
/**
* PHP version 7.3
*
* @category TaskComment
* @package RetailCrm\Api\Model\Entity\Tasks
*/
namespace RetailCrm\Api\Model\Entity\Tasks;
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
class TaskComment
{
/**
* @var int
*
* @JMS\Type("int")
* @JMS\SerializedName("id")
*/
public $id;
/**
* @var string
*
* @JMS\Type("string")
* @JMS\SerializedName("comment")
*/
public $comment;
}

View File

@ -0,0 +1,110 @@
<?php
/**
* PHP version 7.3
*
* @category TaskHistory
* @package RetailCrm\Api\Model\Entity\Tasks
*/
namespace RetailCrm\Api\Model\Entity\Tasks;
use DateTime;
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
/**
* Class TaskHistory
*
* @category TaskHistory
* @package RetailCrm\Api\Model\Entity\Tasks
*/
class TaskHistory
{
/**
* @var int
*
* @JMS\Type("int")
* @JMS\SerializedName("id")
*/
public $id;
/**
* @var DateTime
*
* @JMS\Type("DateTime<'Y-m-d H:i:s'>")
* @JMS\SerializedName("createdAt")
*/
public $createdAt;
/**
* @var bool
*
* @JMS\Type("bool")
* @JMS\SerializedName("created")
*/
public $created;
/**
* @var string
*
* @JMS\Type("string")
* @JMS\SerializedName("source")
*/
public $source;
/**
* @var \RetailCrm\Api\Model\Entity\HistoryUser
*
* @JMS\Type("RetailCrm\Api\Model\Entity\HistoryUser")
* @JMS\SerializedName("user")
*/
public $user;
/**
* @var string
*
* @JMS\Type("string")
* @JMS\SerializedName("field")
*/
public $field;
/**
* @var mixed
*
* @JMS\Type("mixed")
* @JMS\SerializedName("oldValue")
*/
public $oldValue;
/**
* @var mixed
*
* @JMS\Type("mixed")
* @JMS\SerializedName("newValue")
*/
public $newValue;
/**
* @var \RetailCrm\Api\Model\Entity\HistoryApiKey
*
* @JMS\Type("RetailCrm\Api\Model\Entity\HistoryApiKey")
* @JMS\SerializedName("apiKey")
*/
public $apiKey;
/**
* @var \RetailCrm\Api\Model\Entity\Tasks\Task
*
* @JMS\Type("RetailCrm\Api\Model\Entity\Tasks\Task")
* @JMS\SerializedName("task")
*/
public $task;
/**
* @var \RetailCrm\Api\Model\Entity\Tasks\TaskComment
*
* @JMS\Type("RetailCrm\Api\Model\Entity\Tasks\TaskComment")
* @JMS\SerializedName("comment")
*/
public $comment;
}

View File

@ -0,0 +1,54 @@
<?php
/**
* PHP version 7.3
*
* @category TaskHistoryFilter
* @package RetailCrm\Api\Model\Filter\Tasks
*/
namespace RetailCrm\Api\Model\Filter\Tasks;
use DateTime;
use RetailCrm\Api\Component\FormData\Mapping as Form;
/**
* Class TaskHistoryFilter
*
* @category TaskHistoryFilter
* @package RetailCrm\Api\Model\Filter\Tasks
*/
class TaskHistoryFilter
{
/**
* @var int
*
* @Form\Type("int")
* @Form\SerializedName("taskId")
*/
public $taskId;
/**
* @var int
*
* @Form\Type("int")
* @Form\SerializedName("sinceId")
*/
public $sinceId;
/**
* @var DateTime|null
*
* @Form\Type("DateTime<'Y-m-d H:i:s'>")
* @Form\SerializedName("startDate")
*/
public $startDate;
/**
* @var DateTime|null
*
* @Form\Type("DateTime<'Y-m-d H:i:s'>")
* @Form\SerializedName("endDate")
*/
public $endDate;
}

View File

@ -0,0 +1,28 @@
<?php
/**
* PHP version 7.3
*
* @category TaskHistoryRequest
* @package RetailCrm\Api\Model\Request\Tasks
*/
namespace RetailCrm\Api\Model\Request\Tasks;
use RetailCrm\Api\Interfaces\RequestInterface;
use RetailCrm\Api\Model\Filter\Tasks\TaskHistoryFilter;
use RetailCrm\Api\Model\Request\Traits\HistoryPageLimitTrait;
use RetailCrm\Api\Component\FormData\Mapping as Form;
class TaskHistoryRequest implements RequestInterface
{
use HistoryPageLimitTrait;
/**
* @var TaskHistoryFilter
*
* @Form\Type("RetailCrm\Api\Model\Filter\Tasks\TaskHistoryFilter")
* @Form\SerializedName("filter")
*/
public $filter;
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHP version 7.3
*
* @category TasksHistoryResponse
* @package RetailCrm\Api\Model\Response\Tasks
*/
namespace RetailCrm\Api\Model\Response\Tasks;
use DateTime;
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
use RetailCrm\Api\Model\Response\AbstractPaginatedResponse;
class TasksHistoryResponse extends AbstractPaginatedResponse
{
/**
* @var DateTime
*
* @JMS\Type("DateTime<'Y-m-d H:i:s'>")
* @JMS\SerializedName("generatedAt")
*/
public $generatedAt;
/**
* @var \RetailCrm\Api\Model\Entity\Tasks\TaskHistory[]
*
* @JMS\Type("array<RetailCrm\Api\Model\Entity\Tasks\TaskHistory>")
* @JMS\SerializedName("history")
*/
public $history;
}

View File

@ -10,11 +10,13 @@
namespace RetailCrm\Api\ResourceGroup; namespace RetailCrm\Api\ResourceGroup;
use RetailCrm\Api\Enum\RequestMethod; use RetailCrm\Api\Enum\RequestMethod;
use RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest;
use RetailCrm\Api\Model\Request\Tasks\TasksCreateRequest; use RetailCrm\Api\Model\Request\Tasks\TasksCreateRequest;
use RetailCrm\Api\Model\Request\Tasks\TasksRequest; use RetailCrm\Api\Model\Request\Tasks\TasksRequest;
use RetailCrm\Api\Model\Response\IdResponse; use RetailCrm\Api\Model\Response\IdResponse;
use RetailCrm\Api\Model\Response\SuccessResponse; use RetailCrm\Api\Model\Response\SuccessResponse;
use RetailCrm\Api\Model\Response\Tasks\TasksGetResponse; use RetailCrm\Api\Model\Response\Tasks\TasksGetResponse;
use RetailCrm\Api\Model\Response\Tasks\TasksHistoryResponse;
use RetailCrm\Api\Model\Response\Tasks\TasksResponse; use RetailCrm\Api\Model\Response\Tasks\TasksResponse;
/** /**
@ -264,4 +266,67 @@ class Tasks extends AbstractApiResourceGroup
); );
return $response; return $response;
} }
/**
* Makes GET "/api/v5/tasks/history" request.
*
* Example:
* ```php
* use RetailCrm\Api\Factory\SimpleClientFactory;
* use RetailCrm\Api\Interfaces\ApiExceptionInterface;
* use RetailCrm\Api\Model\Filter\Tasks\TaskHistoryFilter;
* use RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest;
*
* $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
*
* $request = new TaskHistoryRequest();
* $request->limit = 100;
* $request->page = 1;
* $request->filter = new TaskHistoryFilter();
* $request->filter->sinceId = 1;
*
* try {
* $response = $client->tasks->history($request);
* } catch (ApiExceptionInterface $exception) {
* echo sprintf(
* 'Error from RetailCRM API (status code: %d): %s',
* $exception->getStatusCode(),
* $exception->getMessage()
* );
*
* if (count($exception->getErrorResponse()->errors) > 0) {
* echo PHP_EOL . 'Errors: ' . implode(', ', $exception->getErrorResponse()->errors);
* }
*
* return;
* }
*
* echo 'Tasks history: ' . print_r($response->history, true);
* ```
*
* @param \RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest|null $request
*
* @return \RetailCrm\Api\Model\Response\Tasks\TasksHistoryResponse
* @throws \RetailCrm\Api\Interfaces\ApiExceptionInterface
* @throws \RetailCrm\Api\Interfaces\ClientExceptionInterface
* @throws \RetailCrm\Api\Exception\Api\AccountDoesNotExistException
* @throws \RetailCrm\Api\Exception\Api\ApiErrorException
* @throws \RetailCrm\Api\Exception\Api\MissingCredentialsException
* @throws \RetailCrm\Api\Exception\Api\MissingParameterException
* @throws \RetailCrm\Api\Exception\Api\ValidationException
* @throws \RetailCrm\Api\Exception\Client\HandlerException
* @throws \RetailCrm\Api\Exception\Client\HttpClientException
*/
public function history(?TaskHistoryRequest $request = null): TasksHistoryResponse
{
/** @var TasksHistoryResponse $response */
$response = $this->sendRequest(
RequestMethod::GET,
'tasks/history',
$request,
TasksHistoryResponse::class
);
return $response;
}
} }

View File

@ -14,6 +14,8 @@ use RetailCrm\Api\Enum\Tasks\TaskStatus;
use RetailCrm\Api\Model\Entity\Tasks\AbstractCustomer; use RetailCrm\Api\Model\Entity\Tasks\AbstractCustomer;
use RetailCrm\Api\Model\Entity\Tasks\Task; use RetailCrm\Api\Model\Entity\Tasks\Task;
use RetailCrm\Api\Model\Filter\Tasks\TaskFilter; use RetailCrm\Api\Model\Filter\Tasks\TaskFilter;
use RetailCrm\Api\Model\Filter\Tasks\TaskHistoryFilter;
use RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest;
use RetailCrm\Api\Model\Request\Tasks\TasksCreateRequest; use RetailCrm\Api\Model\Request\Tasks\TasksCreateRequest;
use RetailCrm\Api\Model\Request\Tasks\TasksRequest; use RetailCrm\Api\Model\Request\Tasks\TasksRequest;
use RetailCrm\TestUtils\Factory\TestClientFactory; use RetailCrm\TestUtils\Factory\TestClientFactory;
@ -175,4 +177,54 @@ EOF;
self::assertModelEqualsToResponse($json, $response); self::assertModelEqualsToResponse($json, $response);
} }
public function testHistory(): void
{
$json = <<<'EOF'
{
"success":true,
"history":[
{
"id": 1,
"createdAt": "2023-03-22 19:00:29",
"created": true,
"source": "rule",
"field": "id",
"oldValue": null,
"newValue": 1,
"task": {
"id": 1,
"text": "",
"commentary": "",
"createdAt": "2023-03-22 19:00:29",
"complete": false,
"performer": 2,
"performerType": "user",
"customer":{
"type": "customer",
"id": 1
}
}
}
]
}
EOF;
$mock = static::createApiMockBuilder('tasks/history');
$mock->matchMethod(RequestMethod::GET)
->reply()
->withBody($json);
$client = TestClientFactory::createClient($mock->getClient());
$request = new TaskHistoryRequest();
$request->limit = 100;
$request->page = 1;
$request->filter = new TaskHistoryFilter();
$request->filter->sinceId = 1;
$response = $client->tasks->history($request);
self::assertModelEqualsToResponse($json, $response, true);
}
} }