Compare commits
No commits in common. "49663d70d9d850e95cda143fd681c6c2827489d3" and "f8a1c2616d7bfe89baca5b372cc4834c7fa586e6" have entirely different histories.
49663d70d9
...
f8a1c2616d
4 changed files with 2 additions and 186 deletions
|
|
@ -42,21 +42,6 @@ class CreatePlan
|
||||||
throw new BadRequestException('name is required');
|
throw new BadRequestException('name is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->dateStart === null) {
|
|
||||||
throw new BadRequestException('date start is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->dateEnd === null) {
|
|
||||||
throw new BadRequestException('date end is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
$startDate = new DateTimeImmutable($request->dateStart);
|
|
||||||
$endDate = new DateTimeImmutable($request->dateEnd);
|
|
||||||
|
|
||||||
if ($endDate < $startDate) {
|
|
||||||
throw new BadRequestException('date end cannot be before date start');
|
|
||||||
}
|
|
||||||
|
|
||||||
$userId = $request->userId;
|
$userId = $request->userId;
|
||||||
$user = $this->userRepo->find($userId);
|
$user = $this->userRepo->find($userId);
|
||||||
if ($user === null) {
|
if ($user === null) {
|
||||||
|
|
@ -74,22 +59,10 @@ class CreatePlan
|
||||||
name: $request->name,
|
name: $request->name,
|
||||||
user: $user,
|
user: $user,
|
||||||
));
|
));
|
||||||
|
foreach ($nodesOfText as $node) {
|
||||||
$dates = [];
|
|
||||||
$currentDate = $startDate;
|
|
||||||
while ($currentDate <= $endDate) {
|
|
||||||
$dates[] = $currentDate;
|
|
||||||
$currentDate = $currentDate->modify('+1 day');
|
|
||||||
}
|
|
||||||
|
|
||||||
$nodesPerDay = (int) ceil(count($nodesOfText) / count($dates));
|
|
||||||
foreach ($nodesOfText as $index => $node) {
|
|
||||||
$dateIndex = (int) floor($index / $nodesPerDay);
|
|
||||||
$scheduledDate = $dates[$dateIndex];
|
|
||||||
|
|
||||||
$this->createScheduledNode->execute(
|
$this->createScheduledNode->execute(
|
||||||
new CreateScheduledNodeRequest(
|
new CreateScheduledNodeRequest(
|
||||||
date: $scheduledDate->format('Y-m-d'),
|
date: '2025-01-01', // TODO: this should be cycling over some list of dates
|
||||||
planId: $plan->getId(),
|
planId: $plan->getId(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,5 @@ class CreatePlanRequest
|
||||||
public ?int $userId,
|
public ?int $userId,
|
||||||
public ?int $textId,
|
public ?int $textId,
|
||||||
public ?string $name,
|
public ?string $name,
|
||||||
public ?string $dateStart,
|
|
||||||
public ?string $dateEnd,
|
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,4 @@ class ScheduledNode
|
||||||
{
|
{
|
||||||
return $this->plan;
|
return $this->plan;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDate(): DateTimeImmutable
|
|
||||||
{
|
|
||||||
return $this->date;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ use App\Text\CreateTextDto;
|
||||||
use App\User\UseCases\CreateUserDto;
|
use App\User\UseCases\CreateUserDto;
|
||||||
use App\User\User;
|
use App\User\User;
|
||||||
use App\ValueObjects\EmailAddress;
|
use App\ValueObjects\EmailAddress;
|
||||||
use DateTimeImmutable;
|
|
||||||
use DomainException;
|
use DomainException;
|
||||||
use Tests\Fakes\FakeNodeRepository;
|
use Tests\Fakes\FakeNodeRepository;
|
||||||
use Tests\Fakes\FakePlanRepository;
|
use Tests\Fakes\FakePlanRepository;
|
||||||
|
|
@ -60,8 +59,6 @@ class CreatePlanTest extends TestCase
|
||||||
userId: 0,
|
userId: 0,
|
||||||
name: 'testPlan',
|
name: 'testPlan',
|
||||||
textId: 0,
|
textId: 0,
|
||||||
dateStart: '2025-01-01',
|
|
||||||
dateEnd: '2025-01-01',
|
|
||||||
));
|
));
|
||||||
$this->assertEquals('testPlan', $plan->getName());
|
$this->assertEquals('testPlan', $plan->getName());
|
||||||
}
|
}
|
||||||
|
|
@ -72,8 +69,6 @@ class CreatePlanTest extends TestCase
|
||||||
userId: 0,
|
userId: 0,
|
||||||
name: 'testPlan',
|
name: 'testPlan',
|
||||||
textId: 0,
|
textId: 0,
|
||||||
dateStart: '2025-01-01',
|
|
||||||
dateEnd: '2025-01-01',
|
|
||||||
));
|
));
|
||||||
$this->assertInstanceOf(User::class, $plan->getUser());
|
$this->assertInstanceOf(User::class, $plan->getUser());
|
||||||
}
|
}
|
||||||
|
|
@ -86,8 +81,6 @@ class CreatePlanTest extends TestCase
|
||||||
userId: 1,
|
userId: 1,
|
||||||
name: 'testPlan',
|
name: 'testPlan',
|
||||||
textId: 0,
|
textId: 0,
|
||||||
dateStart: '2025-01-01',
|
|
||||||
dateEnd: '2025-01-01',
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,8 +92,6 @@ class CreatePlanTest extends TestCase
|
||||||
userId: 0,
|
userId: 0,
|
||||||
name: 'testPlan',
|
name: 'testPlan',
|
||||||
textId: 1,
|
textId: 1,
|
||||||
dateStart: '2025-01-01',
|
|
||||||
dateEnd: '2025-01-01',
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,8 +107,6 @@ class CreatePlanTest extends TestCase
|
||||||
userId: 0,
|
userId: 0,
|
||||||
name: 'testPlan',
|
name: 'testPlan',
|
||||||
textId: 0,
|
textId: 0,
|
||||||
dateStart: '2025-01-01',
|
|
||||||
dateEnd: '2025-01-01',
|
|
||||||
));
|
));
|
||||||
$this->assertNotNull($this->scheduledNodeRepo->find(0));
|
$this->assertNotNull($this->scheduledNodeRepo->find(0));
|
||||||
}
|
}
|
||||||
|
|
@ -139,8 +128,6 @@ class CreatePlanTest extends TestCase
|
||||||
userId: 0,
|
userId: 0,
|
||||||
name: 'testPlan',
|
name: 'testPlan',
|
||||||
textId: 0,
|
textId: 0,
|
||||||
dateStart: '2025-01-01',
|
|
||||||
dateEnd: '2025-01-01',
|
|
||||||
));
|
));
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
1,
|
1,
|
||||||
|
|
@ -157,8 +144,6 @@ class CreatePlanTest extends TestCase
|
||||||
userId: null,
|
userId: null,
|
||||||
name: 'testPlan',
|
name: 'testPlan',
|
||||||
textId: 0,
|
textId: 0,
|
||||||
dateStart: '2025-01-01',
|
|
||||||
dateEnd: '2025-01-01',
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,8 +156,6 @@ class CreatePlanTest extends TestCase
|
||||||
userId: 0,
|
userId: 0,
|
||||||
name: 'testPlan',
|
name: 'testPlan',
|
||||||
textId: null,
|
textId: null,
|
||||||
dateStart: '2025-01-01',
|
|
||||||
dateEnd: '2025-01-01',
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,139 +168,6 @@ class CreatePlanTest extends TestCase
|
||||||
userId: 0,
|
userId: 0,
|
||||||
name: null,
|
name: null,
|
||||||
textId: 0,
|
textId: 0,
|
||||||
dateStart: '2025-01-01',
|
|
||||||
dateEnd: '2025-01-01',
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_throws_if_date_start_is_null(): void
|
|
||||||
{
|
|
||||||
$this->expectException(BadRequestException::class);
|
|
||||||
$this->expectExceptionMessage('date start is required');
|
|
||||||
|
|
||||||
$this->useCase->execute(new CreatePlanRequest(
|
|
||||||
userId: 0,
|
|
||||||
name: 'test',
|
|
||||||
textId: 0,
|
|
||||||
dateStart: null,
|
|
||||||
dateEnd: '2025-01-01',
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_throws_if_date_end_is_null(): void
|
|
||||||
{
|
|
||||||
$this->expectException(BadRequestException::class);
|
|
||||||
$this->expectExceptionMessage('date end is required');
|
|
||||||
|
|
||||||
$this->useCase->execute(new CreatePlanRequest(
|
|
||||||
userId: 0,
|
|
||||||
name: 'test',
|
|
||||||
textId: 0,
|
|
||||||
dateStart: '2025-01-01',
|
|
||||||
dateEnd: null,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_throws_if_date_end_is_before_date_start(): void
|
|
||||||
{
|
|
||||||
$this->expectException(BadRequestException::class);
|
|
||||||
$this->expectExceptionMessage('date end cannot be before date start');
|
|
||||||
|
|
||||||
$this->useCase->execute(new CreatePlanRequest(
|
|
||||||
userId: 0,
|
|
||||||
name: 'test',
|
|
||||||
textId: 0,
|
|
||||||
dateStart: '2025-01-02',
|
|
||||||
dateEnd: '2025-01-01',
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_scheduled_nodes_are_scheduled_on_different_days(): void
|
|
||||||
{
|
|
||||||
$text = $this->textRepo->find(0);
|
|
||||||
$rootNode = $this->nodeRepo->create(new CreateNodeDto(
|
|
||||||
text: $text,
|
|
||||||
title: 'root node',
|
|
||||||
parentNode: null,
|
|
||||||
));
|
|
||||||
$this->nodeRepo->create(new CreateNodeDto(
|
|
||||||
text: $text,
|
|
||||||
title: 'child 1',
|
|
||||||
parentNode: $rootNode,
|
|
||||||
));
|
|
||||||
$this->nodeRepo->create(new CreateNodeDto(
|
|
||||||
text: $text,
|
|
||||||
title: 'child 2',
|
|
||||||
parentNode: $rootNode,
|
|
||||||
));
|
|
||||||
$plan = $this->useCase->execute(new CreatePlanRequest(
|
|
||||||
userId: 0,
|
|
||||||
name: 'testPlan',
|
|
||||||
textId: 0,
|
|
||||||
dateStart: '2025-01-01',
|
|
||||||
dateEnd: '2025-01-02',
|
|
||||||
));
|
|
||||||
$childOne = $this->scheduledNodeRepo->find(0);
|
|
||||||
$childTwo = $this->scheduledNodeRepo->find(1);
|
|
||||||
$this->assertNotNull($childOne);
|
|
||||||
$this->assertNotNull($childTwo);
|
|
||||||
$this->assertEquals(
|
|
||||||
new DateTimeImmutable('2025-01-01'),
|
|
||||||
$childOne->getDate()
|
|
||||||
);
|
|
||||||
$this->assertEquals(
|
|
||||||
new DateTimeImmutable('2025-01-02'),
|
|
||||||
$childTwo->getDate()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_more_scheduled_nodes_than_days(): void
|
|
||||||
{
|
|
||||||
$text = $this->textRepo->find(0);
|
|
||||||
$rootNode = $this->nodeRepo->create(new CreateNodeDto(
|
|
||||||
text: $text,
|
|
||||||
title: 'root node',
|
|
||||||
parentNode: null,
|
|
||||||
));
|
|
||||||
$this->nodeRepo->create(new CreateNodeDto(
|
|
||||||
text: $text,
|
|
||||||
title: 'child 1',
|
|
||||||
parentNode: $rootNode,
|
|
||||||
));
|
|
||||||
$this->nodeRepo->create(new CreateNodeDto(
|
|
||||||
text: $text,
|
|
||||||
title: 'child 2',
|
|
||||||
parentNode: $rootNode,
|
|
||||||
));
|
|
||||||
$this->nodeRepo->create(new CreateNodeDto(
|
|
||||||
text: $text,
|
|
||||||
title: 'child 3',
|
|
||||||
parentNode: $rootNode,
|
|
||||||
));
|
|
||||||
$plan = $this->useCase->execute(new CreatePlanRequest(
|
|
||||||
userId: 0,
|
|
||||||
name: 'testPlan',
|
|
||||||
textId: 0,
|
|
||||||
dateStart: '2025-01-01',
|
|
||||||
dateEnd: '2025-01-02',
|
|
||||||
));
|
|
||||||
$childOne = $this->scheduledNodeRepo->find(0);
|
|
||||||
$childTwo = $this->scheduledNodeRepo->find(1);
|
|
||||||
$childThree = $this->scheduledNodeRepo->find(2);
|
|
||||||
$this->assertNotNull($childOne);
|
|
||||||
$this->assertNotNull($childTwo);
|
|
||||||
$this->assertNotNull($childThree);
|
|
||||||
$this->assertEquals(
|
|
||||||
new DateTimeImmutable('2025-01-01'),
|
|
||||||
$childOne->getDate()
|
|
||||||
);
|
|
||||||
$this->assertEquals(
|
|
||||||
new DateTimeImmutable('2025-01-01'),
|
|
||||||
$childTwo->getDate()
|
|
||||||
);
|
|
||||||
$this->assertEquals(
|
|
||||||
new DateTimeImmutable('2025-01-02'),
|
|
||||||
$childThree->getDate()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue