chore: initial project scaffold
Set up Mangalord with a Rust/axum backend, SvelteKit frontend, Postgres, and Docker Compose deployment. Establishes the architecture and TDD patterns the project will extend: - Hexagonal-ish backend layering (domain / repo / storage / api) with a pluggable Storage trait (LocalStorage today, S3 as a future impl). - Initial migration: users, mangas, chapters, bookmarks. - Vertical slice for mangas (list, search, create, get) with #[sqlx::test] integration coverage and storage unit tests. - SvelteKit frontend using Svelte 5 runes, typed API client, Vitest unit tests and Playwright e2e with route mocking. - CLAUDE.md documenting layering, TDD/git/SemVer workflow rules, and extension points (tags, fulltext search, OCR, S3, auth). - Project-scoped .claude/settings.json with permission allowlist for the toolchain (git, cargo, npm/vite, docker, psql, gh, doc fetches). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
76
backend/src/repo/manga.rs
Normal file
76
backend/src/repo/manga.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
//! Manga persistence.
|
||||
//!
|
||||
//! Plain async functions over `&PgPool` rather than a repository struct —
|
||||
//! each function is easy to test in isolation with `#[sqlx::test]`, and
|
||||
//! handlers depend only on `sqlx::PgPool`, not on a trait object. Swap to
|
||||
//! a trait + impl if a second backend ever becomes necessary.
|
||||
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::domain::manga::{Manga, NewManga};
|
||||
use crate::error::{AppError, AppResult};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ListQuery {
|
||||
pub search: Option<String>,
|
||||
pub limit: i64,
|
||||
pub offset: i64,
|
||||
}
|
||||
|
||||
impl Default for ListQuery {
|
||||
fn default() -> Self {
|
||||
Self { search: None, limit: 50, offset: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn list(pool: &PgPool, query: &ListQuery) -> AppResult<Vec<Manga>> {
|
||||
let pattern = query.search.as_deref().map(|s| format!("%{}%", s));
|
||||
let rows = sqlx::query_as::<_, Manga>(
|
||||
r#"
|
||||
SELECT id, title, author, description, cover_image_path, created_at, updated_at
|
||||
FROM mangas
|
||||
WHERE $1::text IS NULL
|
||||
OR title ILIKE $1
|
||||
OR COALESCE(author, '') ILIKE $1
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $2 OFFSET $3
|
||||
"#,
|
||||
)
|
||||
.bind(pattern)
|
||||
.bind(query.limit)
|
||||
.bind(query.offset)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
Ok(rows)
|
||||
}
|
||||
|
||||
pub async fn get(pool: &PgPool, id: Uuid) -> AppResult<Manga> {
|
||||
sqlx::query_as::<_, Manga>(
|
||||
r#"
|
||||
SELECT id, title, author, description, cover_image_path, created_at, updated_at
|
||||
FROM mangas
|
||||
WHERE id = $1
|
||||
"#,
|
||||
)
|
||||
.bind(id)
|
||||
.fetch_optional(pool)
|
||||
.await?
|
||||
.ok_or(AppError::NotFound)
|
||||
}
|
||||
|
||||
pub async fn create(pool: &PgPool, input: NewManga) -> AppResult<Manga> {
|
||||
let row = sqlx::query_as::<_, Manga>(
|
||||
r#"
|
||||
INSERT INTO mangas (title, author, description)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id, title, author, description, cover_image_path, created_at, updated_at
|
||||
"#,
|
||||
)
|
||||
.bind(&input.title)
|
||||
.bind(&input.author)
|
||||
.bind(&input.description)
|
||||
.fetch_one(pool)
|
||||
.await?;
|
||||
Ok(row)
|
||||
}
|
||||
1
backend/src/repo/mod.rs
Normal file
1
backend/src/repo/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod manga;
|
||||
Reference in New Issue
Block a user