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:
@@ -7,39 +7,39 @@ namespace App\Repository;
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* Data access for the `todo_items` table.
|
||||
* Data access for the `cards` table.
|
||||
*
|
||||
* @phpstan-type TodoItemRow array{
|
||||
* id: int, list_id: int, text: string, complete: bool, position: int,
|
||||
* @phpstan-type CardRow array{
|
||||
* id: int, project_id: int, text: string, complete: bool, position: int,
|
||||
* created_at: string, updated_at: string
|
||||
* }
|
||||
*/
|
||||
final class TodoItemRepository
|
||||
final class CardRepository
|
||||
{
|
||||
public function __construct(private readonly PDO $pdo)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TodoItemRow[]
|
||||
* @return CardRow[]
|
||||
*/
|
||||
public function allForList(int $listId): array
|
||||
public function allForProject(int $projectId): array
|
||||
{
|
||||
$stmt = $this->pdo->prepare(
|
||||
'SELECT * FROM todo_items WHERE list_id = :list ORDER BY position ASC, id ASC'
|
||||
'SELECT * FROM cards WHERE project_id = :project ORDER BY position ASC, id ASC'
|
||||
);
|
||||
$stmt->execute(['list' => $listId]);
|
||||
$stmt->execute(['project' => $projectId]);
|
||||
|
||||
return array_map($this->cast(...), $stmt->fetchAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TodoItemRow|null
|
||||
* @return CardRow|null
|
||||
*/
|
||||
public function findInList(int $id, int $listId): ?array
|
||||
public function findInProject(int $id, int $projectId): ?array
|
||||
{
|
||||
$stmt = $this->pdo->prepare('SELECT * FROM todo_items WHERE id = :id AND list_id = :list');
|
||||
$stmt->execute(['id' => $id, 'list' => $listId]);
|
||||
$stmt = $this->pdo->prepare('SELECT * FROM cards WHERE id = :id AND project_id = :project');
|
||||
$stmt->execute(['id' => $id, 'project' => $projectId]);
|
||||
|
||||
$row = $stmt->fetch();
|
||||
|
||||
@@ -47,34 +47,34 @@ final class TodoItemRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TodoItemRow
|
||||
* @return CardRow
|
||||
*/
|
||||
public function create(int $listId, string $text, bool $complete, ?int $position): array
|
||||
public function create(int $projectId, string $text, bool $complete, ?int $position): array
|
||||
{
|
||||
$position ??= $this->nextPosition($listId);
|
||||
$position ??= $this->nextPosition($projectId);
|
||||
|
||||
$stmt = $this->pdo->prepare(
|
||||
'INSERT INTO todo_items (list_id, text, complete, position)
|
||||
VALUES (:list, :text, :complete, :position)'
|
||||
'INSERT INTO cards (project_id, text, complete, position)
|
||||
VALUES (:project, :text, :complete, :position)'
|
||||
);
|
||||
$stmt->execute([
|
||||
'list' => $listId,
|
||||
'project' => $projectId,
|
||||
'text' => $text,
|
||||
'complete' => $complete ? 1 : 0,
|
||||
'position' => $position,
|
||||
]);
|
||||
|
||||
/** @var TodoItemRow $item */
|
||||
$item = $this->findInList((int) $this->pdo->lastInsertId(), $listId);
|
||||
/** @var CardRow $card */
|
||||
$card = $this->findInProject((int) $this->pdo->lastInsertId(), $projectId);
|
||||
|
||||
return $item;
|
||||
return $card;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{text?: string, complete?: bool, position?: int} $fields
|
||||
* @return TodoItemRow
|
||||
* @return CardRow
|
||||
*/
|
||||
public function update(int $id, int $listId, array $fields): array
|
||||
public function update(int $id, int $projectId, array $fields): array
|
||||
{
|
||||
$sets = ['updated_at = ' . "strftime('%Y-%m-%dT%H:%M:%SZ', 'now')"];
|
||||
$params = ['id' => $id];
|
||||
@@ -92,53 +92,53 @@ final class TodoItemRepository
|
||||
$params['position'] = $fields['position'];
|
||||
}
|
||||
|
||||
$stmt = $this->pdo->prepare('UPDATE todo_items SET ' . implode(', ', $sets) . ' WHERE id = :id');
|
||||
$stmt = $this->pdo->prepare('UPDATE cards SET ' . implode(', ', $sets) . ' WHERE id = :id');
|
||||
$stmt->execute($params);
|
||||
|
||||
/** @var TodoItemRow $item */
|
||||
$item = $this->findInList($id, $listId);
|
||||
/** @var CardRow $card */
|
||||
$card = $this->findInProject($id, $projectId);
|
||||
|
||||
return $item;
|
||||
return $card;
|
||||
}
|
||||
|
||||
public function delete(int $id): void
|
||||
{
|
||||
$this->pdo->prepare('DELETE FROM todo_items WHERE id = :id')->execute(['id' => $id]);
|
||||
$this->pdo->prepare('DELETE FROM cards WHERE id = :id')->execute(['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* IDs of every item in the list, in current position order.
|
||||
* IDs of every card in the project, in current position order.
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function idsForList(int $listId): array
|
||||
public function idsForProject(int $projectId): array
|
||||
{
|
||||
$stmt = $this->pdo->prepare(
|
||||
'SELECT id FROM todo_items WHERE list_id = :list ORDER BY position ASC, id ASC'
|
||||
'SELECT id FROM cards WHERE project_id = :project ORDER BY position ASC, id ASC'
|
||||
);
|
||||
$stmt->execute(['list' => $listId]);
|
||||
$stmt->execute(['project' => $projectId]);
|
||||
|
||||
return array_map(intval(...), $stmt->fetchAll(PDO::FETCH_COLUMN));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign positions 0..n-1 to the given items in one transaction.
|
||||
* Assign positions 0..n-1 to the given cards in one transaction.
|
||||
*
|
||||
* @param int[] $orderedIds every item id in the list, exactly once
|
||||
* @return TodoItemRow[] the list's items in their new order
|
||||
* @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 $listId, array $orderedIds): array
|
||||
public function reorder(int $projectId, array $orderedIds): array
|
||||
{
|
||||
$stmt = $this->pdo->prepare(
|
||||
'UPDATE todo_items SET position = :position,
|
||||
'UPDATE cards SET position = :position,
|
||||
updated_at = ' . "strftime('%Y-%m-%dT%H:%M:%SZ', 'now')" . '
|
||||
WHERE id = :id AND list_id = :list'
|
||||
WHERE id = :id AND project_id = :project'
|
||||
);
|
||||
|
||||
$this->pdo->beginTransaction();
|
||||
try {
|
||||
foreach (array_values($orderedIds) as $position => $id) {
|
||||
$stmt->execute(['position' => $position, 'id' => $id, 'list' => $listId]);
|
||||
$stmt->execute(['position' => $position, 'id' => $id, 'project' => $projectId]);
|
||||
}
|
||||
$this->pdo->commit();
|
||||
} catch (\Throwable $e) {
|
||||
@@ -146,31 +146,31 @@ final class TodoItemRepository
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->allForList($listId);
|
||||
return $this->allForProject($projectId);
|
||||
}
|
||||
|
||||
private function nextPosition(int $listId): int
|
||||
private function nextPosition(int $projectId): int
|
||||
{
|
||||
$stmt = $this->pdo->prepare(
|
||||
'SELECT COALESCE(MAX(position), -1) + 1 FROM todo_items WHERE list_id = :list'
|
||||
'SELECT COALESCE(MAX(position), -1) + 1 FROM cards WHERE project_id = :project'
|
||||
);
|
||||
$stmt->execute(['list' => $listId]);
|
||||
$stmt->execute(['project' => $projectId]);
|
||||
|
||||
return (int) $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $row
|
||||
* @return TodoItemRow
|
||||
* @return CardRow
|
||||
*/
|
||||
private function cast(array $row): array
|
||||
{
|
||||
$row['id'] = (int) $row['id'];
|
||||
$row['list_id'] = (int) $row['list_id'];
|
||||
$row['project_id'] = (int) $row['project_id'];
|
||||
$row['complete'] = (bool) $row['complete'];
|
||||
$row['position'] = (int) $row['position'];
|
||||
|
||||
/** @var TodoItemRow $row */
|
||||
/** @var CardRow $row */
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
@@ -7,20 +7,20 @@ namespace App\Repository;
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* Data access for the `todo_lists` table.
|
||||
* Data access for the `projects` table.
|
||||
*
|
||||
* @phpstan-type TodoListRow array{
|
||||
* @phpstan-type ProjectRow array{
|
||||
* id: int, owner_id: int, title: string, description: string,
|
||||
* item_count: int, completed_count: int, created_at: string, updated_at: string
|
||||
* card_count: int, completed_count: int, created_at: string, updated_at: string
|
||||
* }
|
||||
*/
|
||||
final class TodoListRepository
|
||||
final class ProjectRepository
|
||||
{
|
||||
private const SELECT = <<<'SQL'
|
||||
SELECT l.id, l.owner_id, l.title, l.description, l.created_at, l.updated_at,
|
||||
(SELECT COUNT(*) FROM todo_items i WHERE i.list_id = l.id) AS item_count,
|
||||
(SELECT COUNT(*) FROM todo_items i WHERE i.list_id = l.id AND i.complete = 1) AS completed_count
|
||||
FROM todo_lists l
|
||||
SELECT p.id, p.owner_id, p.title, p.description, p.created_at, p.updated_at,
|
||||
(SELECT COUNT(*) FROM cards c WHERE c.project_id = p.id) AS card_count,
|
||||
(SELECT COUNT(*) FROM cards c WHERE c.project_id = p.id AND c.complete = 1) AS completed_count
|
||||
FROM projects p
|
||||
SQL;
|
||||
|
||||
public function __construct(private readonly PDO $pdo)
|
||||
@@ -28,15 +28,15 @@ final class TodoListRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* Every list owned by the user, always sorted alphabetically by title
|
||||
* Every project owned by the user, always sorted alphabetically by title
|
||||
* (case-insensitive). There is deliberately no other ordering option.
|
||||
*
|
||||
* @return TodoListRow[]
|
||||
* @return ProjectRow[]
|
||||
*/
|
||||
public function allForOwner(int $ownerId): array
|
||||
{
|
||||
$stmt = $this->pdo->prepare(
|
||||
self::SELECT . ' WHERE l.owner_id = :owner ORDER BY l.title COLLATE NOCASE ASC, l.id ASC'
|
||||
self::SELECT . ' WHERE p.owner_id = :owner ORDER BY p.title COLLATE NOCASE ASC, p.id ASC'
|
||||
);
|
||||
$stmt->execute(['owner' => $ownerId]);
|
||||
|
||||
@@ -45,18 +45,18 @@ final class TodoListRepository
|
||||
|
||||
public function countForOwner(int $ownerId): int
|
||||
{
|
||||
$stmt = $this->pdo->prepare('SELECT COUNT(*) FROM todo_lists WHERE owner_id = :owner');
|
||||
$stmt = $this->pdo->prepare('SELECT COUNT(*) FROM projects WHERE owner_id = :owner');
|
||||
$stmt->execute(['owner' => $ownerId]);
|
||||
|
||||
return (int) $stmt->fetchColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TodoListRow|null
|
||||
* @return ProjectRow|null
|
||||
*/
|
||||
public function findOwnedBy(int $id, int $ownerId): ?array
|
||||
{
|
||||
$stmt = $this->pdo->prepare(self::SELECT . ' WHERE l.id = :id AND l.owner_id = :owner');
|
||||
$stmt = $this->pdo->prepare(self::SELECT . ' WHERE p.id = :id AND p.owner_id = :owner');
|
||||
$stmt->execute(['id' => $id, 'owner' => $ownerId]);
|
||||
|
||||
$row = $stmt->fetch();
|
||||
@@ -65,12 +65,12 @@ final class TodoListRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TodoListRow
|
||||
* @return ProjectRow
|
||||
*/
|
||||
public function create(int $ownerId, string $title, string $description): array
|
||||
{
|
||||
$stmt = $this->pdo->prepare(
|
||||
'INSERT INTO todo_lists (owner_id, title, description) VALUES (:owner, :title, :description)'
|
||||
'INSERT INTO projects (owner_id, title, description) VALUES (:owner, :title, :description)'
|
||||
);
|
||||
$stmt->execute([
|
||||
'owner' => $ownerId,
|
||||
@@ -78,15 +78,15 @@ final class TodoListRepository
|
||||
'description' => $description,
|
||||
]);
|
||||
|
||||
/** @var TodoListRow $list */
|
||||
$list = $this->findOwnedBy((int) $this->pdo->lastInsertId(), $ownerId);
|
||||
/** @var ProjectRow $project */
|
||||
$project = $this->findOwnedBy((int) $this->pdo->lastInsertId(), $ownerId);
|
||||
|
||||
return $list;
|
||||
return $project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{title?: string, description?: string} $fields
|
||||
* @return TodoListRow
|
||||
* @return ProjectRow
|
||||
*/
|
||||
public function update(int $id, int $ownerId, array $fields): array
|
||||
{
|
||||
@@ -100,24 +100,24 @@ final class TodoListRepository
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = $this->pdo->prepare('UPDATE todo_lists SET ' . implode(', ', $sets) . ' WHERE id = :id');
|
||||
$stmt = $this->pdo->prepare('UPDATE projects SET ' . implode(', ', $sets) . ' WHERE id = :id');
|
||||
$stmt->execute($params);
|
||||
|
||||
/** @var TodoListRow $list */
|
||||
$list = $this->findOwnedBy($id, $ownerId);
|
||||
/** @var ProjectRow $project */
|
||||
$project = $this->findOwnedBy($id, $ownerId);
|
||||
|
||||
return $list;
|
||||
return $project;
|
||||
}
|
||||
|
||||
public function delete(int $id): void
|
||||
{
|
||||
$this->pdo->prepare('DELETE FROM todo_lists WHERE id = :id')->execute(['id' => $id]);
|
||||
$this->pdo->prepare('DELETE FROM projects WHERE id = :id')->execute(['id' => $id]);
|
||||
}
|
||||
|
||||
/** Bump updated_at, e.g. when the list's items change. */
|
||||
/** Bump updated_at, e.g. when the project's cards change. */
|
||||
public function touch(int $id): void
|
||||
{
|
||||
$this->pdo->prepare('UPDATE todo_lists SET updated_at = ' . $this->nowExpr() . ' WHERE id = :id')
|
||||
$this->pdo->prepare('UPDATE projects SET updated_at = ' . $this->nowExpr() . ' WHERE id = :id')
|
||||
->execute(['id' => $id]);
|
||||
}
|
||||
|
||||
@@ -128,16 +128,16 @@ final class TodoListRepository
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $row
|
||||
* @return TodoListRow
|
||||
* @return ProjectRow
|
||||
*/
|
||||
private function cast(array $row): array
|
||||
{
|
||||
$row['id'] = (int) $row['id'];
|
||||
$row['owner_id'] = (int) $row['owner_id'];
|
||||
$row['item_count'] = (int) $row['item_count'];
|
||||
$row['card_count'] = (int) $row['card_count'];
|
||||
$row['completed_count'] = (int) $row['completed_count'];
|
||||
|
||||
/** @var TodoListRow $row */
|
||||
/** @var ProjectRow $row */
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user