add field quote for message
This commit is contained in:
parent
516e7855a0
commit
e1e484e046
@ -130,6 +130,14 @@ class Message implements ModelInterface
|
||||
*/
|
||||
private $note;
|
||||
|
||||
/**
|
||||
* @var ?Quote $quote
|
||||
*
|
||||
* @Type("RetailCrm\Mg\Bot\Model\Entity\Message\Quote")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $quote;
|
||||
|
||||
/**
|
||||
* @var bool $isRead
|
||||
*
|
||||
@ -403,6 +411,18 @@ class Message implements ModelInterface
|
||||
$this->note = $note;
|
||||
}
|
||||
|
||||
public function getQuote(): ?Quote
|
||||
{
|
||||
return $this->quote ?? null;
|
||||
}
|
||||
|
||||
public function setQuote(?Quote $quote): Message
|
||||
{
|
||||
$this->quote = $quote;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|null
|
||||
*/
|
||||
|
106
src/Bot/Model/Entity/Message/Quote.php
Normal file
106
src/Bot/Model/Entity/Message/Quote.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
|
||||
|
||||
use DateTime;
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
use JMS\Serializer\Annotation\Accessor;
|
||||
use JMS\Serializer\Annotation\SkipWhenEmpty;
|
||||
use JMS\Serializer\Annotation\Type;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\User;
|
||||
use RetailCrm\Mg\Bot\Model\ModelInterface;
|
||||
|
||||
class Quote implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @Type("integer")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @Type("string")
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*
|
||||
* @Type("RetailCrm\Mg\Bot\Model\Entity\User")
|
||||
*/
|
||||
private $from;
|
||||
|
||||
/**
|
||||
* @var DateTime $time
|
||||
*
|
||||
* @Type("DateTime<'Y-m-d\TH:i:sP'>")
|
||||
* @Accessor(getter="getTime",setter="setTime")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $time;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @Type("string")
|
||||
*/
|
||||
private $content;
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(int $id): Quote
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function setType(string $type): Quote
|
||||
{
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFrom(): User
|
||||
{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
public function setFrom(User $from): Quote
|
||||
{
|
||||
$this->from = $from;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTime(): DateTime
|
||||
{
|
||||
return $this->time;
|
||||
}
|
||||
|
||||
public function setTime(DateTime $time): Quote
|
||||
{
|
||||
$this->time = $time;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContent(): string
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function setContent(string $content): Quote
|
||||
{
|
||||
$this->content = $content;
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -37,6 +37,21 @@ class MessageTest extends TestCase
|
||||
self::assertEquals($content, $result->getContent());
|
||||
}
|
||||
|
||||
public function testDeserializationWithQuoute(): void
|
||||
{
|
||||
$json = file_get_contents(__DIR__ . '/../../../Resources/messageWithQuote.json');
|
||||
/** @var Message $message */
|
||||
$message = Serializer::deserialize($json, Message::class);
|
||||
|
||||
self::assertEquals(3373, $message->getId());
|
||||
self::assertNotNull($message->getQuote());
|
||||
self::assertEquals("22144962", $message->getQuote()->getId());
|
||||
self::assertEquals("text", $message->getQuote()->getType());
|
||||
self::assertEquals("11111", $message->getQuote()->getFrom()->getId());
|
||||
self::assertEquals("Something content", $message->getQuote()->getContent());
|
||||
self::assertNotNull($message->getQuote()->getTime());
|
||||
}
|
||||
|
||||
public function testSerialization_NoContent(): void
|
||||
{
|
||||
$item = new Message();
|
||||
|
40
tests/Resources/messageWithQuote.json
Normal file
40
tests/Resources/messageWithQuote.json
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
"id": 3373,
|
||||
"time": "2023-04-26T21:22:19+03:00",
|
||||
"type": "text",
|
||||
"scope": "public",
|
||||
"chat_id": 519717,
|
||||
"is_read": false,
|
||||
"is_edit": false,
|
||||
"status": "seen",
|
||||
"from": {
|
||||
"id": 519896,
|
||||
"external_id": "",
|
||||
"type": "customer",
|
||||
"avatar": "",
|
||||
"name": "Иван Иванов",
|
||||
"username": "Иван",
|
||||
"first_name": "Иван",
|
||||
"last_name": "Иванов"
|
||||
},
|
||||
"content": "А можно при встрече и оплата картой.",
|
||||
"quote": {
|
||||
"id": 22144962,
|
||||
"type": "text",
|
||||
"from": {
|
||||
"id": 11111,
|
||||
"external_id": "116",
|
||||
"type": "user",
|
||||
"avatar": "",
|
||||
"name": "Николай Замышляев",
|
||||
"first_name": "Николай",
|
||||
"last_name": "Замышляев",
|
||||
"available": true
|
||||
},
|
||||
"time": "2023-04-26T21:20:30+03:00",
|
||||
"content": "Something content"
|
||||
},
|
||||
"channel_id": 61,
|
||||
"created_at": "2023-04-26T18:22:19.785679Z",
|
||||
"updated_at": "2023-04-26T18:22:20.533114Z"
|
||||
}
|
Loading…
Reference in New Issue
Block a user