Add comments to tasks
Everyone who may change a task's status (attached subcontractors too) comments on it on the job page. Authors edit and remove their own comments; admin and management may remove anyone's (jobs.remove-any-task-comment). Edited comments show when they were edited, and task cards show the number of comments. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\UseCases;
|
||||
|
||||
use App\Modules\Jobs\Application\Services\TaskCommentFinder;
|
||||
use App\Modules\Jobs\Domain\Contracts\TaskCommentRepository;
|
||||
use App\Modules\Jobs\Domain\Exceptions\NotTaskCommentAuthor;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskCommentNotFound;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
|
||||
/**
|
||||
* Removes the user's own comment, or anyone's when the user may remove
|
||||
* others' comments (admin and management).
|
||||
*/
|
||||
final class RemoveTaskComment
|
||||
{
|
||||
public function __construct(
|
||||
private TaskCommentFinder $finder,
|
||||
private TaskCommentRepository $comments,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws TaskNotFound
|
||||
* @throws TaskCommentNotFound
|
||||
* @throws NotTaskCommentAuthor
|
||||
*/
|
||||
public function execute(int $jobId, int $taskId, int $commentId, int $userId, bool $mayRemoveOthers): void
|
||||
{
|
||||
$this->transactions->run(function () use ($jobId, $taskId, $commentId, $userId, $mayRemoveOthers): void {
|
||||
$comment = $this->finder->find($jobId, $taskId, $commentId);
|
||||
$comment->ensureRemovableBy($userId, $mayRemoveOthers);
|
||||
|
||||
$this->comments->delete($comment);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user