Add new method for get task comments (#188)
This commit is contained in:
parent
72636563ff
commit
3927344dde
37
src/Model/Entity/Tasks/BaseComment.php
Normal file
37
src/Model/Entity/Tasks/BaseComment.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.3
|
||||
*
|
||||
* @category BaseComment
|
||||
* @package RetailCrm\Api\Model\Entity\Tasks
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Api\Model\Entity\Tasks;
|
||||
|
||||
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||
|
||||
/**
|
||||
* Class BaseComment
|
||||
*
|
||||
* @category BaseComment
|
||||
* @package RetailCrm\Api\Model\Entity\Tasks
|
||||
*/
|
||||
class BaseComment
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @JMS\Type("int")
|
||||
* @JMS\SerializedName("id")
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @JMS\Type("string")
|
||||
* @JMS\SerializedName("text")
|
||||
*/
|
||||
public $text;
|
||||
}
|
@ -9,23 +9,38 @@
|
||||
|
||||
namespace RetailCrm\Api\Model\Entity\Tasks;
|
||||
|
||||
use DateTime;
|
||||
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||
|
||||
class TaskComment
|
||||
/**
|
||||
* Class TaskComment
|
||||
*
|
||||
* @category TaskComment
|
||||
* @package RetailCrm\Api\Model\Entity\Tasks
|
||||
*/
|
||||
class TaskComment extends BaseComment
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @JMS\Type("int")
|
||||
* @JMS\SerializedName("id")
|
||||
* @JMS\SerializedName("creator")
|
||||
*/
|
||||
public $id;
|
||||
public $creator;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var DateTime
|
||||
*
|
||||
* @JMS\Type("string")
|
||||
* @JMS\SerializedName("comment")
|
||||
* @JMS\Type("DateTime<'Y-m-d H:i:s'>")
|
||||
* @JMS\SerializedName("createdAt")
|
||||
*/
|
||||
public $comment;
|
||||
public $createdAt;
|
||||
|
||||
/**
|
||||
* @var DateTime
|
||||
*
|
||||
* @JMS\Type("DateTime<'Y-m-d H:i:s'>")
|
||||
* @JMS\SerializedName("updatedAt")
|
||||
*/
|
||||
public $updatedAt;
|
||||
}
|
||||
|
@ -101,9 +101,9 @@ class TaskHistory
|
||||
public $task;
|
||||
|
||||
/**
|
||||
* @var \RetailCrm\Api\Model\Entity\Tasks\TaskComment
|
||||
* @var \RetailCrm\Api\Model\Entity\Tasks\BaseComment
|
||||
*
|
||||
* @JMS\Type("RetailCrm\Api\Model\Entity\Tasks\TaskComment")
|
||||
* @JMS\Type("RetailCrm\Api\Model\Entity\Tasks\BaseComment")
|
||||
* @JMS\SerializedName("comment")
|
||||
*/
|
||||
public $comment;
|
||||
|
24
src/Model/Request/Tasks/TaskGetCommentsRequest.php
Normal file
24
src/Model/Request/Tasks/TaskGetCommentsRequest.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.3
|
||||
*
|
||||
* @category TaskGetCommentsRequest
|
||||
* @package RetailCrm\Api\Model\Request\Tasks
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Api\Model\Request\Tasks;
|
||||
|
||||
use RetailCrm\Api\Interfaces\RequestInterface;
|
||||
use RetailCrm\Api\Model\Request\Traits\PageLimitTrait;
|
||||
|
||||
/**
|
||||
* Class TaskGetCommentsRequest
|
||||
*
|
||||
* @category TaskGetCommentsRequest
|
||||
* @package RetailCrm\Api\Model\Request\Tasks
|
||||
*/
|
||||
class TaskGetCommentsRequest implements RequestInterface
|
||||
{
|
||||
use PageLimitTrait;
|
||||
}
|
31
src/Model/Response/Tasks/TaskGetCommentsResponse.php
Normal file
31
src/Model/Response/Tasks/TaskGetCommentsResponse.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.3
|
||||
*
|
||||
* @category TaskGetCommentsResponse
|
||||
* @package RetailCrm\Api\Model\Response\Tasks
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Api\Model\Response\Tasks;
|
||||
|
||||
use RetailCrm\Api\Model\Entity\Tasks\TaskComment;
|
||||
use RetailCrm\Api\Model\Response\AbstractPaginatedResponse;
|
||||
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||
|
||||
/**
|
||||
* Class TaskGetCommentsResponse
|
||||
*
|
||||
* @category TaskGetCommentsRequest
|
||||
* @package RetailCrm\Api\Model\Response\Tasks
|
||||
*/
|
||||
class TaskGetCommentsResponse extends AbstractPaginatedResponse
|
||||
{
|
||||
/**
|
||||
* @var TaskComment[]
|
||||
*
|
||||
* @JMS\Type("array<RetailCrm\Api\Model\Entity\Tasks\TaskComment>")
|
||||
* @JMS\SerializedName("comments")
|
||||
*/
|
||||
public $comments;
|
||||
}
|
@ -13,6 +13,12 @@ use DateTime;
|
||||
use RetailCrm\Api\Component\Serializer\Annotation as JMS;
|
||||
use RetailCrm\Api\Model\Response\AbstractPaginatedResponse;
|
||||
|
||||
/**
|
||||
* Class TasksHistoryResponse
|
||||
*
|
||||
* @category TasksHistoryResponse
|
||||
* @package RetailCrm\Api\Model\Response\Tasks
|
||||
*/
|
||||
class TasksHistoryResponse extends AbstractPaginatedResponse
|
||||
{
|
||||
/**
|
||||
|
@ -10,11 +10,17 @@
|
||||
namespace RetailCrm\Api\ResourceGroup;
|
||||
|
||||
use RetailCrm\Api\Enum\RequestMethod;
|
||||
use RetailCrm\Api\Exception\ApiException;
|
||||
use RetailCrm\Api\Exception\Client\HandlerException;
|
||||
use RetailCrm\Api\Exception\ClientException;
|
||||
use RetailCrm\Api\Interfaces\ApiExceptionInterface;
|
||||
use RetailCrm\Api\Model\Request\Tasks\TaskGetCommentsRequest;
|
||||
use RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest;
|
||||
use RetailCrm\Api\Model\Request\Tasks\TasksCreateRequest;
|
||||
use RetailCrm\Api\Model\Request\Tasks\TasksRequest;
|
||||
use RetailCrm\Api\Model\Response\IdResponse;
|
||||
use RetailCrm\Api\Model\Response\SuccessResponse;
|
||||
use RetailCrm\Api\Model\Response\Tasks\TaskGetCommentsResponse;
|
||||
use RetailCrm\Api\Model\Response\Tasks\TasksGetResponse;
|
||||
use RetailCrm\Api\Model\Response\Tasks\TasksHistoryResponse;
|
||||
use RetailCrm\Api\Model\Response\Tasks\TasksResponse;
|
||||
@ -329,4 +335,60 @@ class Tasks extends AbstractApiResourceGroup
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes GET "/api/v5/tasks/{id}/comments" request.
|
||||
*
|
||||
* Example:
|
||||
* ```php
|
||||
* use RetailCrm\Api\Factory\SimpleClientFactory;
|
||||
* use RetailCrm\Api\Interfaces\ApiExceptionInterface;
|
||||
* use RetailCrm\Api\Model\Request\Tasks\TaskGetCommentsRequest;
|
||||
*
|
||||
* $client = SimpleClientFactory::createClient('https://test.retailcrm.pro', 'apiKey');
|
||||
*
|
||||
* $request = new TaskGetCommentsRequest();
|
||||
* $request->limit = 100;
|
||||
* $request->page = 1;
|
||||
*
|
||||
* try {
|
||||
* $response = $client->tasks->getComments(1, $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 'Task: ' . print_r($response->task, true);
|
||||
* ```
|
||||
*
|
||||
* @param int $id
|
||||
* @param TaskGetCommentsRequest $request
|
||||
*
|
||||
* @return TaskGetCommentsResponse
|
||||
* @throws ApiException
|
||||
* @throws ClientException
|
||||
* @throws HandlerException
|
||||
* @throws ApiExceptionInterface
|
||||
*/
|
||||
public function getComments(int $id, TaskGetCommentsRequest $request): TaskGetCommentsResponse
|
||||
{
|
||||
/** @var TaskGetCommentsResponse $response */
|
||||
$response = $this->sendRequest(
|
||||
RequestMethod::GET,
|
||||
'tasks/' . $id . '/comments',
|
||||
$request,
|
||||
TaskGetCommentsResponse::class
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ use RetailCrm\Api\Model\Entity\Tasks\AbstractCustomer;
|
||||
use RetailCrm\Api\Model\Entity\Tasks\Task;
|
||||
use RetailCrm\Api\Model\Filter\Tasks\TaskFilter;
|
||||
use RetailCrm\Api\Model\Filter\Tasks\TaskHistoryFilter;
|
||||
use RetailCrm\Api\Model\Request\Tasks\TaskGetCommentsRequest;
|
||||
use RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest;
|
||||
use RetailCrm\Api\Model\Request\Tasks\TasksCreateRequest;
|
||||
use RetailCrm\Api\Model\Request\Tasks\TasksRequest;
|
||||
@ -227,4 +228,50 @@ EOF;
|
||||
|
||||
self::assertModelEqualsToResponse($json, $response, true);
|
||||
}
|
||||
|
||||
public function testGetComments(): void
|
||||
{
|
||||
$json = <<<'EOF'
|
||||
{
|
||||
"success": true,
|
||||
"pagination": {
|
||||
"limit": 20,
|
||||
"totalCount": 4,
|
||||
"currentPage": 1,
|
||||
"totalPageCount": 1
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"id": 1150,
|
||||
"creator": 1,
|
||||
"text": "Тест 2",
|
||||
"createdAt": "2024-02-05 16:58:23",
|
||||
"updatedAt": "2024-02-05 16:58:23"
|
||||
},
|
||||
{
|
||||
"id": 1149,
|
||||
"creator": 1,
|
||||
"text": "Тест 1",
|
||||
"createdAt": "2024-02-05 16:58:19",
|
||||
"updatedAt": "2024-02-05 16:58:19"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF;
|
||||
|
||||
$mock = static::createApiMockBuilder('tasks/1/comments');
|
||||
$mock->matchMethod(RequestMethod::GET)
|
||||
->reply()
|
||||
->withBody($json);
|
||||
|
||||
$client = TestClientFactory::createClient($mock->getClient());
|
||||
|
||||
$request = new TaskGetCommentsRequest();
|
||||
$request->limit = 100;
|
||||
$request->page = 1;
|
||||
|
||||
$response = $client->tasks->getComments(1, $request);
|
||||
|
||||
self::assertModelEqualsToResponse($json, $response);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user