schedule explicit set levels
This commit is contained in:
parent
a64df64b76
commit
3cf1aff6a9
10 changed files with 156 additions and 38 deletions
|
|
@ -11,6 +11,7 @@ use App\Schedule\CreateScheduleDto;
|
|||
use App\Schedule\Schedule;
|
||||
use App\Schedule\ScheduleRepository;
|
||||
use App\Set\Set;
|
||||
use App\Set\SetLevelRepository;
|
||||
use App\Set\SetRepository;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
|
|
@ -19,6 +20,7 @@ class CreateSchedule
|
|||
{
|
||||
public function __construct(
|
||||
private SetRepository $setRepository,
|
||||
private SetLevelRepository $setLevelRepository,
|
||||
private ElementRepository $elementRepository,
|
||||
private ScheduleRepository $scheduleRepository,
|
||||
) {}
|
||||
|
|
@ -38,8 +40,18 @@ class CreateSchedule
|
|||
throw new NotFoundException('set not found');
|
||||
}
|
||||
|
||||
if ($request->elementKind === null || $request->elementKind === '') {
|
||||
throw new BadRequestException('elementKind is required');
|
||||
if ($request->levelId === null || $request->levelId < 1) {
|
||||
throw new BadRequestException('levelId is required');
|
||||
}
|
||||
|
||||
$level = $this->setLevelRepository->find($request->levelId);
|
||||
if (
|
||||
$level === null
|
||||
|| $level->getSet()->getId() !== $set->getId()
|
||||
) {
|
||||
throw new BadRequestException(
|
||||
'level is not available for set',
|
||||
);
|
||||
}
|
||||
|
||||
$startDate = $this->parseDate($request->startDate, 'startDate');
|
||||
|
|
@ -52,14 +64,12 @@ class CreateSchedule
|
|||
|
||||
$elements = array_values(array_filter(
|
||||
$this->orderedElements($set),
|
||||
function (Element $element) use ($request): bool {
|
||||
return $element->getKind() === $request->elementKind;
|
||||
function (Element $element) use ($level): bool {
|
||||
return $element->getLevel()->getId() === $level->getId();
|
||||
},
|
||||
));
|
||||
if ($elements === []) {
|
||||
throw new BadRequestException(
|
||||
'elementKind is not available for set',
|
||||
);
|
||||
throw new BadRequestException('level has no elements');
|
||||
}
|
||||
|
||||
$assignments = $this->assignments(
|
||||
|
|
@ -71,7 +81,7 @@ class CreateSchedule
|
|||
return $this->scheduleRepository->create(new CreateScheduleDto(
|
||||
user: $request->user,
|
||||
setName: $set->getName(),
|
||||
elementKind: $request->elementKind,
|
||||
elementKind: $level->getKind(),
|
||||
startDate: $startDate,
|
||||
targetDate: $targetDate,
|
||||
assignments: $assignments,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ final readonly class CreateScheduleRequest
|
|||
public function __construct(
|
||||
public User $user,
|
||||
public ?int $setId,
|
||||
public ?string $elementKind,
|
||||
public ?int $levelId,
|
||||
public ?string $startDate,
|
||||
public ?string $targetDate,
|
||||
) {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue