Ported all API DTO's (without serializer configuration).

This commit is contained in:
Alexey Skobkin 2023-03-28 22:57:11 +03:00
parent b7e2cbc630
commit 441fdc06b3
No known key found for this signature in database
GPG key ID: 5D5CEF6F221278E7
8 changed files with 111 additions and 288 deletions

View file

@ -1,56 +0,0 @@
<?php
namespace src\PointToolsBundle\DTO\Api;
use src\PointToolsBundle\DTO\Api\Comment;
use src\PointToolsBundle\DTO\Api\Post;
use src\PointToolsBundle\DTO\Api\ValidableInterface;
class MetaPost implements ValidableInterface
{
/**
* @var Post|null
*/
private $post;
/**
* @var Comment[]|null
*/
private $comments;
public function getPost(): ?Post
{
return $this->post;
}
public function setPost(?Post $post): void
{
$this->post = $post;
}
/**
* @return Comment[]|null
*/
public function getComments(): ?array
{
return $this->comments;
}
/**
* @param Comment[]|null $comments
*/
public function setComments(?array $comments): void
{
$this->comments = $comments;
}
public function isValid(): bool
{
if (null !== $this->post && $this->post->isValid()) {
return true;
}
return false;
}
}

View file

@ -1,26 +1,14 @@
<?php
declare(strict_types=1);
namespace src\PointToolsBundle\DTO\Api;
use src\PointToolsBundle\DTO\Api\ValidableInterface;
namespace App\DTO\Api;
/** TODO: Refactor to public readonly */
class Auth implements ValidableInterface
{
/**
* @var string|null
*/
private $token;
/**
* @var string|null
*/
private $csRfToken;
/**
* @var string|null
*/
private $error;
private ?string $token;
private ?string $csRfToken;
private ?string $error;
public function getToken(): ?string
{
@ -54,10 +42,6 @@ class Auth implements ValidableInterface
public function isValid(): bool
{
if (null !== $this->token && null !== $this->csRfToken && null === $this->error) {
return true;
}
return false;
return null !== $this->token && null !== $this->csRfToken && null === $this->error;
}
}

View file

@ -1,46 +1,18 @@
<?php
declare(strict_types=1);
namespace src\PointToolsBundle\DTO\Api;
use src\PointToolsBundle\DTO\Api\User;
use src\PointToolsBundle\DTO\Api\ValidableInterface;
namespace App\DTO\Api;
/** TODO: Refactor to public readonly */
class Comment implements ValidableInterface
{
/**
* @var string|null
*/
private $postId;
/**
* @var int|null
*/
private $number;
/**
* @var int|null
*/
private $toCommentId;
/**
* @var string|null
*/
private $created;
/**
* @var string|null
*/
private $text;
/**
* @var User|null
*/
private $author;
/**
* @var bool|null
*/
private $isRec;
private ?string $postId;
private ?int $number;
private ?int $toCommentId;
private ?string $created;
private ?string $text;
private ?User $author;
private ?bool $isRec;
public function getPostId(): ?string
@ -120,10 +92,6 @@ class Comment implements ValidableInterface
public function isValid(): bool
{
if (null !== $this->postId && null !== $this->number && null !== $this->author && null !== $this->text) {
return true;
}
return false;
return null !== $this->postId && null !== $this->number && null !== $this->author && null !== $this->text;
}
}

40
src/DTO/Api/MetaPost.php Normal file
View file

@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace App\DTO\Api;
/** TODO: Refactor to public readonly */
class MetaPost implements ValidableInterface
{
private ?Post $post;
/** @var Comment[]|null */
private ?array $comments;
public function getPost(): ?Post
{
return $this->post;
}
public function setPost(?Post $post): void
{
$this->post = $post;
}
/** @return Comment[]|null */
public function getComments(): ?array
{
return $this->comments;
}
/** @param Comment[]|null $comments */
public function setComments(?array $comments): void
{
$this->comments = $comments;
}
public function isValid(): bool
{
return null !== $this->post && $this->post->isValid();
}
}

View file

@ -1,52 +1,21 @@
<?php
declare(strict_types=1);
namespace src\PointToolsBundle\DTO\Api;
use src\PointToolsBundle\DTO\Api\User;
use src\PointToolsBundle\DTO\Api\ValidableInterface;
namespace App\DTO\Api;
/** TODO: Refactor to public readonly */
class Post implements ValidableInterface
{
/**
* @var string|null
*/
private $id;
/**
* @var string[]|null
*/
private $tags;
/**
* @var string[]|null
*/
private $files;
/**
* @var User|null
*/
private $author;
/**
* @var string|null
*/
private $text;
/**
* @var string|null
*/
private $created;
/**
* @var string|null
*/
private $type;
/**
* @var bool|null
*/
private $private;
private ?string $id;
/** @var string[]|null */
private ?array $tags;
/** @var string[]|null */
private ?array $files;
private ?User $author;
private ?string $text;
private ?string $created;
private ?string $type;
private ?bool $private;
public function getId(): ?string
{
@ -58,9 +27,7 @@ class Post implements ValidableInterface
$this->id = $id;
}
/**
* @return string[]|null
*/
/** @return string[]|null */
public function getTags(): ?array
{
return $this->tags;
@ -71,9 +38,7 @@ class Post implements ValidableInterface
$this->tags = $tags;
}
/**
* @return string[]|null
*/
/** @return string[]|null */
public function getFiles(): ?array
{
return $this->files;
@ -144,18 +109,13 @@ class Post implements ValidableInterface
public function isValid(): bool
{
if (
null !== $this->id &&
return null !== $this->id &&
null !== $this->author &&
$this->author->isValid() &&
null !== $this->text &&
null !== $this->created// &&
null !== $this->created
// @todo check type existence in incoming data
//null !== $this->type
) {
return true;
}
return false;
;
}
}

View file

@ -1,33 +1,22 @@
<?php
declare(strict_types=1);
namespace src\PointToolsBundle\DTO\Api;
use src\PointToolsBundle\DTO\Api\MetaPost;
use src\PointToolsBundle\DTO\Api\ValidableInterface;
namespace App\DTO\Api;
/** TODO: Refactor to public readonly */
class PostsPage implements ValidableInterface
{
/**
* @var MetaPost[]|null
*/
private $posts;
/** @var MetaPost[]|null */
private ?array $posts;
private ?bool $hasNext;
/**
* @var bool|null
*/
private $hasNext;
/**
* @return MetaPost[]|null
*/
/** @return MetaPost[]|null */
public function getPosts(): ?array
{
return $this->posts;
}
/**
* @param MetaPost[]|null $posts
*/
/** @param MetaPost[]|null $posts */
public function setPosts(?array $posts): void
{
$this->posts = $posts;
@ -45,10 +34,6 @@ class PostsPage implements ValidableInterface
public function isValid(): bool
{
if (null !== $this->posts) {
return true;
}
return false;
return null !== $this->posts;
}
}

View file

@ -1,81 +1,25 @@
<?php
declare(strict_types=1);
namespace src\PointToolsBundle\DTO\Api;
use src\PointToolsBundle\DTO\Api\ValidableInterface;
namespace App\DTO\Api;
/** TODO: Refactor to public readonly */
class User implements ValidableInterface
{
/**
* @var string|null
*/
private $id;
/**
* @var string|null
*/
private $login;
/**
* @var string|null
*/
private $name;
/**
* @var string|null
*/
private $about;
/**
* @var string|null
*/
private $xmpp;
/**
* @var string|null
*/
private $created;
/**
* @var bool|null
*/
private $gender;
/**
* @var bool|null
*/
private $denyAnonymous;
/**
* @var bool|null
*/
private $private;
/**
* @var string|null
*/
private $birthDate;
/**
* @var string|null
*/
private $homepage;
/**
* @var string|null
*/
private $email;
/**
* @var string|null
*/
private $location;
/**
* @var string|null
*/
private $error;
private ?string $id;
private ?string $login;
private ?string $name;
private ?string $about;
private ?string $xmpp;
private ?string $created;
private ?bool $gender;
private ?bool $denyAnonymous;
private ?bool $private;
private ?string $birthDate;
private ?string $homepage;
private ?string $email;
private ?string $location;
private ?string $error;
public function getId(): ?string
{
@ -219,10 +163,6 @@ class User implements ValidableInterface
public function isValid(): bool
{
if (null === $this->error && null !== $this->id && null !== $this->login) {
return true;
}
return false;
return null === $this->error && null !== $this->id && null !== $this->login;
}
}

View file

@ -1,5 +1,7 @@
<?php
namespace src\PointToolsBundle\DTO\Api;
declare(strict_types=1);
namespace App\DTO\Api;
interface ValidableInterface
{