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
This commit is contained in:
Daniel Samson committed 2026-10-31 18:31:05 +00:00
1 parent de96d0b152
commit afa399776f
29 files changed
+2465 -1658

No files matched your search

+14 -7
View File
@@ -1,13 +1,24 @@
"""Pydantic request/response schemas for newzy."""
from schemas.article import ArticleBase, ArticleCreate, ArticleRead, ArticleUpdate
from schemas.article import (
ArticleAdminList,
ArticleBase,
ArticleCreate,
ArticleRead,
ArticleUpdate,
)
from schemas.auth import LoginIn, RegisterIn, TokenOut, UserOut
from schemas.author import AuthorBase, AuthorCreate, AuthorRead, AuthorUpdate
from schemas.category import CategoryBase, CategoryCreate, CategoryRead, CategoryUpdate
from schemas.category import (
CategoryBase,
CategoryCreate,
CategoryRead,
CategoryUpdate,
)
from schemas.common import ErrorDetail, HealthResponse, VersionResponse
from schemas.item import ItemAdminList, ItemCreate, ItemRead, ItemUpdate
__all__ = [
"ArticleAdminList",
"ArticleBase",
"ArticleCreate",
"ArticleRead",
@@ -22,10 +33,6 @@ __all__ = [
"CategoryUpdate",
"ErrorDetail",
"HealthResponse",
"ItemAdminList",
"ItemCreate",
"ItemRead",
"ItemUpdate",
"LoginIn",
"RegisterIn",
"TokenOut",
+22 -2
View File
@@ -1,9 +1,17 @@
"""Schemas for the Article model."""
"""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."""
@@ -31,7 +39,7 @@ class ArticleUpdate(BaseModel):
class ArticleRead(BaseModel):
"""Article as returned by the API."""
"""Article as returned by the API, with related author/category."""
model_config = ConfigDict(from_attributes=True)
@@ -42,3 +50,15 @@ class ArticleRead(BaseModel):
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
-102
View File
@@ -1,102 +0,0 @@
"""Schemas for the Item model (admin area, see ``api.v1.admin``)."""
from datetime import datetime
from urllib.parse import urlsplit
from pydantic import BaseModel, ConfigDict, Field, field_validator
def _clean_title(value: str) -> str:
stripped = value.strip()
if not stripped:
raise ValueError("title must not be empty")
return stripped
def _clean_url(value: str | None) -> str:
"""Normalize an optional URL: empty/blank -> ``""``, otherwise it must
be an absolute ``http://`` or ``https://`` URL."""
if value is None:
return ""
stripped = value.strip()
if not stripped:
return ""
parsed = urlsplit(stripped)
if parsed.scheme not in ("http", "https") or not parsed.netloc:
raise ValueError("must be an absolute http:// or https:// URL")
return stripped
class ItemBase(BaseModel):
"""Fields shared by the item create schema and the read model."""
title: str = Field(..., min_length=1, max_length=300)
url: str = Field(default="", max_length=500)
points: int = Field(default=0, ge=0)
content: str = Field(default="", description="HTML body from the Lexical editor.")
@field_validator("title")
@classmethod
def _strip_title(cls, value: str) -> str:
return _clean_title(value)
@field_validator("url")
@classmethod
def _validate_url(cls, value: str) -> str:
return _clean_url(value)
class ItemCreate(ItemBase):
"""Payload of ``POST /api/v1/admin/items``.
``username`` is optional: when omitted the item belongs to the
authenticated admin.
"""
username: str | None = Field(default=None, min_length=1, max_length=60)
class ItemUpdate(BaseModel):
"""Payload of ``PUT /api/v1/admin/items/{id}`` (all fields optional)."""
title: str | None = Field(default=None, max_length=300)
url: str | None = Field(default=None, max_length=500)
points: int | None = Field(default=None, ge=0)
username: str | None = Field(default=None, min_length=1, max_length=60)
content: str | None = None
@field_validator("title")
@classmethod
def _strip_title(cls, value: str | None) -> str | None:
if value is None:
return None
return _clean_title(value)
@field_validator("url")
@classmethod
def _validate_url(cls, value: str | None) -> str | None:
return None if value is None else _clean_url(value)
class ItemRead(BaseModel):
"""Item as returned by the admin API."""
model_config = ConfigDict(from_attributes=True)
id: int
title: str
url: str
points: int
username: str
content: str
created_at: datetime
class ItemAdminList(BaseModel):
"""Paginated item list of ``GET /api/v1/admin/items``."""
items: list[ItemRead]
total: int
page: int
page_size: int
total_pages: int