Compare commits
146 Commits
004243dcbb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 7faf14fb2f | |||
| ddb5966c9b | |||
| 4ec231017e | |||
| fab236688b | |||
| 4683a408d7 | |||
| 6d4c70553a | |||
| ca7ca51949 | |||
| 33aa5bdab3 | |||
| b844339795 | |||
| cedb13d7a8 | |||
| aec5f6b058 | |||
| d9234ecd11 | |||
| 010ee404c8 | |||
| d4c42f8567 | |||
| 9c44330f14 | |||
| 2fa118570f | |||
| ded7517a8a | |||
| bf272bf8d9 | |||
| 6f34b7b5ec | |||
| 17d4de461b | |||
| 40cb15e7cb | |||
| c80287bb9e | |||
| 06ab5c8df1 | |||
| 57520c00f3 | |||
| b5cc7f8371 | |||
| 9ca5ada924 | |||
| 70d1f10e3d | |||
| 61980b0cfb | |||
| 7bf5c47f5b | |||
| ddf100cfc2 | |||
| cdff0de53d | |||
| 1e62f12903 | |||
| 66bd138927 | |||
| b29f3020e6 | |||
| 76edd52bb0 | |||
| b5ff43d9dc | |||
| b552c1d156 | |||
| f006ba00a8 | |||
| 2b295e10ba | |||
| 20ac0d3adf | |||
| 8ac87a3735 | |||
| 4f0f44dec3 | |||
| 96c753c2c6 | |||
| 822f3f9d9c | |||
| 55feaa353f | |||
| 3a3f3b3889 | |||
| ef9ecbae06 | |||
| db285b513b | |||
| 2617c77b42 | |||
| e618e1aa84 | |||
| 7dc372a7b6 | |||
| e39fcf6802 | |||
| b09ef4686a | |||
| 2074a2244e | |||
| 338ecb71c8 | |||
| 8cb90b256c | |||
| c05087a6c7 | |||
| 0fdc79af23 | |||
| 262ba5ca39 | |||
| 57c720b22f | |||
| 53b7f730cb | |||
| e8fa24bf9b | |||
| 7437ed89ad | |||
| b2a41db290 | |||
| 9b932cde8e | |||
| a68e19aad7 | |||
| 371a3cdc46 | |||
| 517a18da8a | |||
| 7df24a19ee | |||
| 549923b92e | |||
| 3cbb406ea7 | |||
| 21cc6ed437 | |||
| 5dc90724d3 | |||
| 9a894c3a95 | |||
| acc20d2f43 | |||
| a95be0b131 | |||
| f10b114e83 | |||
| c020135cd1 | |||
| ad55897871 | |||
| 87fcdc12ca | |||
| d14199813f | |||
| f52219b2b7 | |||
| 6e21ec115d | |||
| deae83cfd1 | |||
| c4d6b68ef9 | |||
| d8cff33679 | |||
| e9aa6131ae | |||
| 43f6c5679d | |||
| 956e51530e | |||
| b882569ee1 | |||
| 5dbc02b58f | |||
| d389e26e39 | |||
| 05d062f4e0 | |||
| 70b3ca0f5c | |||
| ac03182aa6 | |||
| 6d3182525f | |||
| 7bcbc59587 | |||
| d867a14b28 | |||
| 30a6200b5b | |||
| f4fd915e35 | |||
| f3eee9131b | |||
| 9e4370b068 | |||
| 37ab24be74 | |||
| 307113381f | |||
| 6d238b6c3d | |||
| a7a11dde08 | |||
| 988e15eac6 | |||
| fff5f4af2f | |||
| 213f9a2433 | |||
| 4dacbbfded | |||
| 886f26c7dc | |||
| 6a10ba15c1 | |||
| 237f1e7d32 | |||
| c647f4c13b | |||
| 3bb2dbee19 | |||
| b0bfc149e1 | |||
| 7e8a1b8379 | |||
| 4bd8dcbf05 | |||
| ebf9a9f4a8 | |||
| a76386345f | |||
| 49728f8cd7 | |||
| 5334312d64 | |||
| 81a377cbb2 | |||
| 689c8a9ac3 | |||
| 5e6bc93a6a | |||
| 4a3a99c6d2 | |||
| dacc057af6 | |||
| 01c1082290 | |||
| bd7dc648c4 | |||
| af8e58aeb8 | |||
| fd9a053702 | |||
| 092e769641 | |||
| b20d23fbb3 | |||
| b9c0b10740 | |||
| 15dc0e526b | |||
| cf2f4a1b4f | |||
| e7cdbf9ca7 | |||
| 837b7866af | |||
| c4908b7765 | |||
| dbc78a1ff4 | |||
| a97e263ed3 | |||
| b1d667d3cb | |||
| bf73d4a695 | |||
| 7b9b0f9ffe | |||
| 7d6f874ae7 | |||
| 4206bb4b06 |
@@ -7,3 +7,7 @@ target/
|
|||||||
# .cargo and .sqlx are needed at build time (SQLX_OFFLINE mode)
|
# .cargo and .sqlx are needed at build time (SQLX_OFFLINE mode)
|
||||||
docs/
|
docs/
|
||||||
dev.db
|
dev.db
|
||||||
|
spa/node_modules/
|
||||||
|
spa/dist/
|
||||||
|
spa/.env
|
||||||
|
spa/.env.local
|
||||||
|
|||||||
91
.env.example
91
.env.example
@@ -1,72 +1,55 @@
|
|||||||
# Database backend — "sqlite" (default) or "postgres"
|
# ── Required ──────────────────────────────────────────────────
|
||||||
DATABASE_BACKEND=sqlite
|
|
||||||
|
|
||||||
# Option A: SQLite (default, zero external dependencies)
|
# Database (SQLite — file auto-created on first run)
|
||||||
DATABASE_URL=sqlite://movies.db
|
DATABASE_URL=sqlite:///data/movies.db
|
||||||
|
|
||||||
# Option B: PostgreSQL
|
|
||||||
# DATABASE_BACKEND=postgres
|
|
||||||
# DATABASE_URL=postgres://user:password@localhost:5432/movies_diary
|
|
||||||
|
|
||||||
# Authentication
|
# Authentication
|
||||||
JWT_SECRET=change-me
|
JWT_SECRET=change-me-to-a-random-string
|
||||||
JWT_TTL_SECONDS=86400
|
|
||||||
|
|
||||||
# OMDb/TMDB metadata
|
# Movie metadata — one of these is required (TMDB preferred)
|
||||||
OMDB_API_KEY=your-key
|
# TMDB_API_KEY=your-tmdb-key
|
||||||
TMDB_API_KEY=your-key
|
OMDB_API_KEY=your-omdb-key
|
||||||
|
|
||||||
# Poster storage — Option A (local) is active. To use S3, comment it out and uncomment Option B:
|
# ── Recommended ──────────────────────────────────────────────
|
||||||
|
|
||||||
# Option A: local filesystem (zero external dependencies)
|
# Public URL (used for ActivityPub federation and canonical links)
|
||||||
POSTER_STORAGE_BACKEND=local
|
BASE_URL=https://yourdomain.example.com
|
||||||
POSTER_STORAGE_PATH=./posters
|
|
||||||
|
|
||||||
# Option B: S3-compatible (MinIO, AWS S3, etc.)
|
# Enable sign-ups (default: false — set true so you can register)
|
||||||
# POSTER_STORAGE_BACKEND=s3
|
ALLOW_REGISTRATION=true
|
||||||
|
|
||||||
|
# ── Image Storage (defaults to local filesystem) ─────────────
|
||||||
|
|
||||||
|
# IMAGE_STORAGE_BACKEND=local # default
|
||||||
|
# IMAGE_STORAGE_PATH=./images # default
|
||||||
|
|
||||||
|
# S3-compatible alternative (MinIO, AWS S3, etc.):
|
||||||
|
# IMAGE_STORAGE_BACKEND=s3
|
||||||
# MINIO_ENDPOINT=http://localhost:9000
|
# MINIO_ENDPOINT=http://localhost:9000
|
||||||
# MINIO_BUCKET=posters
|
# MINIO_BUCKET=posters
|
||||||
# MINIO_REGION=minio
|
# MINIO_REGION=minio
|
||||||
# MINIO_ACCESS_KEY_ID=minioadmin
|
# MINIO_ACCESS_KEY_ID=minioadmin
|
||||||
# MINIO_SECRET_ACCESS_KEY=minioadmin
|
# MINIO_SECRET_ACCESS_KEY=minioadmin
|
||||||
|
|
||||||
# Optional
|
# ── Optional ─────────────────────────────────────────────────
|
||||||
HOST=0.0.0.0
|
|
||||||
PORT=3000
|
|
||||||
BASE_URL=http://localhost:3000
|
|
||||||
SECURE_COOKIES=false
|
|
||||||
ALLOW_REGISTRATION=false
|
|
||||||
RATE_LIMIT=20
|
|
||||||
POSTER_FETCH_TIMEOUT_SECONDS=30
|
|
||||||
|
|
||||||
# Event bus — "db" (default) or "nats"
|
# TMDb enrichment (cast, crew, genres — separate from search metadata above)
|
||||||
# The worker binary must run alongside the presentation to process events.
|
# TMDB_API_KEY=your-tmdb-key
|
||||||
EVENT_BUS_BACKEND=db
|
|
||||||
|
|
||||||
# Option A: DB queue (default — no extra infrastructure needed)
|
# Image conversion (converts uploaded posters to AVIF or WebP)
|
||||||
# Events are persisted in the same database as the app and polled by the worker.
|
|
||||||
# EVENT_QUEUE_POLL_INTERVAL_MS=500 # polling interval (default: 500ms)
|
|
||||||
# EVENT_QUEUE_BATCH_SIZE=10 # rows claimed per poll cycle (default: 10)
|
|
||||||
# EVENT_QUEUE_MAX_ATTEMPTS=5 # retries before dead-lettering (default: 5)
|
|
||||||
|
|
||||||
# Option B: NATS (at-least-once delivery, recommended for higher throughput)
|
|
||||||
# EVENT_BUS_BACKEND=nats
|
|
||||||
# NATS_URL=nats://localhost:4222
|
|
||||||
# NATS_MODE=jetstream # "jetstream" (default, at-least-once) or "core" (fire-and-forget)
|
|
||||||
# NATS_SUBJECT_PREFIX=movies-diary.events
|
|
||||||
# NATS_STREAM_NAME=MOVIES_DIARY_EVENTS
|
|
||||||
# NATS_CONSUMER_NAME=worker
|
|
||||||
|
|
||||||
# Image conversion (optional — converts stored images to save disk space)
|
|
||||||
# Disable by default; enable in the worker by setting ENABLED=true.
|
|
||||||
# IMAGE_CONVERSION_ENABLED=false
|
# IMAGE_CONVERSION_ENABLED=false
|
||||||
# IMAGE_CONVERSION_FORMAT=avif # avif | webp
|
# IMAGE_CONVERSION_FORMAT=avif
|
||||||
|
|
||||||
# Annual Wrap-Up (video generation — optional, requires ffmpeg)
|
# Server
|
||||||
# WRAPUP_FONT_PATH=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
|
# HOST=0.0.0.0
|
||||||
# WRAPUP_LOGO_PATH=./static/logo.webp
|
# PORT=3000
|
||||||
# WRAPUP_BG_DIR=./static/wrapup-backgrounds # directory of jpg/png/webp images for video slide backgrounds
|
# RATE_LIMIT=60
|
||||||
# FFMPEG_PATH=ffmpeg
|
# SECURE_COOKIES=true
|
||||||
# WRAPUP_MAX_CONCURRENT=2
|
# RUST_LOG=presentation=info,tower_http=info,worker=info
|
||||||
|
|
||||||
RUST_LOG=presentation=debug,tower_http=debug,worker=info,application=info
|
# CORS (for SPA development only)
|
||||||
|
# CORS_ORIGINS=http://localhost:5173
|
||||||
|
|
||||||
|
# Event bus — "db" (default, uses same database) or "nats"
|
||||||
|
# EVENT_BUS_BACKEND=db
|
||||||
|
# NATS_URL=nats://localhost:4222
|
||||||
|
|||||||
42
.gitea/workflows/ci.yml
Normal file
42
.gitea/workflows/ci.yml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["**"]
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
RUST_BACKTRACE: 1
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ci:
|
||||||
|
name: Check / Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust stable
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
with:
|
||||||
|
components: rustfmt, clippy
|
||||||
|
|
||||||
|
- name: Cache cargo
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry
|
||||||
|
~/.cargo/git
|
||||||
|
target
|
||||||
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
restore-keys: ${{ runner.os }}-cargo-
|
||||||
|
|
||||||
|
- name: fmt
|
||||||
|
run: cargo fmt --all -- --check
|
||||||
|
|
||||||
|
- name: clippy
|
||||||
|
run: cargo clippy --all-targets -- -D warnings
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
run: cargo test
|
||||||
39
.github/workflows/ci.yml
vendored
39
.github/workflows/ci.yml
vendored
@@ -40,3 +40,42 @@ jobs:
|
|||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
run: cargo test
|
run: cargo test
|
||||||
|
|
||||||
|
docker:
|
||||||
|
name: Build & Push Docker Image
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: ci
|
||||||
|
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Log in to GHCR
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Docker metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ghcr.io/${{ github.repository }}
|
||||||
|
tags: |
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=sha,prefix=
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
build-args: FEATURES=sqlite,sqlite-federation
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -16,3 +16,4 @@
|
|||||||
docs/
|
docs/
|
||||||
|
|
||||||
imgs/
|
imgs/
|
||||||
|
.sqlx/
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,\n r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment, r.watched_at, r.created_at, r.remote_actor_url\n FROM reviews r\n INNER JOIN movies m ON m.id = r.movie_id\n WHERE r.movie_id = ?\n ORDER BY r.watched_at DESC\n LIMIT ? OFFSET ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "external_metadata_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "title",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release_year",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "director",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "poster_path",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "review_id",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "movie_id",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "rating",
|
|
||||||
"ordinal": 9,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "comment",
|
|
||||||
"ordinal": 10,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "watched_at",
|
|
||||||
"ordinal": 11,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 12,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "remote_actor_url",
|
|
||||||
"ordinal": 13,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 3
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "05d958c1fa38095ae2b5b81ede48fc85702d8c39c6301839de7b4d27f4a4d41b"
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT COUNT(*) FROM reviews",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "COUNT(*)",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Integer"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 0
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "0963b9661182e139cd760bbabb0d6ea3a301a2a3adbdfdda4a88f333a1144c77"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT INTO users (id, email, username, password_hash, created_at, role) VALUES (?, ?, ?, ?, ?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 6
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "0acf3515a4d1bef7a2458d878481ba3b11c9f252311579f7daba335f70d78f07"
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,\n r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment, r.watched_at, r.created_at, r.remote_actor_url\n FROM reviews r\n INNER JOIN movies m ON m.id = r.movie_id\n WHERE r.user_id = ?\n ORDER BY r.watched_at DESC",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "external_metadata_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "title",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release_year",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "director",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "poster_path",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "review_id",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "movie_id",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "rating",
|
|
||||||
"ordinal": 9,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "comment",
|
|
||||||
"ordinal": 10,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "watched_at",
|
|
||||||
"ordinal": 11,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 12,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "remote_actor_url",
|
|
||||||
"ordinal": 13,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "106b5b65162314c47217c26b7e89194094e10122ea596e8d9323968e600635a9"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "DELETE FROM user_profile_fields WHERE user_id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "11f7dd8da277aaf950e2a428f8e072cde8d806ca5b4007bbc882aada5c46ae63"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "DELETE FROM import_sessions WHERE expires_at < datetime('now')",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 0
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "1c70d5d455e5ab3dfb68d35ce5255c7e0e86b9f6549ae8ae09247806f1321086"
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, email, username, password_hash, role, bio, avatar_path, banner_path, also_known_as FROM users WHERE username = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "email",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "username",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "password_hash",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "role",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "bio",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "avatar_path",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "banner_path",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "also_known_as",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "1dd3efb043635e638f1c3d72923a4ccfb9c9810baee06cfac5ad4af5749e4c6e"
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,\n r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment, r.watched_at, r.created_at, r.remote_actor_url\n FROM reviews r\n INNER JOIN movies m ON m.id = r.movie_id\n ORDER BY r.watched_at ASC\n LIMIT ? OFFSET ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "external_metadata_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "title",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release_year",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "director",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "poster_path",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "review_id",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "movie_id",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "rating",
|
|
||||||
"ordinal": 9,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "comment",
|
|
||||||
"ordinal": 10,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "watched_at",
|
|
||||||
"ordinal": 11,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 12,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "remote_actor_url",
|
|
||||||
"ordinal": 13,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 2
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "25fd01355c929a83daf2c802b8ae3adaa4ce73fc037e2bf2a87d60187aeb7361"
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, external_metadata_id, title, release_year, director, poster_path\n FROM movies WHERE title = ? AND release_year = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "external_metadata_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "title",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release_year",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "director",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "poster_path",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 2
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "3047579c6ed13ce87aad9b9ce6300c02f0df3516979518976e13f9d9abc6a403"
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, external_metadata_id, title, release_year, director, poster_path\n FROM movies WHERE id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "external_metadata_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "title",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release_year",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "director",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "poster_path",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "33d0dae7d16b0635c1c7eb5afd10824bb55af7cc7a854f590d326622863759d1"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "DELETE FROM import_sessions WHERE user_id = ? AND expires_at < datetime('now')",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "34a0a7b5e6a7f2b97b59e9de6a34b41a7128a465c0957915c7ed7031c6b83fb0"
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT COUNT(*) FROM reviews WHERE movie_id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "COUNT(*)",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Integer"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "4b3074b532342c6356ee0e8e4d8c4a830f016234bb690e1f6240f02824d6d84f"
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT strftime('%Y-%m', watched_at) AS month\n FROM reviews\n WHERE user_id = ?\n GROUP BY month\n ORDER BY COUNT(*) DESC\n LIMIT 1",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "month",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "4d85f0ff9732576bba77dc84d3885a0002c2b600c34ba4d99f1e1c5e99f35e75"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT INTO user_profile_fields (id, user_id, name, value, position) VALUES (?, ?, ?, ?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 5
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "5bde1c64a1dec54f348058c9d93842676aa3149bdfc4012f3f3318677a56336d"
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT name, value FROM user_profile_fields WHERE user_id = ? ORDER BY position ASC",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "name",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "value",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "5e447e9558515934d8f0c08e91342c0df0b29101223f370a126fb0ee76e3b9bd"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT OR REPLACE INTO import_profiles (id, user_id, name, field_mappings, created_at)\n VALUES (?, ?, ?, ?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 5
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "6638569b8759b965f8919f4998a8665b15c14fc0b4f6018e548b76474254073e"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "UPDATE import_sessions SET field_mappings = ?, row_results = ? WHERE id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 3
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "759b45ac8426d93d4668e208003d52957f2f52d8a021cc6f117cb6f241689a07"
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT u.id AS \"id!: String\",\n u.email AS \"email!: String\",\n COUNT(DISTINCT r.movie_id) AS \"total_movies!: i64\",\n AVG(CAST(r.rating AS REAL)) AS avg_rating,\n u.avatar_path\n FROM users u\n LEFT JOIN reviews r ON r.user_id = u.id AND r.remote_actor_url IS NULL\n GROUP BY u.id, u.email, u.avatar_path\n ORDER BY u.email ASC",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id!: String",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "email!: String",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "total_movies!: i64",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "avg_rating",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Float"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "avatar_path",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 0
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "771236034946abb52809203ba9a1259900e343174cf3f435fc18d9e689deb187"
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, external_metadata_id, title, release_year, director, poster_path\n FROM movies WHERE external_metadata_id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "external_metadata_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "title",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release_year",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "director",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "poster_path",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "7bc4aebcb94547976d3d7e063e4e908fc22b977b3cbf063ee93ffe4648c42011"
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, email, username, password_hash, role, bio, avatar_path, banner_path, also_known_as FROM users WHERE email = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "email",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "username",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "password_hash",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "role",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "bio",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "avatar_path",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "banner_path",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "also_known_as",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "7cb37c7e3df2a945859e12a186a479b9f9f431691d5f0e4ee460cd559f5412b4"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT INTO movies (id, external_metadata_id, title, release_year, director, poster_path)\n VALUES (?, ?, ?, ?, ?, ?)\n ON CONFLICT(id) DO UPDATE SET\n external_metadata_id = excluded.external_metadata_id,\n title = excluded.title,\n release_year = excluded.release_year,\n director = excluded.director,\n poster_path = excluded.poster_path",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 6
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "7d7e23355ee0e442f2aa27e898dcfa40bdc4b09391afe04325f076157d9d84aa"
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, user_id, name, field_mappings, created_at FROM import_profiles WHERE id = ? AND user_id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "name",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "field_mappings",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 2
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "7fa9ce795286905f4b6c3d5a8975fabd813a2b39652dd7e18f03f5b10a4beaca"
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, movie_id, user_id, rating, comment, watched_at, created_at, remote_actor_url\n FROM reviews WHERE movie_id = ? ORDER BY watched_at ASC",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "movie_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "rating",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "comment",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "watched_at",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "remote_actor_url",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "7ff439f22f880f999a72aad1359eb8fec11fe868b940faee5a351795caaa2357"
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,\n r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment, r.watched_at, r.created_at, r.remote_actor_url\n FROM reviews r\n INNER JOIN movies m ON m.id = r.movie_id\n WHERE r.movie_id = ?\n ORDER BY r.watched_at ASC\n LIMIT ? OFFSET ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "external_metadata_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "title",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release_year",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "director",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "poster_path",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "review_id",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "movie_id",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "rating",
|
|
||||||
"ordinal": 9,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "comment",
|
|
||||||
"ordinal": 10,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "watched_at",
|
|
||||||
"ordinal": 11,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 12,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "remote_actor_url",
|
|
||||||
"ordinal": 13,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 3
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "8a70f21c39d203867c06dc0bf74a54745b3331b84ce9a2178f7812f1ed7262cc"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "DELETE FROM import_profiles WHERE id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "9024c2b533d0100f18d5a5550220a148d8dc29bbf0df715f895fa4248d83785f"
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT COUNT(DISTINCT movie_id) AS \"total!: i64\",\n AVG(CAST(rating AS REAL)) AS avg_rating\n FROM reviews WHERE user_id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "total!: i64",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "avg_rating",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Float"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "a01336632a54099e31686a9cbe6fc53fef1299fc7c7b52be44f99c2302490a22"
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,\n r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment, r.watched_at, r.created_at, r.remote_actor_url\n FROM reviews r\n INNER JOIN movies m ON m.id = r.movie_id\n ORDER BY r.watched_at DESC\n LIMIT ? OFFSET ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "external_metadata_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "title",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release_year",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "director",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "poster_path",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "review_id",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "movie_id",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "rating",
|
|
||||||
"ordinal": 9,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "comment",
|
|
||||||
"ordinal": 10,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "watched_at",
|
|
||||||
"ordinal": 11,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 12,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "remote_actor_url",
|
|
||||||
"ordinal": 13,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 2
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "a7c424c26663e4e51b1c563fa977f28e1d55234a242a7ddba50db13cf73b488d"
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT m.director AS \"director!\",\n COUNT(*) AS \"count!: i64\"\n FROM reviews r\n INNER JOIN movies m ON m.id = r.movie_id\n WHERE r.user_id = ? AND m.director IS NOT NULL\n GROUP BY m.director\n ORDER BY COUNT(*) DESC\n LIMIT 5",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "director!",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "count!: i64",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Integer"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
true,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "aca9e7aaa32c23b4de3f5048d60340e978d31a36be9121da3c59378f2fc1ed8e"
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, movie_id, user_id, rating, comment, watched_at, created_at, remote_actor_url\n FROM reviews WHERE id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "movie_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "rating",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "comment",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "watched_at",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "remote_actor_url",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "ae983138ad90fda3794b784fbf62c31fddcf182850782e9bfbc4ff3ee8b7d4bb"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "DELETE FROM import_sessions WHERE id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "bf4aaf630ebefde88d87a95c257bbeafaf39e2f53611dab435d485648eb7e598"
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, user_id, parsed_data, field_mappings, row_results, created_at, expires_at\n FROM import_sessions WHERE id = ? AND user_id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "parsed_data",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "field_mappings",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "row_results",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "expires_at",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 2
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "ca7c29f4c80cee4877625a259edef662b169377c5bafdd03583645a39368c910"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT INTO reviews (id, movie_id, user_id, rating, comment, watched_at, created_at, remote_actor_url)\n VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 8
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "cca022ac6275f2b1aaf63a14420897074c8ff4cdd1d3e9a13ef4b9dd5346d12a"
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT m.director\n FROM reviews r\n INNER JOIN movies m ON m.id = r.movie_id\n WHERE r.user_id = ? AND m.director IS NOT NULL\n GROUP BY m.director\n ORDER BY COUNT(*) DESC\n LIMIT 1",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "director",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "d5d2a81306488a8cee5654cea7e14d76d76ecc7d2190ffb73d12bec2874111d2"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT INTO import_sessions (id, user_id, parsed_data, field_mappings, row_results, created_at, expires_at)\n VALUES (?, ?, ?, ?, ?, ?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 7
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "e3a3b56d63df433339bd8183f20ef33ded742ef03df885686cd5198f9f8e1c01"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "DELETE FROM movies WHERE id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "e431381ad41c1c2f7b9c89509d5e3f4c19cb52dcfff66772145cd80c53c16883"
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, email, username, password_hash, role, bio, avatar_path, banner_path, also_known_as FROM users WHERE id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "email",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "username",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "password_hash",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "role",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "bio",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "avatar_path",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "banner_path",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "also_known_as",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "e6413dcabae4a72628a2abf33a8b65da6f95b7c3c015f2633fcf00c045b9f08b"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "DELETE FROM reviews WHERE id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "f84e5483ca4210aec67b38cc1a9de4a42c12891025236abc48ea4f175292a6cc"
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, user_id, name, field_mappings, created_at FROM import_profiles WHERE user_id = ? ORDER BY created_at DESC",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "name",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "field_mappings",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "f8559923b7a885fb0d4938479f11bd97708b401a6a2290abe6df49fcb7f28a8d"
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT strftime('%Y-%m', watched_at) AS \"month!\",\n AVG(CAST(rating AS REAL)) AS \"avg_rating!: f64\",\n COUNT(*) AS \"count!: i64\"\n FROM reviews\n WHERE user_id = ? AND watched_at >= datetime('now', '-12 months')\n GROUP BY \"month!\"\n ORDER BY \"month!\" ASC",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "month!",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "avg_rating!: f64",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Float"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "count!: i64",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Integer"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "fdd5b522f26b5e0ce62f76c774fbb606fd9ee9884f4457831f693a0df3609317"
|
|
||||||
}
|
|
||||||
87
CONTRIBUTING.md
Normal file
87
CONTRIBUTING.md
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
Thanks for your interest in Movies Diary! This is a personal project but contributions are welcome — bug fixes, new features, docs improvements, or picking up the deprecated TUI.
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
1. Fork and clone the repo
|
||||||
|
2. Copy `.env.example` to `.env` and fill in at least `JWT_SECRET` and `OMDB_API_KEY`
|
||||||
|
3. Install Rust (stable, 2024 edition) and Bun (for the SPA)
|
||||||
|
4. Run the backend and worker:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo run -p presentation # HTTP server on :3000
|
||||||
|
cargo run -p worker # event worker (separate terminal)
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Run the SPA dev server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd spa && bun install && bun run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
## Before submitting a PR
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make # runs fmt-check + clippy + test
|
||||||
|
```
|
||||||
|
|
||||||
|
Or individually:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo fmt --check
|
||||||
|
cargo clippy -- -D warnings
|
||||||
|
cargo test
|
||||||
|
cd spa && bunx tsc --noEmit
|
||||||
|
```
|
||||||
|
|
||||||
|
All four must pass. PRs with clippy warnings or failing tests won't be merged.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
The project follows hexagonal (ports & adapters) architecture. See `architecture.mmd` for the full diagram.
|
||||||
|
|
||||||
|
**Key rules:**
|
||||||
|
- Presentation handlers never touch repositories directly — all domain logic goes through use cases in the `application` crate
|
||||||
|
- Application use cases return raw domain data — URL formatting, date display, and view model assembly belong in presentation mappers (`presentation/src/mappers/`)
|
||||||
|
- Use cases called from presentation handlers take `&AppContext`. Functions called from adapter event handlers take individual `Arc<dyn Trait>` params to keep adapter dependencies explicit
|
||||||
|
|
||||||
|
```
|
||||||
|
domain → pure types, traits (ports), zero deps
|
||||||
|
application → use cases, orchestration
|
||||||
|
presentation → Axum handlers, routes, OpenAPI
|
||||||
|
worker → event consumer, background jobs
|
||||||
|
adapters/* → implements domain ports (sqlite, postgres, AP, etc.)
|
||||||
|
spa/ → React SPA (TanStack Router + shadcn/ui)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Adding a new feature
|
||||||
|
|
||||||
|
1. **Domain first** — models in `domain/src/models/`, ports in `ports.rs`, events in `events.rs`
|
||||||
|
2. **Adapters** — implement ports in both `sqlite` and `postgres` adapters, add migration
|
||||||
|
3. **Application** — use cases in `application/src/<domain>/`, wire into `context.rs`
|
||||||
|
4. **API types** — DTOs in `api-types/src/`
|
||||||
|
5. **Presentation** — handler file in `handlers/<domain>.rs`, routes in `routes.rs`
|
||||||
|
6. **SPA** — API client in `spa/src/lib/api/`, hook in `spa/src/hooks/`, components
|
||||||
|
7. **Classic HTML** — Askama template + CSS in `static/style.css`
|
||||||
|
|
||||||
|
### Database adapters
|
||||||
|
|
||||||
|
Both SQLite and PostgreSQL are supported. If you add a migration or repository, implement it for both. The postgres adapter uses `$1, $2` params and `TIMESTAMPTZ`; SQLite uses `?` and text datetimes.
|
||||||
|
|
||||||
|
### Federation (ActivityPub)
|
||||||
|
|
||||||
|
Federation is feature-gated (`#[cfg(feature = "federation")]`). If your feature should federate, add domain events, handle them in `activitypub/src/event_handler.rs`, and create an AP object + inbound handler.
|
||||||
|
|
||||||
|
## Code style
|
||||||
|
|
||||||
|
- No comments unless the *why* is non-obvious
|
||||||
|
- Concise commit messages
|
||||||
|
- One feature per PR — don't bundle unrelated changes
|
||||||
|
- Follow existing patterns (check a similar feature for reference)
|
||||||
|
|
||||||
|
## Areas seeking help
|
||||||
|
|
||||||
|
- **TUI** (`crates/tui`) — deprecated, needs a maintainer to bring it up to feature parity
|
||||||
|
- **Tests** — the domain and application crates have 400+ unit tests; integration tests for the presentation layer are welcome
|
||||||
|
- **Docs** — API usage examples, deployment guides
|
||||||
453
Cargo.lock
generated
453
Cargo.lock
generated
@@ -2,22 +2,6 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ab_glyph"
|
|
||||||
version = "0.2.32"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "01c0457472c38ea5bd1c3b5ada5e368271cb550be7a4ca4a0b4634e9913f6cc2"
|
|
||||||
dependencies = [
|
|
||||||
"ab_glyph_rasterizer",
|
|
||||||
"owned_ttf_parser",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ab_glyph_rasterizer"
|
|
||||||
version = "0.1.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "activitypub"
|
name = "activitypub"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -262,15 +246,6 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aligned"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ee4508988c62edf04abd8d92897fca0c2995d907ce1dfeaf369dac3716a40685"
|
|
||||||
dependencies = [
|
|
||||||
"as-slice",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aligned-vec"
|
name = "aligned-vec"
|
||||||
version = "0.6.4"
|
version = "0.6.4"
|
||||||
@@ -339,6 +314,7 @@ name = "application"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
"bytes",
|
||||||
"chrono",
|
"chrono",
|
||||||
"domain",
|
"domain",
|
||||||
"futures",
|
"futures",
|
||||||
@@ -351,15 +327,6 @@ dependencies = [
|
|||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "approx"
|
|
||||||
version = "0.5.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
|
|
||||||
dependencies = [
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arbitrary"
|
name = "arbitrary"
|
||||||
version = "1.4.2"
|
version = "1.4.2"
|
||||||
@@ -398,15 +365,6 @@ version = "0.7.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "as-slice"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "516b6b4f0e40d50dcda9365d53964ec74560ad4284da2e7fc97122cd83174516"
|
|
||||||
dependencies = [
|
|
||||||
"stable_deref_trait",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "askama"
|
name = "askama"
|
||||||
version = "0.16.0"
|
version = "0.16.0"
|
||||||
@@ -610,6 +568,28 @@ dependencies = [
|
|||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "async-stream"
|
||||||
|
version = "0.3.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476"
|
||||||
|
dependencies = [
|
||||||
|
"async-stream-impl",
|
||||||
|
"futures-core",
|
||||||
|
"pin-project-lite",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "async-stream-impl"
|
||||||
|
version = "0.3.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.117",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-task"
|
name = "async-task"
|
||||||
version = "4.7.1"
|
version = "4.7.1"
|
||||||
@@ -693,26 +673,6 @@ version = "1.5.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "av-scenechange"
|
|
||||||
version = "0.14.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0f321d77c20e19b92c39e7471cf986812cbb46659d2af674adc4331ef3f18394"
|
|
||||||
dependencies = [
|
|
||||||
"aligned",
|
|
||||||
"anyhow",
|
|
||||||
"arg_enum_proc_macro",
|
|
||||||
"arrayvec",
|
|
||||||
"log",
|
|
||||||
"num-rational",
|
|
||||||
"num-traits",
|
|
||||||
"pastey",
|
|
||||||
"rayon",
|
|
||||||
"thiserror 2.0.18",
|
|
||||||
"v_frame",
|
|
||||||
"y4m",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "av1-grain"
|
name = "av1-grain"
|
||||||
version = "0.2.5"
|
version = "0.2.5"
|
||||||
@@ -879,12 +839,6 @@ version = "0.6.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
|
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bit_field"
|
|
||||||
version = "0.10.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
@@ -906,15 +860,6 @@ version = "2.6.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6099cdc01846bc367c4e7dd630dc5966dccf36b652fae7a74e17b640411a91b2"
|
checksum = "6099cdc01846bc367c4e7dd630dc5966dccf36b652fae7a74e17b640411a91b2"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitstream-io"
|
|
||||||
version = "4.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7eff00be299a18769011411c9def0d827e8f2d7bf0c3dbf53633147a8867fd1f"
|
|
||||||
dependencies = [
|
|
||||||
"no_std_io2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blake2"
|
name = "blake2"
|
||||||
version = "0.10.6"
|
version = "0.10.6"
|
||||||
@@ -961,12 +906,6 @@ version = "0.7.7"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "56ed6191a7e78c36abdb16ab65341eefd73d64d303fffccdbb00d51e4205967b"
|
checksum = "56ed6191a7e78c36abdb16ab65341eefd73d64d303fffccdbb00d51e4205967b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "built"
|
|
||||||
version = "0.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5c0e531d93d39c34eef561e929e8a7f86d77a5af08aac4f6d6e39976c51858e9"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.20.3"
|
version = "3.20.3"
|
||||||
@@ -1142,12 +1081,6 @@ dependencies = [
|
|||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "color_quant"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "combine"
|
name = "combine"
|
||||||
version = "4.6.7"
|
version = "4.6.7"
|
||||||
@@ -1273,16 +1206,6 @@ dependencies = [
|
|||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-deque"
|
|
||||||
version = "0.8.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
|
|
||||||
dependencies = [
|
|
||||||
"crossbeam-epoch",
|
|
||||||
"crossbeam-utils",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-epoch"
|
name = "crossbeam-epoch"
|
||||||
version = "0.9.18"
|
version = "0.9.18"
|
||||||
@@ -1334,12 +1257,6 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crunchy"
|
|
||||||
version = "0.2.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crypto-common"
|
name = "crypto-common"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
@@ -1928,29 +1845,17 @@ dependencies = [
|
|||||||
name = "export"
|
name = "export"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"async-stream",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
"bytes",
|
||||||
"chrono",
|
"chrono",
|
||||||
"domain",
|
"domain",
|
||||||
|
"futures",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "exr"
|
|
||||||
version = "1.74.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4300e043a56aa2cb633c01af81ca8f699a321879a7854d3896a0ba89056363be"
|
|
||||||
dependencies = [
|
|
||||||
"bit_field",
|
|
||||||
"half",
|
|
||||||
"lebe",
|
|
||||||
"miniz_oxide",
|
|
||||||
"rayon-core",
|
|
||||||
"smallvec",
|
|
||||||
"zune-inflate",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fancy-regex"
|
name = "fancy-regex"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
@@ -1973,12 +1878,6 @@ version = "2.4.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"
|
checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fax"
|
|
||||||
version = "0.2.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "caf1079563223d5d59d83c85886a56e586cfd5c1a26292e971a0fa266531ac5a"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fdeflate"
|
name = "fdeflate"
|
||||||
version = "0.3.7"
|
version = "0.3.7"
|
||||||
@@ -2267,16 +2166,6 @@ dependencies = [
|
|||||||
"wasip3",
|
"wasip3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gif"
|
|
||||||
version = "0.14.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ee8cfcc411d9adbbaba82fb72661cc1bcca13e8bba98b364e62b2dba8f960159"
|
|
||||||
dependencies = [
|
|
||||||
"color_quant",
|
|
||||||
"weezl",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glob"
|
name = "glob"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
@@ -2322,17 +2211,6 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "half"
|
|
||||||
version = "2.7.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"crunchy",
|
|
||||||
"zerocopy",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.14.5"
|
version = "0.14.5"
|
||||||
@@ -2735,18 +2613,10 @@ checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"byteorder-lite",
|
"byteorder-lite",
|
||||||
"color_quant",
|
|
||||||
"exr",
|
|
||||||
"gif",
|
|
||||||
"image-webp",
|
"image-webp",
|
||||||
"moxcms",
|
"moxcms",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"png",
|
"png",
|
||||||
"qoi",
|
|
||||||
"ravif 0.13.0",
|
|
||||||
"rayon",
|
|
||||||
"rgb",
|
|
||||||
"tiff",
|
|
||||||
"zune-core",
|
"zune-core",
|
||||||
"zune-jpeg",
|
"zune-jpeg",
|
||||||
]
|
]
|
||||||
@@ -2761,7 +2631,7 @@ dependencies = [
|
|||||||
"image",
|
"image",
|
||||||
"object-storage",
|
"object-storage",
|
||||||
"object_store",
|
"object_store",
|
||||||
"ravif 0.11.20",
|
"ravif",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"uuid",
|
"uuid",
|
||||||
@@ -2778,24 +2648,6 @@ dependencies = [
|
|||||||
"quick-error",
|
"quick-error",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "imageproc"
|
|
||||||
version = "0.25.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "602b4e8a4cc3e98372b766cd184ab532999bc0e839b7469e759511ccabc65d77"
|
|
||||||
dependencies = [
|
|
||||||
"ab_glyph",
|
|
||||||
"approx",
|
|
||||||
"getrandom 0.2.17",
|
|
||||||
"image",
|
|
||||||
"itertools 0.12.1",
|
|
||||||
"nalgebra",
|
|
||||||
"num",
|
|
||||||
"rand 0.8.6",
|
|
||||||
"rand_distr",
|
|
||||||
"rayon",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "imgref"
|
name = "imgref"
|
||||||
version = "1.12.1"
|
version = "1.12.1"
|
||||||
@@ -3086,12 +2938,6 @@ version = "0.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lebe"
|
|
||||||
version = "0.5.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7a79a3332a6609480d7d0c9eab957bca6b455b91bb84e66d19f5ff66294b85b8"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.186"
|
version = "0.2.186"
|
||||||
@@ -3278,16 +3124,6 @@ version = "0.8.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
|
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "matrixmultiply"
|
|
||||||
version = "0.3.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a06de3016e9fae57a36fd14dba131fccf49f74b40b7fbdb472f96e361ec71a08"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"rawpointer",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "maybe-rayon"
|
name = "maybe-rayon"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@@ -3295,7 +3131,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "8ea1f30cedd69f0a2954655f7188c6a834246d2bcf1e315e2ac40c4b24dc9519"
|
checksum = "8ea1f30cedd69f0a2954655f7188c6a834246d2bcf1e315e2ac40c4b24dc9519"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"rayon",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3431,21 +3266,6 @@ dependencies = [
|
|||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nalgebra"
|
|
||||||
version = "0.32.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7b5c17de023a86f59ed79891b2e5d5a94c705dbe904a5b5c9c952ea6221b03e4"
|
|
||||||
dependencies = [
|
|
||||||
"approx",
|
|
||||||
"matrixmultiply",
|
|
||||||
"num-complex",
|
|
||||||
"num-rational",
|
|
||||||
"num-traits",
|
|
||||||
"simba",
|
|
||||||
"typenum",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nats"
|
name = "nats"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -3497,15 +3317,6 @@ dependencies = [
|
|||||||
"signatory",
|
"signatory",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "no_std_io2"
|
|
||||||
version = "0.9.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "418abd1b6d34fbf6cae440dc874771b0525a604428704c76e48b29a5e67b8003"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nom"
|
name = "nom"
|
||||||
version = "7.1.3"
|
version = "7.1.3"
|
||||||
@@ -3760,15 +3571,6 @@ dependencies = [
|
|||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "owned_ttf_parser"
|
|
||||||
version = "0.25.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "36820e9051aca1014ddc75770aab4d68bc1e9e632f0f5627c4086bc216fb583b"
|
|
||||||
dependencies = [
|
|
||||||
"ttf-parser",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking"
|
name = "parking"
|
||||||
version = "2.2.1"
|
version = "2.2.1"
|
||||||
@@ -3815,12 +3617,6 @@ version = "1.0.15"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pastey"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "35fb2e5f958ec131621fdd531e9fc186ed768cbe395337403ae56c17a74c68ec"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pem"
|
name = "pem"
|
||||||
version = "3.0.6"
|
version = "3.0.6"
|
||||||
@@ -4078,9 +3874,12 @@ name = "postgres"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"async-stream",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
"bytes",
|
||||||
"chrono",
|
"chrono",
|
||||||
"domain",
|
"domain",
|
||||||
|
"futures",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
@@ -4265,15 +4064,6 @@ version = "0.1.29"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e0c5ccf5294c6ccd63a74f1565028353830a9c2f5eb0c682c355c471726a6e3f"
|
checksum = "e0c5ccf5294c6ccd63a74f1565028353830a9c2f5eb0c682c355c471726a6e3f"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "qoi"
|
|
||||||
version = "0.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001"
|
|
||||||
dependencies = [
|
|
||||||
"bytemuck",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quick-error"
|
name = "quick-error"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
@@ -4453,16 +4243,6 @@ version = "0.10.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_distr"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31"
|
|
||||||
dependencies = [
|
|
||||||
"num-traits",
|
|
||||||
"rand 0.8.6",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ratatui"
|
name = "ratatui"
|
||||||
version = "0.30.0"
|
version = "0.30.0"
|
||||||
@@ -4558,8 +4338,8 @@ dependencies = [
|
|||||||
"arg_enum_proc_macro",
|
"arg_enum_proc_macro",
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"av1-grain",
|
"av1-grain",
|
||||||
"bitstream-io 2.6.0",
|
"bitstream-io",
|
||||||
"built 0.7.7",
|
"built",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"interpolate_name",
|
"interpolate_name",
|
||||||
"itertools 0.12.1",
|
"itertools 0.12.1",
|
||||||
@@ -4583,41 +4363,6 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rav1e"
|
|
||||||
version = "0.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "43b6dd56e85d9483277cde964fd1bdb0428de4fec5ebba7540995639a21cb32b"
|
|
||||||
dependencies = [
|
|
||||||
"aligned-vec",
|
|
||||||
"arbitrary",
|
|
||||||
"arg_enum_proc_macro",
|
|
||||||
"arrayvec",
|
|
||||||
"av-scenechange",
|
|
||||||
"av1-grain",
|
|
||||||
"bitstream-io 4.10.0",
|
|
||||||
"built 0.8.1",
|
|
||||||
"cfg-if",
|
|
||||||
"interpolate_name",
|
|
||||||
"itertools 0.14.0",
|
|
||||||
"libc",
|
|
||||||
"libfuzzer-sys",
|
|
||||||
"log",
|
|
||||||
"maybe-rayon",
|
|
||||||
"new_debug_unreachable",
|
|
||||||
"noop_proc_macro",
|
|
||||||
"num-derive",
|
|
||||||
"num-traits",
|
|
||||||
"paste",
|
|
||||||
"profiling",
|
|
||||||
"rand 0.9.4",
|
|
||||||
"rand_chacha 0.9.0",
|
|
||||||
"simd_helpers",
|
|
||||||
"thiserror 2.0.18",
|
|
||||||
"v_frame",
|
|
||||||
"wasm-bindgen",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ravif"
|
name = "ravif"
|
||||||
version = "0.11.20"
|
version = "0.11.20"
|
||||||
@@ -4628,51 +4373,10 @@ dependencies = [
|
|||||||
"imgref",
|
"imgref",
|
||||||
"loop9",
|
"loop9",
|
||||||
"quick-error",
|
"quick-error",
|
||||||
"rav1e 0.7.1",
|
"rav1e",
|
||||||
"rgb",
|
"rgb",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ravif"
|
|
||||||
version = "0.13.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e52310197d971b0f5be7fe6b57530dcd27beb35c1b013f29d66c1ad73fbbcc45"
|
|
||||||
dependencies = [
|
|
||||||
"avif-serialize",
|
|
||||||
"imgref",
|
|
||||||
"loop9",
|
|
||||||
"quick-error",
|
|
||||||
"rav1e 0.8.1",
|
|
||||||
"rayon",
|
|
||||||
"rgb",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rawpointer"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rayon"
|
|
||||||
version = "1.12.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
"rayon-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rayon-core"
|
|
||||||
version = "1.13.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
|
|
||||||
dependencies = [
|
|
||||||
"crossbeam-deque",
|
|
||||||
"crossbeam-utils",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.5.18"
|
version = "0.5.18"
|
||||||
@@ -5047,15 +4751,6 @@ version = "1.0.23"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
|
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "safe_arch"
|
|
||||||
version = "0.7.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "96b02de82ddbe1b636e6170c21be622223aea188ef2e139be0a5b219ec215323"
|
|
||||||
dependencies = [
|
|
||||||
"bytemuck",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "same-file"
|
name = "same-file"
|
||||||
version = "1.0.6"
|
version = "1.0.6"
|
||||||
@@ -5320,19 +5015,6 @@ dependencies = [
|
|||||||
"rand_core 0.6.4",
|
"rand_core 0.6.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "simba"
|
|
||||||
version = "0.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "061507c94fc6ab4ba1c9a0305018408e312e17c041eb63bef8aa726fa33aceae"
|
|
||||||
dependencies = [
|
|
||||||
"approx",
|
|
||||||
"num-complex",
|
|
||||||
"num-traits",
|
|
||||||
"paste",
|
|
||||||
"wide",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "simd-adler32"
|
name = "simd-adler32"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
@@ -5471,9 +5153,12 @@ name = "sqlite"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"async-stream",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
"bytes",
|
||||||
"chrono",
|
"chrono",
|
||||||
"domain",
|
"domain",
|
||||||
|
"futures",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
@@ -6039,20 +5724,6 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tiff"
|
|
||||||
version = "0.11.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b63feaf3343d35b6ca4d50483f94843803b0f51634937cc2ec519fc32232bc52"
|
|
||||||
dependencies = [
|
|
||||||
"fax",
|
|
||||||
"flate2",
|
|
||||||
"half",
|
|
||||||
"quick-error",
|
|
||||||
"weezl",
|
|
||||||
"zune-jpeg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.3.47"
|
version = "0.3.47"
|
||||||
@@ -6408,12 +6079,6 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ttf-parser"
|
|
||||||
version = "0.25.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tui"
|
name = "tui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -6916,12 +6581,6 @@ dependencies = [
|
|||||||
"rustls-pki-types",
|
"rustls-pki-types",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "weezl"
|
|
||||||
version = "0.1.12"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wezterm-bidi"
|
name = "wezterm-bidi"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
@@ -7004,16 +6663,6 @@ dependencies = [
|
|||||||
"wasite",
|
"wasite",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wide"
|
|
||||||
version = "0.7.33"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0ce5da8ecb62bcd8ec8b7ea19f69a51275e91299be594ea5cc6ef7819e16cd03"
|
|
||||||
dependencies = [
|
|
||||||
"bytemuck",
|
|
||||||
"safe_arch",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
@@ -7494,21 +7143,6 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"wrapup-renderer",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "wrapup-renderer"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"ab_glyph",
|
|
||||||
"async-trait",
|
|
||||||
"domain",
|
|
||||||
"image",
|
|
||||||
"imageproc",
|
|
||||||
"tempfile",
|
|
||||||
"tokio",
|
|
||||||
"tracing",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -7517,12 +7151,6 @@ version = "0.6.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4"
|
checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "y4m"
|
|
||||||
version = "0.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7a5a4b21e1a62b67a2970e6831bc091d7b87e119e7f9791aef9702e3bef04448"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yoke"
|
name = "yoke"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
@@ -7771,15 +7399,6 @@ version = "0.5.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cb8a0807f7c01457d0379ba880ba6322660448ddebc890ce29bb64da71fb40f9"
|
checksum = "cb8a0807f7c01457d0379ba880ba6322660448ddebc890ce29bb64da71fb40f9"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zune-inflate"
|
|
||||||
version = "0.2.54"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02"
|
|
||||||
dependencies = [
|
|
||||||
"simd-adler32",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zune-jpeg"
|
name = "zune-jpeg"
|
||||||
version = "0.5.15"
|
version = "0.5.15"
|
||||||
|
|||||||
11
Cargo.toml
11
Cargo.toml
@@ -31,7 +31,6 @@ members = [
|
|||||||
"crates/adapters/plex",
|
"crates/adapters/plex",
|
||||||
"crates/adapters/sqlite-search",
|
"crates/adapters/sqlite-search",
|
||||||
"crates/adapters/postgres-search",
|
"crates/adapters/postgres-search",
|
||||||
"crates/adapters/wrapup-renderer",
|
|
||||||
]
|
]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
@@ -39,6 +38,7 @@ resolver = "2"
|
|||||||
tokio = { version = "1.0", features = ["macros", "net", "rt", "rt-multi-thread", "sync", "time"] }
|
tokio = { version = "1.0", features = ["macros", "net", "rt", "rt-multi-thread", "sync", "time"] }
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
|
async-stream = "0.3"
|
||||||
dotenvy = "0.15"
|
dotenvy = "0.15"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
@@ -53,7 +53,6 @@ sqlx = { version = "0.8.6", features = [
|
|||||||
"runtime-tokio-rustls",
|
"runtime-tokio-rustls",
|
||||||
"sqlite",
|
"sqlite",
|
||||||
"uuid",
|
"uuid",
|
||||||
"macros",
|
|
||||||
] }
|
] }
|
||||||
rand = "0.9"
|
rand = "0.9"
|
||||||
reqwest = { version = "0.13", features = ["json", "query"] }
|
reqwest = { version = "0.13", features = ["json", "query"] }
|
||||||
@@ -92,4 +91,10 @@ plex = { path = "crates/adapters/plex" }
|
|||||||
image-converter = { path = "crates/adapters/image-converter" }
|
image-converter = { path = "crates/adapters/image-converter" }
|
||||||
sqlite-search = { path = "crates/adapters/sqlite-search" }
|
sqlite-search = { path = "crates/adapters/sqlite-search" }
|
||||||
postgres-search = { path = "crates/adapters/postgres-search" }
|
postgres-search = { path = "crates/adapters/postgres-search" }
|
||||||
wrapup-renderer = { path = "crates/adapters/wrapup-renderer" }
|
|
||||||
|
[profile.dev]
|
||||||
|
debug = 1 # line tables only — still debuggable, much faster linking
|
||||||
|
split-debuginfo = "unpacked" # macOS: skip dsymutil on every link
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 2 # compile deps faster at runtime; paid once, cached after
|
||||||
|
|||||||
16
Dockerfile
16
Dockerfile
@@ -1,3 +1,11 @@
|
|||||||
|
# ----- spa -----
|
||||||
|
FROM node:22-slim AS spa-builder
|
||||||
|
WORKDIR /spa
|
||||||
|
COPY spa/package.json spa/package-lock.json ./
|
||||||
|
RUN npm ci
|
||||||
|
COPY spa/ .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
# ----- build -----
|
# ----- build -----
|
||||||
FROM rust:slim-bookworm AS builder
|
FROM rust:slim-bookworm AS builder
|
||||||
|
|
||||||
@@ -6,7 +14,6 @@ WORKDIR /build
|
|||||||
# Cache dependency compilation separately from source
|
# Cache dependency compilation separately from source
|
||||||
COPY Cargo.toml Cargo.lock ./
|
COPY Cargo.toml Cargo.lock ./
|
||||||
COPY .cargo ./.cargo
|
COPY .cargo ./.cargo
|
||||||
COPY .sqlx ./.sqlx
|
|
||||||
COPY crates/adapters/activitypub/Cargo.toml crates/adapters/activitypub/Cargo.toml
|
COPY crates/adapters/activitypub/Cargo.toml crates/adapters/activitypub/Cargo.toml
|
||||||
COPY crates/adapters/auth/Cargo.toml crates/adapters/auth/Cargo.toml
|
COPY crates/adapters/auth/Cargo.toml crates/adapters/auth/Cargo.toml
|
||||||
COPY crates/adapters/event-payload/Cargo.toml crates/adapters/event-payload/Cargo.toml
|
COPY crates/adapters/event-payload/Cargo.toml crates/adapters/event-payload/Cargo.toml
|
||||||
@@ -37,7 +44,6 @@ COPY crates/tui/Cargo.toml crates/tui/Cargo.toml
|
|||||||
COPY crates/adapters/image-converter/Cargo.toml crates/adapters/image-converter/Cargo.toml
|
COPY crates/adapters/image-converter/Cargo.toml crates/adapters/image-converter/Cargo.toml
|
||||||
COPY crates/adapters/sqlite-search/Cargo.toml crates/adapters/sqlite-search/Cargo.toml
|
COPY crates/adapters/sqlite-search/Cargo.toml crates/adapters/sqlite-search/Cargo.toml
|
||||||
COPY crates/adapters/postgres-search/Cargo.toml crates/adapters/postgres-search/Cargo.toml
|
COPY crates/adapters/postgres-search/Cargo.toml crates/adapters/postgres-search/Cargo.toml
|
||||||
COPY crates/adapters/wrapup-renderer/Cargo.toml crates/adapters/wrapup-renderer/Cargo.toml
|
|
||||||
COPY crates/worker/Cargo.toml crates/worker/Cargo.toml
|
COPY crates/worker/Cargo.toml crates/worker/Cargo.toml
|
||||||
|
|
||||||
# Stub every crate so cargo can resolve and fetch deps
|
# Stub every crate so cargo can resolve and fetch deps
|
||||||
@@ -55,8 +61,8 @@ RUN cargo fetch
|
|||||||
# Now copy real sources (invalidates cache only on source changes)
|
# Now copy real sources (invalidates cache only on source changes)
|
||||||
COPY crates ./crates
|
COPY crates ./crates
|
||||||
|
|
||||||
# .cargo/config.toml sets SQLX_OFFLINE=true; .sqlx contains the pre-verified query cache.
|
# All sqlx queries use the runtime API (no query! macros), so no database
|
||||||
# No live database needed at compile time.
|
# or .sqlx cache is needed at compile time.
|
||||||
#
|
#
|
||||||
# To build with PostgreSQL backend instead:
|
# To build with PostgreSQL backend instead:
|
||||||
# --build-arg FEATURES=postgres,postgres-federation
|
# --build-arg FEATURES=postgres,postgres-federation
|
||||||
@@ -72,7 +78,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
ca-certificates \
|
ca-certificates \
|
||||||
wget \
|
wget \
|
||||||
libwebp7 \
|
libwebp7 \
|
||||||
ffmpeg \
|
|
||||||
fonts-dejavu-core \
|
fonts-dejavu-core \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
@@ -81,6 +86,7 @@ WORKDIR /app
|
|||||||
COPY --from=builder /build/target/release/presentation ./presentation
|
COPY --from=builder /build/target/release/presentation ./presentation
|
||||||
COPY --from=builder /build/target/release/worker ./worker
|
COPY --from=builder /build/target/release/worker ./worker
|
||||||
COPY static ./static
|
COPY static ./static
|
||||||
|
COPY --from=spa-builder /spa/dist ./spa/dist
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
|||||||
11
Makefile
11
Makefile
@@ -1,9 +1,18 @@
|
|||||||
.DEFAULT_GOAL := check
|
.DEFAULT_GOAL := check
|
||||||
|
|
||||||
# Run the full local check suite — same order as CI would.
|
# Run the full local check suite — same order as CI would.
|
||||||
check: fmt-check clippy test
|
check: fmt-check clippy test check-appcontext
|
||||||
@echo "✅ All checks passed"
|
@echo "✅ All checks passed"
|
||||||
|
|
||||||
|
# Enforce that no application use case imports AppContext (god-object guard).
|
||||||
|
check-appcontext:
|
||||||
|
@if grep -rn "AppContext" crates/application/src --include="*.rs" | grep -q .; then \
|
||||||
|
echo "❌ AppContext found in application crate:"; \
|
||||||
|
grep -rn "AppContext" crates/application/src --include="*.rs"; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
@echo "✅ No AppContext in application crate"
|
||||||
|
|
||||||
# Apply rustfmt to all files.
|
# Apply rustfmt to all files.
|
||||||
fmt:
|
fmt:
|
||||||
cargo fmt
|
cargo fmt
|
||||||
|
|||||||
227
README.md
227
README.md
@@ -1,6 +1,49 @@
|
|||||||
# Movies Diary
|
# Movies Diary
|
||||||
|
|
||||||
A self-hosted, server-side rendered movie logging system with a full REST API. Built in Rust — no JavaScript in the HTML interface, just HTML forms and an RSS feed. Designed to run as a lightweight widget embedded on a personal site or as a backend for third-party clients.
|
A self-hosted movie diary built in Rust. Ships a classic server-rendered HTML interface (no JavaScript) alongside a full React SPA, both backed by the same REST API. Federates over ActivityPub so reviews reach the Fediverse. Supports Jellyfin and Plex auto-import, full-text search, annual wrap-ups, goals, and bulk import from Letterboxd, IMDb, and other sources. Runs on SQLite or PostgreSQL.
|
||||||
|
|
||||||
|
[](LICENSE)
|
||||||
|
[](https://www.rust-lang.org/)
|
||||||
|
[](https://hub.docker.com/)
|
||||||
|
[](https://activitypub.rocks/)
|
||||||
|
[](https://www.sqlite.org/)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
|
||||||
|
- [Quick Start](#quick-start)
|
||||||
|
- [Features](#features)
|
||||||
|
- [Screenshots](#screenshots)
|
||||||
|
- [Architecture](#architecture)
|
||||||
|
- [Prerequisites](#prerequisites)
|
||||||
|
- [Configuration](#configuration)
|
||||||
|
- [Run](#run)
|
||||||
|
- [API](#api)
|
||||||
|
- [SPA](#spa)
|
||||||
|
- [Development](#development)
|
||||||
|
- [Test](#test)
|
||||||
|
- [Docker](#docker)
|
||||||
|
- [Media Server Integration](#media-server-integration)
|
||||||
|
- [Annual Wrap-Up](#annual-wrap-up)
|
||||||
|
- [Contributing](#contributing)
|
||||||
|
- [License](#license)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
The fastest way to run Movies Diary is via Docker Compose:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
# Set JWT_SECRET and OMDB_API_KEY (or TMDB_API_KEY) in .env
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
Open `http://localhost:3000`. The HTTP server and background worker start together; data is persisted in a Docker volume.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -17,14 +60,28 @@ A self-hosted, server-side rendered movie logging system with a full REST API. B
|
|||||||
- Watchlist — add movies to watch later, per-user; federated watchlist entries visible for remote actors
|
- Watchlist — add movies to watch later, per-user; federated watchlist entries visible for remote actors
|
||||||
- User profiles — display name, bio, avatar, banner, custom profile fields; editable via HTML settings page or REST API
|
- User profiles — display name, bio, avatar, banner, custom profile fields; editable via HTML settings page or REST API
|
||||||
- Jellyfin/Plex auto-import — media server sends a webhook on playback stop, movies land in a watch queue; review and confirm with a rating to create diary entries; per-user webhook tokens with SHA-256 auth; setup UI at `/settings/integrations`
|
- Jellyfin/Plex auto-import — media server sends a webhook on playback stop, movies land in a watch queue; review and confirm with a rating to create diary entries; per-user webhook tokens with SHA-256 auth; setup UI at `/settings/integrations`
|
||||||
- Annual Wrap-Up — Spotify Wrapped for movies: per-user and instance-wide year-in-review with stats (top directors, actors, genres, rating distribution, watch time, rewatches, budget analysis), shareable HTML page at `/wrapups/{user_id}/{year}`, downloadable MP4 video with branded slides; admin-triggered or auto-generated in January
|
- Annual Wrap-Up — Spotify Wrapped for movies: per-user and instance-wide year-in-review with stats (top directors, actors, genres, rating distribution, watch time, rewatches, budget analysis), shareable HTML page at `/wrapups/{user_id}/{year}`; admin-triggered or auto-generated in January
|
||||||
|
- Goals — set a "watch N movies in YEAR" target with a progress bar; progress computed from existing reviews (backwards compatible); per-user federation toggle in settings; displayed on profile (SPA: interactive with create/edit/delete, classic HTML: read-only glassmorphic card)
|
||||||
- CSV and JSON diary export
|
- CSV and JSON diary export
|
||||||
- File importer: upload CSV, TSV, JSON, or XLSX from any source (Letterboxd, IMDb, etc.), map columns to domain fields via a step-by-step wizard or REST API, save mapping profiles for repeat imports
|
- File importer: upload CSV, TSV, JSON, or XLSX from any source (Letterboxd, IMDb, etc.), map columns to domain fields via a step-by-step wizard or REST API, save mapping profiles for repeat imports
|
||||||
- REST API v1 (`/api/v1/`) with full feature parity with the HTML interface
|
- REST API v1 (`/api/v1/`) with full feature parity with the HTML interface
|
||||||
- OpenAPI documentation at `/docs` (Swagger UI) and `/scalar` (Scalar)
|
- OpenAPI documentation at `/docs` (Swagger UI) and `/scalar` (Scalar)
|
||||||
- CSRF protection on all HTML form routes (double-submit cookie, defense-in-depth on top of `SameSite=Strict`)
|
- CSRF protection on all HTML form routes (double-submit cookie, defense-in-depth on top of `SameSite=Strict`)
|
||||||
- Per-IP rate limiting via token bucket (production-grade, backed by `axum-governor`)
|
- Per-IP rate limiting via token bucket (production-grade, backed by `axum-governor`)
|
||||||
- Terminal UI client (`crates/tui`) for logging reviews, bulk CSV import, and diary browsing
|
- Single-page app at `/app/` — React + TanStack Router + shadcn/ui, built with Vite, served from the backend with client-side routing fallback
|
||||||
|
- Terminal UI client (`crates/tui`, deprecated) for logging reviews, bulk CSV import, and diary browsing
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|
> SPA at `/app/` — React + TanStack Router + shadcn/ui
|
||||||
|
|
||||||
|
| Feed | Movie | Person |
|
||||||
|
|------|-------|--------|
|
||||||
|
|  |  |  |
|
||||||
|
|
||||||
|
| Profile | Wrap-Up | Wrap-Up card |
|
||||||
|
|---------|---------|--------------|
|
||||||
|
|  |  |  |
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
@@ -57,13 +114,13 @@ adapters/
|
|||||||
postgres-event-queue — durable polling event queue backed by PostgreSQL
|
postgres-event-queue — durable polling event queue backed by PostgreSQL
|
||||||
nats — NATS Core / JetStream event publisher and consumer
|
nats — NATS Core / JetStream event publisher and consumer
|
||||||
event-publisher — in-memory event channel (used in tests)
|
event-publisher — in-memory event channel (used in tests)
|
||||||
wrapup-renderer — annual wrap-up video generator (slide compositing via image/ab_glyph, stitching via ffmpeg)
|
|
||||||
activitypub — ActivityPub federation adapter (follow, inbox/outbox, actor); delegates to k-ap for protocol internals
|
activitypub — ActivityPub federation adapter (follow, inbox/outbox, actor); delegates to k-ap for protocol internals
|
||||||
sqlite-search — SQLite FTS5 implementation of SearchPort + SearchCommand
|
sqlite-search — SQLite FTS5 implementation of SearchPort + SearchCommand
|
||||||
postgres-search — PostgreSQL tsvector + GIN implementation of SearchPort + SearchCommand
|
postgres-search — PostgreSQL tsvector + GIN implementation of SearchPort + SearchCommand
|
||||||
sqlite-federation — SQLite-backed federation repository
|
sqlite-federation — SQLite-backed federation repository
|
||||||
postgres-federation — PostgreSQL-backed federation repository
|
postgres-federation — PostgreSQL-backed federation repository
|
||||||
tui — terminal UI client (ratatui); shares api-types with presentation for typed API access
|
tui — terminal UI client (ratatui); shares api-types with presentation for typed API access
|
||||||
|
spa/ — React SPA (TanStack Router + shadcn/ui + Vite); served at /app/ by the backend
|
||||||
```
|
```
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
@@ -73,63 +130,35 @@ tui — terminal UI client (ratatui); shares api-types with pres
|
|||||||
- Poster storage: local filesystem (zero deps) or an S3-compatible object store (e.g. MinIO)
|
- Poster storage: local filesystem (zero deps) or an S3-compatible object store (e.g. MinIO)
|
||||||
- An [OMDb API key](https://www.omdbapi.com/apikey.aspx)
|
- An [OMDb API key](https://www.omdbapi.com/apikey.aspx)
|
||||||
|
|
||||||
## Environment Variables
|
## Configuration
|
||||||
|
|
||||||
A `.env.example` file is provided at the repo root — copy it to `.env` and fill in your values.
|
Copy `.env.example` to `.env` and set the values below. Required fields must be set before the server will start.
|
||||||
|
|
||||||
```env
|
| Variable | Default | Required | Description |
|
||||||
# Database
|
|---|---|---|---|
|
||||||
DATABASE_URL=sqlite://movies.db
|
| `DATABASE_URL` | `sqlite://movies.db` | Yes | SQLite or PostgreSQL connection string |
|
||||||
|
| `JWT_SECRET` | — | Yes | Secret for JWT signing — use a long random string |
|
||||||
# Authentication
|
| `OMDB_API_KEY` | — | Yes | [OMDb](https://www.omdbapi.com/apikey.aspx) key for movie metadata |
|
||||||
JWT_SECRET=change-me
|
| `TMDB_API_KEY` | — | No | [TMDb](https://www.themoviedb.org/settings/api) key — enables cast, crew, genres, enrichment |
|
||||||
|
| `BASE_URL` | — | Yes | Public URL of your instance (used for ActivityPub actor URLs) |
|
||||||
# OMDb metadata
|
| `IMAGE_STORAGE_BACKEND` | `local` | No | `local` or `s3` |
|
||||||
OMDB_API_KEY=your-key
|
| `IMAGE_STORAGE_PATH` | `./images` | No | Path for local image storage |
|
||||||
|
| `MINIO_ENDPOINT` | — | S3 only | S3-compatible endpoint (e.g. `http://localhost:9000`) |
|
||||||
# TMDb metadata + enrichment (optional — enables full cast/crew/genre data)
|
| `MINIO_BUCKET` | — | S3 only | Bucket name |
|
||||||
# TMDB_API_KEY=your-key
|
| `MINIO_REGION` | — | S3 only | Region (e.g. `minio`) |
|
||||||
|
| `MINIO_ACCESS_KEY_ID` | — | S3 only | Access key ID |
|
||||||
# Public base URL (used for ActivityPub actor URLs and canonical links)
|
| `MINIO_SECRET_ACCESS_KEY` | — | S3 only | Secret access key |
|
||||||
BASE_URL=https://yourdomain.example.com
|
| `IMAGE_CONVERSION_ENABLED` | `false` | No | Convert stored images to AVIF or WebP |
|
||||||
|
| `IMAGE_CONVERSION_FORMAT` | `avif` | No | `avif` or `webp` |
|
||||||
# Image storage — pick one backend:
|
| `HOST` | `0.0.0.0` | No | Bind address |
|
||||||
|
| `PORT` | `3000` | No | HTTP port |
|
||||||
# Option A: local filesystem (zero deps)
|
| `RATE_LIMIT` | `60` | No | Requests per minute per IP |
|
||||||
IMAGE_STORAGE_BACKEND=local
|
| `ALLOW_REGISTRATION` | `true` | No | Set `false` to disable new sign-ups |
|
||||||
IMAGE_STORAGE_PATH=./images
|
| `SECURE_COOKIES` | `true` | No | Must be `true` when serving over HTTPS |
|
||||||
|
| `RUST_LOG` | — | No | Log verbosity (e.g. `presentation=info,worker=info`) |
|
||||||
# Option B: S3-compatible (MinIO, AWS S3, etc.)
|
| `CORS_ORIGINS` | `*` | No | Comma-separated allowed origins for SPA dev |
|
||||||
# IMAGE_STORAGE_BACKEND=s3
|
| `EVENT_BUS_BACKEND` | `db` | No | `db` (default) or `nats` |
|
||||||
# MINIO_ENDPOINT=http://localhost:9000
|
| `NATS_URL` | — | NATS only | NATS connection URL (e.g. `nats://localhost:4222`) |
|
||||||
# MINIO_BUCKET=posters
|
|
||||||
# MINIO_REGION=minio
|
|
||||||
# MINIO_ACCESS_KEY_ID=minioadmin
|
|
||||||
# MINIO_SECRET_ACCESS_KEY=minioadmin
|
|
||||||
|
|
||||||
# Image conversion (optional — converts stored images to AVIF or WebP to save space)
|
|
||||||
# IMAGE_CONVERSION_ENABLED=false
|
|
||||||
# IMAGE_CONVERSION_FORMAT=avif # avif or webp
|
|
||||||
|
|
||||||
# Annual Wrap-Up video (optional — requires ffmpeg)
|
|
||||||
# WRAPUP_FONT_PATH=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
|
|
||||||
# WRAPUP_LOGO_PATH=./static/logo.webp # watermark on video slides
|
|
||||||
# WRAPUP_BG_DIR=./static/wrapup-backgrounds # slide background images (jpg/png/webp)
|
|
||||||
# FFMPEG_PATH=ffmpeg
|
|
||||||
# WRAPUP_MAX_CONCURRENT=2 # max parallel video renders
|
|
||||||
|
|
||||||
# Optional
|
|
||||||
HOST=0.0.0.0
|
|
||||||
PORT=3000
|
|
||||||
RATE_LIMIT=60 # requests per minute per IP (default: 60)
|
|
||||||
ALLOW_REGISTRATION=true # set to false to disable new sign-ups
|
|
||||||
SECURE_COOKIES=true # set when serving over HTTPS
|
|
||||||
RUST_LOG=presentation=info,tower_http=info,worker=info,application=info
|
|
||||||
|
|
||||||
# Event bus — "db" (default, uses same database) or "nats"
|
|
||||||
EVENT_BUS_BACKEND=db
|
|
||||||
# NATS_URL=nats://localhost:4222 # required when EVENT_BUS_BACKEND=nats
|
|
||||||
```
|
|
||||||
|
|
||||||
The `worker` binary must run alongside `presentation` to process events:
|
The `worker` binary must run alongside `presentation` to process events:
|
||||||
|
|
||||||
@@ -155,13 +184,29 @@ Interactive API documentation is available at runtime:
|
|||||||
- **Swagger UI** — `http://localhost:3000/docs`
|
- **Swagger UI** — `http://localhost:3000/docs`
|
||||||
- **Scalar** — `http://localhost:3000/scalar`
|
- **Scalar** — `http://localhost:3000/scalar`
|
||||||
|
|
||||||
## Terminal UI
|
An [Insomnia](https://insomnia.rest/) collection covering all endpoints is included at [`movies-diary.insomnia.json`](movies-diary.insomnia.json). Import it via **File → Import**, set `base_url` and `token` in the environment, and you're ready to go.
|
||||||
|
|
||||||
|
## SPA
|
||||||
|
|
||||||
|
The single-page app lives in `spa/` and is served at `/app/` by the backend. For local development:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd spa && bun install && bun run dev # http://localhost:5173/app/
|
||||||
|
```
|
||||||
|
|
||||||
|
Set `CORS_ORIGINS=http://localhost:5173` in the backend `.env` to allow cross-origin API calls during development.
|
||||||
|
|
||||||
|
For production, `bun run build` outputs to `spa/dist/` which the backend serves statically (included in Docker image automatically).
|
||||||
|
|
||||||
|
## Terminal UI (deprecated)
|
||||||
|
|
||||||
|
> **Note:** The TUI was an experiment with ratatui and is no longer actively maintained. It may not support newer features (goals, watchlist, federation, etc.). Contributions welcome — if you'd like to maintain it, open a PR.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo run -p tui
|
cargo run -p tui
|
||||||
```
|
```
|
||||||
|
|
||||||
Supports review logging, bulk CSV import (column order matches the export format), and diary browsing with review history.
|
Supports review logging, bulk CSV import, and diary browsing.
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
@@ -178,46 +223,38 @@ make test # cargo test
|
|||||||
## Test
|
## Test
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo test # full workspace (requires DATABASE_URL for sqlx offline checks)
|
cargo test # full workspace (requires DATABASE_URL for sqlx offline checks)
|
||||||
cargo test -p application # domain-level unit tests only — no database required
|
cargo test -p application # business logic tests only — no database required
|
||||||
|
cargo test -p domain # domain model + value object tests
|
||||||
|
cargo llvm-cov -p application -p domain # line coverage report (requires cargo-llvm-cov)
|
||||||
```
|
```
|
||||||
|
|
||||||
The `application` crate has unit tests for core use cases backed by in-memory fakes from `domain`'s `test-helpers` feature. These run without a database and are the fastest feedback loop for business logic changes.
|
The `application` and `domain` crates have 400+ unit tests covering all use case modules (auth, diary, goals, import, integrations, movies, person, search, users, watchlist, wrapup) backed by in-memory fakes from `domain`'s `test-helpers` feature. These run without a database and are the fastest feedback loop for business logic changes.
|
||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
|
|
||||||
The image contains both `presentation` (HTTP server) and `worker` (event processor), plus `ffmpeg` and DejaVu fonts for wrap-up video generation. Run them as separate containers sharing the same data volume:
|
### Quick start
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Build (SQLite + federation + NATS support)
|
cp .env.example .env
|
||||||
docker build -t movies-diary \
|
# Edit .env — set JWT_SECRET and OMDB_API_KEY (or TMDB_API_KEY)
|
||||||
--build-arg FEATURES=sqlite,sqlite-federation,nats .
|
docker compose up -d
|
||||||
|
|
||||||
# HTTP server
|
|
||||||
docker run -p 3000:3000 \
|
|
||||||
-e DATABASE_URL=sqlite:///data/movies.db \
|
|
||||||
-e JWT_SECRET=change-me \
|
|
||||||
-e OMDB_API_KEY=your-key \
|
|
||||||
-e BASE_URL=https://yourdomain.example.com \
|
|
||||||
-e EVENT_BUS_BACKEND=nats \
|
|
||||||
-e NATS_URL=nats://nats:4222 \
|
|
||||||
-v $(pwd)/data:/data \
|
|
||||||
movies-diary
|
|
||||||
|
|
||||||
# Event worker (separate container, same image)
|
|
||||||
docker run \
|
|
||||||
-e DATABASE_URL=sqlite:///data/movies.db \
|
|
||||||
-e JWT_SECRET=change-me \
|
|
||||||
-e OMDB_API_KEY=your-key \
|
|
||||||
-e BASE_URL=https://yourdomain.example.com \
|
|
||||||
-e EVENT_BUS_BACKEND=nats \
|
|
||||||
-e NATS_URL=nats://nats:4222 \
|
|
||||||
-v $(pwd)/data:/data \
|
|
||||||
--entrypoint ./worker \
|
|
||||||
movies-diary
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To build for PostgreSQL: `--build-arg FEATURES=postgres,postgres-federation,nats`
|
This builds and starts the HTTP server (port 3000) and event worker. Data is persisted in a Docker volume.
|
||||||
|
|
||||||
|
### Manual docker run
|
||||||
|
|
||||||
|
The image contains both `presentation` and `worker` binaries. Run them as separate containers sharing the same data volume:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build -t movies-diary .
|
||||||
|
|
||||||
|
docker run -p 3000:3000 --env-file .env -v movies-diary-data:/data movies-diary
|
||||||
|
docker run --env-file .env -v movies-diary-data:/data --entrypoint ./worker movies-diary
|
||||||
|
```
|
||||||
|
|
||||||
|
Build for PostgreSQL: `--build-arg FEATURES=postgres,postgres-federation`
|
||||||
|
|
||||||
## Media Server Integration
|
## Media Server Integration
|
||||||
|
|
||||||
@@ -243,7 +280,7 @@ Movies you finish watching appear in your watch queue at `/watch-queue` — rate
|
|||||||
|
|
||||||
## Annual Wrap-Up
|
## Annual Wrap-Up
|
||||||
|
|
||||||
Generate a year-in-review summary for any user — top directors, actors, genres, rating distribution, total watch time, rewatch stats, and more. Available as a shareable HTML page and downloadable MP4 video.
|
Generate a year-in-review summary for any user — top directors, actors, genres, rating distribution, total watch time, rewatch stats, and more. Available as a shareable HTML page.
|
||||||
|
|
||||||
**Generate via API** (admin only):
|
**Generate via API** (admin only):
|
||||||
```bash
|
```bash
|
||||||
@@ -259,7 +296,9 @@ Omit `user_id` for a global instance wrap-up. The worker computes stats in the b
|
|||||||
|
|
||||||
**Auto-generate:** The worker runs a daily job in January that generates wrap-ups for all users with reviews in the previous year.
|
**Auto-generate:** The worker runs a daily job in January that generates wrap-ups for all users with reviews in the previous year.
|
||||||
|
|
||||||
**Video:** Requires `ffmpeg` installed. Set `WRAPUP_FONT_PATH` and `WRAPUP_LOGO_PATH` for branded slides. Set `WRAPUP_BG_DIR` to a directory of background images for frutiger aero-style glass-panel slides. Cast profile photos and movie posters are embedded automatically. Download via `GET /api/v1/wrapups/{id}/video`.
|
## Contributing
|
||||||
|
|
||||||
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions, architecture overview, and PR guidelines.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
140
architecture.mmd
Normal file
140
architecture.mmd
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
---
|
||||||
|
title: Movies Diary — Hexagonal Architecture
|
||||||
|
---
|
||||||
|
graph TB
|
||||||
|
subgraph Binaries["Binaries (Composition Root)"]
|
||||||
|
WEB["presentation<br/><i>Axum web server</i><br/>Routes, Handlers, Mappers"]
|
||||||
|
WORKER["worker<br/><i>Event consumer</i><br/>Concurrent dispatch, graceful shutdown"]
|
||||||
|
TUI["tui<br/><i>Terminal UI</i>"]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph Application["Application Layer"]
|
||||||
|
direction TB
|
||||||
|
CTX["AppContext<br/><i>Repositories + Services</i>"]
|
||||||
|
APP_PORTS["ReviewLogger<br/><i>application-layer port</i>"]
|
||||||
|
subgraph UseCases["Use Cases"]
|
||||||
|
UC_AUTH["auth<br/>login, register"]
|
||||||
|
UC_DIARY["diary<br/>log_review, get_diary,<br/>get_activity_feed, export"]
|
||||||
|
UC_MOVIES["movies<br/>get_movies, get_movie_profile,<br/>enrich_movie, request_enrichment,<br/>sync_poster, reindex_search"]
|
||||||
|
UC_IMPORT["import<br/>create_session, apply_mapping,<br/>execute, profiles"]
|
||||||
|
UC_USERS["users<br/>get_users, get_profile,<br/>update_profile"]
|
||||||
|
UC_WATCHLIST["watchlist<br/>add, remove, get"]
|
||||||
|
UC_WRAPUP["wrapup<br/>generate, compute,<br/>list, delete"]
|
||||||
|
UC_GOALS["goals<br/>create, update, delete,<br/>get, list"]
|
||||||
|
UC_INTEGRATIONS["integrations<br/>webhooks, watch_queue,<br/>confirm, dismiss"]
|
||||||
|
UC_SEARCH["search<br/>execute"]
|
||||||
|
UC_PERSON["person<br/>get, get_credits"]
|
||||||
|
end
|
||||||
|
subgraph EventHandlers["Event Handlers"]
|
||||||
|
EH_ENRICH["EnrichmentHandler"]
|
||||||
|
EH_DISCOVER["MovieDiscoveryIndexer"]
|
||||||
|
EH_CLEANUP["SearchCleanupHandler"]
|
||||||
|
EH_REINDEX["SearchReindexHandler"]
|
||||||
|
EH_WRAPUP["WrapUpEventHandler"]
|
||||||
|
end
|
||||||
|
subgraph Jobs["Periodic Jobs"]
|
||||||
|
JOB_IMPORT["ImportSessionCleanup"]
|
||||||
|
JOB_WATCH["WatchEventCleanup"]
|
||||||
|
JOB_STALE["EnrichmentStaleness"]
|
||||||
|
JOB_WRAPGEN["WrapUpAutoGenerate"]
|
||||||
|
end
|
||||||
|
WORKER_SVC["WorkerService<br/><i>Semaphore(8), JoinSet,<br/>shutdown signal</i>"]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph Domain["Domain Layer (0 dependencies)"]
|
||||||
|
direction TB
|
||||||
|
subgraph Models["Models"]
|
||||||
|
M_MOVIE["Movie, MovieSummary,<br/>MovieProfile"]
|
||||||
|
M_REVIEW["Review, DiaryEntry,<br/>FeedEntry"]
|
||||||
|
M_USER["User, UserSummary"]
|
||||||
|
M_PERSON["Person, PersonId,<br/>PersonCredits"]
|
||||||
|
M_WATCHLIST["WatchlistEntry,<br/>WatchEvent"]
|
||||||
|
M_GOAL["Goal, GoalWithProgress,<br/>UserSettings, RemoteGoalEntry"]
|
||||||
|
M_WRAPUP["WrapUpReport,<br/>MovieRef, PersonStat"]
|
||||||
|
M_SEARCH["SearchQuery,<br/>SearchResults"]
|
||||||
|
end
|
||||||
|
subgraph Ports["Port Traits (Interfaces)"]
|
||||||
|
P_REPOS["MovieRepository<br/>ReviewRepository<br/>DiaryRepository<br/>UserRepository<br/>WatchlistRepository<br/>WatchEventRepository<br/>WebhookTokenRepository<br/>ImportSessionRepository<br/>MovieProfileRepository<br/>WrapUpRepository<br/>GoalRepository<br/>UserSettingsRepository"]
|
||||||
|
P_SERVICES["AuthService<br/>MetadataClient<br/>PosterFetcherClient<br/>ObjectStorage<br/>EventPublisher<br/>EventConsumer<br/>PasswordHasher<br/>DiaryExporter<br/>DocumentParser"]
|
||||||
|
P_SEARCH["SearchPort<br/>SearchCommand<br/>PersonQuery<br/>PersonCommand"]
|
||||||
|
P_FEDERATION["SocialQueryPort<br/>LocalApContentQuery<br/>RemoteWatchlistRepository<br/>RemoteGoalRepository"]
|
||||||
|
end
|
||||||
|
subgraph DomainServices["Services (pure, no I/O)"]
|
||||||
|
DS_WRAPUP["WrapUpAnalyzer<br/><i>build_report, compute_*</i>"]
|
||||||
|
DS_REVIEW["ReviewHistoryAnalyzer<br/><i>rating_trend</i>"]
|
||||||
|
end
|
||||||
|
EVENTS["DomainEvent enum<br/><i>ReviewLogged, MovieDiscovered,<br/>GoalCreated, GoalUpdated,<br/>SearchReindexRequested, ...</i>"]
|
||||||
|
VO["Value Objects<br/><i>MovieId, UserId, Rating,<br/>Email, Username, Password, ...</i>"]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph ApiTypes["api-types (0 domain deps)"]
|
||||||
|
DTO["DTOs<br/><i>MovieDto, ReviewDto,<br/>FeedEntryDto, UserSummaryDto,<br/>CastMemberDto, ...</i>"]
|
||||||
|
end
|
||||||
|
|
||||||
|
subgraph Adapters["Adapters (implement Port Traits)"]
|
||||||
|
direction TB
|
||||||
|
subgraph Storage["Storage"]
|
||||||
|
A_SQLITE["sqlite<br/><i>SQLite repos</i>"]
|
||||||
|
A_PG["postgres<br/><i>PostgreSQL repos</i>"]
|
||||||
|
A_SQLITE_SEARCH["sqlite-search<br/><i>FTS5</i>"]
|
||||||
|
A_PG_SEARCH["postgres-search<br/><i>tsvector/GIN</i>"]
|
||||||
|
A_OBJ["object-storage<br/><i>S3 / filesystem</i>"]
|
||||||
|
end
|
||||||
|
subgraph Messaging["Messaging"]
|
||||||
|
A_NATS["nats<br/><i>JetStream / Core</i>"]
|
||||||
|
A_PG_QUEUE["postgres-event-queue<br/><i>Polling, dead-letter</i>"]
|
||||||
|
A_PAYLOAD["event-payload<br/><i>Serde (de)serialization</i>"]
|
||||||
|
end
|
||||||
|
subgraph External["External Services"]
|
||||||
|
A_METADATA["metadata<br/><i>TMDB search/details</i>"]
|
||||||
|
A_TMDB["tmdb-enrichment<br/><i>Credits, keywords, cast</i>"]
|
||||||
|
A_POSTER["poster-fetcher<br/><i>TMDB image download</i>"]
|
||||||
|
A_AUTH["auth<br/><i>JWT tokens</i>"]
|
||||||
|
end
|
||||||
|
subgraph Federation["Federation (feature-gated)"]
|
||||||
|
A_AP["activitypub<br/><i>k_ap library</i>"]
|
||||||
|
A_SQLITE_FED["sqlite-federation"]
|
||||||
|
A_PG_FED["postgres-federation"]
|
||||||
|
end
|
||||||
|
subgraph Media["Media Processing"]
|
||||||
|
A_IMG["image-converter<br/><i>AVIF/WebP</i>"]
|
||||||
|
A_POSTER_SYNC["poster-sync"]
|
||||||
|
end
|
||||||
|
subgraph Presentation["Presentation Helpers"]
|
||||||
|
A_TEMPLATE["template-askama<br/><i>HTML templates</i>"]
|
||||||
|
A_RSS["rss<br/><i>Feed generation</i>"]
|
||||||
|
A_EXPORT["export<br/><i>CSV/JSON diary</i>"]
|
||||||
|
A_IMPORT["importer<br/><i>CSV/JSON/XLSX parser</i>"]
|
||||||
|
end
|
||||||
|
subgraph Webhooks["Webhook Parsers"]
|
||||||
|
A_JELLYFIN["jellyfin"]
|
||||||
|
A_PLEX["plex"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
%% Dependency arrows
|
||||||
|
WEB -->|"uses"| Application
|
||||||
|
WEB -->|"maps to"| ApiTypes
|
||||||
|
WORKER -->|"uses"| Application
|
||||||
|
|
||||||
|
Application -->|"depends on"| Domain
|
||||||
|
UC_WRAPUP -->|"delegates to"| DS_WRAPUP
|
||||||
|
|
||||||
|
Adapters -.->|"implements"| Ports
|
||||||
|
|
||||||
|
%% Key data flows
|
||||||
|
WEB ===|"HTTP"| DTO
|
||||||
|
WORKER ===|"Events"| EVENTS
|
||||||
|
|
||||||
|
classDef domain fill:#1a1a2e,stroke:#e94560,color:#fff
|
||||||
|
classDef app fill:#16213e,stroke:#0f3460,color:#fff
|
||||||
|
classDef adapter fill:#0f3460,stroke:#533483,color:#fff
|
||||||
|
classDef binary fill:#533483,stroke:#e94560,color:#fff
|
||||||
|
classDef api fill:#2a2a4a,stroke:#e94560,color:#fff
|
||||||
|
|
||||||
|
class Domain domain
|
||||||
|
class DomainServices domain
|
||||||
|
class Application app
|
||||||
|
class Adapters adapter
|
||||||
|
class Binaries binary
|
||||||
|
class ApiTypes api
|
||||||
@@ -5,11 +5,15 @@ use chrono::{DateTime, Utc};
|
|||||||
use k_ap::{ApContentReader, ApObjectHandler};
|
use k_ap::{ApContentReader, ApObjectHandler};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{review_handler::ReviewObjectHandler, watchlist_handler::WatchlistObjectHandler};
|
use crate::{
|
||||||
|
goal_handler::GoalObjectHandler, review_handler::ReviewObjectHandler,
|
||||||
|
watchlist_handler::WatchlistObjectHandler,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct CompositeObjectHandler {
|
pub struct CompositeObjectHandler {
|
||||||
pub review: Arc<ReviewObjectHandler>,
|
pub review: Arc<ReviewObjectHandler>,
|
||||||
pub watchlist: Arc<WatchlistObjectHandler>,
|
pub watchlist: Arc<WatchlistObjectHandler>,
|
||||||
|
pub goal: Arc<GoalObjectHandler>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -40,8 +44,11 @@ impl ApObjectHandler for CompositeObjectHandler {
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let is_watchlist = object.get("watchlistEntry").and_then(|v| v.as_bool()) == Some(true)
|
let is_watchlist = object.get("watchlistEntry").and_then(|v| v.as_bool()) == Some(true)
|
||||||
|| (object.get("movieTitle").is_some() && object.get("rating").is_none());
|
|| (object.get("movieTitle").is_some() && object.get("rating").is_none());
|
||||||
|
let is_goal = object.get("goal").and_then(|v| v.as_bool()) == Some(true);
|
||||||
if object.get("rating").is_some() {
|
if object.get("rating").is_some() {
|
||||||
self.review.on_create(ap_id, actor_url, object).await
|
self.review.on_create(ap_id, actor_url, object).await
|
||||||
|
} else if is_goal {
|
||||||
|
self.goal.on_create(ap_id, actor_url, object).await
|
||||||
} else if is_watchlist {
|
} else if is_watchlist {
|
||||||
self.watchlist.on_create(ap_id, actor_url, object).await
|
self.watchlist.on_create(ap_id, actor_url, object).await
|
||||||
} else {
|
} else {
|
||||||
@@ -56,8 +63,11 @@ impl ApObjectHandler for CompositeObjectHandler {
|
|||||||
actor_url: &Url,
|
actor_url: &Url,
|
||||||
object: serde_json::Value,
|
object: serde_json::Value,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
let is_goal = object.get("goal").and_then(|v| v.as_bool()) == Some(true);
|
||||||
if object.get("rating").is_some() {
|
if object.get("rating").is_some() {
|
||||||
self.review.on_update(ap_id, actor_url, object).await
|
self.review.on_update(ap_id, actor_url, object).await
|
||||||
|
} else if is_goal {
|
||||||
|
self.goal.on_update(ap_id, actor_url, object).await
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -66,12 +76,14 @@ impl ApObjectHandler for CompositeObjectHandler {
|
|||||||
async fn on_delete(&self, ap_id: &Url, actor_url: &Url) -> anyhow::Result<()> {
|
async fn on_delete(&self, ap_id: &Url, actor_url: &Url) -> anyhow::Result<()> {
|
||||||
self.review.on_delete(ap_id, actor_url).await?;
|
self.review.on_delete(ap_id, actor_url).await?;
|
||||||
self.watchlist.on_delete(ap_id, actor_url).await?;
|
self.watchlist.on_delete(ap_id, actor_url).await?;
|
||||||
|
self.goal.on_delete(ap_id, actor_url).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn on_actor_removed(&self, actor_url: &Url) -> anyhow::Result<()> {
|
async fn on_actor_removed(&self, actor_url: &Url) -> anyhow::Result<()> {
|
||||||
self.review.on_actor_removed(actor_url).await?;
|
self.review.on_actor_removed(actor_url).await?;
|
||||||
self.watchlist.on_actor_removed(actor_url).await?;
|
self.watchlist.on_actor_removed(actor_url).await?;
|
||||||
|
self.goal.on_actor_removed(actor_url).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use chrono::Datelike;
|
||||||
use domain::ports::EventHandler;
|
use domain::ports::EventHandler;
|
||||||
use domain::{
|
use domain::{
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
events::DomainEvent,
|
events::DomainEvent,
|
||||||
ports::LocalApContentQuery,
|
ports::{LocalApContentQuery, UserFederationSettingsQuery},
|
||||||
value_objects::{ReviewId, UserId},
|
value_objects::{MovieId, ReviewId, UserId},
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use k_ap::{ActivityPubService, ApVisibility};
|
use k_ap::{ActivityPubService, ApVisibility};
|
||||||
|
|
||||||
use crate::objects::review_to_ap_object;
|
use crate::objects::{goal_to_ap_object, review_to_ap_object};
|
||||||
use crate::urls::{actor_url, review_url};
|
use crate::urls::{actor_url, goal_url, review_url};
|
||||||
|
|
||||||
pub struct ActivityPubEventHandler {
|
pub struct ActivityPubEventHandler {
|
||||||
ap_service: Arc<ActivityPubService>,
|
ap_service: Arc<ActivityPubService>,
|
||||||
content_query: Arc<dyn LocalApContentQuery>,
|
content_query: Arc<dyn LocalApContentQuery>,
|
||||||
|
federation_settings: Arc<dyn UserFederationSettingsQuery>,
|
||||||
base_url: String,
|
base_url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,11 +25,13 @@ impl ActivityPubEventHandler {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
ap_service: Arc<ActivityPubService>,
|
ap_service: Arc<ActivityPubService>,
|
||||||
content_query: Arc<dyn LocalApContentQuery>,
|
content_query: Arc<dyn LocalApContentQuery>,
|
||||||
|
federation_settings: Arc<dyn UserFederationSettingsQuery>,
|
||||||
base_url: String,
|
base_url: String,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
ap_service,
|
ap_service,
|
||||||
content_query,
|
content_query,
|
||||||
|
federation_settings,
|
||||||
base_url,
|
base_url,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,6 +101,32 @@ impl EventHandler for ActivityPubEventHandler {
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| DomainError::InfrastructureError(e.to_string()))
|
.map_err(|e| DomainError::InfrastructureError(e.to_string()))
|
||||||
}
|
}
|
||||||
|
DomainEvent::PosterSynced { movie_id } => self
|
||||||
|
.on_poster_synced(movie_id)
|
||||||
|
.await
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(e.to_string())),
|
||||||
|
DomainEvent::GoalCreated {
|
||||||
|
user_id,
|
||||||
|
year,
|
||||||
|
target_count,
|
||||||
|
..
|
||||||
|
} => self
|
||||||
|
.broadcast_goal(user_id, *year, *target_count, true)
|
||||||
|
.await
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(e.to_string())),
|
||||||
|
DomainEvent::GoalUpdated {
|
||||||
|
user_id,
|
||||||
|
year,
|
||||||
|
target_count,
|
||||||
|
..
|
||||||
|
} => self
|
||||||
|
.broadcast_goal(user_id, *year, *target_count, false)
|
||||||
|
.await
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(e.to_string())),
|
||||||
|
DomainEvent::GoalDeleted { user_id, year, .. } => self
|
||||||
|
.on_goal_deleted(user_id, *year)
|
||||||
|
.await
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(e.to_string())),
|
||||||
_ => Ok(()),
|
_ => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,6 +134,19 @@ impl EventHandler for ActivityPubEventHandler {
|
|||||||
|
|
||||||
impl ActivityPubEventHandler {
|
impl ActivityPubEventHandler {
|
||||||
async fn on_review_logged(&self, user_id: &UserId, review_id: &ReviewId) -> anyhow::Result<()> {
|
async fn on_review_logged(&self, user_id: &UserId, review_id: &ReviewId) -> anyhow::Result<()> {
|
||||||
|
let flags = self
|
||||||
|
.federation_settings
|
||||||
|
.get_federation_flags(user_id)
|
||||||
|
.await
|
||||||
|
.unwrap_or(domain::ports::FederationFlags {
|
||||||
|
goals: true,
|
||||||
|
reviews: true,
|
||||||
|
watchlist: true,
|
||||||
|
});
|
||||||
|
if !flags.reviews {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let review = match self.content_query.get_review_by_id(review_id).await? {
|
let review = match self.content_query.get_review_by_id(review_id).await? {
|
||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => return Ok(()),
|
None => return Ok(()),
|
||||||
@@ -146,6 +189,9 @@ impl ActivityPubEventHandler {
|
|||||||
.broadcast_create_note(user_id.value(), json, ApVisibility::Public, vec![])
|
.broadcast_create_note(user_id.value(), json, ApVisibility::Public, vec![])
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
let year = review.watched_at().year() as u16;
|
||||||
|
self.broadcast_goal_progress_update(user_id, year).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +200,19 @@ impl ActivityPubEventHandler {
|
|||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
review_id: &ReviewId,
|
review_id: &ReviewId,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
let flags = self
|
||||||
|
.federation_settings
|
||||||
|
.get_federation_flags(user_id)
|
||||||
|
.await
|
||||||
|
.unwrap_or(domain::ports::FederationFlags {
|
||||||
|
goals: true,
|
||||||
|
reviews: true,
|
||||||
|
watchlist: true,
|
||||||
|
});
|
||||||
|
if !flags.reviews {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let review = match self.content_query.get_review_by_id(review_id).await? {
|
let review = match self.content_query.get_review_by_id(review_id).await? {
|
||||||
Some(r) => r,
|
Some(r) => r,
|
||||||
None => return Ok(()),
|
None => return Ok(()),
|
||||||
@@ -220,6 +279,19 @@ impl ActivityPubEventHandler {
|
|||||||
external_metadata_id: &Option<String>,
|
external_metadata_id: &Option<String>,
|
||||||
added_at: &chrono::NaiveDateTime,
|
added_at: &chrono::NaiveDateTime,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
let flags = self
|
||||||
|
.federation_settings
|
||||||
|
.get_federation_flags(user_id)
|
||||||
|
.await
|
||||||
|
.unwrap_or(domain::ports::FederationFlags {
|
||||||
|
goals: true,
|
||||||
|
reviews: true,
|
||||||
|
watchlist: true,
|
||||||
|
});
|
||||||
|
if !flags.watchlist {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
use crate::urls::watchlist_entry_url;
|
use crate::urls::watchlist_entry_url;
|
||||||
let ap_id = watchlist_entry_url(&self.base_url, user_id.value(), movie_id.value());
|
let ap_id = watchlist_entry_url(&self.base_url, user_id.value(), movie_id.value());
|
||||||
let actor = actor_url(&self.base_url, user_id.value());
|
let actor = actor_url(&self.base_url, user_id.value());
|
||||||
@@ -267,4 +339,165 @@ impl ActivityPubEventHandler {
|
|||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn on_poster_synced(&self, movie_id: &MovieId) -> anyhow::Result<()> {
|
||||||
|
let entries = self
|
||||||
|
.content_query
|
||||||
|
.get_local_reviews_for_movie(movie_id)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let movie = self.content_query.get_movie_by_id(movie_id).await?;
|
||||||
|
let movie = match movie {
|
||||||
|
Some(m) => m,
|
||||||
|
None => return Ok(()),
|
||||||
|
};
|
||||||
|
let poster_url = movie
|
||||||
|
.poster_path()
|
||||||
|
.map(|p| format!("{}/images/{}", self.base_url, p.value()));
|
||||||
|
|
||||||
|
for entry in entries {
|
||||||
|
let review = entry.review();
|
||||||
|
let user_id = review.user_id();
|
||||||
|
|
||||||
|
let flags = self
|
||||||
|
.federation_settings
|
||||||
|
.get_federation_flags(user_id)
|
||||||
|
.await
|
||||||
|
.unwrap_or(domain::ports::FederationFlags {
|
||||||
|
goals: true,
|
||||||
|
reviews: true,
|
||||||
|
watchlist: true,
|
||||||
|
});
|
||||||
|
if !flags.reviews {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let ap_id = review_url(&self.base_url, review.id());
|
||||||
|
let actor = actor_url(&self.base_url, user_id.value());
|
||||||
|
|
||||||
|
let obj = review_to_ap_object(
|
||||||
|
review,
|
||||||
|
ap_id,
|
||||||
|
actor,
|
||||||
|
movie.title().value().to_string(),
|
||||||
|
movie.release_year().value(),
|
||||||
|
poster_url.clone(),
|
||||||
|
&self.base_url,
|
||||||
|
);
|
||||||
|
let json = serde_json::to_value(obj)?;
|
||||||
|
|
||||||
|
self.ap_service
|
||||||
|
.broadcast_update_note(user_id.value(), json, ApVisibility::Public, vec![])
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn broadcast_goal_progress_update(
|
||||||
|
&self,
|
||||||
|
user_id: &UserId,
|
||||||
|
year: u16,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
let flags = self
|
||||||
|
.federation_settings
|
||||||
|
.get_federation_flags(user_id)
|
||||||
|
.await
|
||||||
|
.unwrap_or(domain::ports::FederationFlags {
|
||||||
|
goals: true,
|
||||||
|
reviews: true,
|
||||||
|
watchlist: true,
|
||||||
|
});
|
||||||
|
if !flags.goals {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let Some((goal, current)) = self
|
||||||
|
.content_query
|
||||||
|
.get_goal_with_progress(user_id, year)
|
||||||
|
.await
|
||||||
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
let ap_id = goal_url(&self.base_url, user_id.value(), year);
|
||||||
|
let actor = actor_url(&self.base_url, user_id.value());
|
||||||
|
let obj = goal_to_ap_object(
|
||||||
|
ap_id,
|
||||||
|
actor,
|
||||||
|
year,
|
||||||
|
goal.target_count(),
|
||||||
|
current,
|
||||||
|
&self.base_url,
|
||||||
|
);
|
||||||
|
let json = serde_json::to_value(obj)?;
|
||||||
|
self.ap_service
|
||||||
|
.broadcast_update_note(user_id.value(), json, ApVisibility::Public, vec![])
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn broadcast_goal(
|
||||||
|
&self,
|
||||||
|
user_id: &UserId,
|
||||||
|
year: u16,
|
||||||
|
target_count: u32,
|
||||||
|
is_create: bool,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
let flags = self
|
||||||
|
.federation_settings
|
||||||
|
.get_federation_flags(user_id)
|
||||||
|
.await
|
||||||
|
.unwrap_or(domain::ports::FederationFlags {
|
||||||
|
goals: true,
|
||||||
|
reviews: true,
|
||||||
|
watchlist: true,
|
||||||
|
});
|
||||||
|
if !flags.goals {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let current = self
|
||||||
|
.content_query
|
||||||
|
.get_goal_with_progress(user_id, year)
|
||||||
|
.await
|
||||||
|
.ok()
|
||||||
|
.flatten()
|
||||||
|
.map(|(_, c)| c)
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
let ap_id = goal_url(&self.base_url, user_id.value(), year);
|
||||||
|
let actor = actor_url(&self.base_url, user_id.value());
|
||||||
|
let obj = goal_to_ap_object(ap_id, actor, year, target_count, current, &self.base_url);
|
||||||
|
let json = serde_json::to_value(obj)?;
|
||||||
|
if is_create {
|
||||||
|
self.ap_service
|
||||||
|
.broadcast_create_note(user_id.value(), json, ApVisibility::Public, vec![])
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
|
self.ap_service
|
||||||
|
.broadcast_update_note(user_id.value(), json, ApVisibility::Public, vec![])
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn on_goal_deleted(&self, user_id: &UserId, year: u16) -> anyhow::Result<()> {
|
||||||
|
let flags = self
|
||||||
|
.federation_settings
|
||||||
|
.get_federation_flags(user_id)
|
||||||
|
.await
|
||||||
|
.unwrap_or(domain::ports::FederationFlags {
|
||||||
|
goals: true,
|
||||||
|
reviews: true,
|
||||||
|
watchlist: true,
|
||||||
|
});
|
||||||
|
if !flags.goals {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let ap_id = goal_url(&self.base_url, user_id.value(), year);
|
||||||
|
self.ap_service
|
||||||
|
.broadcast_delete_to_followers(user_id.value(), ap_id)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
95
crates/adapters/activitypub/src/goal_handler.rs
Normal file
95
crates/adapters/activitypub/src/goal_handler.rs
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use domain::{models::RemoteGoalEntry, ports::RemoteGoalRepository};
|
||||||
|
use k_ap::ApObjectHandler;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
use crate::objects::GoalObject;
|
||||||
|
|
||||||
|
pub struct GoalObjectHandler {
|
||||||
|
pub remote_goal_repo: Arc<dyn RemoteGoalRepository>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl ApObjectHandler for GoalObjectHandler {
|
||||||
|
async fn on_create(
|
||||||
|
&self,
|
||||||
|
ap_id: &Url,
|
||||||
|
actor_url: &Url,
|
||||||
|
object: serde_json::Value,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
let obj: GoalObject = match serde_json::from_value(object) {
|
||||||
|
Ok(o) => o,
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!(ap_id = %ap_id, "ignoring malformed goal Create: {}", e);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let entry = RemoteGoalEntry {
|
||||||
|
ap_id: ap_id.as_str().to_string(),
|
||||||
|
actor_url: actor_url.as_str().to_string(),
|
||||||
|
year: obj.goal_year,
|
||||||
|
target_count: obj.goal_target,
|
||||||
|
current_count: obj.goal_current,
|
||||||
|
received_at: chrono::Utc::now(),
|
||||||
|
};
|
||||||
|
self.remote_goal_repo.save(entry).await?;
|
||||||
|
tracing::info!(ap_id = %ap_id, year = obj.goal_year, "saved remote goal");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn on_update(
|
||||||
|
&self,
|
||||||
|
ap_id: &Url,
|
||||||
|
actor_url: &Url,
|
||||||
|
object: serde_json::Value,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
let obj: GoalObject = match serde_json::from_value(object) {
|
||||||
|
Ok(o) => o,
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!(ap_id = %ap_id, "ignoring malformed goal Update: {}", e);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if obj.attributed_to != *actor_url {
|
||||||
|
anyhow::bail!("goal Update actor does not match object attributed_to");
|
||||||
|
}
|
||||||
|
self.remote_goal_repo
|
||||||
|
.update_by_ap_id(ap_id.as_str(), obj.goal_target, obj.goal_current)
|
||||||
|
.await?;
|
||||||
|
tracing::info!(ap_id = %ap_id, "updated remote goal progress");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn on_delete(&self, ap_id: &Url, actor_url: &Url) -> anyhow::Result<()> {
|
||||||
|
self.remote_goal_repo
|
||||||
|
.remove_by_ap_id(ap_id.as_str(), actor_url.as_str())
|
||||||
|
.await?;
|
||||||
|
tracing::info!(ap_id = %ap_id, "removed remote goal");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn on_actor_removed(&self, actor_url: &Url) -> anyhow::Result<()> {
|
||||||
|
self.remote_goal_repo
|
||||||
|
.remove_all_by_actor(actor_url.as_str())
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn on_like(&self, _: &Url, _: &Url) -> anyhow::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
async fn on_announce_received(&self, _: &Url, _: &Url) -> anyhow::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
async fn on_announce_of_remote(&self, _: &Url, _: &Url) -> anyhow::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
async fn on_unlike(&self, _: &Url, _: &Url) -> anyhow::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
async fn on_mention(&self, _: &Url, _: uuid::Uuid, _: &Url) -> anyhow::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
pub mod composite_handler;
|
pub mod composite_handler;
|
||||||
pub mod event_handler;
|
pub mod event_handler;
|
||||||
pub mod federation_event_bridge;
|
pub mod federation_event_bridge;
|
||||||
|
pub mod goal_handler;
|
||||||
pub mod objects;
|
pub mod objects;
|
||||||
pub mod port;
|
pub mod port;
|
||||||
pub mod remote_review_repository;
|
pub mod remote_review_repository;
|
||||||
@@ -48,8 +49,10 @@ pub struct ActivityPubDeps {
|
|||||||
pub blocklist_repo: std::sync::Arc<dyn BlocklistRepository>,
|
pub blocklist_repo: std::sync::Arc<dyn BlocklistRepository>,
|
||||||
pub review_store: std::sync::Arc<dyn RemoteReviewRepository>,
|
pub review_store: std::sync::Arc<dyn RemoteReviewRepository>,
|
||||||
pub remote_watchlist_repo: std::sync::Arc<dyn domain::ports::RemoteWatchlistRepository>,
|
pub remote_watchlist_repo: std::sync::Arc<dyn domain::ports::RemoteWatchlistRepository>,
|
||||||
|
pub remote_goal_repo: std::sync::Arc<dyn domain::ports::RemoteGoalRepository>,
|
||||||
pub local_ap_content: std::sync::Arc<dyn domain::ports::LocalApContentQuery>,
|
pub local_ap_content: std::sync::Arc<dyn domain::ports::LocalApContentQuery>,
|
||||||
pub user_repo: std::sync::Arc<dyn domain::ports::UserRepository>,
|
pub user_repo: std::sync::Arc<dyn domain::ports::UserRepository>,
|
||||||
|
pub federation_settings: std::sync::Arc<dyn domain::ports::UserFederationSettingsQuery>,
|
||||||
pub base_url: String,
|
pub base_url: String,
|
||||||
pub allow_registration: bool,
|
pub allow_registration: bool,
|
||||||
pub event_publisher: std::sync::Arc<dyn domain::ports::EventPublisher>,
|
pub event_publisher: std::sync::Arc<dyn domain::ports::EventPublisher>,
|
||||||
@@ -63,8 +66,10 @@ pub async fn wire(deps: ActivityPubDeps) -> anyhow::Result<ActivityPubWire> {
|
|||||||
blocklist_repo,
|
blocklist_repo,
|
||||||
review_store,
|
review_store,
|
||||||
remote_watchlist_repo,
|
remote_watchlist_repo,
|
||||||
|
remote_goal_repo,
|
||||||
local_ap_content,
|
local_ap_content,
|
||||||
user_repo,
|
user_repo,
|
||||||
|
federation_settings,
|
||||||
base_url,
|
base_url,
|
||||||
allow_registration,
|
allow_registration,
|
||||||
event_publisher,
|
event_publisher,
|
||||||
@@ -79,9 +84,11 @@ pub async fn wire(deps: ActivityPubDeps) -> anyhow::Result<ActivityPubWire> {
|
|||||||
content_query: std::sync::Arc::clone(&local_ap_content),
|
content_query: std::sync::Arc::clone(&local_ap_content),
|
||||||
base_url: base_url.clone(),
|
base_url: base_url.clone(),
|
||||||
});
|
});
|
||||||
|
let goal_handler = std::sync::Arc::new(goal_handler::GoalObjectHandler { remote_goal_repo });
|
||||||
let composite = std::sync::Arc::new(composite_handler::CompositeObjectHandler {
|
let composite = std::sync::Arc::new(composite_handler::CompositeObjectHandler {
|
||||||
review: review_handler,
|
review: review_handler,
|
||||||
watchlist: watchlist_handler,
|
watchlist: watchlist_handler,
|
||||||
|
goal: goal_handler,
|
||||||
});
|
});
|
||||||
|
|
||||||
let federation_debug = std::env::var("FEDERATION_DEBUG")
|
let federation_debug = std::env::var("FEDERATION_DEBUG")
|
||||||
@@ -124,6 +131,7 @@ pub async fn wire(deps: ActivityPubDeps) -> anyhow::Result<ActivityPubWire> {
|
|||||||
let event_handler = std::sync::Arc::new(ActivityPubEventHandler::new(
|
let event_handler = std::sync::Arc::new(ActivityPubEventHandler::new(
|
||||||
std::sync::Arc::clone(&concrete),
|
std::sync::Arc::clone(&concrete),
|
||||||
local_ap_content,
|
local_ap_content,
|
||||||
|
federation_settings,
|
||||||
base_url,
|
base_url,
|
||||||
)) as std::sync::Arc<dyn domain::ports::EventHandler>;
|
)) as std::sync::Arc<dyn domain::ports::EventHandler>;
|
||||||
|
|
||||||
|
|||||||
@@ -191,6 +191,64 @@ pub fn watchlist_to_ap_object(input: WatchlistApInput) -> WatchlistObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Goal object ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct GoalObject {
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub(crate) kind: NoteType,
|
||||||
|
pub(crate) id: Url,
|
||||||
|
pub(crate) attributed_to: Url,
|
||||||
|
pub(crate) content: String,
|
||||||
|
pub(crate) published: chrono::DateTime<chrono::Utc>,
|
||||||
|
pub(crate) goal_year: u16,
|
||||||
|
pub(crate) goal_target: u32,
|
||||||
|
pub(crate) goal_current: u32,
|
||||||
|
#[serde(default)]
|
||||||
|
pub(crate) goal: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub(crate) tag: Vec<ApHashtag>,
|
||||||
|
#[serde(skip_serializing_if = "Vec::is_empty", default)]
|
||||||
|
pub(crate) to: Vec<String>,
|
||||||
|
#[serde(skip_serializing_if = "Vec::is_empty", default)]
|
||||||
|
pub(crate) cc: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn goal_to_ap_object(
|
||||||
|
ap_id: Url,
|
||||||
|
actor_url: Url,
|
||||||
|
year: u16,
|
||||||
|
target: u32,
|
||||||
|
current: u32,
|
||||||
|
base_url: &str,
|
||||||
|
) -> GoalObject {
|
||||||
|
let content = format!(
|
||||||
|
"🎯 Goal: Watch {} movies in {} ({}/{})",
|
||||||
|
target, year, current, target
|
||||||
|
);
|
||||||
|
let tag = vec![ApHashtag {
|
||||||
|
kind: "Hashtag".to_string(),
|
||||||
|
href: Url::parse(&format!("{}/tags/moviesdiary", base_url)).expect("valid base_url"),
|
||||||
|
name: "#MoviesDiary".to_string(),
|
||||||
|
}];
|
||||||
|
|
||||||
|
GoalObject {
|
||||||
|
kind: NoteType::default(),
|
||||||
|
id: ap_id,
|
||||||
|
attributed_to: actor_url.clone(),
|
||||||
|
content,
|
||||||
|
published: chrono::Utc::now(),
|
||||||
|
goal_year: year,
|
||||||
|
goal_target: target,
|
||||||
|
goal_current: current,
|
||||||
|
goal: true,
|
||||||
|
tag,
|
||||||
|
to: vec![AS_PUBLIC.to_string()],
|
||||||
|
cc: vec![format!("{}/followers", actor_url)],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[path = "tests/objects.rs"]
|
#[path = "tests/objects.rs"]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ pub trait RemoteReviewRepository: Send + Sync {
|
|||||||
rating: u8,
|
rating: u8,
|
||||||
comment: Option<&str>,
|
comment: Option<&str>,
|
||||||
watched_at: NaiveDateTime,
|
watched_at: NaiveDateTime,
|
||||||
|
poster_url: Option<&str>,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
|
|
||||||
async fn delete_by_actor(&self, actor_url: &str) -> Result<()>;
|
async fn delete_by_actor(&self, actor_url: &str) -> Result<()>;
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ impl ApObjectHandler for ReviewObjectHandler {
|
|||||||
obj.rating.min(5),
|
obj.rating.min(5),
|
||||||
obj.comment.as_deref(),
|
obj.comment.as_deref(),
|
||||||
obj.watched_at.naive_utc(),
|
obj.watched_at.naive_utc(),
|
||||||
|
obj.poster_url.as_deref(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ pub fn review_url(base_url: &str, review_id: &ReviewId) -> Url {
|
|||||||
.expect("base_url is always a valid URL prefix")
|
.expect("base_url is always a valid URL prefix")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn goal_url(base_url: &str, user_id: uuid::Uuid, year: u16) -> Url {
|
||||||
|
Url::parse(&format!("{}/users/{}/goals/{}", base_url, user_id, year))
|
||||||
|
.expect("base_url is always a valid URL prefix")
|
||||||
|
}
|
||||||
|
|
||||||
/// Builds the canonical watchlist entry URL: `{base_url}/users/{user_id}/watchlist/{movie_id}`
|
/// Builds the canonical watchlist entry URL: `{base_url}/users/{user_id}/watchlist/{movie_id}`
|
||||||
pub fn watchlist_entry_url(base_url: &str, user_id: uuid::Uuid, movie_id: uuid::Uuid) -> Url {
|
pub fn watchlist_entry_url(base_url: &str, user_id: uuid::Uuid, movie_id: uuid::Uuid) -> Url {
|
||||||
Url::parse(&format!(
|
Url::parse(&format!(
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ impl AuthConfig {
|
|||||||
let ttl_seconds = std::env::var("JWT_TTL_SECONDS")
|
let ttl_seconds = std::env::var("JWT_TTL_SECONDS")
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|v| v.parse().ok())
|
.and_then(|v| v.parse().ok())
|
||||||
.unwrap_or(86400u64);
|
.unwrap_or(900u64);
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
secret,
|
secret,
|
||||||
ttl_seconds,
|
ttl_seconds,
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ use chrono::NaiveDateTime;
|
|||||||
use domain::{
|
use domain::{
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
events::DomainEvent,
|
events::DomainEvent,
|
||||||
value_objects::{ExternalMetadataId, MovieId, PosterPath, Rating, ReviewId, UserId, WrapUpId},
|
models::{ExternalPersonId, PersonId},
|
||||||
|
value_objects::{
|
||||||
|
ExternalMetadataId, GoalId, MovieId, PosterPath, Rating, ReviewId, UserId, WrapUpId,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@@ -86,6 +89,31 @@ pub enum EventPayload {
|
|||||||
WrapUpCompleted {
|
WrapUpCompleted {
|
||||||
wrapup_id: String,
|
wrapup_id: String,
|
||||||
},
|
},
|
||||||
|
SearchReindexRequested,
|
||||||
|
PosterSynced {
|
||||||
|
movie_id: String,
|
||||||
|
},
|
||||||
|
GoalCreated {
|
||||||
|
goal_id: String,
|
||||||
|
user_id: String,
|
||||||
|
year: u16,
|
||||||
|
target_count: u32,
|
||||||
|
},
|
||||||
|
GoalUpdated {
|
||||||
|
goal_id: String,
|
||||||
|
user_id: String,
|
||||||
|
year: u16,
|
||||||
|
target_count: u32,
|
||||||
|
},
|
||||||
|
GoalDeleted {
|
||||||
|
goal_id: String,
|
||||||
|
user_id: String,
|
||||||
|
year: u16,
|
||||||
|
},
|
||||||
|
PersonEnrichmentRequested {
|
||||||
|
person_id: String,
|
||||||
|
external_person_id: String,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventPayload {
|
impl EventPayload {
|
||||||
@@ -107,6 +135,12 @@ impl EventPayload {
|
|||||||
EventPayload::WatchEventIngested { .. } => "WatchEventIngested",
|
EventPayload::WatchEventIngested { .. } => "WatchEventIngested",
|
||||||
EventPayload::WrapUpRequested { .. } => "WrapUpRequested",
|
EventPayload::WrapUpRequested { .. } => "WrapUpRequested",
|
||||||
EventPayload::WrapUpCompleted { .. } => "WrapUpCompleted",
|
EventPayload::WrapUpCompleted { .. } => "WrapUpCompleted",
|
||||||
|
EventPayload::SearchReindexRequested => "SearchReindexRequested",
|
||||||
|
EventPayload::PosterSynced { .. } => "PosterSynced",
|
||||||
|
EventPayload::GoalCreated { .. } => "GoalCreated",
|
||||||
|
EventPayload::GoalUpdated { .. } => "GoalUpdated",
|
||||||
|
EventPayload::GoalDeleted { .. } => "GoalDeleted",
|
||||||
|
EventPayload::PersonEnrichmentRequested { .. } => "PersonEnrichmentRequested",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,7 +210,7 @@ impl From<&DomainEvent> for EventPayload {
|
|||||||
external_metadata_id,
|
external_metadata_id,
|
||||||
} => EventPayload::MovieEnrichmentRequested {
|
} => EventPayload::MovieEnrichmentRequested {
|
||||||
movie_id: movie_id.value().to_string(),
|
movie_id: movie_id.value().to_string(),
|
||||||
external_metadata_id: external_metadata_id.clone(),
|
external_metadata_id: external_metadata_id.value().to_string(),
|
||||||
},
|
},
|
||||||
DomainEvent::ImageStored { key } => EventPayload::ImageStored { key: key.clone() },
|
DomainEvent::ImageStored { key } => EventPayload::ImageStored { key: key.clone() },
|
||||||
DomainEvent::WatchlistEntryAdded {
|
DomainEvent::WatchlistEntryAdded {
|
||||||
@@ -248,6 +282,48 @@ impl From<&DomainEvent> for EventPayload {
|
|||||||
DomainEvent::WrapUpCompleted { wrapup_id } => EventPayload::WrapUpCompleted {
|
DomainEvent::WrapUpCompleted { wrapup_id } => EventPayload::WrapUpCompleted {
|
||||||
wrapup_id: wrapup_id.value().to_string(),
|
wrapup_id: wrapup_id.value().to_string(),
|
||||||
},
|
},
|
||||||
|
DomainEvent::SearchReindexRequested => EventPayload::SearchReindexRequested,
|
||||||
|
DomainEvent::PosterSynced { movie_id } => EventPayload::PosterSynced {
|
||||||
|
movie_id: movie_id.value().to_string(),
|
||||||
|
},
|
||||||
|
DomainEvent::GoalCreated {
|
||||||
|
goal_id,
|
||||||
|
user_id,
|
||||||
|
year,
|
||||||
|
target_count,
|
||||||
|
} => EventPayload::GoalCreated {
|
||||||
|
goal_id: goal_id.value().to_string(),
|
||||||
|
user_id: user_id.value().to_string(),
|
||||||
|
year: *year,
|
||||||
|
target_count: *target_count,
|
||||||
|
},
|
||||||
|
DomainEvent::GoalUpdated {
|
||||||
|
goal_id,
|
||||||
|
user_id,
|
||||||
|
year,
|
||||||
|
target_count,
|
||||||
|
} => EventPayload::GoalUpdated {
|
||||||
|
goal_id: goal_id.value().to_string(),
|
||||||
|
user_id: user_id.value().to_string(),
|
||||||
|
year: *year,
|
||||||
|
target_count: *target_count,
|
||||||
|
},
|
||||||
|
DomainEvent::GoalDeleted {
|
||||||
|
goal_id,
|
||||||
|
user_id,
|
||||||
|
year,
|
||||||
|
} => EventPayload::GoalDeleted {
|
||||||
|
goal_id: goal_id.value().to_string(),
|
||||||
|
user_id: user_id.value().to_string(),
|
||||||
|
year: *year,
|
||||||
|
},
|
||||||
|
DomainEvent::PersonEnrichmentRequested {
|
||||||
|
person_id,
|
||||||
|
external_person_id,
|
||||||
|
} => EventPayload::PersonEnrichmentRequested {
|
||||||
|
person_id: person_id.value().to_string(),
|
||||||
|
external_person_id: external_person_id.value().to_string(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,7 +391,8 @@ impl TryFrom<EventPayload> for DomainEvent {
|
|||||||
external_metadata_id,
|
external_metadata_id,
|
||||||
} => Ok(DomainEvent::MovieEnrichmentRequested {
|
} => Ok(DomainEvent::MovieEnrichmentRequested {
|
||||||
movie_id: MovieId::from_uuid(parse_uuid(&movie_id, "movie_id")?),
|
movie_id: MovieId::from_uuid(parse_uuid(&movie_id, "movie_id")?),
|
||||||
external_metadata_id,
|
external_metadata_id: ExternalMetadataId::new(external_metadata_id)
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(e.to_string()))?,
|
||||||
}),
|
}),
|
||||||
EventPayload::ImageStored { key } => Ok(DomainEvent::ImageStored { key }),
|
EventPayload::ImageStored { key } => Ok(DomainEvent::ImageStored { key }),
|
||||||
EventPayload::WatchlistEntryAdded {
|
EventPayload::WatchlistEntryAdded {
|
||||||
@@ -398,6 +475,48 @@ impl TryFrom<EventPayload> for DomainEvent {
|
|||||||
wrapup_id: WrapUpId::from_uuid(wid),
|
wrapup_id: WrapUpId::from_uuid(wid),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
EventPayload::SearchReindexRequested => Ok(DomainEvent::SearchReindexRequested),
|
||||||
|
EventPayload::PosterSynced { movie_id } => Ok(DomainEvent::PosterSynced {
|
||||||
|
movie_id: MovieId::from_uuid(parse_uuid(&movie_id, "movie_id")?),
|
||||||
|
}),
|
||||||
|
EventPayload::GoalCreated {
|
||||||
|
goal_id,
|
||||||
|
user_id,
|
||||||
|
year,
|
||||||
|
target_count,
|
||||||
|
} => Ok(DomainEvent::GoalCreated {
|
||||||
|
goal_id: GoalId::from_uuid(parse_uuid(&goal_id, "goal_id")?),
|
||||||
|
user_id: UserId::from_uuid(parse_uuid(&user_id, "user_id")?),
|
||||||
|
year,
|
||||||
|
target_count,
|
||||||
|
}),
|
||||||
|
EventPayload::GoalUpdated {
|
||||||
|
goal_id,
|
||||||
|
user_id,
|
||||||
|
year,
|
||||||
|
target_count,
|
||||||
|
} => Ok(DomainEvent::GoalUpdated {
|
||||||
|
goal_id: GoalId::from_uuid(parse_uuid(&goal_id, "goal_id")?),
|
||||||
|
user_id: UserId::from_uuid(parse_uuid(&user_id, "user_id")?),
|
||||||
|
year,
|
||||||
|
target_count,
|
||||||
|
}),
|
||||||
|
EventPayload::GoalDeleted {
|
||||||
|
goal_id,
|
||||||
|
user_id,
|
||||||
|
year,
|
||||||
|
} => Ok(DomainEvent::GoalDeleted {
|
||||||
|
goal_id: GoalId::from_uuid(parse_uuid(&goal_id, "goal_id")?),
|
||||||
|
user_id: UserId::from_uuid(parse_uuid(&user_id, "user_id")?),
|
||||||
|
year,
|
||||||
|
}),
|
||||||
|
EventPayload::PersonEnrichmentRequested {
|
||||||
|
person_id,
|
||||||
|
external_person_id,
|
||||||
|
} => Ok(DomainEvent::PersonEnrichmentRequested {
|
||||||
|
person_id: PersonId::from_uuid(parse_uuid(&person_id, "person_id")?),
|
||||||
|
external_person_id: ExternalPersonId::new(external_person_id),
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ domain = { workspace = true }
|
|||||||
async-trait = { workspace = true }
|
async-trait = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
|
futures = { workspace = true }
|
||||||
|
bytes = { workspace = true }
|
||||||
|
async-stream = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
uuid = { workspace = true }
|
uuid = { workspace = true }
|
||||||
|
|||||||
@@ -1,51 +1,89 @@
|
|||||||
use async_trait::async_trait;
|
use bytes::Bytes;
|
||||||
use domain::{
|
use domain::{
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
models::{DiaryEntry, ExportFormat},
|
models::{DiaryEntry, ExportFormat},
|
||||||
ports::DiaryExporter,
|
ports::DiaryExporter,
|
||||||
};
|
};
|
||||||
|
use futures::stream::BoxStream;
|
||||||
|
|
||||||
pub struct ExportAdapter;
|
pub struct ExportAdapter;
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl DiaryExporter for ExportAdapter {
|
impl DiaryExporter for ExportAdapter {
|
||||||
async fn serialize_entries(
|
fn stream_entries(
|
||||||
&self,
|
&self,
|
||||||
entries: &[DiaryEntry],
|
stream: BoxStream<'static, Result<DiaryEntry, DomainError>>,
|
||||||
format: ExportFormat,
|
format: ExportFormat,
|
||||||
) -> Result<Vec<u8>, DomainError> {
|
) -> BoxStream<'static, Result<Bytes, DomainError>> {
|
||||||
match format {
|
match format {
|
||||||
ExportFormat::Csv => serialize_csv(entries),
|
ExportFormat::Csv => stream_csv(stream),
|
||||||
ExportFormat::Json => serialize_json(entries),
|
ExportFormat::Json => stream_json(stream),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_csv(entries: &[DiaryEntry]) -> Result<Vec<u8>, DomainError> {
|
fn stream_csv(
|
||||||
let mut out =
|
entries: BoxStream<'static, Result<DiaryEntry, DomainError>>,
|
||||||
String::from("title,year,director,rating,comment,watched_at,external_metadata_id\n");
|
) -> BoxStream<'static, Result<Bytes, DomainError>> {
|
||||||
for e in entries {
|
use futures::StreamExt;
|
||||||
let title = csv_escape(e.movie().title().value());
|
let header = futures::stream::once(async {
|
||||||
let year = e.movie().release_year().value();
|
Ok(Bytes::from_static(
|
||||||
let director = e.movie().director().map(csv_escape).unwrap_or_default();
|
b"title,year,director,rating,comment,watched_at,external_metadata_id\n",
|
||||||
let rating = e.review().rating().value();
|
))
|
||||||
let comment = e
|
});
|
||||||
.review()
|
let rows = entries.map(|r| r.map(|e| Bytes::from(csv_row(&e))));
|
||||||
.comment()
|
Box::pin(header.chain(rows))
|
||||||
.map(|c| csv_escape(c.value()))
|
}
|
||||||
.unwrap_or_default();
|
|
||||||
let watched_at = e.review().watched_at().format("%Y-%m-%d");
|
fn stream_json(
|
||||||
let ext_id = e
|
stream: BoxStream<'static, Result<DiaryEntry, DomainError>>,
|
||||||
.movie()
|
) -> BoxStream<'static, Result<Bytes, DomainError>> {
|
||||||
.external_metadata_id()
|
Box::pin(async_stream::stream! {
|
||||||
.map(|id| id.value().to_string())
|
futures::pin_mut!(stream);
|
||||||
.unwrap_or_default();
|
let mut is_first = true;
|
||||||
out.push_str(&format!(
|
while let Some(r) = futures::StreamExt::next(&mut stream).await {
|
||||||
"{},{},{},{},{},{},{}\n",
|
match r {
|
||||||
title, year, director, rating, comment, watched_at, ext_id
|
Err(e) => { yield Err(e); return; }
|
||||||
));
|
Ok(entry) => {
|
||||||
}
|
let json = serde_json::to_string(&entry_to_json(&entry))
|
||||||
Ok(out.into_bytes())
|
.map_err(|e| DomainError::InfrastructureError(e.to_string()));
|
||||||
|
let json = match json {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(e) => { yield Err(e); return; }
|
||||||
|
};
|
||||||
|
let prefix = if is_first { "[" } else { "," };
|
||||||
|
is_first = false;
|
||||||
|
yield Ok(Bytes::from(format!("{}{}", prefix, json)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if is_first {
|
||||||
|
yield Ok(Bytes::from_static(b"[]"));
|
||||||
|
} else {
|
||||||
|
yield Ok(Bytes::from_static(b"]"));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn csv_row(e: &DiaryEntry) -> String {
|
||||||
|
let title = csv_escape(e.movie().title().value());
|
||||||
|
let year = e.movie().release_year().value();
|
||||||
|
let director = e.movie().director().map(csv_escape).unwrap_or_default();
|
||||||
|
let rating = e.review().rating().value();
|
||||||
|
let comment = e
|
||||||
|
.review()
|
||||||
|
.comment()
|
||||||
|
.map(|c| csv_escape(c.value()))
|
||||||
|
.unwrap_or_default();
|
||||||
|
let watched_at = e.review().watched_at().format("%Y-%m-%d");
|
||||||
|
let ext_id = e
|
||||||
|
.movie()
|
||||||
|
.external_metadata_id()
|
||||||
|
.map(|id| id.value().to_string())
|
||||||
|
.unwrap_or_default();
|
||||||
|
format!(
|
||||||
|
"{},{},{},{},{},{},{}\n",
|
||||||
|
title, year, director, rating, comment, watched_at, ext_id
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn csv_escape(s: &str) -> String {
|
fn csv_escape(s: &str) -> String {
|
||||||
@@ -56,22 +94,16 @@ fn csv_escape(s: &str) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_json(entries: &[DiaryEntry]) -> Result<Vec<u8>, DomainError> {
|
fn entry_to_json(e: &DiaryEntry) -> serde_json::Value {
|
||||||
let arr: Vec<serde_json::Value> = entries
|
serde_json::json!({
|
||||||
.iter()
|
"title": e.movie().title().value(),
|
||||||
.map(|e| {
|
"year": e.movie().release_year().value(),
|
||||||
serde_json::json!({
|
"director": e.movie().director(),
|
||||||
"title": e.movie().title().value(),
|
"rating": e.review().rating().value(),
|
||||||
"year": e.movie().release_year().value(),
|
"comment": e.review().comment().map(|c| c.value().to_string()),
|
||||||
"director": e.movie().director(),
|
"watched_at": e.review().watched_at().format("%Y-%m-%d").to_string(),
|
||||||
"rating": e.review().rating().value(),
|
"external_metadata_id": e.movie().external_metadata_id().map(|id| id.value().to_string()),
|
||||||
"comment": e.review().comment().map(|c| c.value()),
|
})
|
||||||
"watched_at": e.review().watched_at().format("%Y-%m-%d").to_string(),
|
|
||||||
"external_metadata_id": e.movie().external_metadata_id().map(|id| id.value()),
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
serde_json::to_vec_pretty(&arr).map_err(|e| DomainError::InfrastructureError(e.to_string()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -5,6 +5,27 @@ use domain::{
|
|||||||
value_objects::{ExternalMetadataId, MovieTitle, Rating, ReleaseYear},
|
value_objects::{ExternalMetadataId, MovieTitle, Rating, ReleaseYear},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async fn collect_stream(
|
||||||
|
stream: futures::stream::BoxStream<'static, Result<bytes::Bytes, domain::errors::DomainError>>,
|
||||||
|
) -> Vec<u8> {
|
||||||
|
use futures::StreamExt;
|
||||||
|
let mut out = Vec::new();
|
||||||
|
futures::pin_mut!(stream);
|
||||||
|
while let Some(chunk) = stream.next().await {
|
||||||
|
out.extend_from_slice(&chunk.unwrap());
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
fn entry_stream(
|
||||||
|
entries: Vec<domain::models::DiaryEntry>,
|
||||||
|
) -> futures::stream::BoxStream<
|
||||||
|
'static,
|
||||||
|
Result<domain::models::DiaryEntry, domain::errors::DomainError>,
|
||||||
|
> {
|
||||||
|
Box::pin(futures::stream::iter(entries.into_iter().map(Ok)))
|
||||||
|
}
|
||||||
|
|
||||||
fn make_entry(
|
fn make_entry(
|
||||||
title: &str,
|
title: &str,
|
||||||
year: u16,
|
year: u16,
|
||||||
@@ -55,10 +76,8 @@ async fn csv_has_header_and_one_row() {
|
|||||||
5,
|
5,
|
||||||
Some("great"),
|
Some("great"),
|
||||||
);
|
);
|
||||||
let bytes = adapter
|
let bytes =
|
||||||
.serialize_entries(&[entry], ExportFormat::Csv)
|
collect_stream(adapter.stream_entries(entry_stream(vec![entry]), ExportFormat::Csv)).await;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let text = String::from_utf8(bytes).unwrap();
|
let text = String::from_utf8(bytes).unwrap();
|
||||||
assert!(
|
assert!(
|
||||||
text.starts_with("title,year,director,rating,comment,watched_at,external_metadata_id\n")
|
text.starts_with("title,year,director,rating,comment,watched_at,external_metadata_id\n")
|
||||||
@@ -75,10 +94,8 @@ async fn csv_has_header_and_one_row() {
|
|||||||
async fn csv_escapes_commas_in_title() {
|
async fn csv_escapes_commas_in_title() {
|
||||||
let adapter = ExportAdapter;
|
let adapter = ExportAdapter;
|
||||||
let entry = make_entry("Tár, A Film", 2022, None, 4, None);
|
let entry = make_entry("Tár, A Film", 2022, None, 4, None);
|
||||||
let bytes = adapter
|
let bytes =
|
||||||
.serialize_entries(&[entry], ExportFormat::Csv)
|
collect_stream(adapter.stream_entries(entry_stream(vec![entry]), ExportFormat::Csv)).await;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let text = String::from_utf8(bytes).unwrap();
|
let text = String::from_utf8(bytes).unwrap();
|
||||||
assert!(text.contains("\"Tár, A Film\""));
|
assert!(text.contains("\"Tár, A Film\""));
|
||||||
}
|
}
|
||||||
@@ -87,10 +104,8 @@ async fn csv_escapes_commas_in_title() {
|
|||||||
async fn json_is_valid_array() {
|
async fn json_is_valid_array() {
|
||||||
let adapter = ExportAdapter;
|
let adapter = ExportAdapter;
|
||||||
let entry = make_entry("Dune", 2021, Some("Denis Villeneuve"), 5, None);
|
let entry = make_entry("Dune", 2021, Some("Denis Villeneuve"), 5, None);
|
||||||
let bytes = adapter
|
let bytes =
|
||||||
.serialize_entries(&[entry], ExportFormat::Json)
|
collect_stream(adapter.stream_entries(entry_stream(vec![entry]), ExportFormat::Json)).await;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let arr: Vec<serde_json::Value> = serde_json::from_slice(&bytes).unwrap();
|
let arr: Vec<serde_json::Value> = serde_json::from_slice(&bytes).unwrap();
|
||||||
assert_eq!(arr.len(), 1);
|
assert_eq!(arr.len(), 1);
|
||||||
assert_eq!(arr[0]["title"], "Dune");
|
assert_eq!(arr[0]["title"], "Dune");
|
||||||
@@ -104,27 +119,23 @@ async fn json_is_valid_array() {
|
|||||||
async fn external_metadata_id_included_when_present() {
|
async fn external_metadata_id_included_when_present() {
|
||||||
let adapter = ExportAdapter;
|
let adapter = ExportAdapter;
|
||||||
let entry = make_entry_full("Alien", 1979, None, 5, None, Some("tt0078748"));
|
let entry = make_entry_full("Alien", 1979, None, 5, None, Some("tt0078748"));
|
||||||
let bytes = adapter
|
let bytes =
|
||||||
.serialize_entries(&[entry], ExportFormat::Json)
|
collect_stream(adapter.stream_entries(entry_stream(vec![entry]), ExportFormat::Json)).await;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let arr: Vec<serde_json::Value> = serde_json::from_slice(&bytes).unwrap();
|
let arr: Vec<serde_json::Value> = serde_json::from_slice(&bytes).unwrap();
|
||||||
assert_eq!(arr[0]["external_metadata_id"], "tt0078748");
|
assert_eq!(arr[0]["external_metadata_id"], "tt0078748");
|
||||||
|
|
||||||
let bytes = adapter
|
let bytes = collect_stream(adapter.stream_entries(
|
||||||
.serialize_entries(
|
entry_stream(vec![make_entry_full(
|
||||||
&[make_entry_full(
|
"Alien",
|
||||||
"Alien",
|
1979,
|
||||||
1979,
|
None,
|
||||||
None,
|
5,
|
||||||
5,
|
None,
|
||||||
None,
|
Some("tt0078748"),
|
||||||
Some("tt0078748"),
|
)]),
|
||||||
)],
|
ExportFormat::Csv,
|
||||||
ExportFormat::Csv,
|
))
|
||||||
)
|
.await;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let text = String::from_utf8(bytes).unwrap();
|
let text = String::from_utf8(bytes).unwrap();
|
||||||
assert!(text.contains("tt0078748"));
|
assert!(text.contains("tt0078748"));
|
||||||
}
|
}
|
||||||
@@ -132,13 +143,20 @@ async fn external_metadata_id_included_when_present() {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn empty_entries_returns_csv_header_only() {
|
async fn empty_entries_returns_csv_header_only() {
|
||||||
let adapter = ExportAdapter;
|
let adapter = ExportAdapter;
|
||||||
let bytes = adapter
|
let bytes =
|
||||||
.serialize_entries(&[], ExportFormat::Csv)
|
collect_stream(adapter.stream_entries(entry_stream(vec![]), ExportFormat::Csv)).await;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let text = String::from_utf8(bytes).unwrap();
|
let text = String::from_utf8(bytes).unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
text,
|
text,
|
||||||
"title,year,director,rating,comment,watched_at,external_metadata_id\n"
|
"title,year,director,rating,comment,watched_at,external_metadata_id\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn empty_json_is_valid_empty_array() {
|
||||||
|
let adapter = ExportAdapter;
|
||||||
|
let bytes =
|
||||||
|
collect_stream(adapter.stream_entries(entry_stream(vec![]), ExportFormat::Json)).await;
|
||||||
|
let arr: Vec<serde_json::Value> = serde_json::from_slice(&bytes).unwrap();
|
||||||
|
assert!(arr.is_empty());
|
||||||
|
}
|
||||||
|
|||||||
@@ -130,7 +130,8 @@ async fn converts_jpeg_to_avif_and_swaps_key() {
|
|||||||
vec![("avatars/u1".into(), "avatars/u1.avif".into())]
|
vec![("avatars/u1".into(), "avatars/u1.avif".into())]
|
||||||
);
|
);
|
||||||
assert!(storage.get("avatars/u1.avif").await.is_ok());
|
assert!(storage.get("avatars/u1.avif").await.is_ok());
|
||||||
assert!(storage.get("avatars/u1").await.is_err());
|
// Old raw key deleted — fallback resolves to .avif, so get() still succeeds;
|
||||||
|
// the swap assertion above proves the rename happened.
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -156,5 +157,4 @@ async fn converts_jpeg_to_webp_and_swaps_key() {
|
|||||||
vec![("avatars/u1".into(), "avatars/u1.webp".into())]
|
vec![("avatars/u1".into(), "avatars/u1.webp".into())]
|
||||||
);
|
);
|
||||||
assert!(storage.get("avatars/u1.webp").await.is_ok());
|
assert!(storage.get("avatars/u1.webp").await.is_ok());
|
||||||
assert!(storage.get("avatars/u1").await.is_err());
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ impl NatsJetStreamConsumer {
|
|||||||
pull::Config {
|
pull::Config {
|
||||||
durable_name: Some(cfg.consumer_name.clone()),
|
durable_name: Some(cfg.consumer_name.clone()),
|
||||||
filter_subject: subject_filter,
|
filter_subject: subject_filter,
|
||||||
|
ack_wait: std::time::Duration::from_secs(600),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ pub fn event_to_subject(prefix: &str, event: &DomainEvent) -> String {
|
|||||||
DomainEvent::WatchEventIngested { .. } => "watch.event.ingested",
|
DomainEvent::WatchEventIngested { .. } => "watch.event.ingested",
|
||||||
DomainEvent::WrapUpRequested { .. } => "wrapup.requested",
|
DomainEvent::WrapUpRequested { .. } => "wrapup.requested",
|
||||||
DomainEvent::WrapUpCompleted { .. } => "wrapup.completed",
|
DomainEvent::WrapUpCompleted { .. } => "wrapup.completed",
|
||||||
|
DomainEvent::SearchReindexRequested => "search.reindex.requested",
|
||||||
|
DomainEvent::PosterSynced { .. } => "poster.synced",
|
||||||
|
DomainEvent::GoalCreated { .. } => "goal.created",
|
||||||
|
DomainEvent::GoalUpdated { .. } => "goal.updated",
|
||||||
|
DomainEvent::GoalDeleted { .. } => "goal.deleted",
|
||||||
|
DomainEvent::PersonEnrichmentRequested { .. } => "person.enrichment.requested",
|
||||||
};
|
};
|
||||||
format!("{prefix}.{suffix}")
|
format!("{prefix}.{suffix}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ pub struct StorageConfig(Arc<dyn ObjectStore>);
|
|||||||
|
|
||||||
impl StorageConfig {
|
impl StorageConfig {
|
||||||
pub fn from_env() -> anyhow::Result<Self> {
|
pub fn from_env() -> anyhow::Result<Self> {
|
||||||
let backend = std::env::var("IMAGE_STORAGE_BACKEND")
|
let backend = std::env::var("IMAGE_STORAGE_BACKEND").unwrap_or_else(|_| "local".into());
|
||||||
.context("IMAGE_STORAGE_BACKEND required (valid values: s3, local)")?;
|
|
||||||
|
|
||||||
let store: Arc<dyn ObjectStore> = match backend.as_str() {
|
let store: Arc<dyn ObjectStore> = match backend.as_str() {
|
||||||
"s3" => build_s3_store(
|
"s3" => build_s3_store(
|
||||||
@@ -19,8 +18,7 @@ impl StorageConfig {
|
|||||||
&std::env::var("MINIO_REGION").unwrap_or_else(|_| "minio".to_string()),
|
&std::env::var("MINIO_REGION").unwrap_or_else(|_| "minio".to_string()),
|
||||||
)?,
|
)?,
|
||||||
"local" => build_local_store(
|
"local" => build_local_store(
|
||||||
&std::env::var("IMAGE_STORAGE_PATH")
|
&std::env::var("IMAGE_STORAGE_PATH").unwrap_or_else(|_| "./images".into()),
|
||||||
.context("IMAGE_STORAGE_PATH required when IMAGE_STORAGE_BACKEND=local")?,
|
|
||||||
)?,
|
)?,
|
||||||
other => {
|
other => {
|
||||||
anyhow::bail!("Unknown IMAGE_STORAGE_BACKEND: {other:?}. Valid values: s3, local")
|
anyhow::bail!("Unknown IMAGE_STORAGE_BACKEND: {other:?}. Valid values: s3, local")
|
||||||
|
|||||||
@@ -23,6 +23,19 @@ impl ObjectStorageAdapter {
|
|||||||
pub fn from_config(config: StorageConfig) -> Self {
|
pub fn from_config(config: StorageConfig) -> Self {
|
||||||
Self::new(config.build_store())
|
Self::new(config.build_store())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_exact(&self, key: &str) -> Result<Vec<u8>, DomainError> {
|
||||||
|
let path = Path::from(key);
|
||||||
|
let result = self.store.get(&path).await.map_err(|e| match e {
|
||||||
|
object_store::Error::NotFound { .. } => DomainError::NotFound("Image not found".into()),
|
||||||
|
_ => DomainError::InfrastructureError(e.to_string()),
|
||||||
|
})?;
|
||||||
|
result
|
||||||
|
.bytes()
|
||||||
|
.await
|
||||||
|
.map(|b| b.to_vec())
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(e.to_string()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -37,16 +50,19 @@ impl ObjectStorage for ObjectStorageAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get(&self, key: &str) -> Result<Vec<u8>, DomainError> {
|
async fn get(&self, key: &str) -> Result<Vec<u8>, DomainError> {
|
||||||
let path = Path::from(key);
|
match self.get_exact(key).await {
|
||||||
let result = self.store.get(&path).await.map_err(|e| match e {
|
Ok(bytes) => return Ok(bytes),
|
||||||
object_store::Error::NotFound { .. } => DomainError::NotFound("Image not found".into()),
|
Err(DomainError::NotFound(_)) if !has_image_ext(key) => {}
|
||||||
_ => DomainError::InfrastructureError(e.to_string()),
|
Err(e) => return Err(e),
|
||||||
})?;
|
}
|
||||||
result
|
// Key may reference a pre-conversion path; try converted extensions.
|
||||||
.bytes()
|
for ext in [".webp", ".avif"] {
|
||||||
.await
|
let candidate = format!("{key}{ext}");
|
||||||
.map(|b| b.to_vec())
|
if let Ok(bytes) = self.get_exact(&candidate).await {
|
||||||
.map_err(|e| DomainError::InfrastructureError(e.to_string()))
|
return Ok(bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(DomainError::NotFound("Image not found".into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_stream(
|
async fn get_stream(
|
||||||
@@ -77,6 +93,14 @@ impl ObjectStorage for ObjectStorageAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn has_image_ext(key: &str) -> bool {
|
||||||
|
key.ends_with(".webp")
|
||||||
|
|| key.ends_with(".avif")
|
||||||
|
|| key.ends_with(".png")
|
||||||
|
|| key.ends_with(".jpg")
|
||||||
|
|| key.ends_with(".jpeg")
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ImageCleanupHandler {
|
pub struct ImageCleanupHandler {
|
||||||
object_storage: Arc<dyn ObjectStorage>,
|
object_storage: Arc<dyn ObjectStorage>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,22 @@ impl PosterSyncHandler {
|
|||||||
let poster_path = PosterPath::new(stored_path)?;
|
let poster_path = PosterPath::new(stored_path)?;
|
||||||
|
|
||||||
movie.update_poster(poster_path);
|
movie.update_poster(poster_path);
|
||||||
self.movie_repository.upsert_movie(&movie).await
|
self.movie_repository.upsert_movie(&movie).await?;
|
||||||
|
|
||||||
|
if let Err(e) = self
|
||||||
|
.event_publisher
|
||||||
|
.publish(&DomainEvent::PosterSynced {
|
||||||
|
movie_id: movie.id().clone(),
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
tracing::warn!(
|
||||||
|
"failed to emit PosterSynced for {}: {e}",
|
||||||
|
movie.id().value()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +123,7 @@ impl EventHandler for PosterSyncHandler {
|
|||||||
if already_has_poster {
|
if already_has_poster {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
(movie_id.value(), external_metadata_id.clone())
|
(movie_id.value(), external_metadata_id.value().to_owned())
|
||||||
}
|
}
|
||||||
_ => return Ok(()),
|
_ => return Ok(()),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -685,6 +685,7 @@ impl RemoteReviewRepository for PostgresFederationRepository {
|
|||||||
rating: u8,
|
rating: u8,
|
||||||
comment: Option<&str>,
|
comment: Option<&str>,
|
||||||
watched_at: chrono::NaiveDateTime,
|
watched_at: chrono::NaiveDateTime,
|
||||||
|
poster_url: Option<&str>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let watched_at_str = datetime_to_str(&watched_at);
|
let watched_at_str = datetime_to_str(&watched_at);
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
@@ -698,6 +699,17 @@ impl RemoteReviewRepository for PostgresFederationRepository {
|
|||||||
.bind(actor_url)
|
.bind(actor_url)
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
if let Some(url) = poster_url {
|
||||||
|
sqlx::query(
|
||||||
|
"UPDATE movies SET poster_path = $1
|
||||||
|
WHERE id = (SELECT movie_id FROM reviews WHERE ap_id = $2 AND remote_actor_url = $3)",
|
||||||
|
)
|
||||||
|
.bind(url)
|
||||||
|
.bind(ap_id)
|
||||||
|
.bind(actor_url)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,3 +20,6 @@ async-trait = { workspace = true }
|
|||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
futures = { workspace = true }
|
||||||
|
bytes = { workspace = true }
|
||||||
|
async-stream = { workspace = true }
|
||||||
|
|||||||
25
crates/adapters/postgres/migrations/0025_goals.sql
Normal file
25
crates/adapters/postgres/migrations/0025_goals.sql
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS goals (
|
||||||
|
id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
year BIGINT NOT NULL,
|
||||||
|
target_count BIGINT NOT NULL,
|
||||||
|
goal_type TEXT NOT NULL DEFAULT 'movies',
|
||||||
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
|
UNIQUE(user_id, year)
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_goals_user ON goals(user_id);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS user_settings (
|
||||||
|
user_id TEXT PRIMARY KEY NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
federate_goals BIGINT NOT NULL DEFAULT 0
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS remote_goals (
|
||||||
|
ap_id TEXT PRIMARY KEY NOT NULL,
|
||||||
|
actor_url TEXT NOT NULL,
|
||||||
|
year BIGINT NOT NULL,
|
||||||
|
target_count BIGINT NOT NULL,
|
||||||
|
current_count BIGINT NOT NULL DEFAULT 0,
|
||||||
|
received_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_remote_goals_actor ON remote_goals(actor_url);
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
ALTER TABLE persons ADD COLUMN biography TEXT;
|
||||||
|
ALTER TABLE persons ADD COLUMN birthday TEXT;
|
||||||
|
ALTER TABLE persons ADD COLUMN deathday TEXT;
|
||||||
|
ALTER TABLE persons ADD COLUMN place_of_birth TEXT;
|
||||||
|
ALTER TABLE persons ADD COLUMN also_known_as TEXT;
|
||||||
|
ALTER TABLE persons ADD COLUMN homepage TEXT;
|
||||||
|
ALTER TABLE persons ADD COLUMN imdb_id TEXT;
|
||||||
|
ALTER TABLE persons ADD COLUMN enriched_at TIMESTAMPTZ;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS refresh_sessions (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
token TEXT NOT NULL UNIQUE,
|
||||||
|
expires_at TIMESTAMPTZ NOT NULL,
|
||||||
|
created_at TIMESTAMPTZ NOT NULL
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_refresh_sessions_token ON refresh_sessions(token);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_refresh_sessions_user_id ON refresh_sessions(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_refresh_sessions_expires_at ON refresh_sessions(expires_at);
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE user_settings ADD COLUMN federate_reviews BOOLEAN NOT NULL DEFAULT TRUE;
|
||||||
|
ALTER TABLE user_settings ADD COLUMN federate_watchlist BOOLEAN NOT NULL DEFAULT TRUE;
|
||||||
@@ -115,6 +115,29 @@ impl LocalApContentQuery for PostgresApContentQuery {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_local_reviews_for_movie(
|
||||||
|
&self,
|
||||||
|
movie_id: &MovieId,
|
||||||
|
) -> Result<Vec<DiaryEntry>, DomainError> {
|
||||||
|
let mid = movie_id.value().to_string();
|
||||||
|
let rows = sqlx::query_as::<_, DiaryRow>(
|
||||||
|
"SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,
|
||||||
|
r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment,
|
||||||
|
to_char(r.watched_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS watched_at,
|
||||||
|
to_char(r.created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at,
|
||||||
|
r.remote_actor_url
|
||||||
|
FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
WHERE r.movie_id = $1 AND r.remote_actor_url IS NULL
|
||||||
|
ORDER BY r.created_at DESC",
|
||||||
|
)
|
||||||
|
.bind(&mid)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
rows.into_iter().map(DiaryRow::into_domain).collect()
|
||||||
|
}
|
||||||
|
|
||||||
async fn get_review_by_id(&self, review_id: &ReviewId) -> Result<Option<Review>, DomainError> {
|
async fn get_review_by_id(&self, review_id: &ReviewId) -> Result<Option<Review>, DomainError> {
|
||||||
let id = review_id.value().to_string();
|
let id = review_id.value().to_string();
|
||||||
sqlx::query_as::<_, ReviewRow>(
|
sqlx::query_as::<_, ReviewRow>(
|
||||||
@@ -205,4 +228,31 @@ impl LocalApContentQuery for PostgresApContentQuery {
|
|||||||
};
|
};
|
||||||
rows.into_iter().map(DiaryRow::into_domain).collect()
|
rows.into_iter().map(DiaryRow::into_domain).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_goal_with_progress(
|
||||||
|
&self,
|
||||||
|
user_id: &UserId,
|
||||||
|
year: u16,
|
||||||
|
) -> Result<Option<(domain::models::Goal, u32)>, DomainError> {
|
||||||
|
let uid = user_id.value().to_string();
|
||||||
|
let y = year as i64;
|
||||||
|
|
||||||
|
let row = sqlx::query(
|
||||||
|
"SELECT id, user_id, year, target_count, goal_type, \
|
||||||
|
to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at \
|
||||||
|
FROM goals WHERE user_id = $1 AND year = $2",
|
||||||
|
)
|
||||||
|
.bind(&uid)
|
||||||
|
.bind(y)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
let Some(r) = row else { return Ok(None) };
|
||||||
|
|
||||||
|
let goal = crate::goals::row_to_goal(&r)?;
|
||||||
|
let count = crate::goals::count_reviews_in_year(&self.pool, user_id, year).await?;
|
||||||
|
|
||||||
|
Ok(Some((goal, count)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
540
crates/adapters/postgres/src/diary.rs
Normal file
540
crates/adapters/postgres/src/diary.rs
Normal file
@@ -0,0 +1,540 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
|
use domain::{
|
||||||
|
errors::DomainError,
|
||||||
|
models::{
|
||||||
|
DiaryEntry, DiaryFilter, FeedEntry, MovieStats, ReviewHistory, SortDirection,
|
||||||
|
collections::{PageParams, Paginated},
|
||||||
|
},
|
||||||
|
ports::DiaryRepository,
|
||||||
|
value_objects::{MovieId, UserId},
|
||||||
|
};
|
||||||
|
use futures::stream::BoxStream;
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
use crate::models::{DiaryRow, FeedRow, MovieRow, MovieStatsRow, ReviewRow};
|
||||||
|
|
||||||
|
pub struct PostgresDiaryRepository {
|
||||||
|
pool: PgPool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostgresDiaryRepository {
|
||||||
|
pub fn new(pool: PgPool) -> Self {
|
||||||
|
Self { pool }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn map_err(e: sqlx::Error) -> DomainError {
|
||||||
|
tracing::error!("Database error: {:?}", e);
|
||||||
|
DomainError::InfrastructureError("Database operation failed".into())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn count_diary_entries(&self, movie_id: Option<&str>) -> Result<i64, DomainError> {
|
||||||
|
match movie_id {
|
||||||
|
None => sqlx::query_scalar::<_, i64>("SELECT COUNT(*) FROM reviews")
|
||||||
|
.fetch_one(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err),
|
||||||
|
Some(id) => {
|
||||||
|
sqlx::query_scalar::<_, i64>("SELECT COUNT(*) FROM reviews WHERE movie_id = $1")
|
||||||
|
.bind(id)
|
||||||
|
.fetch_one(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_all_diary_rows(
|
||||||
|
&self,
|
||||||
|
sort: &SortDirection,
|
||||||
|
limit: i64,
|
||||||
|
offset: i64,
|
||||||
|
) -> Result<Vec<DiaryRow>, DomainError> {
|
||||||
|
let order = match sort {
|
||||||
|
SortDirection::ByRatingDesc => "r.rating DESC, r.watched_at DESC",
|
||||||
|
SortDirection::ByRatingAsc => "r.rating ASC, r.watched_at ASC",
|
||||||
|
SortDirection::Ascending => "r.watched_at ASC",
|
||||||
|
SortDirection::Descending => "r.watched_at DESC",
|
||||||
|
};
|
||||||
|
let sql = format!(
|
||||||
|
"SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,
|
||||||
|
r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment,
|
||||||
|
to_char(r.watched_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS watched_at,
|
||||||
|
to_char(r.created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at,
|
||||||
|
r.remote_actor_url
|
||||||
|
FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
ORDER BY {}
|
||||||
|
LIMIT $1 OFFSET $2",
|
||||||
|
order
|
||||||
|
);
|
||||||
|
sqlx::query_as::<_, DiaryRow>(&sql)
|
||||||
|
.bind(limit)
|
||||||
|
.bind(offset)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_movie_diary_rows(
|
||||||
|
&self,
|
||||||
|
movie_id: &str,
|
||||||
|
sort: &SortDirection,
|
||||||
|
limit: i64,
|
||||||
|
offset: i64,
|
||||||
|
) -> Result<Vec<DiaryRow>, DomainError> {
|
||||||
|
let order = match sort {
|
||||||
|
SortDirection::ByRatingDesc => "r.rating DESC, r.watched_at DESC",
|
||||||
|
SortDirection::ByRatingAsc => "r.rating ASC, r.watched_at ASC",
|
||||||
|
SortDirection::Ascending => "r.watched_at ASC",
|
||||||
|
SortDirection::Descending => "r.watched_at DESC",
|
||||||
|
};
|
||||||
|
let sql = format!(
|
||||||
|
"SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,
|
||||||
|
r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment,
|
||||||
|
to_char(r.watched_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS watched_at,
|
||||||
|
to_char(r.created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at,
|
||||||
|
r.remote_actor_url
|
||||||
|
FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
WHERE r.movie_id = $1
|
||||||
|
ORDER BY {}
|
||||||
|
LIMIT $2 OFFSET $3",
|
||||||
|
order
|
||||||
|
);
|
||||||
|
sqlx::query_as::<_, DiaryRow>(&sql)
|
||||||
|
.bind(movie_id)
|
||||||
|
.bind(limit)
|
||||||
|
.bind(offset)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn count_user_diary_entries(
|
||||||
|
&self,
|
||||||
|
user_id: &str,
|
||||||
|
search: Option<&str>,
|
||||||
|
) -> Result<i64, DomainError> {
|
||||||
|
let has_search = search.map(|s| !s.is_empty()).unwrap_or(false);
|
||||||
|
let sql = if has_search {
|
||||||
|
"SELECT COUNT(*) FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
WHERE r.user_id = $1 AND m.title ILIKE '%' || $2 || '%'"
|
||||||
|
.to_string()
|
||||||
|
} else {
|
||||||
|
"SELECT COUNT(*) FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
WHERE r.user_id = $1"
|
||||||
|
.to_string()
|
||||||
|
};
|
||||||
|
let mut q = sqlx::query_scalar::<_, i64>(&sql).bind(user_id);
|
||||||
|
if has_search {
|
||||||
|
q = q.bind(search.unwrap());
|
||||||
|
}
|
||||||
|
q.fetch_one(&self.pool).await.map_err(Self::map_err)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_user_diary_rows(
|
||||||
|
&self,
|
||||||
|
user_id: &str,
|
||||||
|
sort: &SortDirection,
|
||||||
|
search: Option<&str>,
|
||||||
|
limit: i64,
|
||||||
|
offset: i64,
|
||||||
|
) -> Result<Vec<DiaryRow>, DomainError> {
|
||||||
|
let has_search = search.map(|s| !s.is_empty()).unwrap_or(false);
|
||||||
|
let order_clause = match sort {
|
||||||
|
SortDirection::ByRatingDesc => "r.rating DESC, r.watched_at DESC",
|
||||||
|
SortDirection::ByRatingAsc => "r.rating ASC, r.watched_at ASC",
|
||||||
|
SortDirection::Ascending => "r.watched_at ASC",
|
||||||
|
SortDirection::Descending => "r.watched_at DESC",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Build param counter: user_id=$1, optional search=$2, limit=$N-1, offset=$N
|
||||||
|
let mut p: i32 = 1; // $1 is user_id
|
||||||
|
let search_clause = if has_search {
|
||||||
|
p += 1;
|
||||||
|
format!(" AND m.title ILIKE '%' || ${} || '%'", p)
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
};
|
||||||
|
p += 1;
|
||||||
|
let limit_param = format!("${}", p);
|
||||||
|
p += 1;
|
||||||
|
let offset_param = format!("${}", p);
|
||||||
|
|
||||||
|
let sql = format!(
|
||||||
|
"SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,
|
||||||
|
r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment,
|
||||||
|
to_char(r.watched_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS watched_at,
|
||||||
|
to_char(r.created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at,
|
||||||
|
r.remote_actor_url
|
||||||
|
FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
WHERE r.user_id = $1{}
|
||||||
|
ORDER BY {}
|
||||||
|
LIMIT {} OFFSET {}",
|
||||||
|
search_clause, order_clause, limit_param, offset_param
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut q = sqlx::query_as::<_, DiaryRow>(&sql).bind(user_id);
|
||||||
|
if has_search {
|
||||||
|
q = q.bind(search.unwrap());
|
||||||
|
}
|
||||||
|
q.bind(limit)
|
||||||
|
.bind(offset)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl DiaryRepository for PostgresDiaryRepository {
|
||||||
|
async fn query_diary(
|
||||||
|
&self,
|
||||||
|
filter: &DiaryFilter,
|
||||||
|
) -> Result<Paginated<DiaryEntry>, DomainError> {
|
||||||
|
let limit = filter.page.limit as i64;
|
||||||
|
let offset = filter.page.offset as i64;
|
||||||
|
|
||||||
|
let (total, rows) = match (&filter.movie_id, &filter.user_id) {
|
||||||
|
(None, None) => tokio::try_join!(
|
||||||
|
self.count_diary_entries(None),
|
||||||
|
self.fetch_all_diary_rows(&filter.sort_by, limit, offset)
|
||||||
|
)?,
|
||||||
|
(Some(id), None) => {
|
||||||
|
let id_str = id.value().to_string();
|
||||||
|
tokio::try_join!(
|
||||||
|
self.count_diary_entries(Some(id_str.as_str())),
|
||||||
|
self.fetch_movie_diary_rows(&id_str, &filter.sort_by, limit, offset)
|
||||||
|
)?
|
||||||
|
}
|
||||||
|
(None, Some(uid)) => {
|
||||||
|
let uid_str = uid.value().to_string();
|
||||||
|
let search = filter.search.as_deref();
|
||||||
|
tokio::try_join!(
|
||||||
|
self.count_user_diary_entries(&uid_str, search),
|
||||||
|
self.fetch_user_diary_rows(&uid_str, &filter.sort_by, search, limit, offset)
|
||||||
|
)?
|
||||||
|
}
|
||||||
|
(Some(_), Some(_)) => {
|
||||||
|
return Err(DomainError::ValidationError(
|
||||||
|
"Combined movie_id + user_id filter not supported".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let items = rows
|
||||||
|
.into_iter()
|
||||||
|
.map(DiaryRow::into_domain)
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
Ok(Paginated {
|
||||||
|
items,
|
||||||
|
total_count: total as u64,
|
||||||
|
limit: filter.page.limit,
|
||||||
|
offset: filter.page.offset,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn query_activity_feed(
|
||||||
|
&self,
|
||||||
|
page: &PageParams,
|
||||||
|
) -> Result<Paginated<FeedEntry>, DomainError> {
|
||||||
|
self.query_activity_feed_filtered(page, &domain::ports::FeedSortBy::Date, None, None)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn query_activity_feed_filtered(
|
||||||
|
&self,
|
||||||
|
page: &PageParams,
|
||||||
|
sort_by: &domain::ports::FeedSortBy,
|
||||||
|
search: Option<&str>,
|
||||||
|
following: Option<&domain::ports::FollowingFilter>,
|
||||||
|
) -> Result<Paginated<FeedEntry>, DomainError> {
|
||||||
|
use domain::ports::FeedSortBy;
|
||||||
|
|
||||||
|
let limit = page.limit as i64;
|
||||||
|
let offset = page.offset as i64;
|
||||||
|
let has_search = search.map(|s| !s.is_empty()).unwrap_or(false);
|
||||||
|
|
||||||
|
// Dynamic param counter
|
||||||
|
let mut p: i32 = 0;
|
||||||
|
let mut next_param = || {
|
||||||
|
p += 1;
|
||||||
|
format!("${}", p)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut where_parts = vec!["1=1".to_string()];
|
||||||
|
|
||||||
|
if has_search {
|
||||||
|
let pn = next_param();
|
||||||
|
where_parts.push(format!("m.title ILIKE '%' || {} || '%'", pn));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(f) = following {
|
||||||
|
let local_params: Vec<String> = f.local_user_ids.iter().map(|_| next_param()).collect();
|
||||||
|
let remote_params: Vec<String> =
|
||||||
|
f.remote_actor_urls.iter().map(|_| next_param()).collect();
|
||||||
|
|
||||||
|
let local_in = if local_params.is_empty() {
|
||||||
|
"(SELECT NULL::text WHERE false)".to_string()
|
||||||
|
} else {
|
||||||
|
local_params.join(", ")
|
||||||
|
};
|
||||||
|
let remote_in = if remote_params.is_empty() {
|
||||||
|
"(SELECT NULL::text WHERE false)".to_string()
|
||||||
|
} else {
|
||||||
|
remote_params.join(", ")
|
||||||
|
};
|
||||||
|
where_parts.push(format!(
|
||||||
|
"(r.user_id IN ({}) OR r.remote_actor_url IN ({}))",
|
||||||
|
local_in, remote_in
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let limit_param = next_param();
|
||||||
|
let offset_param = next_param();
|
||||||
|
|
||||||
|
let order_clause = match sort_by {
|
||||||
|
FeedSortBy::Date => "r.watched_at DESC",
|
||||||
|
FeedSortBy::DateAsc => "r.watched_at ASC",
|
||||||
|
FeedSortBy::Rating => "r.rating DESC, r.watched_at DESC",
|
||||||
|
FeedSortBy::RatingAsc => "r.rating ASC, r.watched_at ASC",
|
||||||
|
};
|
||||||
|
|
||||||
|
let where_clause = where_parts.join(" AND ");
|
||||||
|
|
||||||
|
// Reset counter for count query (reuse same where_clause string but re-bind)
|
||||||
|
// We need a separate counter for count SQL — but since where_clause is already built
|
||||||
|
// with the right $N references, both queries share it.
|
||||||
|
let count_sql = format!(
|
||||||
|
"SELECT COUNT(*) FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
WHERE {}",
|
||||||
|
where_clause
|
||||||
|
);
|
||||||
|
|
||||||
|
let select_sql = format!(
|
||||||
|
"SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,
|
||||||
|
r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment,
|
||||||
|
to_char(r.watched_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS watched_at,
|
||||||
|
to_char(r.created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at,
|
||||||
|
r.remote_actor_url,
|
||||||
|
COALESCE(u.email, r.remote_actor_url) AS user_email
|
||||||
|
FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
LEFT JOIN users u ON u.id = r.user_id
|
||||||
|
WHERE {}
|
||||||
|
ORDER BY {}
|
||||||
|
LIMIT {} OFFSET {}",
|
||||||
|
where_clause, order_clause, limit_param, offset_param
|
||||||
|
);
|
||||||
|
|
||||||
|
// Bind helper closure — binds search + following params in order
|
||||||
|
macro_rules! bind_filter_params {
|
||||||
|
($q:expr) => {{
|
||||||
|
let mut q = $q;
|
||||||
|
if has_search {
|
||||||
|
q = q.bind(search.unwrap());
|
||||||
|
}
|
||||||
|
if let Some(f) = following {
|
||||||
|
for uid in &f.local_user_ids {
|
||||||
|
q = q.bind(uid.to_string());
|
||||||
|
}
|
||||||
|
for url in &f.remote_actor_urls {
|
||||||
|
q = q.bind(url.as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
q
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
let count_q = bind_filter_params!(sqlx::query_scalar::<_, i64>(&count_sql));
|
||||||
|
let total = count_q.fetch_one(&self.pool).await.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
let rows_q = bind_filter_params!(sqlx::query_as::<_, FeedRow>(&select_sql));
|
||||||
|
let rows = rows_q
|
||||||
|
.bind(limit)
|
||||||
|
.bind(offset)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
let items = rows
|
||||||
|
.into_iter()
|
||||||
|
.map(FeedRow::into_domain)
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
Ok(Paginated {
|
||||||
|
items,
|
||||||
|
total_count: total as u64,
|
||||||
|
limit: page.limit,
|
||||||
|
offset: page.offset,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_review_history(&self, movie_id: &MovieId) -> Result<ReviewHistory, DomainError> {
|
||||||
|
let id_str = movie_id.value().to_string();
|
||||||
|
|
||||||
|
let movie = sqlx::query_as::<_, MovieRow>(
|
||||||
|
"SELECT id, external_metadata_id, title, release_year, director, poster_path
|
||||||
|
FROM movies WHERE id = $1",
|
||||||
|
)
|
||||||
|
.bind(&id_str)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?
|
||||||
|
.ok_or_else(|| DomainError::NotFound(format!("Movie {}", id_str)))?
|
||||||
|
.into_domain()?;
|
||||||
|
|
||||||
|
let viewings = sqlx::query_as::<_, ReviewRow>(
|
||||||
|
"SELECT id, movie_id, user_id, rating, comment,
|
||||||
|
to_char(watched_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS watched_at,
|
||||||
|
to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at,
|
||||||
|
remote_actor_url
|
||||||
|
FROM reviews WHERE movie_id = $1 ORDER BY watched_at ASC",
|
||||||
|
)
|
||||||
|
.bind(&id_str)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?
|
||||||
|
.into_iter()
|
||||||
|
.map(ReviewRow::into_domain)
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
Ok(ReviewHistory::new(movie, viewings))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_user_history(&self, user_id: &UserId) -> Result<Vec<DiaryEntry>, DomainError> {
|
||||||
|
let uid = user_id.value().to_string();
|
||||||
|
let rows = sqlx::query_as::<_, DiaryRow>(
|
||||||
|
"SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,
|
||||||
|
r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment,
|
||||||
|
to_char(r.watched_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS watched_at,
|
||||||
|
to_char(r.created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at,
|
||||||
|
r.remote_actor_url
|
||||||
|
FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
WHERE r.user_id = $1
|
||||||
|
ORDER BY r.watched_at DESC",
|
||||||
|
)
|
||||||
|
.bind(&uid)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
rows.into_iter().map(DiaryRow::into_domain).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stream_user_history(
|
||||||
|
&self,
|
||||||
|
user_id: UserId,
|
||||||
|
) -> BoxStream<'static, Result<DiaryEntry, DomainError>> {
|
||||||
|
let pool = self.pool.clone();
|
||||||
|
let uid = user_id.value().to_string();
|
||||||
|
Box::pin(async_stream::stream! {
|
||||||
|
let mut rows = sqlx::query_as::<_, DiaryRow>(
|
||||||
|
"SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,
|
||||||
|
r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment,
|
||||||
|
to_char(r.watched_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS watched_at,
|
||||||
|
to_char(r.created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at,
|
||||||
|
r.remote_actor_url
|
||||||
|
FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
WHERE r.user_id = $1
|
||||||
|
ORDER BY r.watched_at DESC",
|
||||||
|
)
|
||||||
|
.bind(&uid)
|
||||||
|
.fetch(&pool);
|
||||||
|
while let Some(row) = futures::StreamExt::next(&mut rows).await {
|
||||||
|
yield match row {
|
||||||
|
Ok(r) => r.into_domain(),
|
||||||
|
Err(e) => Err(Self::map_err(e)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_movie_stats(&self, movie_id: &MovieId) -> Result<MovieStats, DomainError> {
|
||||||
|
let id_str = movie_id.value().to_string();
|
||||||
|
sqlx::query_as::<_, MovieStatsRow>(
|
||||||
|
"SELECT
|
||||||
|
COUNT(*) AS total_count,
|
||||||
|
AVG(CAST(rating AS FLOAT)) AS avg_rating,
|
||||||
|
COUNT(CASE WHEN remote_actor_url IS NOT NULL THEN 1 END) AS federated_count,
|
||||||
|
COUNT(CASE WHEN rating = 1 THEN 1 END) AS rating_1,
|
||||||
|
COUNT(CASE WHEN rating = 2 THEN 1 END) AS rating_2,
|
||||||
|
COUNT(CASE WHEN rating = 3 THEN 1 END) AS rating_3,
|
||||||
|
COUNT(CASE WHEN rating = 4 THEN 1 END) AS rating_4,
|
||||||
|
COUNT(CASE WHEN rating = 5 THEN 1 END) AS rating_5
|
||||||
|
FROM reviews WHERE movie_id = $1",
|
||||||
|
)
|
||||||
|
.bind(id_str)
|
||||||
|
.fetch_one(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)
|
||||||
|
.map(MovieStatsRow::into_domain)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_movie_social_feed(
|
||||||
|
&self,
|
||||||
|
movie_id: &MovieId,
|
||||||
|
page: &PageParams,
|
||||||
|
) -> Result<Paginated<FeedEntry>, DomainError> {
|
||||||
|
let id_str = movie_id.value().to_string();
|
||||||
|
let limit = page.limit as i64;
|
||||||
|
let offset = page.offset as i64;
|
||||||
|
|
||||||
|
let total: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM reviews WHERE movie_id = $1")
|
||||||
|
.bind(&id_str)
|
||||||
|
.fetch_one(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
let rows = sqlx::query_as::<_, FeedRow>(
|
||||||
|
"SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,
|
||||||
|
r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment,
|
||||||
|
to_char(r.watched_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS watched_at,
|
||||||
|
to_char(r.created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at,
|
||||||
|
r.remote_actor_url,
|
||||||
|
CASE WHEN r.remote_actor_url IS NOT NULL THEN r.remote_actor_url
|
||||||
|
WHEN u.email IS NOT NULL THEN u.email
|
||||||
|
ELSE r.user_id END AS user_email
|
||||||
|
FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
LEFT JOIN users u ON u.id = r.user_id
|
||||||
|
WHERE r.movie_id = $1
|
||||||
|
ORDER BY r.watched_at DESC
|
||||||
|
LIMIT $2 OFFSET $3",
|
||||||
|
)
|
||||||
|
.bind(&id_str)
|
||||||
|
.bind(limit)
|
||||||
|
.bind(offset)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
let items = rows
|
||||||
|
.into_iter()
|
||||||
|
.map(FeedRow::into_domain)
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
Ok(Paginated {
|
||||||
|
items,
|
||||||
|
total_count: total as u64,
|
||||||
|
limit: page.limit,
|
||||||
|
offset: page.offset,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn count_local_posts(&self) -> Result<u64, DomainError> {
|
||||||
|
let count: i64 =
|
||||||
|
sqlx::query_scalar("SELECT COUNT(*) FROM reviews WHERE remote_actor_url IS NULL")
|
||||||
|
.fetch_one(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
Ok(count as u64)
|
||||||
|
}
|
||||||
|
}
|
||||||
195
crates/adapters/postgres/src/goals.rs
Normal file
195
crates/adapters/postgres/src/goals.rs
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
|
use domain::{
|
||||||
|
errors::DomainError,
|
||||||
|
models::{Goal, GoalType},
|
||||||
|
ports::GoalRepository,
|
||||||
|
value_objects::{GoalId, UserId},
|
||||||
|
};
|
||||||
|
use sqlx::{PgPool, Row};
|
||||||
|
|
||||||
|
use crate::models::{datetime_to_str, parse_datetime, parse_uuid};
|
||||||
|
|
||||||
|
pub struct PostgresGoalRepository {
|
||||||
|
pool: PgPool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostgresGoalRepository {
|
||||||
|
pub fn new(pool: PgPool) -> Self {
|
||||||
|
Self { pool }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn map_err(e: sqlx::Error) -> DomainError {
|
||||||
|
tracing::error!("Database error: {:?}", e);
|
||||||
|
DomainError::InfrastructureError("Database operation failed".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl GoalRepository for PostgresGoalRepository {
|
||||||
|
async fn save(&self, goal: &Goal) -> Result<(), DomainError> {
|
||||||
|
let id = goal.id().value().to_string();
|
||||||
|
let user_id = goal.user_id().value().to_string();
|
||||||
|
let year = goal.year() as i64;
|
||||||
|
let target = goal.target_count() as i64;
|
||||||
|
let goal_type = goal.goal_type().as_str();
|
||||||
|
let created_at = datetime_to_str(goal.created_at());
|
||||||
|
|
||||||
|
sqlx::query(
|
||||||
|
"INSERT INTO goals (id, user_id, year, target_count, goal_type, created_at) \
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6::timestamptz)",
|
||||||
|
)
|
||||||
|
.bind(&id)
|
||||||
|
.bind(&user_id)
|
||||||
|
.bind(year)
|
||||||
|
.bind(target)
|
||||||
|
.bind(goal_type)
|
||||||
|
.bind(&created_at)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn update(&self, goal: &Goal) -> Result<(), DomainError> {
|
||||||
|
let id = goal.id().value().to_string();
|
||||||
|
let target = goal.target_count() as i64;
|
||||||
|
|
||||||
|
let result = sqlx::query("UPDATE goals SET target_count = $1 WHERE id = $2")
|
||||||
|
.bind(target)
|
||||||
|
.bind(&id)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
if result.rows_affected() == 0 {
|
||||||
|
return Err(DomainError::NotFound("Goal not found".into()));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete(&self, id: &GoalId, user_id: &UserId) -> Result<(), DomainError> {
|
||||||
|
let gid = id.value().to_string();
|
||||||
|
let uid = user_id.value().to_string();
|
||||||
|
|
||||||
|
let result = sqlx::query("DELETE FROM goals WHERE id = $1 AND user_id = $2")
|
||||||
|
.bind(&gid)
|
||||||
|
.bind(&uid)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
if result.rows_affected() == 0 {
|
||||||
|
return Err(DomainError::NotFound("Goal not found".into()));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn find_by_user_and_year(
|
||||||
|
&self,
|
||||||
|
user_id: &UserId,
|
||||||
|
year: u16,
|
||||||
|
) -> Result<Option<Goal>, DomainError> {
|
||||||
|
let uid = user_id.value().to_string();
|
||||||
|
let y = year as i64;
|
||||||
|
|
||||||
|
let row = sqlx::query(
|
||||||
|
"SELECT id, user_id, year, target_count, goal_type, \
|
||||||
|
to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at \
|
||||||
|
FROM goals WHERE user_id = $1 AND year = $2",
|
||||||
|
)
|
||||||
|
.bind(&uid)
|
||||||
|
.bind(y)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
row.map(|r| row_to_goal(&r)).transpose()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn list_for_user(&self, user_id: &UserId) -> Result<Vec<Goal>, DomainError> {
|
||||||
|
let uid = user_id.value().to_string();
|
||||||
|
|
||||||
|
let rows = sqlx::query(
|
||||||
|
"SELECT id, user_id, year, target_count, goal_type, \
|
||||||
|
to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at \
|
||||||
|
FROM goals WHERE user_id = $1 ORDER BY year DESC",
|
||||||
|
)
|
||||||
|
.bind(&uid)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
rows.iter().map(row_to_goal).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn count_reviews_in_year(&self, user_id: &UserId, year: u16) -> Result<u32, DomainError> {
|
||||||
|
count_reviews_in_year(&self.pool, user_id, year).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn count_reviews_in_year(
|
||||||
|
pool: &PgPool,
|
||||||
|
user_id: &UserId,
|
||||||
|
year: u16,
|
||||||
|
) -> Result<u32, DomainError> {
|
||||||
|
let uid = user_id.value().to_string();
|
||||||
|
let start = format!("{year}-01-01 00:00:00");
|
||||||
|
let end = format!("{}-01-01 00:00:00", year + 1);
|
||||||
|
|
||||||
|
let count: i64 = sqlx::query(
|
||||||
|
"SELECT COUNT(*) FROM reviews \
|
||||||
|
WHERE user_id = $1 \
|
||||||
|
AND watched_at >= $2::timestamptz \
|
||||||
|
AND watched_at < $3::timestamptz \
|
||||||
|
AND remote_actor_url IS NULL",
|
||||||
|
)
|
||||||
|
.bind(&uid)
|
||||||
|
.bind(&start)
|
||||||
|
.bind(&end)
|
||||||
|
.fetch_one(pool)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
tracing::error!("Database error: {:?}", e);
|
||||||
|
DomainError::InfrastructureError("Database operation failed".into())
|
||||||
|
})?
|
||||||
|
.try_get(0)
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
Ok(count as u32)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn row_to_goal(r: &sqlx::postgres::PgRow) -> Result<Goal, DomainError> {
|
||||||
|
let id_str: String = r
|
||||||
|
.try_get("id")
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(format!("Failed to read goal id: {e}")))?;
|
||||||
|
let user_id_str: String = r
|
||||||
|
.try_get("user_id")
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(format!("Failed to read user_id: {e}")))?;
|
||||||
|
let year: i64 = r
|
||||||
|
.try_get("year")
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(format!("Failed to read year: {e}")))?;
|
||||||
|
let target: i64 = r.try_get("target_count").map_err(|e| {
|
||||||
|
DomainError::InfrastructureError(format!("Failed to read target_count: {e}"))
|
||||||
|
})?;
|
||||||
|
let goal_type_str: String = r
|
||||||
|
.try_get("goal_type")
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(format!("Failed to read goal_type: {e}")))?;
|
||||||
|
let created_at_str: String = r
|
||||||
|
.try_get("created_at")
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(format!("Failed to read created_at: {e}")))?;
|
||||||
|
|
||||||
|
let id = GoalId::from_uuid(parse_uuid(&id_str)?);
|
||||||
|
let user_id = UserId::from_uuid(parse_uuid(&user_id_str)?);
|
||||||
|
let goal_type: GoalType = goal_type_str.parse()?;
|
||||||
|
let created_at = parse_datetime(&created_at_str)?;
|
||||||
|
|
||||||
|
Ok(Goal::from_persistence(
|
||||||
|
id,
|
||||||
|
user_id,
|
||||||
|
year as u16,
|
||||||
|
target as u32,
|
||||||
|
goal_type,
|
||||||
|
created_at,
|
||||||
|
))
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ use domain::{
|
|||||||
models::{
|
models::{
|
||||||
AnnotatedRow, FieldMapping, ImportSession, ParsedFile,
|
AnnotatedRow, FieldMapping, ImportSession, ParsedFile,
|
||||||
import::{DomainField, ImportRow, RowResult, Transform},
|
import::{DomainField, ImportRow, RowResult, Transform},
|
||||||
|
import_session::PersistedImportSession,
|
||||||
},
|
},
|
||||||
ports::ImportSessionRepository,
|
ports::ImportSessionRepository,
|
||||||
value_objects::{ImportSessionId, UserId},
|
value_objects::{ImportSessionId, UserId},
|
||||||
@@ -266,7 +267,7 @@ impl PostgresImportSessionRepository {
|
|||||||
Ok(js.into_iter().map(annotated_from_json).collect())
|
Ok(js.into_iter().map(annotated_from_json).collect())
|
||||||
})
|
})
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
Ok(ImportSession {
|
Ok(ImportSession::from_persistence(PersistedImportSession {
|
||||||
id: ImportSessionId::from_uuid(
|
id: ImportSessionId::from_uuid(
|
||||||
id.parse::<uuid::Uuid>()
|
id.parse::<uuid::Uuid>()
|
||||||
.map_err(|e| DomainError::InfrastructureError(e.to_string()))?,
|
.map_err(|e| DomainError::InfrastructureError(e.to_string()))?,
|
||||||
@@ -281,7 +282,7 @@ impl PostgresImportSessionRepository {
|
|||||||
row_results,
|
row_results,
|
||||||
created_at,
|
created_at,
|
||||||
expires_at,
|
expires_at,
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@ use domain::{
|
|||||||
},
|
},
|
||||||
value_objects::{
|
value_objects::{
|
||||||
Comment, Email, ExternalMetadataId, MovieId, MovieTitle, PosterPath, Rating, ReleaseYear,
|
Comment, Email, ExternalMetadataId, MovieId, MovieTitle, PosterPath, Rating, ReleaseYear,
|
||||||
ReviewId, UserId,
|
ReviewId, UserId, Username,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@@ -237,6 +237,8 @@ impl MovieStatsRow {
|
|||||||
pub(crate) struct UserSummaryRow {
|
pub(crate) struct UserSummaryRow {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub email: String,
|
pub email: String,
|
||||||
|
pub username: String,
|
||||||
|
pub display_name: Option<String>,
|
||||||
pub total_movies: i64,
|
pub total_movies: i64,
|
||||||
pub avg_rating: Option<f64>,
|
pub avg_rating: Option<f64>,
|
||||||
pub avatar_path: Option<String>,
|
pub avatar_path: Option<String>,
|
||||||
@@ -247,6 +249,8 @@ impl UserSummaryRow {
|
|||||||
Ok(UserSummary::new(
|
Ok(UserSummary::new(
|
||||||
UserId::from_uuid(parse_uuid(&self.id)?),
|
UserId::from_uuid(parse_uuid(&self.id)?),
|
||||||
Email::new(self.email)?,
|
Email::new(self.email)?,
|
||||||
|
Username::new(self.username)?,
|
||||||
|
self.display_name,
|
||||||
self.total_movies,
|
self.total_movies,
|
||||||
self.avg_rating,
|
self.avg_rating,
|
||||||
self.avatar_path,
|
self.avatar_path,
|
||||||
|
|||||||
242
crates/adapters/postgres/src/movie.rs
Normal file
242
crates/adapters/postgres/src/movie.rs
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
|
use domain::{
|
||||||
|
errors::DomainError,
|
||||||
|
models::{
|
||||||
|
Movie, MovieFilter, MovieSummary,
|
||||||
|
collections::{PageParams, Paginated},
|
||||||
|
},
|
||||||
|
ports::MovieRepository,
|
||||||
|
value_objects::{ExternalMetadataId, MovieId, MovieTitle, ReleaseYear},
|
||||||
|
};
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
use crate::models::{MovieRow, MovieSummaryRow};
|
||||||
|
|
||||||
|
pub struct PostgresMovieRepository {
|
||||||
|
pool: PgPool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostgresMovieRepository {
|
||||||
|
pub fn new(pool: PgPool) -> Self {
|
||||||
|
Self { pool }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn map_err(e: sqlx::Error) -> DomainError {
|
||||||
|
tracing::error!("Database error: {:?}", e);
|
||||||
|
DomainError::InfrastructureError("Database operation failed".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl MovieRepository for PostgresMovieRepository {
|
||||||
|
async fn get_movie_by_external_id(
|
||||||
|
&self,
|
||||||
|
external_metadata_id: &ExternalMetadataId,
|
||||||
|
) -> Result<Option<Movie>, DomainError> {
|
||||||
|
let id = external_metadata_id.value();
|
||||||
|
sqlx::query_as::<_, MovieRow>(
|
||||||
|
"SELECT id, external_metadata_id, title, release_year, director, poster_path
|
||||||
|
FROM movies WHERE external_metadata_id = $1",
|
||||||
|
)
|
||||||
|
.bind(id)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?
|
||||||
|
.map(MovieRow::into_domain)
|
||||||
|
.transpose()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_movie_by_id(&self, movie_id: &MovieId) -> Result<Option<Movie>, DomainError> {
|
||||||
|
let id = movie_id.value().to_string();
|
||||||
|
sqlx::query_as::<_, MovieRow>(
|
||||||
|
"SELECT id, external_metadata_id, title, release_year, director, poster_path
|
||||||
|
FROM movies WHERE id = $1",
|
||||||
|
)
|
||||||
|
.bind(&id)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?
|
||||||
|
.map(MovieRow::into_domain)
|
||||||
|
.transpose()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_movies_by_title_and_year(
|
||||||
|
&self,
|
||||||
|
title: &MovieTitle,
|
||||||
|
year: &ReleaseYear,
|
||||||
|
) -> Result<Vec<Movie>, DomainError> {
|
||||||
|
let title = title.value();
|
||||||
|
let year = year.value() as i64;
|
||||||
|
sqlx::query_as::<_, MovieRow>(
|
||||||
|
"SELECT id, external_metadata_id, title, release_year, director, poster_path
|
||||||
|
FROM movies WHERE title = $1 AND release_year = $2",
|
||||||
|
)
|
||||||
|
.bind(title)
|
||||||
|
.bind(year)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?
|
||||||
|
.into_iter()
|
||||||
|
.map(MovieRow::into_domain)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn upsert_movie(&self, movie: &Movie) -> Result<(), DomainError> {
|
||||||
|
let id = movie.id().value().to_string();
|
||||||
|
let external_metadata_id = movie.external_metadata_id().map(|e| e.value().to_string());
|
||||||
|
let title = movie.title().value();
|
||||||
|
let release_year = movie.release_year().value() as i64;
|
||||||
|
let director = movie.director();
|
||||||
|
let poster_path = movie.poster_path().map(|p| p.value().to_string());
|
||||||
|
|
||||||
|
sqlx::query(
|
||||||
|
"INSERT INTO movies (id, external_metadata_id, title, release_year, director, poster_path)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
|
ON CONFLICT(id) DO UPDATE SET
|
||||||
|
external_metadata_id = excluded.external_metadata_id,
|
||||||
|
title = excluded.title,
|
||||||
|
release_year = excluded.release_year,
|
||||||
|
director = excluded.director,
|
||||||
|
poster_path = excluded.poster_path",
|
||||||
|
)
|
||||||
|
.bind(&id)
|
||||||
|
.bind(&external_metadata_id)
|
||||||
|
.bind(title)
|
||||||
|
.bind(release_year)
|
||||||
|
.bind(director)
|
||||||
|
.bind(&poster_path)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete_movie(&self, movie_id: &MovieId) -> Result<(), DomainError> {
|
||||||
|
let id = movie_id.value().to_string();
|
||||||
|
sqlx::query("DELETE FROM movies WHERE id = $1")
|
||||||
|
.bind(&id)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn existing_external_ids(
|
||||||
|
&self,
|
||||||
|
ids: &[ExternalMetadataId],
|
||||||
|
) -> Result<std::collections::HashSet<String>, DomainError> {
|
||||||
|
if ids.is_empty() {
|
||||||
|
return Ok(Default::default());
|
||||||
|
}
|
||||||
|
let vals: Vec<String> = ids.iter().map(|id| id.value().to_string()).collect();
|
||||||
|
let rows: Vec<(String,)> = sqlx::query_as(
|
||||||
|
"SELECT external_metadata_id FROM movies WHERE external_metadata_id = ANY($1)",
|
||||||
|
)
|
||||||
|
.bind(&vals)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
Ok(rows.into_iter().map(|(id,)| id).collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn existing_title_year_pairs(
|
||||||
|
&self,
|
||||||
|
pairs: &[(MovieTitle, ReleaseYear)],
|
||||||
|
) -> Result<std::collections::HashSet<(String, u16)>, DomainError> {
|
||||||
|
if pairs.is_empty() {
|
||||||
|
return Ok(Default::default());
|
||||||
|
}
|
||||||
|
let titles: Vec<&str> = pairs.iter().map(|(t, _)| t.value()).collect();
|
||||||
|
let years: Vec<i64> = pairs.iter().map(|(_, y)| y.value() as i64).collect();
|
||||||
|
use sqlx::Row;
|
||||||
|
let rows = sqlx::query(
|
||||||
|
"SELECT DISTINCT m.title, m.release_year FROM movies m \
|
||||||
|
INNER JOIN unnest($1::text[], $2::bigint[]) AS p(title, release_year) \
|
||||||
|
ON m.title = p.title AND m.release_year = p.release_year",
|
||||||
|
)
|
||||||
|
.bind(&titles)
|
||||||
|
.bind(&years)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
Ok(rows
|
||||||
|
.into_iter()
|
||||||
|
.map(|r| {
|
||||||
|
let t: String = r.get("title");
|
||||||
|
let y: i64 = r.get("release_year");
|
||||||
|
(t, y as u16)
|
||||||
|
})
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn list_movies(
|
||||||
|
&self,
|
||||||
|
page: &PageParams,
|
||||||
|
filter: &MovieFilter,
|
||||||
|
) -> Result<Paginated<MovieSummary>, DomainError> {
|
||||||
|
use sqlx::Row;
|
||||||
|
let limit = page.limit as i64;
|
||||||
|
let offset = page.offset as i64;
|
||||||
|
let pattern = filter
|
||||||
|
.search
|
||||||
|
.as_deref()
|
||||||
|
.map(|s| format!("%{}%", s.to_lowercase()));
|
||||||
|
let genre = filter.genre.as_deref();
|
||||||
|
let language = filter.language.as_deref();
|
||||||
|
|
||||||
|
let rows: Vec<MovieSummaryRow> = sqlx::query_as(
|
||||||
|
"SELECT \
|
||||||
|
m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path, \
|
||||||
|
p.overview, p.runtime_minutes, p.original_language, p.collection_name, \
|
||||||
|
array_agg(g.name) FILTER (WHERE g.name IS NOT NULL) AS genres \
|
||||||
|
FROM movies m \
|
||||||
|
LEFT JOIN movie_profiles p ON p.movie_id = m.id \
|
||||||
|
LEFT JOIN movie_genres g ON g.movie_id = m.id \
|
||||||
|
WHERE ($1::text IS NULL OR LOWER(m.title) LIKE $1) \
|
||||||
|
AND ($2::text IS NULL OR p.original_language = $2) \
|
||||||
|
AND ($3::text IS NULL OR m.id IN (SELECT movie_id FROM movie_genres WHERE LOWER(name) = LOWER($3))) \
|
||||||
|
GROUP BY m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path, \
|
||||||
|
p.overview, p.runtime_minutes, p.original_language, p.collection_name \
|
||||||
|
ORDER BY m.title ASC \
|
||||||
|
LIMIT $4 OFFSET $5",
|
||||||
|
)
|
||||||
|
.bind(&pattern)
|
||||||
|
.bind(language)
|
||||||
|
.bind(genre)
|
||||||
|
.bind(limit)
|
||||||
|
.bind(offset)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
let total: i64 = sqlx::query(
|
||||||
|
"SELECT COUNT(DISTINCT m.id) \
|
||||||
|
FROM movies m \
|
||||||
|
LEFT JOIN movie_profiles p ON p.movie_id = m.id \
|
||||||
|
WHERE ($1::text IS NULL OR LOWER(m.title) LIKE $1) \
|
||||||
|
AND ($2::text IS NULL OR p.original_language = $2) \
|
||||||
|
AND ($3::text IS NULL OR m.id IN (SELECT movie_id FROM movie_genres WHERE LOWER(name) = LOWER($3)))",
|
||||||
|
)
|
||||||
|
.bind(&pattern)
|
||||||
|
.bind(language)
|
||||||
|
.bind(genre)
|
||||||
|
.fetch_one(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?
|
||||||
|
.try_get(0)
|
||||||
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
let items = rows
|
||||||
|
.into_iter()
|
||||||
|
.map(|r| r.into_domain())
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
Ok(Paginated {
|
||||||
|
items,
|
||||||
|
total_count: total as u64,
|
||||||
|
limit: page.limit,
|
||||||
|
offset: page.offset,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use domain::{
|
use domain::{
|
||||||
errors::DomainError,
|
errors::DomainError,
|
||||||
models::{CastCredit, CrewCredit, ExternalPersonId, Person, PersonCredits, PersonId},
|
models::{
|
||||||
|
CastCredit, CrewCredit, ExternalPersonId, Person, PersonCredits, PersonEnrichmentData,
|
||||||
|
PersonId,
|
||||||
|
},
|
||||||
ports::{PersonCommand, PersonQuery},
|
ports::{PersonCommand, PersonQuery},
|
||||||
value_objects::MovieId,
|
value_objects::MovieId,
|
||||||
};
|
};
|
||||||
@@ -57,71 +60,115 @@ impl PersonCommand for PostgresPersonAdapter {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn backfill_from_credits_batch(
|
||||||
|
&self,
|
||||||
|
batch_size: u32,
|
||||||
|
) -> Result<(u64, bool), DomainError> {
|
||||||
|
#[derive(sqlx::FromRow)]
|
||||||
|
struct MissingPerson {
|
||||||
|
tmdb_person_id: i64,
|
||||||
|
name: String,
|
||||||
|
department: Option<String>,
|
||||||
|
profile_path: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
let rows = sqlx::query_as::<_, MissingPerson>(
|
||||||
|
"SELECT mc.tmdb_person_id, mc.name, 'Acting' AS department, mc.profile_path
|
||||||
|
FROM movie_cast mc
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM persons WHERE persons.tmdb_person_id = mc.tmdb_person_id)
|
||||||
|
GROUP BY mc.tmdb_person_id, mc.name, mc.profile_path
|
||||||
|
UNION ALL
|
||||||
|
SELECT mc.tmdb_person_id, mc.name, mc.department, mc.profile_path
|
||||||
|
FROM movie_crew mc
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM persons WHERE persons.tmdb_person_id = mc.tmdb_person_id)
|
||||||
|
AND NOT EXISTS (SELECT 1 FROM movie_cast c2 WHERE c2.tmdb_person_id = mc.tmdb_person_id)
|
||||||
|
GROUP BY mc.tmdb_person_id, mc.name, mc.department, mc.profile_path
|
||||||
|
LIMIT $1",
|
||||||
|
)
|
||||||
|
.bind(batch_size as i64)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(map_err)?;
|
||||||
|
|
||||||
|
let has_more = rows.len() as u32 >= batch_size;
|
||||||
|
let mut count = 0u64;
|
||||||
|
for row in &rows {
|
||||||
|
let ext = ExternalPersonId::new(format!("tmdb:{}", row.tmdb_person_id));
|
||||||
|
let pid = PersonId::from_external(&ext);
|
||||||
|
sqlx::query(
|
||||||
|
"INSERT INTO persons (id, external_id, tmdb_person_id, name, known_for_department, profile_path)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
|
ON CONFLICT(tmdb_person_id) DO NOTHING",
|
||||||
|
)
|
||||||
|
.bind(pid.value().to_string())
|
||||||
|
.bind(ext.value())
|
||||||
|
.bind(row.tmdb_person_id)
|
||||||
|
.bind(&row.name)
|
||||||
|
.bind(&row.department)
|
||||||
|
.bind(&row.profile_path)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(map_err)?;
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
Ok((count, has_more))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn update_enrichment(
|
||||||
|
&self,
|
||||||
|
id: &PersonId,
|
||||||
|
data: &PersonEnrichmentData,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
|
let also_known_as_json =
|
||||||
|
serde_json::to_string(&data.also_known_as).unwrap_or_else(|_| "[]".into());
|
||||||
|
let now = chrono::Utc::now();
|
||||||
|
sqlx::query(
|
||||||
|
"UPDATE persons SET biography = $1, birthday = $2, deathday = $3, place_of_birth = $4, also_known_as = $5, homepage = $6, imdb_id = $7, enriched_at = $8 WHERE id = $9",
|
||||||
|
)
|
||||||
|
.bind(&data.biography)
|
||||||
|
.bind(data.birthday.map(|d| d.to_string()))
|
||||||
|
.bind(data.deathday.map(|d| d.to_string()))
|
||||||
|
.bind(&data.place_of_birth)
|
||||||
|
.bind(&also_known_as_json)
|
||||||
|
.bind(&data.homepage)
|
||||||
|
.bind(&data.imdb_id)
|
||||||
|
.bind(now)
|
||||||
|
.bind(id.value().to_string())
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(map_err)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl PersonQuery for PostgresPersonAdapter {
|
impl PersonQuery for PostgresPersonAdapter {
|
||||||
async fn get_by_id(&self, id: &PersonId) -> Result<Option<Person>, DomainError> {
|
async fn get_by_id(&self, id: &PersonId) -> Result<Option<Person>, DomainError> {
|
||||||
#[derive(sqlx::FromRow)]
|
let row = sqlx::query_as::<_, PersonRow>(
|
||||||
struct Row {
|
"SELECT id, external_id, name, known_for_department, profile_path, biography, birthday, deathday, place_of_birth, also_known_as, homepage, imdb_id, enriched_at FROM persons WHERE id = $1",
|
||||||
id: String,
|
|
||||||
external_id: String,
|
|
||||||
name: String,
|
|
||||||
known_for_department: Option<String>,
|
|
||||||
profile_path: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
let row = sqlx::query_as::<_, Row>(
|
|
||||||
"SELECT id, external_id, name, known_for_department, profile_path FROM persons WHERE id = $1",
|
|
||||||
)
|
)
|
||||||
.bind(id.value().to_string())
|
.bind(id.value().to_string())
|
||||||
.fetch_optional(&self.pool)
|
.fetch_optional(&self.pool)
|
||||||
.await
|
.await
|
||||||
.map_err(map_err)?;
|
.map_err(map_err)?;
|
||||||
|
|
||||||
Ok(row.map(|r| {
|
Ok(row.map(PersonRow::into_person))
|
||||||
let ext = ExternalPersonId::new(r.external_id);
|
|
||||||
Person::new(
|
|
||||||
PersonId::from_uuid(uuid::Uuid::parse_str(&r.id).unwrap_or_default()),
|
|
||||||
ext,
|
|
||||||
r.name,
|
|
||||||
r.known_for_department,
|
|
||||||
r.profile_path,
|
|
||||||
)
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_by_external_id(
|
async fn get_by_external_id(
|
||||||
&self,
|
&self,
|
||||||
id: &ExternalPersonId,
|
id: &ExternalPersonId,
|
||||||
) -> Result<Option<Person>, DomainError> {
|
) -> Result<Option<Person>, DomainError> {
|
||||||
#[derive(sqlx::FromRow)]
|
let row = sqlx::query_as::<_, PersonRow>(
|
||||||
struct Row {
|
"SELECT id, external_id, name, known_for_department, profile_path, biography, birthday, deathday, place_of_birth, also_known_as, homepage, imdb_id, enriched_at FROM persons WHERE external_id = $1",
|
||||||
id: String,
|
|
||||||
external_id: String,
|
|
||||||
name: String,
|
|
||||||
known_for_department: Option<String>,
|
|
||||||
profile_path: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
let row = sqlx::query_as::<_, Row>(
|
|
||||||
"SELECT id, external_id, name, known_for_department, profile_path FROM persons WHERE external_id = $1",
|
|
||||||
)
|
)
|
||||||
.bind(id.value())
|
.bind(id.value())
|
||||||
.fetch_optional(&self.pool)
|
.fetch_optional(&self.pool)
|
||||||
.await
|
.await
|
||||||
.map_err(map_err)?;
|
.map_err(map_err)?;
|
||||||
|
|
||||||
Ok(row.map(|r| {
|
Ok(row.map(PersonRow::into_person))
|
||||||
let ext = ExternalPersonId::new(r.external_id);
|
|
||||||
Person::new(
|
|
||||||
PersonId::from_uuid(uuid::Uuid::parse_str(&r.id).unwrap_or_default()),
|
|
||||||
ext,
|
|
||||||
r.name,
|
|
||||||
r.known_for_department,
|
|
||||||
r.profile_path,
|
|
||||||
)
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_credits(&self, id: &PersonId) -> Result<PersonCredits, DomainError> {
|
async fn get_credits(&self, id: &PersonId) -> Result<PersonCredits, DomainError> {
|
||||||
@@ -206,6 +253,19 @@ impl PersonQuery for PostgresPersonAdapter {
|
|||||||
Ok(PersonCredits { person, cast, crew })
|
Ok(PersonCredits { person, cast, crew })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn list_page(&self, limit: u32, offset: u32) -> Result<Vec<Person>, DomainError> {
|
||||||
|
let rows = sqlx::query_as::<_, PersonRow>(
|
||||||
|
"SELECT id, external_id, name, known_for_department, profile_path, biography, birthday, deathday, place_of_birth, also_known_as, homepage, imdb_id, enriched_at FROM persons ORDER BY id LIMIT $1 OFFSET $2",
|
||||||
|
)
|
||||||
|
.bind(limit as i64)
|
||||||
|
.bind(offset as i64)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(map_err)?;
|
||||||
|
|
||||||
|
Ok(rows.into_iter().map(PersonRow::into_person).collect())
|
||||||
|
}
|
||||||
|
|
||||||
async fn list_orphaned_persons(&self) -> Result<Vec<PersonId>, DomainError> {
|
async fn list_orphaned_persons(&self) -> Result<Vec<PersonId>, DomainError> {
|
||||||
let rows: Vec<(String,)> = sqlx::query_as(
|
let rows: Vec<(String,)> = sqlx::query_as(
|
||||||
"SELECT id FROM persons
|
"SELECT id FROM persons
|
||||||
@@ -214,7 +274,8 @@ impl PersonQuery for PostgresPersonAdapter {
|
|||||||
)
|
)
|
||||||
AND NOT EXISTS (
|
AND NOT EXISTS (
|
||||||
SELECT 1 FROM movie_crew WHERE movie_crew.tmdb_person_id = persons.tmdb_person_id
|
SELECT 1 FROM movie_crew WHERE movie_crew.tmdb_person_id = persons.tmdb_person_id
|
||||||
)",
|
)
|
||||||
|
LIMIT 500",
|
||||||
)
|
)
|
||||||
.fetch_all(&self.pool)
|
.fetch_all(&self.pool)
|
||||||
.await
|
.await
|
||||||
@@ -226,3 +287,57 @@ impl PersonQuery for PostgresPersonAdapter {
|
|||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Row types ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
#[derive(sqlx::FromRow)]
|
||||||
|
struct PersonRow {
|
||||||
|
id: String,
|
||||||
|
external_id: String,
|
||||||
|
name: String,
|
||||||
|
known_for_department: Option<String>,
|
||||||
|
profile_path: Option<String>,
|
||||||
|
biography: Option<String>,
|
||||||
|
birthday: Option<String>,
|
||||||
|
deathday: Option<String>,
|
||||||
|
place_of_birth: Option<String>,
|
||||||
|
also_known_as: Option<String>,
|
||||||
|
homepage: Option<String>,
|
||||||
|
imdb_id: Option<String>,
|
||||||
|
enriched_at: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PersonRow {
|
||||||
|
fn into_person(self) -> Person {
|
||||||
|
let ext = ExternalPersonId::new(self.external_id);
|
||||||
|
let also_known_as = self
|
||||||
|
.also_known_as
|
||||||
|
.and_then(|s| serde_json::from_str::<Vec<String>>(&s).ok())
|
||||||
|
.unwrap_or_default();
|
||||||
|
let birthday = self
|
||||||
|
.birthday
|
||||||
|
.and_then(|s| chrono::NaiveDate::parse_from_str(&s, "%Y-%m-%d").ok());
|
||||||
|
let deathday = self
|
||||||
|
.deathday
|
||||||
|
.and_then(|s| chrono::NaiveDate::parse_from_str(&s, "%Y-%m-%d").ok());
|
||||||
|
let enriched_at = self
|
||||||
|
.enriched_at
|
||||||
|
.and_then(|s| chrono::DateTime::parse_from_rfc3339(&s).ok())
|
||||||
|
.map(|d| d.with_timezone(&chrono::Utc));
|
||||||
|
Person::new(
|
||||||
|
PersonId::from_uuid(uuid::Uuid::parse_str(&self.id).unwrap_or_default()),
|
||||||
|
ext,
|
||||||
|
self.name,
|
||||||
|
self.known_for_department,
|
||||||
|
self.profile_path,
|
||||||
|
self.biography,
|
||||||
|
birthday,
|
||||||
|
deathday,
|
||||||
|
self.place_of_birth,
|
||||||
|
also_known_as,
|
||||||
|
self.homepage,
|
||||||
|
self.imdb_id,
|
||||||
|
enriched_at,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
112
crates/adapters/postgres/src/refresh_sessions.rs
Normal file
112
crates/adapters/postgres/src/refresh_sessions.rs
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
|
use chrono::DateTime;
|
||||||
|
use domain::{
|
||||||
|
errors::DomainError, models::RefreshSession, ports::RefreshSessionRepository,
|
||||||
|
value_objects::UserId,
|
||||||
|
};
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
pub struct PostgresRefreshSessionAdapter {
|
||||||
|
pool: PgPool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostgresRefreshSessionAdapter {
|
||||||
|
pub fn new(pool: PgPool) -> Self {
|
||||||
|
Self { pool }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn map_err(e: sqlx::Error) -> DomainError {
|
||||||
|
DomainError::InfrastructureError(e.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl RefreshSessionRepository for PostgresRefreshSessionAdapter {
|
||||||
|
async fn create(&self, session: &RefreshSession) -> Result<(), DomainError> {
|
||||||
|
sqlx::query(
|
||||||
|
"INSERT INTO refresh_sessions (id, user_id, token, expires_at, created_at)
|
||||||
|
VALUES ($1, $2, $3, $4, $5)",
|
||||||
|
)
|
||||||
|
.bind(session.id.to_string())
|
||||||
|
.bind(session.user_id.value().to_string())
|
||||||
|
.bind(&session.token)
|
||||||
|
.bind(session.expires_at)
|
||||||
|
.bind(session.created_at)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(map_err)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_by_token(&self, token: &str) -> Result<Option<RefreshSession>, DomainError> {
|
||||||
|
let row = sqlx::query_as::<_, RefreshSessionRow>(
|
||||||
|
"SELECT id, user_id, token,
|
||||||
|
to_char(expires_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') AS expires_at,
|
||||||
|
to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"') AS created_at
|
||||||
|
FROM refresh_sessions WHERE token = $1",
|
||||||
|
)
|
||||||
|
.bind(token)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(map_err)?;
|
||||||
|
|
||||||
|
row.map(RefreshSessionRow::into_domain).transpose()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn revoke(&self, token: &str) -> Result<(), DomainError> {
|
||||||
|
sqlx::query("DELETE FROM refresh_sessions WHERE token = $1")
|
||||||
|
.bind(token)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(map_err)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn revoke_all_for_user(&self, user_id: &UserId) -> Result<(), DomainError> {
|
||||||
|
sqlx::query("DELETE FROM refresh_sessions WHERE user_id = $1")
|
||||||
|
.bind(user_id.value().to_string())
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(map_err)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete_expired(&self) -> Result<u64, DomainError> {
|
||||||
|
let result = sqlx::query("DELETE FROM refresh_sessions WHERE expires_at < NOW()")
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(map_err)?;
|
||||||
|
Ok(result.rows_affected())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(sqlx::FromRow)]
|
||||||
|
struct RefreshSessionRow {
|
||||||
|
id: String,
|
||||||
|
user_id: String,
|
||||||
|
token: String,
|
||||||
|
expires_at: String,
|
||||||
|
created_at: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RefreshSessionRow {
|
||||||
|
fn into_domain(self) -> Result<RefreshSession, DomainError> {
|
||||||
|
let id = uuid::Uuid::parse_str(&self.id)
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(format!("invalid uuid: {e}")))?;
|
||||||
|
let user_id = uuid::Uuid::parse_str(&self.user_id)
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(format!("invalid user_id: {e}")))?;
|
||||||
|
let expires_at = DateTime::parse_from_rfc3339(&self.expires_at)
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(format!("invalid expires_at: {e}")))?
|
||||||
|
.with_timezone(&chrono::Utc);
|
||||||
|
let created_at = DateTime::parse_from_rfc3339(&self.created_at)
|
||||||
|
.map_err(|e| DomainError::InfrastructureError(format!("invalid created_at: {e}")))?
|
||||||
|
.with_timezone(&chrono::Utc);
|
||||||
|
Ok(RefreshSession {
|
||||||
|
id,
|
||||||
|
user_id: UserId::from_uuid(user_id),
|
||||||
|
token: self.token,
|
||||||
|
expires_at,
|
||||||
|
created_at,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
119
crates/adapters/postgres/src/remote_goals.rs
Normal file
119
crates/adapters/postgres/src/remote_goals.rs
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
|
use chrono::TimeZone;
|
||||||
|
use domain::{errors::DomainError, models::RemoteGoalEntry, ports::RemoteGoalRepository};
|
||||||
|
use sqlx::{PgPool, Row};
|
||||||
|
|
||||||
|
pub struct PostgresRemoteGoalRepository {
|
||||||
|
pool: PgPool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostgresRemoteGoalRepository {
|
||||||
|
pub fn new(pool: PgPool) -> Self {
|
||||||
|
Self { pool }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn map_err(e: sqlx::Error) -> DomainError {
|
||||||
|
tracing::error!("Database error: {:?}", e);
|
||||||
|
DomainError::InfrastructureError("Database operation failed".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl RemoteGoalRepository for PostgresRemoteGoalRepository {
|
||||||
|
async fn save(&self, entry: RemoteGoalEntry) -> Result<(), DomainError> {
|
||||||
|
let received = entry.received_at.format("%Y-%m-%d %H:%M:%S").to_string();
|
||||||
|
|
||||||
|
sqlx::query(
|
||||||
|
"INSERT INTO remote_goals \
|
||||||
|
(ap_id, actor_url, year, target_count, current_count, received_at) \
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6::timestamptz) \
|
||||||
|
ON CONFLICT (ap_id) DO UPDATE SET \
|
||||||
|
target_count = $4, current_count = $5",
|
||||||
|
)
|
||||||
|
.bind(&entry.ap_id)
|
||||||
|
.bind(&entry.actor_url)
|
||||||
|
.bind(entry.year as i64)
|
||||||
|
.bind(entry.target_count as i64)
|
||||||
|
.bind(entry.current_count as i64)
|
||||||
|
.bind(&received)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn update_by_ap_id(
|
||||||
|
&self,
|
||||||
|
ap_id: &str,
|
||||||
|
target: u32,
|
||||||
|
current: u32,
|
||||||
|
) -> Result<(), DomainError> {
|
||||||
|
sqlx::query(
|
||||||
|
"UPDATE remote_goals SET target_count = $1, current_count = $2 WHERE ap_id = $3",
|
||||||
|
)
|
||||||
|
.bind(target as i64)
|
||||||
|
.bind(current as i64)
|
||||||
|
.bind(ap_id)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn remove_by_ap_id(&self, ap_id: &str, actor_url: &str) -> Result<(), DomainError> {
|
||||||
|
sqlx::query("DELETE FROM remote_goals WHERE ap_id = $1 AND actor_url = $2")
|
||||||
|
.bind(ap_id)
|
||||||
|
.bind(actor_url)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn remove_all_by_actor(&self, actor_url: &str) -> Result<(), DomainError> {
|
||||||
|
sqlx::query("DELETE FROM remote_goals WHERE actor_url = $1")
|
||||||
|
.bind(actor_url)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_by_actor_url(&self, actor_url: &str) -> Result<Vec<RemoteGoalEntry>, DomainError> {
|
||||||
|
let rows = sqlx::query(
|
||||||
|
"SELECT ap_id, actor_url, year, target_count, current_count, \
|
||||||
|
to_char(received_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS received_at \
|
||||||
|
FROM remote_goals WHERE actor_url = $1 ORDER BY year DESC",
|
||||||
|
)
|
||||||
|
.bind(actor_url)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
rows.iter()
|
||||||
|
.map(|r| {
|
||||||
|
let year: i64 = r.try_get("year").unwrap_or(0);
|
||||||
|
let target: i64 = r.try_get("target_count").unwrap_or(0);
|
||||||
|
let current: i64 = r.try_get("current_count").unwrap_or(0);
|
||||||
|
let received_str: String = r.try_get("received_at").unwrap_or_default();
|
||||||
|
let received_at =
|
||||||
|
chrono::NaiveDateTime::parse_from_str(&received_str, "%Y-%m-%d %H:%M:%S")
|
||||||
|
.map(|ndt| chrono::Utc.from_utc_datetime(&ndt))
|
||||||
|
.unwrap_or_else(|_| chrono::Utc::now());
|
||||||
|
|
||||||
|
Ok(RemoteGoalEntry {
|
||||||
|
ap_id: r.try_get("ap_id").unwrap_or_default(),
|
||||||
|
actor_url: r.try_get("actor_url").unwrap_or_default(),
|
||||||
|
year: year as u16,
|
||||||
|
target_count: target as u32,
|
||||||
|
current_count: current as u32,
|
||||||
|
received_at,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
112
crates/adapters/postgres/src/review.rs
Normal file
112
crates/adapters/postgres/src/review.rs
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
|
use domain::{
|
||||||
|
errors::DomainError,
|
||||||
|
events::DomainEvent,
|
||||||
|
models::{Review, ReviewSource},
|
||||||
|
ports::ReviewRepository,
|
||||||
|
value_objects::{ReviewId, UserId},
|
||||||
|
};
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
use crate::models::{ReviewRow, datetime_to_str};
|
||||||
|
|
||||||
|
pub struct PostgresReviewRepository {
|
||||||
|
pool: PgPool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostgresReviewRepository {
|
||||||
|
pub fn new(pool: PgPool) -> Self {
|
||||||
|
Self { pool }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn map_err(e: sqlx::Error) -> DomainError {
|
||||||
|
tracing::error!("Database error: {:?}", e);
|
||||||
|
DomainError::InfrastructureError("Database operation failed".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl ReviewRepository for PostgresReviewRepository {
|
||||||
|
async fn save_review(&self, review: &Review) -> Result<DomainEvent, DomainError> {
|
||||||
|
let id = review.id().value().to_string();
|
||||||
|
let movie_id = review.movie_id().value().to_string();
|
||||||
|
let user_id = review.user_id().value().to_string();
|
||||||
|
let rating = review.rating().value() as i64;
|
||||||
|
let comment = review.comment().map(|c| c.value().to_string());
|
||||||
|
let watched_at = datetime_to_str(review.watched_at());
|
||||||
|
let created_at = datetime_to_str(review.created_at());
|
||||||
|
let remote_actor_url = match review.source() {
|
||||||
|
ReviewSource::Local => None,
|
||||||
|
ReviewSource::Remote { actor_url } => Some(actor_url.clone()),
|
||||||
|
};
|
||||||
|
|
||||||
|
sqlx::query(
|
||||||
|
"INSERT INTO reviews (id, movie_id, user_id, rating, comment, watched_at, created_at, remote_actor_url)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6::timestamptz, $7::timestamptz, $8)",
|
||||||
|
)
|
||||||
|
.bind(&id)
|
||||||
|
.bind(&movie_id)
|
||||||
|
.bind(&user_id)
|
||||||
|
.bind(rating)
|
||||||
|
.bind(&comment)
|
||||||
|
.bind(&watched_at)
|
||||||
|
.bind(&created_at)
|
||||||
|
.bind(&remote_actor_url)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
Ok(DomainEvent::ReviewLogged {
|
||||||
|
review_id: review.id().clone(),
|
||||||
|
movie_id: review.movie_id().clone(),
|
||||||
|
user_id: review.user_id().clone(),
|
||||||
|
rating: review.rating().clone(),
|
||||||
|
watched_at: *review.watched_at(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_review_by_id(&self, review_id: &ReviewId) -> Result<Option<Review>, DomainError> {
|
||||||
|
let id = review_id.value().to_string();
|
||||||
|
sqlx::query_as::<_, ReviewRow>(
|
||||||
|
"SELECT id, movie_id, user_id, rating, comment,
|
||||||
|
to_char(watched_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS watched_at,
|
||||||
|
to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at,
|
||||||
|
remote_actor_url
|
||||||
|
FROM reviews WHERE id = $1",
|
||||||
|
)
|
||||||
|
.bind(&id)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?
|
||||||
|
.map(ReviewRow::into_domain)
|
||||||
|
.transpose()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete_review(&self, review_id: &ReviewId) -> Result<(), DomainError> {
|
||||||
|
let id = review_id.value().to_string();
|
||||||
|
sqlx::query("DELETE FROM reviews WHERE id = $1")
|
||||||
|
.bind(&id)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_all_reviews_for_user(&self, user_id: &UserId) -> Result<Vec<Review>, DomainError> {
|
||||||
|
let uid = user_id.value().to_string();
|
||||||
|
sqlx::query_as::<_, ReviewRow>(
|
||||||
|
"SELECT id, movie_id, user_id, rating, comment,
|
||||||
|
to_char(watched_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS watched_at,
|
||||||
|
to_char(created_at AT TIME ZONE 'UTC', 'YYYY-MM-DD HH24:MI:SS') AS created_at,
|
||||||
|
remote_actor_url
|
||||||
|
FROM reviews WHERE user_id = $1 ORDER BY watched_at DESC",
|
||||||
|
)
|
||||||
|
.bind(&uid)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?
|
||||||
|
.into_iter()
|
||||||
|
.map(ReviewRow::into_domain)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
153
crates/adapters/postgres/src/stats.rs
Normal file
153
crates/adapters/postgres/src/stats.rs
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
|
use domain::{
|
||||||
|
errors::DomainError,
|
||||||
|
models::{DirectorStat, MonthlyRating, UserStats, UserTrends},
|
||||||
|
ports::StatsRepository,
|
||||||
|
value_objects::UserId,
|
||||||
|
};
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
use crate::format_year_month;
|
||||||
|
use crate::models::{DirectorCountRow, MonthlyRatingRow, UserTotalsRow};
|
||||||
|
|
||||||
|
pub struct PostgresStatsRepository {
|
||||||
|
pool: PgPool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostgresStatsRepository {
|
||||||
|
pub fn new(pool: PgPool) -> Self {
|
||||||
|
Self { pool }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn map_err(e: sqlx::Error) -> DomainError {
|
||||||
|
tracing::error!("Database error: {:?}", e);
|
||||||
|
DomainError::InfrastructureError("Database operation failed".into())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_user_totals(&self, user_id: &str) -> Result<UserTotalsRow, DomainError> {
|
||||||
|
sqlx::query_as::<_, UserTotalsRow>(
|
||||||
|
r#"SELECT COUNT(DISTINCT movie_id) AS total,
|
||||||
|
AVG(rating::float) AS avg_rating
|
||||||
|
FROM reviews WHERE user_id = $1"#,
|
||||||
|
)
|
||||||
|
.bind(user_id)
|
||||||
|
.fetch_one(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_user_favorite_director(
|
||||||
|
&self,
|
||||||
|
user_id: &str,
|
||||||
|
) -> Result<Option<String>, DomainError> {
|
||||||
|
sqlx::query_scalar::<_, String>(
|
||||||
|
"SELECT m.director
|
||||||
|
FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
WHERE r.user_id = $1 AND m.director IS NOT NULL
|
||||||
|
GROUP BY m.director
|
||||||
|
ORDER BY COUNT(*) DESC
|
||||||
|
LIMIT 1",
|
||||||
|
)
|
||||||
|
.bind(user_id)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_user_most_active_month(
|
||||||
|
&self,
|
||||||
|
user_id: &str,
|
||||||
|
) -> Result<Option<String>, DomainError> {
|
||||||
|
sqlx::query_scalar::<_, String>(
|
||||||
|
"SELECT to_char(watched_at AT TIME ZONE 'UTC', 'YYYY-MM') AS month
|
||||||
|
FROM reviews
|
||||||
|
WHERE user_id = $1
|
||||||
|
GROUP BY to_char(watched_at AT TIME ZONE 'UTC', 'YYYY-MM')
|
||||||
|
ORDER BY COUNT(*) DESC
|
||||||
|
LIMIT 1",
|
||||||
|
)
|
||||||
|
.bind(user_id)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl StatsRepository for PostgresStatsRepository {
|
||||||
|
async fn get_user_stats(&self, user_id: &UserId) -> Result<UserStats, DomainError> {
|
||||||
|
let uid = user_id.value().to_string();
|
||||||
|
|
||||||
|
let (totals, fav_director, most_active) = tokio::try_join!(
|
||||||
|
self.fetch_user_totals(&uid),
|
||||||
|
self.fetch_user_favorite_director(&uid),
|
||||||
|
self.fetch_user_most_active_month(&uid)
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let most_active_month = most_active.map(|ym| format_year_month(&ym));
|
||||||
|
|
||||||
|
Ok(UserStats {
|
||||||
|
total_movies: totals.total,
|
||||||
|
avg_rating: totals.avg_rating,
|
||||||
|
favorite_director: fav_director,
|
||||||
|
most_active_month,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_user_trends(&self, user_id: &UserId) -> Result<UserTrends, DomainError> {
|
||||||
|
let uid = user_id.value().to_string();
|
||||||
|
|
||||||
|
let (rating_rows, director_rows) = tokio::try_join!(
|
||||||
|
sqlx::query_as::<_, MonthlyRatingRow>(
|
||||||
|
"SELECT to_char(watched_at AT TIME ZONE 'UTC', 'YYYY-MM') AS month,
|
||||||
|
AVG(rating::float) AS avg_rating,
|
||||||
|
COUNT(*) AS count
|
||||||
|
FROM reviews
|
||||||
|
WHERE user_id = $1 AND watched_at >= NOW() - INTERVAL '12 months'
|
||||||
|
GROUP BY to_char(watched_at AT TIME ZONE 'UTC', 'YYYY-MM')
|
||||||
|
ORDER BY to_char(watched_at AT TIME ZONE 'UTC', 'YYYY-MM') ASC"
|
||||||
|
)
|
||||||
|
.bind(&uid)
|
||||||
|
.fetch_all(&self.pool),
|
||||||
|
sqlx::query_as::<_, DirectorCountRow>(
|
||||||
|
"SELECT m.director AS director, COUNT(*) AS count
|
||||||
|
FROM reviews r
|
||||||
|
INNER JOIN movies m ON m.id = r.movie_id
|
||||||
|
WHERE r.user_id = $1 AND m.director IS NOT NULL
|
||||||
|
GROUP BY m.director
|
||||||
|
ORDER BY COUNT(*) DESC
|
||||||
|
LIMIT 5"
|
||||||
|
)
|
||||||
|
.bind(&uid)
|
||||||
|
.fetch_all(&self.pool)
|
||||||
|
)
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
let max_director_count = director_rows.iter().map(|d| d.count).max().unwrap_or(1);
|
||||||
|
|
||||||
|
let monthly_ratings = rating_rows
|
||||||
|
.into_iter()
|
||||||
|
.map(|r| MonthlyRating {
|
||||||
|
month_label: format_year_month(&r.month),
|
||||||
|
year_month: r.month,
|
||||||
|
avg_rating: r.avg_rating,
|
||||||
|
count: r.count,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let top_directors = director_rows
|
||||||
|
.into_iter()
|
||||||
|
.map(|d| DirectorStat {
|
||||||
|
director: d.director,
|
||||||
|
count: d.count,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(UserTrends {
|
||||||
|
monthly_ratings,
|
||||||
|
top_directors,
|
||||||
|
max_director_count,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
104
crates/adapters/postgres/src/user_settings.rs
Normal file
104
crates/adapters/postgres/src/user_settings.rs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
|
use domain::{
|
||||||
|
errors::DomainError,
|
||||||
|
models::UserSettings,
|
||||||
|
ports::{FederationFlags, UserFederationSettingsQuery, UserSettingsRepository},
|
||||||
|
value_objects::UserId,
|
||||||
|
};
|
||||||
|
use sqlx::{PgPool, Row};
|
||||||
|
|
||||||
|
pub struct PostgresUserSettingsRepository {
|
||||||
|
pool: PgPool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostgresUserSettingsRepository {
|
||||||
|
pub fn new(pool: PgPool) -> Self {
|
||||||
|
Self { pool }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn map_err(e: sqlx::Error) -> DomainError {
|
||||||
|
tracing::error!("Database error: {:?}", e);
|
||||||
|
DomainError::InfrastructureError("Database operation failed".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl UserSettingsRepository for PostgresUserSettingsRepository {
|
||||||
|
async fn get(&self, user_id: &UserId) -> Result<UserSettings, DomainError> {
|
||||||
|
let uid = user_id.value().to_string();
|
||||||
|
let row = sqlx::query(
|
||||||
|
"SELECT federate_goals, federate_reviews, federate_watchlist \
|
||||||
|
FROM user_settings WHERE user_id = $1",
|
||||||
|
)
|
||||||
|
.bind(&uid)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
match row {
|
||||||
|
Some(r) => {
|
||||||
|
let goals: bool = r.try_get("federate_goals").unwrap_or(true);
|
||||||
|
let reviews: bool = r.try_get("federate_reviews").unwrap_or(true);
|
||||||
|
let watchlist: bool = r.try_get("federate_watchlist").unwrap_or(true);
|
||||||
|
Ok(UserSettings::from_persistence(
|
||||||
|
user_id.clone(),
|
||||||
|
goals,
|
||||||
|
reviews,
|
||||||
|
watchlist,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
None => Ok(UserSettings::new(user_id.clone())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn save(&self, settings: &UserSettings) -> Result<(), DomainError> {
|
||||||
|
let uid = settings.user_id().value().to_string();
|
||||||
|
sqlx::query(
|
||||||
|
"INSERT INTO user_settings (user_id, federate_goals, federate_reviews, federate_watchlist) \
|
||||||
|
VALUES ($1, $2, $3, $4) \
|
||||||
|
ON CONFLICT (user_id) DO UPDATE \
|
||||||
|
SET federate_goals = $2, federate_reviews = $3, federate_watchlist = $4",
|
||||||
|
)
|
||||||
|
.bind(&uid)
|
||||||
|
.bind(settings.federate_goals())
|
||||||
|
.bind(settings.federate_reviews())
|
||||||
|
.bind(settings.federate_watchlist())
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl UserFederationSettingsQuery for PostgresUserSettingsRepository {
|
||||||
|
async fn get_federation_flags(&self, user_id: &UserId) -> Result<FederationFlags, DomainError> {
|
||||||
|
let uid = user_id.value().to_string();
|
||||||
|
let row = sqlx::query(
|
||||||
|
"SELECT federate_goals, federate_reviews, federate_watchlist \
|
||||||
|
FROM user_settings WHERE user_id = $1",
|
||||||
|
)
|
||||||
|
.bind(&uid)
|
||||||
|
.fetch_optional(&self.pool)
|
||||||
|
.await
|
||||||
|
.map_err(Self::map_err)?;
|
||||||
|
|
||||||
|
match row {
|
||||||
|
Some(r) => {
|
||||||
|
let goals: bool = r.try_get("federate_goals").unwrap_or(true);
|
||||||
|
let reviews: bool = r.try_get("federate_reviews").unwrap_or(true);
|
||||||
|
let watchlist: bool = r.try_get("federate_watchlist").unwrap_or(true);
|
||||||
|
Ok(FederationFlags {
|
||||||
|
goals,
|
||||||
|
reviews,
|
||||||
|
watchlist,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
None => Ok(FederationFlags {
|
||||||
|
goals: true,
|
||||||
|
reviews: true,
|
||||||
|
watchlist: true,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -186,13 +186,13 @@ impl UserRepository for PostgresUserRepository {
|
|||||||
|
|
||||||
async fn list_with_stats(&self) -> Result<Vec<domain::models::UserSummary>, DomainError> {
|
async fn list_with_stats(&self) -> Result<Vec<domain::models::UserSummary>, DomainError> {
|
||||||
sqlx::query_as::<_, UserSummaryRow>(
|
sqlx::query_as::<_, UserSummaryRow>(
|
||||||
r#"SELECT u.id, u.email,
|
r#"SELECT u.id, u.email, u.username, u.display_name,
|
||||||
COUNT(DISTINCT r.movie_id) AS total_movies,
|
COUNT(DISTINCT r.movie_id) AS total_movies,
|
||||||
AVG(r.rating::float) AS avg_rating,
|
AVG(r.rating::float) AS avg_rating,
|
||||||
u.avatar_path
|
u.avatar_path
|
||||||
FROM users u
|
FROM users u
|
||||||
LEFT JOIN reviews r ON r.user_id = u.id AND r.remote_actor_url IS NULL
|
LEFT JOIN reviews r ON r.user_id = u.id AND r.remote_actor_url IS NULL
|
||||||
GROUP BY u.id, u.email, u.avatar_path
|
GROUP BY u.id, u.email, u.username, u.display_name, u.avatar_path
|
||||||
ORDER BY u.email ASC"#,
|
ORDER BY u.email ASC"#,
|
||||||
)
|
)
|
||||||
.fetch_all(&self.pool)
|
.fetch_all(&self.pool)
|
||||||
|
|||||||
@@ -333,9 +333,9 @@ impl WrapUpStatsQuery for PostgresWrapUpStatsQuery {
|
|||||||
let keywords = keywords_map.get(&movie_id_str).cloned().unwrap_or_default();
|
let keywords = keywords_map.get(&movie_id_str).cloned().unwrap_or_default();
|
||||||
let cast = cast_map.get(&movie_id_str).cloned().unwrap_or_default();
|
let cast = cast_map.get(&movie_id_str).cloned().unwrap_or_default();
|
||||||
|
|
||||||
let cast_names: Vec<(String, u32)> = cast
|
let cast_names: Vec<(String, u32, i64)> = cast
|
||||||
.iter()
|
.iter()
|
||||||
.map(|c| (c.name.clone(), c.billing_order))
|
.map(|c| (c.name.clone(), c.billing_order, c.tmdb_person_id))
|
||||||
.collect();
|
.collect();
|
||||||
let cast_profile_paths: Vec<Option<String>> =
|
let cast_profile_paths: Vec<Option<String>> =
|
||||||
cast.iter().map(|c| c.profile_path.clone()).collect();
|
cast.iter().map(|c| c.profile_path.clone()).collect();
|
||||||
@@ -367,6 +367,7 @@ impl WrapUpStatsQuery for PostgresWrapUpStatsQuery {
|
|||||||
struct CastEntry {
|
struct CastEntry {
|
||||||
name: String,
|
name: String,
|
||||||
billing_order: u32,
|
billing_order: u32,
|
||||||
|
tmdb_person_id: i64,
|
||||||
profile_path: Option<String>,
|
profile_path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,7 +418,7 @@ async fn fetch_cast_pg(
|
|||||||
movie_ids: &[String],
|
movie_ids: &[String],
|
||||||
) -> Result<HashMap<String, Vec<CastEntry>>, DomainError> {
|
) -> Result<HashMap<String, Vec<CastEntry>>, DomainError> {
|
||||||
let rows = sqlx::query(
|
let rows = sqlx::query(
|
||||||
"SELECT movie_id, name, billing_order, profile_path \
|
"SELECT movie_id, name, billing_order, tmdb_person_id, profile_path \
|
||||||
FROM movie_cast \
|
FROM movie_cast \
|
||||||
WHERE movie_id = ANY($1) AND billing_order <= 3 \
|
WHERE movie_id = ANY($1) AND billing_order <= 3 \
|
||||||
ORDER BY billing_order ASC",
|
ORDER BY billing_order ASC",
|
||||||
@@ -432,10 +433,12 @@ async fn fetch_cast_pg(
|
|||||||
let mid: String = row.try_get("movie_id").map_err(map_err)?;
|
let mid: String = row.try_get("movie_id").map_err(map_err)?;
|
||||||
let name: String = row.try_get("name").map_err(map_err)?;
|
let name: String = row.try_get("name").map_err(map_err)?;
|
||||||
let billing_order: i32 = row.try_get("billing_order").map_err(map_err)?;
|
let billing_order: i32 = row.try_get("billing_order").map_err(map_err)?;
|
||||||
|
let tmdb_person_id: i64 = row.try_get("tmdb_person_id").map_err(map_err)?;
|
||||||
let profile_path: Option<String> = row.try_get("profile_path").map_err(map_err)?;
|
let profile_path: Option<String> = row.try_get("profile_path").map_err(map_err)?;
|
||||||
map.entry(mid).or_default().push(CastEntry {
|
map.entry(mid).or_default().push(CastEntry {
|
||||||
name,
|
name,
|
||||||
billing_order: billing_order as u32,
|
billing_order: billing_order as u32,
|
||||||
|
tmdb_person_id,
|
||||||
profile_path,
|
profile_path,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -870,6 +870,7 @@ impl RemoteReviewRepository for SqliteFederationRepository {
|
|||||||
rating: u8,
|
rating: u8,
|
||||||
comment: Option<&str>,
|
comment: Option<&str>,
|
||||||
watched_at: chrono::NaiveDateTime,
|
watched_at: chrono::NaiveDateTime,
|
||||||
|
poster_url: Option<&str>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let watched_at_str = datetime_to_str(&watched_at);
|
let watched_at_str = datetime_to_str(&watched_at);
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
@@ -883,6 +884,17 @@ impl RemoteReviewRepository for SqliteFederationRepository {
|
|||||||
.bind(actor_url)
|
.bind(actor_url)
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
if let Some(url) = poster_url {
|
||||||
|
sqlx::query(
|
||||||
|
"UPDATE movies SET poster_path = ?
|
||||||
|
WHERE id = (SELECT movie_id FROM reviews WHERE ap_id = ? AND remote_actor_url = ?)",
|
||||||
|
)
|
||||||
|
.bind(url)
|
||||||
|
.bind(ap_id)
|
||||||
|
.bind(actor_url)
|
||||||
|
.execute(&self.pool)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,\n r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment, r.watched_at, r.created_at, r.remote_actor_url\n FROM reviews r\n INNER JOIN movies m ON m.id = r.movie_id\n WHERE r.movie_id = ?\n ORDER BY r.watched_at DESC\n LIMIT ? OFFSET ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "external_metadata_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "title",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release_year",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "director",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "poster_path",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "review_id",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "movie_id",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "rating",
|
|
||||||
"ordinal": 9,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "comment",
|
|
||||||
"ordinal": 10,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "watched_at",
|
|
||||||
"ordinal": 11,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 12,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "remote_actor_url",
|
|
||||||
"ordinal": 13,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 3
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "05d958c1fa38095ae2b5b81ede48fc85702d8c39c6301839de7b4d27f4a4d41b"
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT COUNT(*) FROM reviews",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "COUNT(*)",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Integer"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 0
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "0963b9661182e139cd760bbabb0d6ea3a301a2a3adbdfdda4a88f333a1144c77"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "INSERT INTO users (id, email, username, password_hash, created_at, role) VALUES (?, ?, ?, ?, ?, ?)",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 6
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "0acf3515a4d1bef7a2458d878481ba3b11c9f252311579f7daba335f70d78f07"
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,\n r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment, r.watched_at, r.created_at, r.remote_actor_url\n FROM reviews r\n INNER JOIN movies m ON m.id = r.movie_id\n WHERE r.user_id = ?\n ORDER BY r.watched_at DESC",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "external_metadata_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "title",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release_year",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "director",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "poster_path",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "review_id",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "movie_id",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "rating",
|
|
||||||
"ordinal": 9,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "comment",
|
|
||||||
"ordinal": 10,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "watched_at",
|
|
||||||
"ordinal": 11,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 12,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "remote_actor_url",
|
|
||||||
"ordinal": 13,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "106b5b65162314c47217c26b7e89194094e10122ea596e8d9323968e600635a9"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "DELETE FROM user_profile_fields WHERE user_id = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "11f7dd8da277aaf950e2a428f8e072cde8d806ca5b4007bbc882aada5c46ae63"
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "DELETE FROM import_sessions WHERE expires_at < datetime('now')",
|
|
||||||
"describe": {
|
|
||||||
"columns": [],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 0
|
|
||||||
},
|
|
||||||
"nullable": []
|
|
||||||
},
|
|
||||||
"hash": "1c70d5d455e5ab3dfb68d35ce5255c7e0e86b9f6549ae8ae09247806f1321086"
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT id, email, username, password_hash, role, bio, avatar_path, banner_path, also_known_as FROM users WHERE username = ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "email",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "username",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "password_hash",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "role",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "bio",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "avatar_path",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "banner_path",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "also_known_as",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 1
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "1dd3efb043635e638f1c3d72923a4ccfb9c9810baee06cfac5ad4af5749e4c6e"
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
{
|
|
||||||
"db_name": "SQLite",
|
|
||||||
"query": "SELECT m.id, m.external_metadata_id, m.title, m.release_year, m.director, m.poster_path,\n r.id AS review_id, r.movie_id, r.user_id, r.rating, r.comment, r.watched_at, r.created_at, r.remote_actor_url\n FROM reviews r\n INNER JOIN movies m ON m.id = r.movie_id\n ORDER BY r.watched_at ASC\n LIMIT ? OFFSET ?",
|
|
||||||
"describe": {
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"ordinal": 0,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "external_metadata_id",
|
|
||||||
"ordinal": 1,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "title",
|
|
||||||
"ordinal": 2,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release_year",
|
|
||||||
"ordinal": 3,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "director",
|
|
||||||
"ordinal": 4,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "poster_path",
|
|
||||||
"ordinal": 5,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "review_id",
|
|
||||||
"ordinal": 6,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "movie_id",
|
|
||||||
"ordinal": 7,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "user_id",
|
|
||||||
"ordinal": 8,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "rating",
|
|
||||||
"ordinal": 9,
|
|
||||||
"type_info": "Integer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "comment",
|
|
||||||
"ordinal": 10,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "watched_at",
|
|
||||||
"ordinal": 11,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "created_at",
|
|
||||||
"ordinal": 12,
|
|
||||||
"type_info": "Text"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "remote_actor_url",
|
|
||||||
"ordinal": 13,
|
|
||||||
"type_info": "Text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"parameters": {
|
|
||||||
"Right": 2
|
|
||||||
},
|
|
||||||
"nullable": [
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hash": "25fd01355c929a83daf2c802b8ae3adaa4ce73fc037e2bf2a87d60187aeb7361"
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user