add schedule rescheduling
This commit is contained in:
parent
b8eeb093d3
commit
7576ccaf09
9 changed files with 314 additions and 5 deletions
|
|
@ -38,6 +38,39 @@ class EloquentScheduleRepository implements ScheduleRepository
|
|||
});
|
||||
}
|
||||
|
||||
public function reschedule(RescheduleScheduleDto $dto): Schedule
|
||||
{
|
||||
return DB::transaction(function () use ($dto): Schedule {
|
||||
$model = ScheduleModel::query()
|
||||
->where('id', $dto->scheduleId)
|
||||
->where('user_id', $dto->user->getId())
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
if ($model === null) {
|
||||
throw new DomainException(
|
||||
"Schedule with id {$dto->scheduleId} not found",
|
||||
);
|
||||
}
|
||||
|
||||
$model->start_date = $dto->startDate->format('Y-m-d');
|
||||
$model->target_date = $dto->targetDate->format('Y-m-d');
|
||||
$model->save();
|
||||
|
||||
foreach ($dto->assignments as $assignmentDto) {
|
||||
ScheduleAssignmentModel::query()
|
||||
->where('id', $assignmentDto->id)
|
||||
->where('schedule_id', $dto->scheduleId)
|
||||
->whereNull('completed_at')
|
||||
->update([
|
||||
'scheduled_date' => $assignmentDto->scheduledDate
|
||||
->format('Y-m-d'),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->toDomain($model, $dto->user);
|
||||
});
|
||||
}
|
||||
|
||||
public function findForUser(int $id, User $user): ?Schedule
|
||||
{
|
||||
$model = ScheduleModel::query()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue