File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed
Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 1919 * @property int $author_id
2020 * @property Carbon $created_at
2121 * @property Carbon $updated_at
22+ * @property int $comments_count
23+ * @property User $author
2224 */
2325final class Tweet extends Model
2426{
@@ -71,6 +73,16 @@ public function getAuthorId(): int
7173 return $ this ->author_id ;
7274 }
7375
76+ public function getAuthor (): User
77+ {
78+ return $ this ->author ;
79+ }
80+
81+ public function getCommentsCount (): int
82+ {
83+ return $ this ->comments_count ;
84+ }
85+
7486 public function changeContent (string $ text ): void
7587 {
7688 if (empty ($ text )) {
Original file line number Diff line number Diff line change 88use App \Http \Presenter \CollectionAsArrayPresenter ;
99use Illuminate \Support \Collection ;
1010use App \Http \Presenter \User \UserArrayPresenter ;
11- use App \Http \Presenter \Comment \CommentAsArrayPresenter ;
1211
1312final class TweetArrayPresenter implements CollectionAsArrayPresenter
1413{
1514 private $ userPresenter ;
16- private $ commentPresenter ;
1715
18- public function __construct (
19- UserArrayPresenter $ userPresenter ,
20- CommentAsArrayPresenter $ commentPresenter
21- ) {
16+ public function __construct (UserArrayPresenter $ userPresenter )
17+ {
2218 $ this ->userPresenter = $ userPresenter ;
23- $ this ->commentPresenter = $ commentPresenter ;
2419 }
2520
2621 public function present (Tweet $ tweet ): array
@@ -30,8 +25,8 @@ public function present(Tweet $tweet): array
3025 'text ' => $ tweet ->getText (),
3126 'image_url ' => $ tweet ->getImageUrl (),
3227 'created_at ' => $ tweet ->getCreatedAt ()->toDateTimeString (),
33- 'author ' => $ this ->userPresenter ->present ($ tweet ->author ),
34- 'comments ' => $ this -> commentPresenter -> presentCollection ( $ tweet ->comments )
28+ 'author ' => $ this ->userPresenter ->present ($ tweet ->getAuthor () ),
29+ 'comments_count ' => $ tweet ->getCommentsCount ( )
3530 ];
3631 }
3732
You can’t perform that action at this time.
0 commit comments