Add machines with day-by-day work lists for job tasks
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -6,14 +6,21 @@ namespace App\Modules\Jobs\Application\UseCases;
|
||||
|
||||
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
use App\Modules\Jobs\Domain\Events\TaskCompleted;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||
use App\Modules\Shared\Application\Contracts\EventDispatcher;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
|
||||
/**
|
||||
* Changes a task's status. A task newly marked done is published as
|
||||
* completed, so that e.g. a machine's work list closes its row.
|
||||
*/
|
||||
final class ChangeTaskStatus
|
||||
{
|
||||
public function __construct(
|
||||
private TaskRepository $tasks,
|
||||
private TransactionManager $transactions,
|
||||
private EventDispatcher $events,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -23,8 +30,14 @@ final class ChangeTaskStatus
|
||||
{
|
||||
$this->transactions->run(function () use ($jobId, $taskId, $status): void {
|
||||
$task = $this->tasks->findForJob($jobId, $taskId) ?? throw new TaskNotFound($jobId, $taskId);
|
||||
$wasDone = $task->status() === TaskStatus::Done;
|
||||
|
||||
$task->changeStatus($status);
|
||||
$this->tasks->save($task);
|
||||
|
||||
if (! $wasDone && $status === TaskStatus::Done) {
|
||||
$this->events->dispatch(new TaskCompleted($taskId, $jobId));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Modules\Jobs\Domain\Contracts\TaskRepository;
|
||||
use App\Modules\Jobs\Domain\Entities\Task;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
use App\Modules\Jobs\Domain\Events\PeopleAddedToTask;
|
||||
use App\Modules\Jobs\Domain\Events\TaskCompleted;
|
||||
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
|
||||
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
|
||||
@@ -49,6 +50,7 @@ final class UpdateTask
|
||||
|
||||
$before = self::planningInput($task);
|
||||
$peopleBefore = PeopleAddedToTask::peopleOf($task);
|
||||
$wasDone = $task->status() === TaskStatus::Done;
|
||||
|
||||
$task->changeDetails(
|
||||
$data->workTypeId,
|
||||
@@ -75,6 +77,10 @@ final class UpdateTask
|
||||
if ($added !== null) {
|
||||
$this->events->dispatch($added);
|
||||
}
|
||||
|
||||
if (! $wasDone && $task->status() === TaskStatus::Done) {
|
||||
$this->events->dispatch(new TaskCompleted($taskId, $jobId));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user