Post: id, userId (fk -> User), title, body, createdAt as DateTimeImmutable. CreatePostDto readonly with explicit createdAt (use case supplies it via Clock; entity remains pure). PostRepository: create, find, findByUserId, findRecent (limit), delete.
41 lines
682 B
PHP
41 lines
682 B
PHP
<?php
|
|
|
|
namespace App\Post;
|
|
|
|
use DateTimeImmutable;
|
|
|
|
class Post
|
|
{
|
|
public function __construct(
|
|
private int $id,
|
|
private int $userId,
|
|
private string $title,
|
|
private string $body,
|
|
private DateTimeImmutable $createdAt,
|
|
) {}
|
|
|
|
public function getId(): int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getUserId(): int
|
|
{
|
|
return $this->userId;
|
|
}
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return $this->title;
|
|
}
|
|
|
|
public function getBody(): string
|
|
{
|
|
return $this->body;
|
|
}
|
|
|
|
public function getCreatedAt(): DateTimeImmutable
|
|
{
|
|
return $this->createdAt;
|
|
}
|
|
}
|