1
0
mirror of synced 2024-11-24 06:16:27 +03:00

Add new method for get task comments (#188)

This commit is contained in:
Uryvskiy Dima 2024-02-08 12:52:58 +03:00 committed by GitHub
parent 72636563ff
commit 3927344dde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 256 additions and 34 deletions

View 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;
}

View File

@ -9,23 +9,38 @@
namespace RetailCrm\Api\Model\Entity\Tasks; namespace RetailCrm\Api\Model\Entity\Tasks;
use DateTime;
use RetailCrm\Api\Component\Serializer\Annotation as JMS; 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 * @var int
* *
* @JMS\Type("int") * @JMS\Type("int")
* @JMS\SerializedName("id") * @JMS\SerializedName("creator")
*/ */
public $id; public $creator;
/** /**
* @var string * @var DateTime
* *
* @JMS\Type("string") * @JMS\Type("DateTime<'Y-m-d H:i:s'>")
* @JMS\SerializedName("comment") * @JMS\SerializedName("createdAt")
*/ */
public $comment; public $createdAt;
/**
* @var DateTime
*
* @JMS\Type("DateTime<'Y-m-d H:i:s'>")
* @JMS\SerializedName("updatedAt")
*/
public $updatedAt;
} }

View File

@ -101,9 +101,9 @@ class TaskHistory
public $task; 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") * @JMS\SerializedName("comment")
*/ */
public $comment; public $comment;

View 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;
}

View 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;
}

View File

@ -13,6 +13,12 @@ use DateTime;
use RetailCrm\Api\Component\Serializer\Annotation as JMS; use RetailCrm\Api\Component\Serializer\Annotation as JMS;
use RetailCrm\Api\Model\Response\AbstractPaginatedResponse; use RetailCrm\Api\Model\Response\AbstractPaginatedResponse;
/**
* Class TasksHistoryResponse
*
* @category TasksHistoryResponse
* @package RetailCrm\Api\Model\Response\Tasks
*/
class TasksHistoryResponse extends AbstractPaginatedResponse class TasksHistoryResponse extends AbstractPaginatedResponse
{ {
/** /**

View File

@ -10,11 +10,17 @@
namespace RetailCrm\Api\ResourceGroup; namespace RetailCrm\Api\ResourceGroup;
use RetailCrm\Api\Enum\RequestMethod; 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\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\TaskGetCommentsResponse;
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\TasksHistoryResponse;
use RetailCrm\Api\Model\Response\Tasks\TasksResponse; use RetailCrm\Api\Model\Response\Tasks\TasksResponse;
@ -329,4 +335,60 @@ class Tasks extends AbstractApiResourceGroup
return $response; 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;
}
} }

View File

@ -15,6 +15,7 @@ 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\Filter\Tasks\TaskHistoryFilter;
use RetailCrm\Api\Model\Request\Tasks\TaskGetCommentsRequest;
use RetailCrm\Api\Model\Request\Tasks\TaskHistoryRequest; 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;
@ -182,31 +183,31 @@ EOF;
{ {
$json = <<<'EOF' $json = <<<'EOF'
{ {
"success":true, "success": true,
"history":[ "history": [
{ {
"id": 1, "id": 1,
"createdAt": "2023-03-22 19:00:29", "createdAt": "2023-03-22 19:00:29",
"created": true, "created": true,
"source": "rule", "source": "rule",
"field": "id", "field": "id",
"oldValue": null, "oldValue": null,
"newValue": 1, "newValue": 1,
"task": { "task": {
"id": 1, "id": 1,
"text": "", "text": "",
"commentary": "", "commentary": "",
"createdAt": "2023-03-22 19:00:29", "createdAt": "2023-03-22 19:00:29",
"complete": false, "complete": false,
"performer": 2, "performer": 2,
"performerType": "user", "performerType": "user",
"customer":{ "customer": {
"type": "customer", "type": "customer",
"id": 1 "id": 1
}
}
} }
] }
}
]
} }
EOF; EOF;
@ -215,7 +216,7 @@ EOF;
->reply() ->reply()
->withBody($json); ->withBody($json);
$client = TestClientFactory::createClient($mock->getClient()); $client = TestClientFactory::createClient($mock->getClient());
$request = new TaskHistoryRequest(); $request = new TaskHistoryRequest();
$request->limit = 100; $request->limit = 100;
@ -227,4 +228,50 @@ EOF;
self::assertModelEqualsToResponse($json, $response, true); 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);
}
} }