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]>
41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?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);
|
|
});
|
|
}
|
|
}
|