current init

This commit is contained in:
Marek
2026-03-30 15:42:44 +02:00
parent c5229e48ed
commit 2f96caaa23
366 changed files with 6093 additions and 11029 deletions

View File

@@ -0,0 +1,61 @@
<?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): Response
{
$this->categoryManager->deleteCategory($category);
return new Response(status: Response::HTTP_NO_CONTENT);
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Controller\Api;
use App\DTO\Request\UpdateTaskRequest;
use App\Entity\Task;
use App\Service\TaskManager;
use App\Service\TaskSerializer;
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', name: 'tasks.')]
class TaskController extends AbstractController
{
public function __construct(
private TaskManager $taskManager,
private TaskSerializer $taskSerializer,
) {}
#[Route('/{id}', name: 'show', methods: ['GET'])]
public function show(Task $task): JsonResponse
{
$response = $this->taskSerializer->serializeTask($task);
return $this->json($response);
}
#[Route('/{id}', name: 'update', methods: ['PUT'])]
public function update(#[MapRequestPayload] UpdateTaskRequest $dto, Task $task): JsonResponse
{
$result = $this->taskManager->updateTask($task, $dto);
return $this->json($result);
}
#[Route('/{id}', name: 'delete', methods: ['DELETE'])]
public function delete(Task $task): Response
{
$this->taskManager->deleteTask($task);
return new Response(status: Response::HTTP_NO_CONTENT);
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace App\Controller\Api;
use App\DTO\Request\CreateSchemaRequest;
use App\DTO\Request\ToggleRequest;
use App\DTO\Request\UpdateSchemaRequest;
use App\Entity\TaskSchema;
use App\Repository\TaskSchemaRepository;
use App\Service\TaskSchemaManager;
use App\Service\TaskViewBuilder;
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,
private TaskViewBuilder $taskViewBuilder,
) {}
#[Route('', name: 'api_schemas_index', methods: ['GET'])]
public function index(): JsonResponse
{
$schemas = $this->schemaRepository->findAll();
return $this->json($schemas, context: ['groups' => ['schema:read', 'category:read']]);
}
#[Route('/week', name: 'api_schemas_week', methods: ['GET'])]
public function week(Request $request): JsonResponse
{
$startParam = $request->query->get('start');
$start = $startParam ? new \DateTimeImmutable($startParam) : new \DateTimeImmutable('today');
return $this->json($this->taskViewBuilder->buildWeekView($start));
}
#[Route('/all', name: 'api_schemas_all', methods: ['GET'])]
public function allSchemas(): JsonResponse
{
$schemas = $this->schemaRepository->findBy([], ['createdAt' => 'DESC']);
return $this->json($schemas, context: ['groups' => ['schema:read', 'category:read']]);
}
#[Route('/all-tasks', name: 'api_schemas_all_tasks', methods: ['GET'])]
public function allTasks(): JsonResponse
{
return $this->json($this->taskViewBuilder->buildAllTasksView());
}
#[Route('/{id}', name: 'api_schemas_show', methods: ['GET'])]
public function show(TaskSchema $schema): JsonResponse
{
return $this->json($schema, context: ['groups' => ['schema:read', 'category:read']]);
}
#[Route('', name: 'api_schemas_create', methods: ['POST'])]
public function create(#[MapRequestPayload] CreateSchemaRequest $dto): JsonResponse
{
$schema = $this->schemaManager->createSchema($dto);
return $this->json($schema, Response::HTTP_CREATED, context: ['groups' => ['schema:read', 'category:read']]);
}
#[Route('/{id}', name: 'api_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: 'api_schemas_delete', methods: ['DELETE'])]
public function delete(TaskSchema $schema): JsonResponse
{
$this->schemaManager->deleteSchema($schema);
return $this->json(null, Response::HTTP_NO_CONTENT);
}
#[Route('/{id}/toggle', name: 'api_schemas_toggle', methods: ['PATCH'])]
public function toggle(TaskSchema $schema, #[MapRequestPayload] ToggleRequest $dto): JsonResponse
{
$result = $this->schemaManager->toggleTaskStatus($schema, $dto);
return $this->json($result);
}
}