Skip to content

Add Categories table and API (#91, 1/5) - #227

Draft
NotThaDev wants to merge 4 commits into
mainfrom
feature/91-categories-api
Draft

NotThaDev wants to merge 4 commits into
mainfrom
feature/91-categories-api

Conversation

@NotThaDev

Copy link
Copy Markdown
Owner

Part 1 of 5 for #91.

What

  • New Categories table: Id, UserId (null = system), Key, Name, Kind, Group, Icon, Color.
    • 58 system rows are seeded from today's frontend data and are locked (no edit or delete).
    • Custom categories start at id 1000.
  • api/categories: GET (system + mine), POST, PUT {id}, DELETE {id}, GET {id}/usage.
  • Deleting a custom category moves its transactions to Other and disables the rules that target it (they are re-pointed to Other, because the FK is Restrict).
  • Transaction.CategoryId and CategoryRule.TargetCategoryId replace the enum columns.
    • Every write checks that the category is a system one or the caller's own; otherwise 400.
    • The list filter accepts categoryId.
  • Migration AddCategories, generated then edited by hand: create + seed → UPDATE +1 (enum renumbered from 1) → rename columns → FKs → identity sequence at 1000. Down() reverses every step.

Why

  • The enum stays as named ids for business logic: (int)TransactionCategory.X == system Category.Id. Analytics, importer and matcher are unchanged until PR 2.
  • The JSON contract is backward compatible: category / targetCategory strings are still returned and accepted, and categoryId wins when both are sent. Today's frontend keeps working. The legacy fields are removed in PR 5.

Tested

  • dotnet test: 176/176 (20 new: CRUD, validation, system rows locked, user B cannot read, edit, delete or assign user A's category, delete fallback, legacy JSON, filter).
  • dotnet build and dotnet format --verify-no-changes: clean.
  • Migration on an isolated Postgres DB, with rows seeded at the previous migration:
    • old Coffe/Other/Transfer → CategoryId 1/25/57 with the matching keys, rule Food → 2;
    • 58 seed rows, the next custom id is 1000, the FK rejects unknown ids;
    • Down() restores 0/24/56, and the migration re-applies cleanly.

Out of scope (next PRs)

  • Analytics, reports, import and the rule matcher keyed by category id, plus the rule backfill (PR 2). Until then, a custom category serializes as a number in analytics responses. No UI can create one before PR 4.
  • Frontend (PRs 3–4), cleanup (PR 5).

🤖 Generated with Claude Code

…ategoryId (#91)

System categories are seeded (ids = enum values, renumbered from 1) and locked.
Custom categories start at id 1000. Deleting one moves its transactions to Other
and disables the rules that target it. The legacy category/targetCategory strings
stay in the JSON contract until the cleanup PR.
… feature/91-categories-api

# Conflicts:
#	.claude/skills/backend/SKILL.md
… feature/91-categories-api

# Conflicts:
#	.claude/skills/backend/SKILL.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant