feat: manga metadata with status, authors, genres, tags, and search filters (0.15.0)

Adds first-class manga metadata across the stack:

- **Status** (ongoing / completed), **alternative titles**, normalized
  **multi-author** support, **curated genres** (13 seeded), and
  **free-form user tags** (case-insensitive, globally shared). Each is
  modelled as its own table joined to mangas; `mangas.author` is
  backfilled into `authors` + `manga_authors` and dropped.
- New endpoints: `PATCH /v1/mangas/:id` (three-state `description`),
  `POST/DELETE /v1/mangas/:id/tags[/:tag_id]`, `GET /v1/genres`,
  `GET /v1/tags?search=`.
- `GET /v1/mangas` now returns `MangaCard` (with authors + genres
  batched in) and supports `?status=`, `?author_id=`, `?genre_id=`,
  `?tag_id=` filters — AND across facets, with empty-array no-op
  semantics for the unnest primitive.
- `GET /v1/mangas/:id` returns the enriched `MangaDetail` with tags.
- Frontend: reusable `Chip` component; manga detail page renders
  authors as chips linking to `/authors/:id` (Phase 2), a status
  badge, alt titles, genres, and tags with inline add/remove (only
  the attacher sees remove); upload form supports multi-author /
  multi-genre / alt titles / status; search page gets a collapsible
  URL-synced filter panel with keyboard-navigable tag autocomplete.
- 126 backend tests (incl. AND-across-facets primitive, case-insens
  author/tag de-dup, transactional create rollback, PATCH semantics
  for missing / null / set on description); 72 frontend tests +
  svelte-check clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-05-17 14:32:03 +02:00
parent 60cc7712fa
commit 59d380b6d7
34 changed files with 3614 additions and 174 deletions

88
backend/src/repo/genre.rs Normal file
View File

@@ -0,0 +1,88 @@
use std::collections::BTreeMap;
use sqlx::{PgConnection, PgPool};
use uuid::Uuid;
use crate::domain::genre::{Genre, GenreRef};
use crate::error::AppResult;
pub async fn list_all(pool: &PgPool) -> AppResult<Vec<Genre>> {
let rows = sqlx::query_as::<_, Genre>(
"SELECT id, name FROM genres ORDER BY lower(name)",
)
.fetch_all(pool)
.await?;
Ok(rows)
}
pub async fn list_for_manga(pool: &PgPool, manga_id: Uuid) -> AppResult<Vec<GenreRef>> {
let rows = sqlx::query_as::<_, GenreRef>(
r#"
SELECT g.id, g.name
FROM manga_genres mg
JOIN genres g ON g.id = mg.genre_id
WHERE mg.manga_id = $1
ORDER BY lower(g.name)
"#,
)
.bind(manga_id)
.fetch_all(pool)
.await?;
Ok(rows)
}
pub async fn load_for_mangas(
pool: &PgPool,
manga_ids: &[Uuid],
) -> AppResult<BTreeMap<Uuid, Vec<GenreRef>>> {
if manga_ids.is_empty() {
return Ok(BTreeMap::new());
}
let rows: Vec<(Uuid, Uuid, String)> = sqlx::query_as(
r#"
SELECT mg.manga_id, g.id, g.name
FROM manga_genres mg
JOIN genres g ON g.id = mg.genre_id
WHERE mg.manga_id = ANY($1)
ORDER BY mg.manga_id, lower(g.name)
"#,
)
.bind(manga_ids)
.fetch_all(pool)
.await?;
let mut grouped: BTreeMap<Uuid, Vec<GenreRef>> = BTreeMap::new();
for (manga_id, id, name) in rows {
grouped.entry(manga_id).or_default().push(GenreRef { id, name });
}
Ok(grouped)
}
/// Replace the manga's genres. Unknown ids are silently ignored: the
/// FK constraint would reject them, so we filter upstream rather than
/// surface a 500 here. (The API layer validates the set against
/// `list_all` first.)
pub async fn set_for_manga(
conn: &mut PgConnection,
manga_id: Uuid,
genre_ids: &[Uuid],
) -> AppResult<()> {
sqlx::query("DELETE FROM manga_genres WHERE manga_id = $1")
.bind(manga_id)
.execute(&mut *conn)
.await?;
if genre_ids.is_empty() {
return Ok(());
}
sqlx::query(
r#"
INSERT INTO manga_genres (manga_id, genre_id)
SELECT $1, unnest($2::uuid[])
ON CONFLICT DO NOTHING
"#,
)
.bind(manga_id)
.bind(genre_ids)
.execute(&mut *conn)
.await?;
Ok(())
}