1
0
mirror of synced 2024-11-28 06:06:02 +03:00

add quote field to the message type

This commit is contained in:
Pavel 2023-06-07 16:00:13 +03:00 committed by GitHub
commit 59e9c8d3be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 181 additions and 0 deletions

View File

@ -130,6 +130,14 @@ class Message implements ModelInterface
*/ */
private $note; private $note;
/**
* @var ?Quote $quote
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Message\Quote")
* @SkipWhenEmpty()
*/
private $quote;
/** /**
* @var bool $isRead * @var bool $isRead
* *
@ -403,6 +411,18 @@ class Message implements ModelInterface
$this->note = $note; $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 * @return bool|null
*/ */

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

View File

@ -37,6 +37,21 @@ class MessageTest extends TestCase
self::assertEquals($content, $result->getContent()); 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 public function testSerialization_NoContent(): void
{ {
$item = new Message(); $item = new Message();

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