Add category management UI and service layer

Users can now create, edit, and delete custom categories from Settings → Categories. System categories (45 built-in) are shown read-only. Backend adds update_category() and delete_category() service functions; frontend has a new categories API module and a full CRUD section in SettingsPage with filter tabs, colour picker, and delete confirmation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
megaproxy 2026-04-23 11:50:28 +00:00
parent 8ef3bb2965
commit 6111424f47
5 changed files with 455 additions and 22 deletions

View file

@ -133,3 +133,51 @@ async def create_category(
db.add(cat)
await db.flush()
return {"id": str(cat.id), "name": cat.name, "type": cat.type, "icon": cat.icon, "color": cat.color, "is_system": False}
async def update_category(
db: AsyncSession,
user_id: uuid.UUID,
category_id: uuid.UUID,
name: str | None,
color: str | None,
icon: str | None,
) -> dict | None:
result = await db.execute(
select(Category).where(
Category.id == category_id,
Category.user_id == user_id,
Category.is_system == False,
)
)
cat = result.scalar_one_or_none()
if cat is None:
return None
if name is not None:
cat.name = name
if color is not None:
cat.color = color
if icon is not None:
cat.icon = icon
await db.flush()
return {"id": str(cat.id), "name": cat.name, "type": cat.type, "icon": cat.icon, "color": cat.color, "is_system": False}
async def delete_category(
db: AsyncSession,
user_id: uuid.UUID,
category_id: uuid.UUID,
) -> bool:
result = await db.execute(
select(Category).where(
Category.id == category_id,
Category.user_id == user_id,
Category.is_system == False,
)
)
cat = result.scalar_one_or_none()
if cat is None:
return False
await db.delete(cat)
await db.flush()
return True