add Comment entity, dto, repository interface

This commit is contained in:
Yisroel Baum 2026-05-06 22:13:37 +03:00
parent 015e61caf7
commit 0d589340d9
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 73 additions and 0 deletions

View file

@ -0,0 +1,41 @@
<?php
namespace App\Comment;
use DateTimeImmutable;
class Comment
{
public function __construct(
private int $id,
private int $postId,
private int $userId,
private string $body,
private DateTimeImmutable $createdAt,
) {}
public function getId(): int
{
return $this->id;
}
public function getPostId(): int
{
return $this->postId;
}
public function getUserId(): int
{
return $this->userId;
}
public function getBody(): string
{
return $this->body;
}
public function getCreatedAt(): DateTimeImmutable
{
return $this->createdAt;
}
}

View file

@ -0,0 +1,17 @@
<?php
namespace App\Comment;
interface CommentRepository
{
public function create(CreateCommentDto $dto): Comment;
public function find(int $id): ?Comment;
/**
* @return Comment[]
*/
public function findByPostId(int $postId): array;
public function delete(int $id): void;
}

View file

@ -0,0 +1,15 @@
<?php
namespace App\Comment;
use DateTimeImmutable;
readonly class CreateCommentDto
{
public function __construct(
public int $postId,
public int $userId,
public string $body,
public DateTimeImmutable $createdAt,
) {}
}