add assignment completion api
This commit is contained in:
parent
916f070455
commit
350d2ec0b7
11 changed files with 281 additions and 16 deletions
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Schedule\UseCases\SetAssignmentCompletion;
|
||||
|
||||
use App\Auth\Clock;
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\Exceptions\NotFoundException;
|
||||
use App\Schedule\ScheduleAssignment;
|
||||
use App\Schedule\ScheduleRepository;
|
||||
|
||||
class SetAssignmentCompletion
|
||||
{
|
||||
public function __construct(
|
||||
private ScheduleRepository $scheduleRepository,
|
||||
private Clock $clock,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws BadRequestException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function execute(
|
||||
SetAssignmentCompletionRequest $request,
|
||||
): ScheduleAssignment {
|
||||
if ($request->completed === null) {
|
||||
throw new BadRequestException(
|
||||
'completed must be a boolean',
|
||||
);
|
||||
}
|
||||
|
||||
$assignment = $this->scheduleRepository->findAssignmentForUser(
|
||||
$request->assignmentId,
|
||||
$request->user,
|
||||
);
|
||||
if ($assignment === null) {
|
||||
throw new NotFoundException('assignment not found');
|
||||
}
|
||||
|
||||
if ($request->completed) {
|
||||
$assignment->complete($this->clock->now());
|
||||
} else {
|
||||
$assignment->reopen();
|
||||
}
|
||||
|
||||
return $this->scheduleRepository->updateAssignment($assignment);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue