Files
Daniel Samson afa399776f feat(admin): rebuild admin area around the Article domain
The admin area was managing a Hacker News-style Item model that the
public site never consumed, so the homepage always fell back to sample
data. Rebuild the admin area around the real public content model.

Backend:
- Remove the Item model, schema and admin API
- Admin API now manages articles at /api/v1/admin/articles (CRUD) with
  /api/v1/admin/authors and /api/v1/admin/categories reference data
- Add public read-only article endpoints (/api/v1/articles,
  /api/v1/articles/{id}): no auth, published-only, newest-first
- Rewrite Article schemas; ArticleRead embeds author and category
- Add idempotent seed_content.py dev seeder (3 authors, 4 categories,
  6 published articles)

Frontend:
- Admin UI rewritten around articles: AdminDashboard list, new
  EditArticlePage (create/edit, author/category selects, published
  toggle, Lexical editor, debounced auto-save)
- Replace AdminItem types and api client with the article domain
- Update App routes, AdminLayout sidebar, DeleteConfirmation, Lexical
  editor labels and Home/client comments to article terminology

Tests:
- Rewrite admin unit tests and the Playwright admin e2e spec for the
  article domain; add test_articles.py for the public endpoints and
  seeder
2026-10-31 18:31:05 +00:00

65 lines
1.7 KiB
Python

"""Schemas for the Article model.
``ArticleRead`` embeds the related ``author`` and ``category`` so both the
public feed and the admin area can render full article details from a single
payload (the ORM relationships are loaded via ``from_attributes``).
"""
from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field
from schemas.author import AuthorRead
from schemas.category import CategoryRead
class ArticleBase(BaseModel):
"""Fields shared by create/update/read article schemas."""
title: str = Field(..., min_length=1, max_length=200)
content: str = Field(..., min_length=1)
class ArticleCreate(ArticleBase):
"""Payload for creating an article."""
author_id: int = Field(..., ge=1)
category_id: int = Field(..., ge=1)
published: bool = False
class ArticleUpdate(BaseModel):
"""Payload for updating an article (all fields optional)."""
title: str | None = Field(default=None, min_length=1, max_length=200)
content: str | None = Field(default=None, min_length=1)
author_id: int | None = Field(default=None, ge=1)
category_id: int | None = Field(default=None, ge=1)
published: bool | None = None
class ArticleRead(BaseModel):
"""Article as returned by the API, with related author/category."""
model_config = ConfigDict(from_attributes=True)
id: int
title: str
content: str
author_id: int
category_id: int
created_at: datetime
published: bool
author: AuthorRead
category: CategoryRead
class ArticleAdminList(BaseModel):
"""Paginated article list of ``GET /api/v1/admin/articles``."""
articles: list[ArticleRead]
total: int
page: int
page_size: int
total_pages: int