Skip to content

Commit

Permalink
add quote field to the message type
Browse files Browse the repository at this point in the history
  • Loading branch information
Neur0toxine authored Jun 7, 2023
2 parents 516e785 + e1e484e commit 59e9c8d
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Bot/Model/Entity/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -403,6 +411,18 @@ public function setNote(string $note): void
$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
*/
Expand Down
106 changes: 106 additions & 0 deletions src/Bot/Model/Entity/Message/Quote.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
15 changes: 15 additions & 0 deletions tests/Bot/Tests/Model/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ public function testDeserialization_WithContent($content): void
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();
Expand Down
40 changes: 40 additions & 0 deletions tests/Resources/messageWithQuote.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 59e9c8d

Please sign in to comment.