Rename lists -> projects and items -> cards throughout

Project scope shifts from a todo list to a project-management app. This is a
straight terminology rename across code, comments, migrations, tests, and
docs — no behaviour change.

- DB: table todo_lists -> projects, todo_items -> cards, column
  todo_items.list_id -> cards.project_id, indexes renamed. Migrations 003/004
  rewritten in place (destructive; recreate the volume with `down -v`).
- API: /api/lists -> /api/projects, nested /items -> /cards, reorder body
  item_ids -> card_ids, JSON keys list/lists/item/items -> project/projects/
  card/cards, item_count -> card_count, list_id -> project_id, and the
  matching error messages.
- PHP: TodoList/TodoItem Repository + Controller -> Project/Card; shared SQL
  aliases l/i -> p/c.
- Frontend: stores lists.ts/items.ts -> projects.ts/cards.ts (useProjectsStore
  / useCardsStore, MAX_PROJECTS), ListView -> ProjectView, TodoItemRow ->
  CardRow, route /lists/:id -> /projects/:id (name "project"), types TodoList/
  TodoItem -> Project/Card, and all UI copy. CSS .lists*/.list-head* ->
  .projects*/.project-head*, .item* -> .card-row* (kept the generic .card
  panel class), .items -> .cards.
- Product name in the header, PWA manifest, index.html title and package
  descriptions -> "Project Manager" / "Projects".

Backend suite: 37 passing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-04 11:28:59 +01:00
co-authored by Claude Sonnet 5
parent be592f38fc
commit c66e5ceb9b
30 changed files with 1068 additions and 1065 deletions
+176
View File
@@ -0,0 +1,176 @@
<?php
declare(strict_types=1);
namespace App\Repository;
use PDO;
/**
* Data access for the `cards` table.
*
* @phpstan-type CardRow array{
* id: int, project_id: int, text: string, complete: bool, position: int,
* created_at: string, updated_at: string
* }
*/
final class CardRepository
{
public function __construct(private readonly PDO $pdo)
{
}
/**
* @return CardRow[]
*/
public function allForProject(int $projectId): array
{
$stmt = $this->pdo->prepare(
'SELECT * FROM cards WHERE project_id = :project ORDER BY position ASC, id ASC'
);
$stmt->execute(['project' => $projectId]);
return array_map($this->cast(...), $stmt->fetchAll());
}
/**
* @return CardRow|null
*/
public function findInProject(int $id, int $projectId): ?array
{
$stmt = $this->pdo->prepare('SELECT * FROM cards WHERE id = :id AND project_id = :project');
$stmt->execute(['id' => $id, 'project' => $projectId]);
$row = $stmt->fetch();
return $row === false ? null : $this->cast($row);
}
/**
* @return CardRow
*/
public function create(int $projectId, string $text, bool $complete, ?int $position): array
{
$position ??= $this->nextPosition($projectId);
$stmt = $this->pdo->prepare(
'INSERT INTO cards (project_id, text, complete, position)
VALUES (:project, :text, :complete, :position)'
);
$stmt->execute([
'project' => $projectId,
'text' => $text,
'complete' => $complete ? 1 : 0,
'position' => $position,
]);
/** @var CardRow $card */
$card = $this->findInProject((int) $this->pdo->lastInsertId(), $projectId);
return $card;
}
/**
* @param array{text?: string, complete?: bool, position?: int} $fields
* @return CardRow
*/
public function update(int $id, int $projectId, array $fields): array
{
$sets = ['updated_at = ' . "strftime('%Y-%m-%dT%H:%M:%SZ', 'now')"];
$params = ['id' => $id];
if (array_key_exists('text', $fields)) {
$sets[] = 'text = :text';
$params['text'] = $fields['text'];
}
if (array_key_exists('complete', $fields)) {
$sets[] = 'complete = :complete';
$params['complete'] = $fields['complete'] ? 1 : 0;
}
if (array_key_exists('position', $fields)) {
$sets[] = 'position = :position';
$params['position'] = $fields['position'];
}
$stmt = $this->pdo->prepare('UPDATE cards SET ' . implode(', ', $sets) . ' WHERE id = :id');
$stmt->execute($params);
/** @var CardRow $card */
$card = $this->findInProject($id, $projectId);
return $card;
}
public function delete(int $id): void
{
$this->pdo->prepare('DELETE FROM cards WHERE id = :id')->execute(['id' => $id]);
}
/**
* IDs of every card in the project, in current position order.
*
* @return int[]
*/
public function idsForProject(int $projectId): array
{
$stmt = $this->pdo->prepare(
'SELECT id FROM cards WHERE project_id = :project ORDER BY position ASC, id ASC'
);
$stmt->execute(['project' => $projectId]);
return array_map(intval(...), $stmt->fetchAll(PDO::FETCH_COLUMN));
}
/**
* Assign positions 0..n-1 to the given cards in one transaction.
*
* @param int[] $orderedIds every card id in the project, exactly once
* @return CardRow[] the project's cards in their new order
*/
public function reorder(int $projectId, array $orderedIds): array
{
$stmt = $this->pdo->prepare(
'UPDATE cards SET position = :position,
updated_at = ' . "strftime('%Y-%m-%dT%H:%M:%SZ', 'now')" . '
WHERE id = :id AND project_id = :project'
);
$this->pdo->beginTransaction();
try {
foreach (array_values($orderedIds) as $position => $id) {
$stmt->execute(['position' => $position, 'id' => $id, 'project' => $projectId]);
}
$this->pdo->commit();
} catch (\Throwable $e) {
$this->pdo->rollBack();
throw $e;
}
return $this->allForProject($projectId);
}
private function nextPosition(int $projectId): int
{
$stmt = $this->pdo->prepare(
'SELECT COALESCE(MAX(position), -1) + 1 FROM cards WHERE project_id = :project'
);
$stmt->execute(['project' => $projectId]);
return (int) $stmt->fetchColumn();
}
/**
* @param array<string, mixed> $row
* @return CardRow
*/
private function cast(array $row): array
{
$row['id'] = (int) $row['id'];
$row['project_id'] = (int) $row['project_id'];
$row['complete'] = (bool) $row['complete'];
$row['position'] = (int) $row['position'];
/** @var CardRow $row */
return $row;
}
}