Skip to content

Commit ccdc457

Browse files
committed
Include likes count into tweet entity and presenter
1 parent e89940e commit ccdc457

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

backend/app/Entity/Tweet.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @property Carbon $created_at
2222
* @property Carbon $updated_at
2323
* @property int $comments_count
24+
* @property int $likes_count
2425
* @property User $author
2526
*/
2627
final class Tweet extends Model
@@ -90,6 +91,11 @@ public function getCommentsCount(): int
9091
return (int)$this->comments_count;
9192
}
9293

94+
public function getLikesCount(): int
95+
{
96+
return (int)$this->likes_count;
97+
}
98+
9399
public function changeContent(string $text): void
94100
{
95101
if (empty($text)) {

backend/app/Http/Presenter/Tweet/TweetArrayPresenter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public function present(Tweet $tweet): array
2626
'image_url' => $tweet->getImageUrl(),
2727
'created_at' => $tweet->getCreatedAt()->toDateTimeString(),
2828
'author' => $this->userPresenter->present($tweet->getAuthor()),
29-
'comments_count' => $tweet->getCommentsCount()
29+
'comments_count' => $tweet->getCommentsCount(),
30+
'likes_count' => $tweet->getLikesCount()
3031
];
3132
}
3233

0 commit comments

Comments
 (0)