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,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20260323230657 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TABLE category (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, color VARCHAR(7) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
|
||||
$this->addSql('CREATE TABLE task (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, status VARCHAR(20) NOT NULL, task_type VARCHAR(20) NOT NULL, deadline DATE DEFAULT NULL, interval_type VARCHAR(20) DEFAULT NULL, start_date DATE DEFAULT NULL, end_date DATE DEFAULT NULL, weekdays JSON DEFAULT NULL, month_days JSON DEFAULT NULL, category_id INT DEFAULT NULL, INDEX IDX_527EDB2512469DE2 (category_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
|
||||
$this->addSql('ALTER TABLE task ADD CONSTRAINT FK_527EDB2512469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE SET NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE task DROP FOREIGN KEY FK_527EDB2512469DE2');
|
||||
$this->addSql('DROP TABLE category');
|
||||
$this->addSql('DROP TABLE task');
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20260324141105 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TABLE task_completion (id INT AUTO_INCREMENT NOT NULL, date DATE NOT NULL, task_id INT NOT NULL, INDEX IDX_24C57CD18DB60186 (task_id), UNIQUE INDEX UNIQ_24C57CD18DB60186AA9E377A (task_id, date), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
|
||||
$this->addSql('ALTER TABLE task_completion ADD CONSTRAINT FK_24C57CD18DB60186 FOREIGN KEY (task_id) REFERENCES task (id) ON DELETE CASCADE');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE task_completion DROP FOREIGN KEY FK_24C57CD18DB60186');
|
||||
$this->addSql('DROP TABLE task_completion');
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20260324154816 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE TABLE task_occurrence (id INT AUTO_INCREMENT NOT NULL, date DATE NOT NULL, status VARCHAR(20) NOT NULL, task_id INT NOT NULL, INDEX IDX_A2EECA5C8DB60186 (task_id), UNIQUE INDEX UNIQ_A2EECA5C8DB60186AA9E377A (task_id, date), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
|
||||
$this->addSql('ALTER TABLE task_occurrence ADD CONSTRAINT FK_A2EECA5C8DB60186 FOREIGN KEY (task_id) REFERENCES task (id) ON DELETE CASCADE');
|
||||
$this->addSql("INSERT INTO task_occurrence (task_id, date, status) SELECT task_id, date, 'erledigt' FROM task_completion");
|
||||
$this->addSql('ALTER TABLE task_completion DROP FOREIGN KEY FK_24C57CD18DB60186');
|
||||
$this->addSql('DROP TABLE task_completion');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE task_occurrence DROP FOREIGN KEY FK_A2EECA5C8DB60186');
|
||||
$this->addSql('DROP TABLE task_occurrence');
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20260325064344 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE task_occurrence ADD name VARCHAR(255) DEFAULT NULL, ADD category_overridden TINYINT NOT NULL, ADD category_id INT DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE task_occurrence ADD CONSTRAINT FK_A2EECA5C12469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE SET NULL');
|
||||
$this->addSql('CREATE INDEX IDX_A2EECA5C12469DE2 ON task_occurrence (category_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE task_occurrence DROP FOREIGN KEY FK_A2EECA5C12469DE2');
|
||||
$this->addSql('DROP INDEX IDX_A2EECA5C12469DE2 ON task_occurrence');
|
||||
$this->addSql('ALTER TABLE task_occurrence DROP name, DROP category_overridden, DROP category_id');
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260326165702 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Rename task → task_schema, task_occurrence → task';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// 1. Drop FKs on task_occurrence that reference task
|
||||
$this->addSql('ALTER TABLE task_occurrence DROP FOREIGN KEY FK_A2EECA5C8DB60186');
|
||||
|
||||
// 2. Drop FK on task.category_id
|
||||
$this->addSql('ALTER TABLE task DROP FOREIGN KEY FK_527EDB2512469DE2');
|
||||
|
||||
// 3. Rename tables
|
||||
$this->addSql('RENAME TABLE task TO task_schema');
|
||||
$this->addSql('RENAME TABLE task_occurrence TO task');
|
||||
|
||||
// 4. Re-create FK: task.task_id → task_schema.id
|
||||
$this->addSql('ALTER TABLE task ADD CONSTRAINT FK_527EDB258DB60186 FOREIGN KEY (task_id) REFERENCES task_schema (id) ON DELETE CASCADE');
|
||||
|
||||
// 5. Re-create FK: task_schema.category_id → category.id
|
||||
$this->addSql('ALTER TABLE task_schema ADD CONSTRAINT FK_8327C58112469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE SET NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// Drop FKs
|
||||
$this->addSql('ALTER TABLE task DROP FOREIGN KEY FK_527EDB258DB60186');
|
||||
$this->addSql('ALTER TABLE task_schema DROP FOREIGN KEY FK_8327C58112469DE2');
|
||||
|
||||
// Rename back
|
||||
$this->addSql('RENAME TABLE task TO task_occurrence');
|
||||
$this->addSql('RENAME TABLE task_schema TO task');
|
||||
|
||||
// Re-create original FKs
|
||||
$this->addSql('ALTER TABLE task_occurrence ADD CONSTRAINT FK_A2EECA5C8DB60186 FOREIGN KEY (task_id) REFERENCES task (id) ON DELETE CASCADE');
|
||||
$this->addSql('ALTER TABLE task ADD CONSTRAINT FK_527EDB2512469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE SET NULL');
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20260330210659 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE task ADD created_at DATETIME NOT NULL, CHANGE date date DATE DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE task RENAME INDEX idx_a2eeca5c8db60186 TO IDX_527EDB258DB60186');
|
||||
$this->addSql('ALTER TABLE task RENAME INDEX idx_a2eeca5c12469de2 TO IDX_527EDB2512469DE2');
|
||||
$this->addSql('ALTER TABLE task RENAME INDEX uniq_a2eeca5c8db60186aa9e377a TO UNIQ_527EDB258DB60186AA9E377A');
|
||||
$this->addSql('ALTER TABLE task_schema ADD year_days JSON DEFAULT NULL, ADD created_at DATETIME NOT NULL, DROP interval_type');
|
||||
$this->addSql('ALTER TABLE task_schema RENAME INDEX idx_527edb2512469de2 TO IDX_8327C58112469DE2');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE task DROP created_at, CHANGE date date DATE NOT NULL');
|
||||
$this->addSql('ALTER TABLE task RENAME INDEX idx_527edb258db60186 TO IDX_A2EECA5C8DB60186');
|
||||
$this->addSql('ALTER TABLE task RENAME INDEX idx_527edb2512469de2 TO IDX_A2EECA5C12469DE2');
|
||||
$this->addSql('ALTER TABLE task RENAME INDEX uniq_527edb258db60186aa9e377a TO UNIQ_A2EECA5C8DB60186AA9E377A');
|
||||
$this->addSql('ALTER TABLE task_schema ADD interval_type VARCHAR(20) DEFAULT NULL, DROP year_days, DROP created_at');
|
||||
$this->addSql('ALTER TABLE task_schema RENAME INDEX idx_8327c58112469de2 TO IDX_527EDB2512469DE2');
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260331120000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Remove categoryOverridden: backfill task.category_id from schema, then drop column';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('UPDATE task t INNER JOIN task_schema ts ON t.task_id = ts.id SET t.category_id = ts.category_id WHERE t.category_overridden = 0');
|
||||
$this->addSql('ALTER TABLE task DROP category_overridden');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE task ADD category_overridden TINYINT(1) NOT NULL DEFAULT 0');
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260331150000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Major refactoring: English enums, unified days field, nullable task.schema, detach single tasks';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// 1. Migrate enum values to English
|
||||
$this->addSql("UPDATE task SET status = 'active' WHERE status = 'aktiv'");
|
||||
$this->addSql("UPDATE task SET status = 'done' WHERE status = 'erledigt'");
|
||||
|
||||
$this->addSql("UPDATE task_schema SET status = 'active' WHERE status = 'aktiv'");
|
||||
$this->addSql("UPDATE task_schema SET status = 'disabled' WHERE status IN ('erledigt', 'inaktiv')");
|
||||
|
||||
$this->addSql("UPDATE task_schema SET task_type = 'single' WHERE task_type = 'einzel'");
|
||||
$this->addSql("UPDATE task_schema SET task_type = 'daily' WHERE task_type = 'taeglich'");
|
||||
$this->addSql("UPDATE task_schema SET task_type = 'custom' WHERE task_type IN ('multi', 'woechentlich', 'monatlich', 'jaehrlich')");
|
||||
|
||||
// 2. Add unified days column
|
||||
$this->addSql('ALTER TABLE task_schema ADD days JSON DEFAULT NULL');
|
||||
|
||||
// 3. Migrate weekdays/monthDays/yearDays into days JSON via PHP
|
||||
$this->migrateDaysData();
|
||||
|
||||
// 4. Drop old columns from task_schema
|
||||
$this->addSql('ALTER TABLE task_schema DROP deadline, DROP weekdays, DROP month_days, DROP year_days');
|
||||
|
||||
// 5. Backfill task names/categories from schema (for all tasks that relied on getEffectiveName fallback)
|
||||
$this->addSql("UPDATE task t INNER JOIN task_schema ts ON t.task_id = ts.id SET t.name = ts.name WHERE t.name IS NULL");
|
||||
$this->addSql("UPDATE task t INNER JOIN task_schema ts ON t.task_id = ts.id SET t.category_id = ts.category_id WHERE t.category_id IS NULL AND ts.category_id IS NOT NULL");
|
||||
|
||||
// 6. Detach single tasks
|
||||
$this->addSql("UPDATE task t INNER JOIN task_schema ts ON t.task_id = ts.id SET t.name = ts.name WHERE ts.task_type = 'single' AND t.name IS NULL");
|
||||
$this->addSql("UPDATE task t INNER JOIN task_schema ts ON t.task_id = ts.id SET t.category_id = ts.category_id WHERE ts.task_type = 'single' AND t.category_id IS NULL");
|
||||
|
||||
// Drop FK + unique constraint before modifying task_id
|
||||
$this->addSql('ALTER TABLE task DROP FOREIGN KEY FK_527EDB258DB60186');
|
||||
$this->addSql('DROP INDEX UNIQ_527EDB258DB60186AA9E377A ON task');
|
||||
|
||||
// Detach single tasks
|
||||
$this->addSql("UPDATE task t INNER JOIN task_schema ts ON t.task_id = ts.id SET t.task_id = NULL WHERE ts.task_type = 'single'");
|
||||
|
||||
// Delete single schemas
|
||||
$this->addSql("DELETE FROM task_schema WHERE task_type = 'single'");
|
||||
|
||||
// Make task_id nullable with SET NULL on delete
|
||||
$this->addSql('ALTER TABLE task MODIFY task_id INT DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE task ADD CONSTRAINT FK_527EDB258DB60186 FOREIGN KEY (task_id) REFERENCES task_schema (id) ON DELETE SET NULL');
|
||||
}
|
||||
|
||||
private function migrateDaysData(): void
|
||||
{
|
||||
$rows = $this->connection->fetchAllAssociative(
|
||||
'SELECT id, weekdays, month_days, year_days FROM task_schema'
|
||||
);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$days = [];
|
||||
|
||||
$weekdays = $row['weekdays'] ? json_decode($row['weekdays'], true) : null;
|
||||
$monthDays = $row['month_days'] ? json_decode($row['month_days'], true) : null;
|
||||
$yearDays = $row['year_days'] ? json_decode($row['year_days'], true) : null;
|
||||
|
||||
if (!empty($weekdays)) {
|
||||
$days['week'] = $weekdays;
|
||||
}
|
||||
if (!empty($monthDays)) {
|
||||
$days['month'] = $monthDays;
|
||||
}
|
||||
if (!empty($yearDays)) {
|
||||
$days['year'] = $yearDays;
|
||||
}
|
||||
|
||||
if (!empty($days)) {
|
||||
$this->connection->executeStatement(
|
||||
'UPDATE task_schema SET days = ? WHERE id = ?',
|
||||
[json_encode($days), $row['id']]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE task_schema ADD deadline DATE DEFAULT NULL, ADD weekdays JSON DEFAULT NULL, ADD month_days JSON DEFAULT NULL, ADD year_days JSON DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE task_schema DROP days');
|
||||
|
||||
$this->addSql('ALTER TABLE task DROP FOREIGN KEY FK_527EDB258DB60186');
|
||||
$this->addSql('ALTER TABLE task MODIFY task_id INT NOT NULL');
|
||||
$this->addSql('ALTER TABLE task ADD CONSTRAINT FK_527EDB258DB60186 FOREIGN KEY (task_id) REFERENCES task_schema (id) ON DELETE CASCADE');
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_527EDB258DB60186AA9E377A ON task (task_id, date)');
|
||||
|
||||
$this->addSql("UPDATE task SET status = 'aktiv' WHERE status = 'active'");
|
||||
$this->addSql("UPDATE task SET status = 'erledigt' WHERE status = 'done'");
|
||||
$this->addSql("UPDATE task_schema SET status = 'aktiv' WHERE status = 'active'");
|
||||
$this->addSql("UPDATE task_schema SET status = 'inaktiv' WHERE status = 'disabled'");
|
||||
$this->addSql("UPDATE task_schema SET task_type = 'einzel' WHERE task_type = 'single'");
|
||||
$this->addSql("UPDATE task_schema SET task_type = 'taeglich' WHERE task_type = 'daily'");
|
||||
}
|
||||
}
|
||||
123
backend/plan.md
123
backend/plan.md
@@ -1,123 +0,0 @@
|
||||
# Kategorien
|
||||
|
||||
## Entity
|
||||
|
||||
Category(id, name, color) — Farbkodierte Kategorie für Aufgaben
|
||||
|
||||
## Controller
|
||||
|
||||
CategoryController::index() — Alle Kategorien abrufen
|
||||
CategoryController::show(id) — Einzelne Kategorie abrufen
|
||||
CategoryController::create() — Neue Kategorie anlegen (201)
|
||||
CategoryController::update(id) — Kategorie aktualisieren
|
||||
CategoryController::delete(id) — Kategorie löschen (204)
|
||||
|
||||
## Service
|
||||
|
||||
CategoryManager::createCategory() — Neue Kategorie anlegen
|
||||
CategoryManager::updateCategory() — Kategorie aktualisieren
|
||||
CategoryManager::deleteCategory() — Kategorie löschen
|
||||
|
||||
## DTO
|
||||
|
||||
CreateCategoryRequest(name, color) — Kategorie anlegen
|
||||
UpdateCategoryRequest(name, color) — Kategorie ändern
|
||||
|
||||
## Repository
|
||||
|
||||
CategoryRepository — Standard Doctrine-Repository (keine eigenen Methoden)
|
||||
|
||||
---
|
||||
|
||||
# Aufgaben
|
||||
|
||||
## Entity
|
||||
|
||||
Task(id, schema, name, category, categoryOverridden, date, status, createdAt) — Einzelne Aufgabe eines Schemas
|
||||
|
||||
## Controller
|
||||
|
||||
TaskController::show(id) — Einzelnen Task abrufen
|
||||
TaskController::update(id) — Task aktualisieren (Name, Kategorie, Status, Datum)
|
||||
TaskController::delete(id) — Task löschen (204)
|
||||
|
||||
---
|
||||
|
||||
# Entity
|
||||
|
||||
TaskSchema(id, name, status, taskType, category, deadline, startDate, endDate, weekdays, monthDays, yearDays, createdAt) — Vorlage für wiederkehrende Aufgaben
|
||||
|
||||
# Controller
|
||||
|
||||
TaskSchemaController::index() — Alle Schemas abrufen
|
||||
TaskSchemaController::week(?start) — Wochenansicht ab Datum (Default: heute)
|
||||
TaskSchemaController::allSchemas() — Alle Schemas sortiert nach Erstellung
|
||||
TaskSchemaController::allTasks() — Alle Tasks über alle Schemas
|
||||
TaskSchemaController::show(id) — Einzelnes Schema abrufen
|
||||
TaskSchemaController::create() — Neues Schema anlegen (201)
|
||||
TaskSchemaController::update(id) — Schema aktualisieren + Tasks synchronisieren
|
||||
TaskSchemaController::delete(id) — Schema löschen (204)
|
||||
TaskSchemaController::toggle(id) — Task-Status umschalten (aktiv↔erledigt)
|
||||
|
||||
# Service
|
||||
|
||||
TaskManager::updateTask() — Task aktualisieren (Name, Kategorie, Status, Datum)
|
||||
TaskManager::toggleTaskStatus() — Task-Status umschalten (aktiv↔erledigt)
|
||||
TaskManager::deleteTask() — Task löschen
|
||||
|
||||
TaskSchemaManager::createSchema() — Neues Schema anlegen
|
||||
TaskSchemaManager::updateSchema() — Schema aktualisieren + Tasks synchronisieren
|
||||
TaskSchemaManager::deleteSchema() — Schema löschen
|
||||
|
||||
TaskGenerator::generateForRange() — Fehlende Tasks für einen Zeitraum erzeugen
|
||||
TaskGenerator::generateForTasksWithoutDate() — Tasks für Einzel-Schemas ohne Deadline erzeugen
|
||||
|
||||
TaskSynchronizer::syncForSchema() — Tasks nach Schema-Update synchronisieren
|
||||
|
||||
DeadlineCalculator::getDeadlinesForRange() — Fälligkeitsdaten anhand Wiederholungsregeln berechnen
|
||||
|
||||
TaskViewBuilder::buildWeekView() — Wochenansicht nach Tagen gruppiert
|
||||
TaskViewBuilder::buildAllTasksView() — Alle Tasks sortiert
|
||||
|
||||
# DTO
|
||||
|
||||
## Request
|
||||
|
||||
CreateSchemaRequest(name, categoryId, status, taskType, deadline, startDate, endDate, weekdays, monthDays, yearDays) — Schema anlegen
|
||||
UpdateSchemaRequest(name, categoryId, hasCategoryId, status, taskType, deadline, startDate, endDate, weekdays, monthDays, yearDays) — Schema ändern
|
||||
UpdateTaskRequest(name, categoryId, status, date) — Task ändern
|
||||
ToggleRequest(date) — Task-Status umschalten
|
||||
|
||||
## Response
|
||||
|
||||
WeekViewResponse(tasksWithoutDeadline[], days[]) — Wochenansicht
|
||||
DayResponse(date, tasks[]) — Tagesansicht mit Tasks
|
||||
ToggleResponse(completed) — Toggle-Ergebnis
|
||||
|
||||
# Enum
|
||||
|
||||
TaskStatus — Aufgabenstatus (aktiv, erledigt)
|
||||
TaskSchemaStatus — Schemastatus (aktiv, erledigt, inaktiv)
|
||||
TaskSchemaType — Wiederholungstyp (einzel, taeglich, multi, woechentlich, monatlich, jaehrlich)
|
||||
|
||||
# Repository
|
||||
|
||||
TaskRepository::findBySchemaAndDate() — Task anhand Schema und Datum finden
|
||||
TaskRepository::findInRange() — Alle Tasks in einem Zeitraum (ohne inaktive Schemas)
|
||||
TaskRepository::getExistingKeys() — Set aus "schemaId-YYYY-MM-DD" Keys für existierende Tasks
|
||||
TaskRepository::findBySchemaFromDate() — Tasks eines Schemas ab einem Datum
|
||||
TaskRepository::deleteFutureBySchema() — Zukünftige Tasks eines Schemas löschen
|
||||
TaskRepository::deleteFutureActiveBySchema() — Zukünftige aktive Tasks eines Schemas löschen
|
||||
TaskRepository::findAllSorted() — Alle Tasks mit Datum, sortiert nach Datum absteigend
|
||||
TaskRepository::findWithoutDate() — Alle aktiven Tasks ohne Datum, sortiert nach Erstellung
|
||||
|
||||
TaskSchemaRepository::findActiveSchemasInRange() — Aktive Schemas in einem Zeitraum finden
|
||||
|
||||
# Migration
|
||||
|
||||
Version20260323230657 — Erstellt Category- und Task-Tabelle (initiales Schema)
|
||||
Version20260324141105 — Erstellt task_completion-Tabelle mit Unique-Constraint (task_id, date)
|
||||
Version20260324154816 — Ersetzt task_completion durch task_occurrence, migriert Daten
|
||||
Version20260325064344 — Ergänzt name, category_overridden, category_id auf task_occurrence
|
||||
Version20260326165702 — Benennt task→task_schema und task_occurrence→task um
|
||||
Version20260330210659 — Ergänzt year_days, created_at; entfernt interval_type; passt Indizes an
|
||||
@@ -1,82 +0,0 @@
|
||||
# Backend
|
||||
## Entity
|
||||
- Task - Aufgaben Tabele
|
||||
- Category - Kategorie Tabele
|
||||
- Schema - TaksSchema Tabele
|
||||
## Enum
|
||||
- TaskStatus - Aufgaben Status
|
||||
- TaskSchemaStatus - Schema Status
|
||||
- TaskSchemaType - Schema Typen
|
||||
## Controller
|
||||
- TaskController - Aufgaben Aktionen
|
||||
- TaskSchemaController - Schema Aktionen
|
||||
- CategoryController - Kategorie Aktioenen
|
||||
## Services
|
||||
- TaskManager -
|
||||
- TaskSchemaManager -
|
||||
- CategoryManager -
|
||||
- TaskGenerator -
|
||||
- TaskSynchronizer -
|
||||
- DeadlineCalculator -
|
||||
## Repositorys
|
||||
- TaskRepository - Aufgaben Abfragen
|
||||
- CategoryRepository - Kategorie Abfragem
|
||||
- TaskSchemaRepository - Schema Abfragen
|
||||
|
||||
|
||||
|
||||
## Task
|
||||
|
||||
- Wird verwendet um Aufgaben anzuzeigen
|
||||
- Entity
|
||||
- name - Name der Aufgabe
|
||||
- status - Status der Aufgabe (active, done)
|
||||
- date - Deadline, null for no deadline
|
||||
- schema - schemaId, null no schema
|
||||
- category - categoryId, null no category
|
||||
- Controller
|
||||
- index() - Alle Tasks zurückgeben
|
||||
- show(id) - Ein Task zurückgeben
|
||||
- create() - Task erstellen
|
||||
- update(id) - Task aktualisieren
|
||||
- delete(id) - Task entfernen
|
||||
- toggle(id) - Status switchen (active, done)
|
||||
- Werden durch Schemas erstellt
|
||||
|
||||
## Category
|
||||
|
||||
- Kategorien die von Aufgaben und Schemas verwendet werden
|
||||
- Entity
|
||||
- name - Kategoriename
|
||||
- color - Hex-Farbe
|
||||
- Controller
|
||||
- index() - Alle Kategorien zurückgeben
|
||||
- show(id) - Eine Kategorie zurückgeben
|
||||
- create() - Kategorie erstellen
|
||||
- update(id) - Kategorie aktualisieren
|
||||
- delete(id) - Kategorie entfernen
|
||||
|
||||
## Schema
|
||||
|
||||
- Template um Aufgaben zu erstellen
|
||||
- Entity
|
||||
- name - Name für erstellte Aufgaben
|
||||
- status - Status für Schema (active, disabled)
|
||||
- category - Kategorie für erstellte Aufgaben
|
||||
- type
|
||||
- single - Einmal erstellt, schema = null
|
||||
- daily - Für jeden Tag erstellt, schema = id
|
||||
- custom - Benutzerdefiniert erstellt, schema = id
|
||||
- start - Startdatum für type=daily,custom
|
||||
- end - Enddatum für type=daily, custom
|
||||
- days - Tage für type=custom
|
||||
- week - Array für Wochentage (1-7)
|
||||
- month - Array für Monatstage (1-31)
|
||||
- year - Array für Jahrestage (1-365/366)
|
||||
- Controller
|
||||
- index() - Alle Schema zurückgeben
|
||||
- show(id) - Eine Schema zurückgeben
|
||||
- create() - Schema erstellen
|
||||
- update(id) - Schema aktualisieren
|
||||
- delete(id) - Schema entfernen
|
||||
- Anpasung -> Alle Tasks anpassen (keine Vergangenheit)
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use App\DTO\Request\CreateCategoryRequest;
|
||||
use App\DTO\Request\UpdateCategoryRequest;
|
||||
use App\Entity\Category;
|
||||
use App\Repository\CategoryRepository;
|
||||
use App\Service\CategoryManager;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
#[Route('/api/categories', name: 'categories.')]
|
||||
class CategoryController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private CategoryRepository $categoryRepository,
|
||||
private CategoryManager $categoryManager,
|
||||
) {}
|
||||
|
||||
#[Route('', name: 'index', methods: ['GET'])]
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$categories = $this->categoryRepository->findAll();
|
||||
|
||||
return $this->json($categories, context: ['groups' => ['category:read']]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'show', methods: ['GET'])]
|
||||
public function show(Category $category): JsonResponse
|
||||
{
|
||||
return $this->json($category, context: ['groups' => ['category:read']]);
|
||||
}
|
||||
|
||||
#[Route('', name: 'create', methods: ['POST'])]
|
||||
public function create(#[MapRequestPayload] CreateCategoryRequest $dto): JsonResponse
|
||||
{
|
||||
$category = $this->categoryManager->createCategory($dto);
|
||||
|
||||
return $this->json($category, Response::HTTP_CREATED, context: ['groups' => ['category:read']]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'update', methods: ['PUT'])]
|
||||
public function update(#[MapRequestPayload] UpdateCategoryRequest $dto, Category $category): JsonResponse
|
||||
{
|
||||
$category = $this->categoryManager->updateCategory($category, $dto);
|
||||
|
||||
return $this->json($category, context: ['groups' => ['category:read']]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'delete', methods: ['DELETE'])]
|
||||
public function delete(Category $category): JsonResponse
|
||||
{
|
||||
$this->categoryManager->deleteCategory($category);
|
||||
|
||||
return $this->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use App\DTO\Request\CreateTaskRequest;
|
||||
use App\DTO\Request\UpdateTaskRequest;
|
||||
use App\Entity\Task;
|
||||
use App\Repository\TaskRepository;
|
||||
use App\Service\TaskGenerator;
|
||||
use App\Service\TaskManager;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
#[Route('/api/tasks')]
|
||||
class TaskController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private TaskManager $taskManager,
|
||||
private TaskGenerator $taskGenerator,
|
||||
private TaskRepository $taskRepository,
|
||||
) {}
|
||||
|
||||
#[Route('', name: 'tasks.index', methods: ['GET'])]
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$today = new \DateTimeImmutable('today');
|
||||
$end = $today->modify('+6 days');
|
||||
$this->taskGenerator->generateForRange($today, $end);
|
||||
|
||||
$tasks = $this->taskRepository->findAllWithRelations();
|
||||
|
||||
return $this->json($tasks, context: ['groups' => ['task:read', 'category:read']]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'tasks.show', methods: ['GET'])]
|
||||
public function show(Task $task): JsonResponse
|
||||
{
|
||||
return $this->json($task, context: ['groups' => ['task:read', 'category:read']]);
|
||||
}
|
||||
|
||||
#[Route('', name: 'tasks.create', methods: ['POST'])]
|
||||
public function create(#[MapRequestPayload] CreateTaskRequest $dto): JsonResponse
|
||||
{
|
||||
$task = $this->taskManager->createTask($dto);
|
||||
|
||||
return $this->json($task, Response::HTTP_CREATED, context: ['groups' => ['task:read', 'category:read']]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'tasks.update', methods: ['PUT'])]
|
||||
public function update(#[MapRequestPayload] UpdateTaskRequest $dto, Task $task): JsonResponse
|
||||
{
|
||||
$task = $this->taskManager->updateTask($task, $dto);
|
||||
|
||||
return $this->json($task, context: ['groups' => ['task:read', 'category:read']]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'tasks.delete', methods: ['DELETE'])]
|
||||
public function delete(Task $task): JsonResponse
|
||||
{
|
||||
$this->taskManager->deleteTask($task);
|
||||
|
||||
return $this->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
#[Route('/{id}/toggle', name: 'tasks.toggle', methods: ['PATCH'])]
|
||||
public function toggle(Task $task): JsonResponse
|
||||
{
|
||||
$task = $this->taskManager->toggleTask($task);
|
||||
|
||||
return $this->json($task, context: ['groups' => ['task:read', 'category:read']]);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use App\DTO\Request\CreateSchemaRequest;
|
||||
use App\DTO\Request\UpdateSchemaRequest;
|
||||
use App\Entity\TaskSchema;
|
||||
use App\Repository\TaskSchemaRepository;
|
||||
use App\Service\TaskSchemaManager;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
#[Route('/api/schemas')]
|
||||
class TaskSchemaController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private TaskSchemaRepository $schemaRepository,
|
||||
private TaskSchemaManager $schemaManager,
|
||||
) {}
|
||||
|
||||
#[Route('', name: 'schemas.index', methods: ['GET'])]
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$schemas = $this->schemaRepository->findBy([], ['createdAt' => 'DESC']);
|
||||
|
||||
return $this->json($schemas, context: ['groups' => ['schema:read', 'category:read']]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'schemas.show', methods: ['GET'])]
|
||||
public function show(TaskSchema $schema): JsonResponse
|
||||
{
|
||||
return $this->json($schema, context: ['groups' => ['schema:read', 'category:read']]);
|
||||
}
|
||||
|
||||
#[Route('', name: 'schemas.create', methods: ['POST'])]
|
||||
public function create(#[MapRequestPayload] CreateSchemaRequest $dto): JsonResponse
|
||||
{
|
||||
$result = $this->schemaManager->createSchema($dto);
|
||||
|
||||
if (is_array($result)) {
|
||||
return $this->json($result, Response::HTTP_CREATED, context: ['groups' => ['task:read', 'category:read']]);
|
||||
}
|
||||
|
||||
return $this->json($result, Response::HTTP_CREATED, context: ['groups' => ['schema:read', 'category:read']]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'schemas.update', methods: ['PUT'])]
|
||||
public function update(#[MapRequestPayload] UpdateSchemaRequest $dto, TaskSchema $schema): JsonResponse
|
||||
{
|
||||
$schema = $this->schemaManager->updateSchema($schema, $dto);
|
||||
|
||||
return $this->json($schema, context: ['groups' => ['schema:read', 'category:read']]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'schemas.delete', methods: ['DELETE'])]
|
||||
public function delete(TaskSchema $schema, Request $request): JsonResponse
|
||||
{
|
||||
$deleteTasks = (bool) $request->query->get('deleteTasks', false);
|
||||
$this->schemaManager->deleteSchema($schema, $deleteTasks);
|
||||
|
||||
return $this->json(null, Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\DTO\Request;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class CreateCategoryRequest
|
||||
{
|
||||
#[Assert\NotBlank]
|
||||
#[Assert\Length(max: 255)]
|
||||
public string $name;
|
||||
|
||||
#[Assert\NotBlank]
|
||||
#[Assert\CssColor(formats: Assert\CssColor::HEX_LONG)]
|
||||
public string $color;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\DTO\Request;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class CreateSchemaRequest
|
||||
{
|
||||
use SchemaValidationTrait;
|
||||
|
||||
#[Assert\NotBlank]
|
||||
#[Assert\Length(max: 255)]
|
||||
public ?string $name = null;
|
||||
|
||||
public ?int $categoryId = null;
|
||||
public ?string $status = null;
|
||||
public ?string $type = null;
|
||||
public ?string $startDate = null;
|
||||
public ?string $endDate = null;
|
||||
public ?array $days = null;
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\DTO\Request;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class CreateTaskRequest
|
||||
{
|
||||
#[Assert\NotBlank]
|
||||
#[Assert\Length(max: 255)]
|
||||
public ?string $name = null;
|
||||
|
||||
public ?int $categoryId = null;
|
||||
public ?string $date = null;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\DTO\Request;
|
||||
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
trait SchemaValidationTrait
|
||||
{
|
||||
public function validate(ExecutionContextInterface $context): void
|
||||
{
|
||||
if ($this->type !== null && $this->type !== 'single') {
|
||||
if ($this->startDate !== null && $this->endDate !== null && $this->endDate < $this->startDate) {
|
||||
$context->buildViolation('endDate muss >= startDate sein.')
|
||||
->atPath('endDate')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type === 'single') {
|
||||
$year = $this->days['year'] ?? null;
|
||||
if (empty($year)) {
|
||||
$context->buildViolation('Mindestens ein Datum muss ausgewählt werden.')
|
||||
->atPath('days')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->type === 'custom') {
|
||||
if (empty($this->days)) {
|
||||
$context->buildViolation('days darf nicht leer sein.')
|
||||
->atPath('days')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\DTO\Request;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class UpdateCategoryRequest
|
||||
{
|
||||
#[Assert\Length(min: 1, max: 255)]
|
||||
public ?string $name = null;
|
||||
|
||||
#[Assert\CssColor(formats: Assert\CssColor::HEX_LONG)]
|
||||
public ?string $color = null;
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\DTO\Request;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class UpdateSchemaRequest
|
||||
{
|
||||
use SchemaValidationTrait;
|
||||
|
||||
#[Assert\NotBlank]
|
||||
#[Assert\Length(max: 255)]
|
||||
public ?string $name = null;
|
||||
|
||||
public ?int $categoryId = null;
|
||||
public bool $hasCategoryId = false;
|
||||
public ?string $status = null;
|
||||
public ?string $type = null;
|
||||
public ?string $startDate = null;
|
||||
public ?string $endDate = null;
|
||||
public ?array $days = null;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\DTO\Request;
|
||||
|
||||
class UpdateTaskRequest
|
||||
{
|
||||
public ?string $name = null;
|
||||
public ?int $categoryId = null;
|
||||
public ?string $status = null;
|
||||
public ?string $date = null;
|
||||
}
|
||||
0
backend/src/Entity/.gitignore
vendored
0
backend/src/Entity/.gitignore
vendored
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\CategoryRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity(repositoryClass: CategoryRepository::class)]
|
||||
class Category
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['category:read', 'task:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['category:read', 'category:write', 'task:read'])]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\Column(length: 7)]
|
||||
#[Groups(['category:read', 'category:write', 'task:read'])]
|
||||
private ?string $color = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getColor(): ?string
|
||||
{
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
public function setColor(string $color): static
|
||||
{
|
||||
$this->color = $color;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Enum\TaskStatus;
|
||||
use App\Repository\TaskRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
|
||||
#[ORM\Entity(repositoryClass: TaskRepository::class)]
|
||||
class Task
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
}
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['task:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(name: 'task_id', nullable: true, onDelete: 'SET NULL')]
|
||||
private ?TaskSchema $schema = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
#[Groups(['task:read'])]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
|
||||
#[Groups(['task:read'])]
|
||||
private ?Category $category = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
|
||||
#[Groups(['task:read'])]
|
||||
private ?\DateTimeInterface $date = null;
|
||||
|
||||
#[ORM\Column(length: 20, enumType: TaskStatus::class)]
|
||||
#[Groups(['task:read'])]
|
||||
private TaskStatus $status = TaskStatus::Active;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
|
||||
private \DateTimeInterface $createdAt;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
#[Groups(['task:read'])]
|
||||
#[SerializedName('schemaId')]
|
||||
public function getSchemaId(): ?int
|
||||
{
|
||||
return $this->schema?->getId();
|
||||
}
|
||||
|
||||
public function getSchema(): ?TaskSchema
|
||||
{
|
||||
return $this->schema;
|
||||
}
|
||||
|
||||
public function setSchema(?TaskSchema $schema): static
|
||||
{
|
||||
$this->schema = $schema;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(?string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCategory(): ?Category
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function setCategory(?Category $category): static
|
||||
{
|
||||
$this->category = $category;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDate(): ?\DateTimeInterface
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function setDate(?\DateTimeInterface $date): static
|
||||
{
|
||||
$this->date = $date;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStatus(): TaskStatus
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setStatus(TaskStatus $status): static
|
||||
{
|
||||
$this->status = $status;
|
||||
return $this;
|
||||
}
|
||||
|
||||
#[Groups(['task:read'])]
|
||||
#[SerializedName('isPast')]
|
||||
public function isPast(): bool
|
||||
{
|
||||
return $this->date !== null && $this->date < new \DateTimeImmutable('today');
|
||||
}
|
||||
|
||||
public function getCreatedAt(): \DateTimeInterface
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreatedAt(\DateTimeInterface $createdAt): static
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Enum\TaskSchemaStatus;
|
||||
use App\Enum\TaskSchemaType;
|
||||
use App\Repository\TaskSchemaRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
|
||||
#[ORM\Entity(repositoryClass: TaskSchemaRepository::class)]
|
||||
class TaskSchema
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
#[Groups(['schema:read'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['schema:read', 'schema:write'])]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\Column(length: 20, enumType: TaskSchemaStatus::class)]
|
||||
#[Groups(['schema:read', 'schema:write'])]
|
||||
private TaskSchemaStatus $status = TaskSchemaStatus::Active;
|
||||
|
||||
#[ORM\Column(name: 'task_type', length: 20, enumType: TaskSchemaType::class)]
|
||||
#[Groups(['schema:read', 'schema:write'])]
|
||||
#[SerializedName('type')]
|
||||
private TaskSchemaType $taskType = TaskSchemaType::Single;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(onDelete: 'SET NULL')]
|
||||
#[Groups(['schema:read'])]
|
||||
private ?Category $category = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
|
||||
#[Groups(['schema:read', 'schema:write'])]
|
||||
private ?\DateTimeInterface $startDate = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
|
||||
#[Groups(['schema:read', 'schema:write'])]
|
||||
private ?\DateTimeInterface $endDate = null;
|
||||
|
||||
#[ORM\Column(type: Types::JSON, nullable: true)]
|
||||
#[Groups(['schema:read', 'schema:write'])]
|
||||
private ?array $days = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
|
||||
#[Groups(['schema:read'])]
|
||||
private \DateTimeInterface $createdAt;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStatus(): TaskSchemaStatus
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setStatus(TaskSchemaStatus $status): static
|
||||
{
|
||||
$this->status = $status;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTaskType(): TaskSchemaType
|
||||
{
|
||||
return $this->taskType;
|
||||
}
|
||||
|
||||
public function setTaskType(TaskSchemaType $taskType): static
|
||||
{
|
||||
$this->taskType = $taskType;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCategory(): ?Category
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function setCategory(?Category $category): static
|
||||
{
|
||||
$this->category = $category;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStartDate(): ?\DateTimeInterface
|
||||
{
|
||||
return $this->startDate;
|
||||
}
|
||||
|
||||
public function setStartDate(?\DateTimeInterface $startDate): static
|
||||
{
|
||||
$this->startDate = $startDate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEndDate(): ?\DateTimeInterface
|
||||
{
|
||||
return $this->endDate;
|
||||
}
|
||||
|
||||
public function setEndDate(?\DateTimeInterface $endDate): static
|
||||
{
|
||||
$this->endDate = $endDate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDays(): ?array
|
||||
{
|
||||
return $this->days;
|
||||
}
|
||||
|
||||
public function setDays(?array $days): static
|
||||
{
|
||||
$this->days = $days;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): \DateTimeInterface
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enum;
|
||||
|
||||
enum TaskSchemaStatus: string
|
||||
{
|
||||
case Active = 'active';
|
||||
case Disabled = 'disabled';
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enum;
|
||||
|
||||
enum TaskSchemaType: string
|
||||
{
|
||||
case Single = 'single';
|
||||
case Daily = 'daily';
|
||||
case Custom = 'custom';
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enum;
|
||||
|
||||
enum TaskStatus: string
|
||||
{
|
||||
case Active = 'active';
|
||||
case Done = 'done';
|
||||
}
|
||||
0
backend/src/Repository/.gitignore
vendored
0
backend/src/Repository/.gitignore
vendored
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Category;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Category>
|
||||
*/
|
||||
class CategoryRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Category::class);
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Task;
|
||||
use App\Entity\TaskSchema;
|
||||
use App\Enum\TaskSchemaStatus;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Task>
|
||||
*/
|
||||
class TaskRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Task::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Task[]
|
||||
*/
|
||||
public function findAllWithRelations(): array
|
||||
{
|
||||
return $this->createQueryBuilder('task')
|
||||
->leftJoin('task.schema', 'schema')
|
||||
->leftJoin('task.category', 'category')
|
||||
->addSelect('schema', 'category')
|
||||
->where('task.schema IS NULL OR schema.status != :disabled')
|
||||
->setParameter('disabled', TaskSchemaStatus::Disabled)
|
||||
->orderBy('task.date', 'ASC')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
public function findBySchemaAndDate(TaskSchema $schema, \DateTimeInterface $date): ?Task
|
||||
{
|
||||
return $this->createQueryBuilder('task')
|
||||
->where('task.schema = :schema')
|
||||
->andWhere('task.date = :date')
|
||||
->setParameter('schema', $schema)
|
||||
->setParameter('date', $date)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Task[]
|
||||
*/
|
||||
public function findInRange(\DateTimeInterface $from, \DateTimeInterface $to): array
|
||||
{
|
||||
return $this->createQueryBuilder('task')
|
||||
->leftJoin('task.schema', 'schema')
|
||||
->leftJoin('task.category', 'category')
|
||||
->addSelect('schema', 'category')
|
||||
->where('task.date >= :from')
|
||||
->andWhere('task.date <= :to')
|
||||
->andWhere('task.schema IS NULL OR schema.status != :disabled')
|
||||
->setParameter('from', $from)
|
||||
->setParameter('to', $to)
|
||||
->setParameter('disabled', TaskSchemaStatus::Disabled)
|
||||
->orderBy('task.date', 'ASC')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, true> Set of "schemaId-YYYY-MM-DD" keys
|
||||
*/
|
||||
public function getExistingKeys(\DateTimeInterface $from, \DateTimeInterface $to): array
|
||||
{
|
||||
$rows = $this->createQueryBuilder('task')
|
||||
->select('IDENTITY(task.schema) AS schemaId', 'task.date')
|
||||
->where('task.date >= :from')
|
||||
->andWhere('task.date <= :to')
|
||||
->andWhere('task.schema IS NOT NULL')
|
||||
->setParameter('from', $from)
|
||||
->setParameter('to', $to)
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
|
||||
$set = [];
|
||||
foreach ($rows as $row) {
|
||||
$date = $row['date'] instanceof \DateTimeInterface
|
||||
? $row['date']->format('Y-m-d')
|
||||
: $row['date'];
|
||||
$set[$row['schemaId'] . '-' . $date] = true;
|
||||
}
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Task[]
|
||||
*/
|
||||
public function findBySchemaFromDate(TaskSchema $schema, \DateTimeInterface $fromDate): array
|
||||
{
|
||||
return $this->createQueryBuilder('task')
|
||||
->where('task.schema = :schema')
|
||||
->andWhere('task.date >= :from')
|
||||
->setParameter('schema', $schema)
|
||||
->setParameter('from', $fromDate)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\TaskSchema;
|
||||
use App\Enum\TaskSchemaStatus;
|
||||
use App\Enum\TaskSchemaType;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<TaskSchema>
|
||||
*/
|
||||
class TaskSchemaRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, TaskSchema::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TaskSchema[]
|
||||
*/
|
||||
public function findActiveSchemasInRange(\DateTimeInterface $from, \DateTimeInterface $to): array
|
||||
{
|
||||
return $this->createQueryBuilder('t')
|
||||
->where('t.status = :active')
|
||||
->andWhere('t.taskType IN (:types)')
|
||||
->andWhere('t.startDate <= :to')
|
||||
->andWhere('t.endDate IS NULL OR t.endDate >= :from')
|
||||
->setParameter('active', TaskSchemaStatus::Active)
|
||||
->setParameter('types', [TaskSchemaType::Daily, TaskSchemaType::Custom])
|
||||
->setParameter('from', $from)
|
||||
->setParameter('to', $to)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
}
|
||||
@@ -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