reset to setup module state
Remove Task Manager implementation to match `# Setup module` in module.md. Backend src/ reduced to Kernel.php + empty Entity/, all migrations deleted, database dropped and recreated. Frontend components/views/services/stores removed, App.vue/router/style.css reduced to skeletons. CLAUDE.md shortened to Setup-stand. Old backend/plan.md, plan2.md removed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\DTO\Request\CreateCategoryRequest;
|
||||
use App\DTO\Request\UpdateCategoryRequest;
|
||||
use App\Entity\Category;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class CategoryManager
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
) {}
|
||||
|
||||
public function createCategory(CreateCategoryRequest $request): Category
|
||||
{
|
||||
$category = new Category();
|
||||
$category->setName($request->name);
|
||||
$category->setColor($request->color);
|
||||
|
||||
$this->em->persist($category);
|
||||
$this->em->flush();
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
public function updateCategory(Category $category, UpdateCategoryRequest $request): Category
|
||||
{
|
||||
$category->setName($request->name);
|
||||
$category->setColor($request->color);
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
public function deleteCategory(Category $category): void
|
||||
{
|
||||
$this->em->remove($category);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\TaskSchema;
|
||||
use App\Enum\TaskSchemaType;
|
||||
|
||||
class DeadlineCalculator
|
||||
{
|
||||
/**
|
||||
* @return \DateTimeInterface[]
|
||||
*/
|
||||
public function getDeadlinesForRange(TaskSchema $schema, \DateTimeInterface $from, \DateTimeInterface $to): array
|
||||
{
|
||||
$startDate = $schema->getStartDate();
|
||||
if ($startDate === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$effectiveFrom = $from > $startDate ? $from : $startDate;
|
||||
$endDate = $schema->getEndDate();
|
||||
$effectiveTo = $endDate !== null && $to > $endDate ? $endDate : $to;
|
||||
|
||||
if ($effectiveFrom > $effectiveTo) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$deadlines = [];
|
||||
$current = new \DateTimeImmutable($effectiveFrom->format('Y-m-d'));
|
||||
$end = new \DateTimeImmutable($effectiveTo->format('Y-m-d'));
|
||||
|
||||
while ($current <= $end) {
|
||||
if ($this->matchesType($schema, $current)) {
|
||||
$deadlines[] = $current;
|
||||
}
|
||||
$current = $current->modify('+1 day');
|
||||
}
|
||||
|
||||
return $deadlines;
|
||||
}
|
||||
|
||||
private function matchesType(TaskSchema $schema, \DateTimeImmutable $date): bool
|
||||
{
|
||||
return match ($schema->getTaskType()) {
|
||||
TaskSchemaType::Daily => true,
|
||||
TaskSchemaType::Custom => $this->matchesDays($schema, $date),
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
private function matchesDays(TaskSchema $schema, \DateTimeImmutable $date): bool
|
||||
{
|
||||
$days = $schema->getDays() ?? [];
|
||||
|
||||
if (!empty($days['week']) && in_array((int) $date->format('N'), $days['week'], true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!empty($days['month']) && in_array((int) $date->format('j'), $days['month'], true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!empty($days['year'])) {
|
||||
$month = (int) $date->format('n');
|
||||
$day = (int) $date->format('j');
|
||||
foreach ($days['year'] as $yd) {
|
||||
if (($yd['month'] ?? 0) === $month && ($yd['day'] ?? 0) === $day) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Task;
|
||||
use App\Repository\TaskRepository;
|
||||
use App\Repository\TaskSchemaRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class TaskGenerator
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private TaskSchemaRepository $schemaRepository,
|
||||
private TaskRepository $taskRepository,
|
||||
private DeadlineCalculator $deadlineCalculator,
|
||||
) {}
|
||||
|
||||
public function generateForRange(\DateTimeInterface $from, \DateTimeInterface $to): void
|
||||
{
|
||||
$schemas = $this->schemaRepository->findActiveSchemasInRange($from, $to);
|
||||
$existingKeys = $this->taskRepository->getExistingKeys($from, $to);
|
||||
|
||||
$hasNew = false;
|
||||
|
||||
foreach ($schemas as $schema) {
|
||||
$deadlines = $this->deadlineCalculator->getDeadlinesForRange($schema, $from, $to);
|
||||
|
||||
foreach ($deadlines as $deadline) {
|
||||
$key = $schema->getId() . '-' . $deadline->format('Y-m-d');
|
||||
if (!isset($existingKeys[$key])) {
|
||||
$task = new Task();
|
||||
$task->setSchema($schema);
|
||||
$task->setDate(new \DateTime($deadline->format('Y-m-d')));
|
||||
$task->setName($schema->getName());
|
||||
$task->setCategory($schema->getCategory());
|
||||
|
||||
$this->em->persist($task);
|
||||
$existingKeys[$key] = true;
|
||||
$hasNew = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($hasNew) {
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\DTO\Request\CreateTaskRequest;
|
||||
use App\DTO\Request\UpdateTaskRequest;
|
||||
use App\Entity\Task;
|
||||
use App\Enum\TaskStatus;
|
||||
use App\Repository\CategoryRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class TaskManager
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private CategoryRepository $categoryRepository,
|
||||
) {}
|
||||
|
||||
public function createTask(CreateTaskRequest $request): Task
|
||||
{
|
||||
$task = new Task();
|
||||
$task->setName($request->name);
|
||||
|
||||
if ($request->categoryId !== null) {
|
||||
$category = $this->categoryRepository->find($request->categoryId);
|
||||
$task->setCategory($category);
|
||||
}
|
||||
|
||||
if ($request->date !== null) {
|
||||
$task->setDate(new \DateTime($request->date));
|
||||
}
|
||||
|
||||
$this->em->persist($task);
|
||||
$this->em->flush();
|
||||
|
||||
return $task;
|
||||
}
|
||||
|
||||
public function updateTask(Task $task, UpdateTaskRequest $request): Task
|
||||
{
|
||||
$task->setName($request->name);
|
||||
|
||||
$category = $request->categoryId !== null
|
||||
? $this->categoryRepository->find($request->categoryId)
|
||||
: null;
|
||||
$task->setCategory($category);
|
||||
|
||||
$status = TaskStatus::tryFrom($request->status);
|
||||
if ($status !== null) {
|
||||
$task->setStatus($status);
|
||||
}
|
||||
|
||||
$task->setDate($request->date ? new \DateTime($request->date) : null);
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
return $task;
|
||||
}
|
||||
|
||||
public function toggleTask(Task $task): Task
|
||||
{
|
||||
$newStatus = $task->getStatus() === TaskStatus::Active
|
||||
? TaskStatus::Done
|
||||
: TaskStatus::Active;
|
||||
$task->setStatus($newStatus);
|
||||
$this->em->flush();
|
||||
|
||||
return $task;
|
||||
}
|
||||
|
||||
public function deleteTask(Task $task): void
|
||||
{
|
||||
$this->em->remove($task);
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\DTO\Request\CreateSchemaRequest;
|
||||
use App\DTO\Request\UpdateSchemaRequest;
|
||||
use App\Entity\Task;
|
||||
use App\Entity\TaskSchema;
|
||||
use App\Enum\TaskSchemaStatus;
|
||||
use App\Enum\TaskSchemaType;
|
||||
use App\Repository\CategoryRepository;
|
||||
use App\Repository\TaskRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class TaskSchemaManager
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private CategoryRepository $categoryRepository,
|
||||
private TaskRepository $taskRepository,
|
||||
private TaskSynchronizer $taskSynchronizer,
|
||||
) {}
|
||||
|
||||
public function createSchema(CreateSchemaRequest $request): TaskSchema|array
|
||||
{
|
||||
$schema = new TaskSchema();
|
||||
$schema->setName($request->name ?? '');
|
||||
|
||||
$this->applyFields($schema, $request);
|
||||
$this->resolveCategory($schema, $request);
|
||||
$this->applyDefaults($schema);
|
||||
|
||||
$this->em->persist($schema);
|
||||
$this->em->flush();
|
||||
|
||||
if ($schema->getTaskType() === TaskSchemaType::Single) {
|
||||
$tasks = $this->createSingleTasks($schema);
|
||||
$this->em->remove($schema);
|
||||
$this->em->flush();
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public function updateSchema(TaskSchema $schema, UpdateSchemaRequest $request): TaskSchema
|
||||
{
|
||||
if ($request->name !== null) {
|
||||
$schema->setName($request->name);
|
||||
}
|
||||
|
||||
$this->applyFields($schema, $request);
|
||||
$this->resolveCategory($schema, $request);
|
||||
$this->applyDefaults($schema);
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
$this->taskSynchronizer->syncForSchema($schema);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public function deleteSchema(TaskSchema $schema, bool $deleteTasks = false): void
|
||||
{
|
||||
if ($deleteTasks) {
|
||||
$tasks = $this->taskRepository->findBy(['schema' => $schema]);
|
||||
foreach ($tasks as $task) {
|
||||
$this->em->remove($task);
|
||||
}
|
||||
}
|
||||
|
||||
$this->em->remove($schema);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
private function applyFields(TaskSchema $schema, CreateSchemaRequest|UpdateSchemaRequest $request): void
|
||||
{
|
||||
if ($request->status !== null) {
|
||||
$status = TaskSchemaStatus::tryFrom($request->status);
|
||||
if ($status !== null) {
|
||||
$schema->setStatus($status);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->type !== null) {
|
||||
$taskType = TaskSchemaType::tryFrom($request->type);
|
||||
if ($taskType !== null) {
|
||||
$schema->setTaskType($taskType);
|
||||
}
|
||||
}
|
||||
|
||||
$schema->setStartDate($request->startDate !== null ? new \DateTime($request->startDate) : null);
|
||||
$schema->setEndDate($request->endDate !== null ? new \DateTime($request->endDate) : null);
|
||||
$schema->setDays($request->days);
|
||||
}
|
||||
|
||||
private function resolveCategory(TaskSchema $schema, UpdateSchemaRequest|CreateSchemaRequest $request): void
|
||||
{
|
||||
if ($request instanceof UpdateSchemaRequest) {
|
||||
if ($request->hasCategoryId) {
|
||||
if ($request->categoryId !== null) {
|
||||
$category = $this->categoryRepository->find($request->categoryId);
|
||||
$schema->setCategory($category);
|
||||
} else {
|
||||
$schema->setCategory(null);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($request->categoryId !== null) {
|
||||
$category = $this->categoryRepository->find($request->categoryId);
|
||||
$schema->setCategory($category);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function applyDefaults(TaskSchema $schema): void
|
||||
{
|
||||
if ($schema->getTaskType() !== TaskSchemaType::Single && $schema->getStartDate() === null) {
|
||||
$schema->setStartDate(new \DateTime('today'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Task[]
|
||||
*/
|
||||
private function createSingleTasks(TaskSchema $schema): array
|
||||
{
|
||||
$days = $schema->getDays()['year'] ?? [];
|
||||
$tasks = [];
|
||||
|
||||
foreach ($days as $yd) {
|
||||
$month = $yd['month'] ?? 1;
|
||||
$day = $yd['day'] ?? 1;
|
||||
$date = new \DateTime(sprintf('%d-%02d-%02d', (int) date('Y'), $month, $day));
|
||||
|
||||
$task = new Task();
|
||||
$task->setName($schema->getName());
|
||||
$task->setCategory($schema->getCategory());
|
||||
$task->setDate($date);
|
||||
|
||||
$this->em->persist($task);
|
||||
$tasks[] = $task;
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Task;
|
||||
use App\Entity\TaskSchema;
|
||||
use App\Repository\TaskRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class TaskSynchronizer
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private TaskRepository $taskRepository,
|
||||
private DeadlineCalculator $deadlineCalculator,
|
||||
) {}
|
||||
|
||||
public function syncForSchema(TaskSchema $schema): void
|
||||
{
|
||||
$today = new \DateTimeImmutable('today');
|
||||
$end = $this->calculateSyncEnd($schema, $today);
|
||||
|
||||
$deadlines = $this->deadlineCalculator->getDeadlinesForRange($schema, $today, $end);
|
||||
$shouldExist = [];
|
||||
foreach ($deadlines as $deadline) {
|
||||
$shouldExist[$deadline->format('Y-m-d')] = true;
|
||||
}
|
||||
|
||||
$existingByDate = $this->loadExistingByDate($schema, $today);
|
||||
|
||||
$this->removeObsoleteTasks($existingByDate, $shouldExist);
|
||||
$this->resetFutureOverrides($schema, $existingByDate);
|
||||
$this->createMissingTasks($schema, $deadlines, $existingByDate);
|
||||
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
private function calculateSyncEnd(TaskSchema $schema, \DateTimeImmutable $today): \DateTimeImmutable
|
||||
{
|
||||
$minEnd = $today->modify('+6 days');
|
||||
$end = $schema->getEndDate()
|
||||
? new \DateTimeImmutable($schema->getEndDate()->format('Y-m-d'))
|
||||
: $minEnd;
|
||||
|
||||
return $end < $minEnd ? $minEnd : $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, Task>
|
||||
*/
|
||||
private function loadExistingByDate(TaskSchema $schema, \DateTimeImmutable $today): array
|
||||
{
|
||||
$futureTasks = $this->taskRepository->findBySchemaFromDate($schema, $today);
|
||||
$existingByDate = [];
|
||||
foreach ($futureTasks as $task) {
|
||||
$existingByDate[$task->getDate()->format('Y-m-d')] = $task;
|
||||
}
|
||||
|
||||
return $existingByDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, Task> $existingByDate
|
||||
* @param array<string, true> $shouldExist
|
||||
*/
|
||||
private function removeObsoleteTasks(array &$existingByDate, array $shouldExist): void
|
||||
{
|
||||
foreach ($existingByDate as $dateKey => $task) {
|
||||
if (!isset($shouldExist[$dateKey])) {
|
||||
$this->em->remove($task);
|
||||
unset($existingByDate[$dateKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, Task> $existingByDate
|
||||
*/
|
||||
private function resetFutureOverrides(TaskSchema $schema, array $existingByDate): void
|
||||
{
|
||||
foreach ($existingByDate as $task) {
|
||||
$task->setName($schema->getName());
|
||||
$task->setCategory($schema->getCategory());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTimeInterface[] $deadlines
|
||||
* @param array<string, Task> $existingByDate
|
||||
*/
|
||||
private function createMissingTasks(TaskSchema $schema, array $deadlines, array $existingByDate): void
|
||||
{
|
||||
foreach ($deadlines as $deadline) {
|
||||
$dateKey = $deadline->format('Y-m-d');
|
||||
if (!isset($existingByDate[$dateKey])) {
|
||||
$task = new Task();
|
||||
$task->setSchema($schema);
|
||||
$task->setDate(new \DateTime($dateKey));
|
||||
$task->setName($schema->getName());
|
||||
$task->setCategory($schema->getCategory());
|
||||
|
||||
$this->em->persist($task);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user