You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
772 B

7 years ago
<?php
namespace core\services\post;
use core\entities\post\PostComment;
use core\forms\post\PostCommentForm;
use core\repositories\post\PostRepository;
use core\repositories\user\UserRepository;
class PostCommentService
{
3 years ago
private PostRepository $posts;
private UserRepository $users;
7 years ago
public function __construct(PostRepository $posts, UserRepository $users)
{
$this->posts = $posts;
$this->users = $users;
}
public function create($postId, $userId, PostCommentForm $form): PostComment
{
$post = $this->posts->get($postId);
$user = $this->users->get($userId);
$comment = $post->addComment($user->id, $form->parentId, $form->text);
$this->posts->save($post);
return $comment;
}
3 years ago
}