Compare commits
87 Commits
30cc89242d
...
epic/FA-mi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec967770d3 | ||
|
|
579e05b853 | ||
| e7435435c1 | |||
|
|
dd7aa4b044 | ||
|
|
1b9da7441c | ||
| 055ef33666 | |||
|
|
48ee43c4f6 | ||
| 98ae4ea4f2 | |||
|
|
15e1a84f55 | ||
|
|
70d4ba201a | ||
|
|
b69bcd6bf4 | ||
|
|
c97654631b | ||
|
|
1ecfd9cc99 | ||
|
|
19ae4a8089 | ||
|
|
f8a45ad891 | ||
|
|
f67c5c610c | ||
| b5d4694f12 | |||
|
|
6d47153a42 | ||
| dbbc2fd8dc | |||
|
|
176c94297b | ||
|
|
8b3faa8f6c | ||
|
|
d87bd81190 | ||
|
|
bee805c441 | ||
|
|
5013da69c2 | ||
| d8e3ec7ec9 | |||
|
|
3612c89b99 | ||
|
|
ebb2e6e7fc | ||
|
|
01d3b94050 | ||
|
|
c0290cc5af | ||
| 1d950b7721 | |||
|
|
7738bcf438 | ||
| 61e0cb69d8 | |||
|
|
02525d611a | ||
| c21fe0fbd5 | |||
|
|
bbc0b5ec7d | ||
| 5527c15ae7 | |||
|
|
1e374e6eeb | ||
| c710f14257 | |||
|
|
6c10077505 | ||
| fecb3e6f43 | |||
|
|
f0ea71e00e | ||
| 45afb57df5 | |||
|
|
6fd76f6787 | ||
| baad092f07 | |||
|
|
4fb34bdef7 | ||
| 89a2cf6db1 | |||
|
|
f830773af5 | ||
| 7185b95c65 | |||
|
|
8b44cf2f0c | ||
| ac48889f4c | |||
|
|
5c52d29da9 | ||
| 16004ad938 | |||
|
|
d109db2155 | ||
| 89dff0980b | |||
|
|
e70c39ea75 | ||
|
|
81e4e88ad4 | ||
| c9d93a4e55 | |||
| 9527d94928 | |||
|
|
c2fdeca6c4 | ||
| aae17021af | |||
|
|
c60aaf2bdb | ||
|
|
b2f4548807 | ||
|
|
8d6f0d6cfd | ||
| bc83bffb4b | |||
|
|
75e96cbee5 | ||
|
|
9c82d648cd | ||
|
|
78612ea29d | ||
| 4412a1f658 | |||
| 12e3c5dfdd | |||
|
|
b71d9031e1 | ||
|
|
09ebdb1b2a | ||
| 43d5ada7fb | |||
|
|
4635ed1b4e | ||
|
|
920fd00910 | ||
|
|
0d9f788678 | ||
|
|
0938c16a76 | ||
|
|
f25cbc1a04 | ||
|
|
078eaf5237 | ||
|
|
b9115d78a9 | ||
|
|
7e94f06853 | ||
|
|
50263109ab | ||
|
|
6ebfe81ae3 | ||
|
|
80aac63f7d | ||
|
|
adc99c7000 | ||
| 87075be61e | |||
| 259dc08aea | |||
| 2203d2ee54 |
@@ -3,18 +3,34 @@ name: Build Gateway
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- 'FictionArchive.API/**'
|
||||
tags:
|
||||
- 'v*.*.*'
|
||||
|
||||
env:
|
||||
REGISTRY: ${{ gitea.server_url }}
|
||||
IMAGE_NAME: ${{ gitea.repository_owner }}/fictionarchive-api
|
||||
|
||||
jobs:
|
||||
build-gateway:
|
||||
build-subgraphs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
service:
|
||||
- name: novel-service
|
||||
project: FictionArchive.Service.NovelService
|
||||
subgraph: Novel
|
||||
- name: translation-service
|
||||
project: FictionArchive.Service.TranslationService
|
||||
subgraph: Translation
|
||||
- name: scheduler-service
|
||||
project: FictionArchive.Service.SchedulerService
|
||||
subgraph: Scheduler
|
||||
- name: user-service
|
||||
project: FictionArchive.Service.UserService
|
||||
subgraph: User
|
||||
- name: usernoveldata-service
|
||||
project: FictionArchive.Service.UserNovelDataService
|
||||
subgraph: UserNovelData
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
@@ -27,44 +43,81 @@ jobs:
|
||||
- name: Install Fusion CLI
|
||||
run: dotnet tool install -g HotChocolate.Fusion.CommandLine
|
||||
|
||||
- name: Add .NET tools to PATH
|
||||
run: echo "$HOME/.dotnet/tools" >> $GITHUB_PATH
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore ${{ matrix.service.project }}/${{ matrix.service.project }}.csproj
|
||||
|
||||
- name: Build
|
||||
run: dotnet build ${{ matrix.service.project }}/${{ matrix.service.project }}.csproj -c Release --no-restore
|
||||
|
||||
- name: Export schema
|
||||
run: |
|
||||
dotnet run -c Release --no-launch-profile \
|
||||
--project ${{ matrix.service.project }}/${{ matrix.service.project }}.csproj \
|
||||
-- schema export --output schema.graphql
|
||||
|
||||
- name: Pack subgraph
|
||||
run: fusion subgraph pack -w ${{ matrix.service.project }}
|
||||
|
||||
- name: Upload subgraph package
|
||||
uses: christopherhx/gitea-upload-artifact@v4
|
||||
with:
|
||||
name: ${{ matrix.service.name }}-subgraph
|
||||
path: ${{ matrix.service.project }}/*.fsp
|
||||
retention-days: 30
|
||||
|
||||
build-gateway:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-subgraphs
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
- name: Install Fusion CLI
|
||||
run: dotnet tool install -g HotChocolate.Fusion.CommandLine
|
||||
|
||||
- name: Add .NET tools to PATH
|
||||
run: echo "$HOME/.dotnet/tools" >> $GITHUB_PATH
|
||||
|
||||
- name: Create subgraphs directory
|
||||
run: mkdir -p subgraphs
|
||||
|
||||
# Download all subgraph packages from latest successful builds
|
||||
- name: Download Novel Service subgraph
|
||||
uses: actions/download-artifact@v4
|
||||
uses: christopherhx/gitea-download-artifact@v4
|
||||
with:
|
||||
name: novel-service-subgraph
|
||||
path: subgraphs/novel
|
||||
continue-on-error: true
|
||||
|
||||
- name: Download Translation Service subgraph
|
||||
uses: actions/download-artifact@v4
|
||||
uses: christopherhx/gitea-download-artifact@v4
|
||||
with:
|
||||
name: translation-service-subgraph
|
||||
path: subgraphs/translation
|
||||
continue-on-error: true
|
||||
|
||||
- name: Download Scheduler Service subgraph
|
||||
uses: actions/download-artifact@v4
|
||||
uses: christopherhx/gitea-download-artifact@v4
|
||||
with:
|
||||
name: scheduler-service-subgraph
|
||||
path: subgraphs/scheduler
|
||||
continue-on-error: true
|
||||
|
||||
- name: Download User Service subgraph
|
||||
uses: actions/download-artifact@v4
|
||||
uses: christopherhx/gitea-download-artifact@v4
|
||||
with:
|
||||
name: user-service-subgraph
|
||||
path: subgraphs/user
|
||||
continue-on-error: true
|
||||
|
||||
- name: Download File Service subgraph
|
||||
uses: actions/download-artifact@v4
|
||||
- name: Download UserNovelData Service subgraph
|
||||
uses: christopherhx/gitea-download-artifact@v4
|
||||
with:
|
||||
name: file-service-subgraph
|
||||
path: subgraphs/file
|
||||
continue-on-error: true
|
||||
name: usernoveldata-service-subgraph
|
||||
path: subgraphs/usernoveldata
|
||||
|
||||
- name: Configure subgraph URLs for Docker
|
||||
run: |
|
||||
@@ -95,13 +148,13 @@ jobs:
|
||||
- name: Build gateway
|
||||
run: dotnet build FictionArchive.API/FictionArchive.API.csproj -c Release --no-restore -p:SkipFusionBuild=true
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test FictionArchive.sln -c Release --no-build --verbosity normal
|
||||
continue-on-error: true
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Extract registry hostname
|
||||
id: registry
|
||||
run: echo "HOST=$(echo '${{ gitea.server_url }}' | sed 's|https\?://||')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Log in to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
@@ -116,7 +169,7 @@ jobs:
|
||||
file: FictionArchive.API/Dockerfile
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }}
|
||||
${{ steps.registry.outputs.HOST }}/${{ env.IMAGE_NAME }}:latest
|
||||
${{ steps.registry.outputs.HOST }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
name: Build Subgraphs
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- 'FictionArchive.Service.*/**'
|
||||
- 'FictionArchive.Common/**'
|
||||
- 'FictionArchive.Service.Shared/**'
|
||||
|
||||
jobs:
|
||||
build-subgraphs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
service:
|
||||
- name: novel-service
|
||||
project: FictionArchive.Service.NovelService
|
||||
subgraph: Novel
|
||||
- name: translation-service
|
||||
project: FictionArchive.Service.TranslationService
|
||||
subgraph: Translation
|
||||
- name: scheduler-service
|
||||
project: FictionArchive.Service.SchedulerService
|
||||
subgraph: Scheduler
|
||||
- name: user-service
|
||||
project: FictionArchive.Service.UserService
|
||||
subgraph: User
|
||||
- name: file-service
|
||||
project: FictionArchive.Service.FileService
|
||||
subgraph: File
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
- name: Install Fusion CLI
|
||||
run: dotnet tool install -g HotChocolate.Fusion.CommandLine
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore ${{ matrix.service.project }}/${{ matrix.service.project }}.csproj
|
||||
|
||||
- name: Build
|
||||
run: dotnet build ${{ matrix.service.project }}/${{ matrix.service.project }}.csproj -c Release --no-restore
|
||||
|
||||
- name: Export schema
|
||||
run: |
|
||||
dotnet run -c Release --no-launch-profile \
|
||||
--project ${{ matrix.service.project }}/${{ matrix.service.project }}.csproj \
|
||||
-- schema export --output ${{ matrix.service.project }}/schema.graphql
|
||||
|
||||
- name: Pack subgraph
|
||||
run: fusion subgraph pack -w ${{ matrix.service.project }}
|
||||
|
||||
- name: Upload subgraph package
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ matrix.service.name }}-subgraph
|
||||
path: ${{ matrix.service.project }}/*.fsp
|
||||
retention-days: 30
|
||||
|
||||
# Trigger gateway build after all subgraphs are built
|
||||
trigger-gateway:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-subgraphs
|
||||
steps:
|
||||
- name: Trigger gateway workflow
|
||||
run: |
|
||||
curl -X POST \
|
||||
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/actions/workflows/build-gateway.yml/dispatches" \
|
||||
-d '{"ref":"master"}'
|
||||
@@ -20,14 +20,6 @@ jobs:
|
||||
with:
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- name: Install Fusion CLI
|
||||
run: dotnet tool install -g HotChocolate.Fusion.CommandLine
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore FictionArchive.sln
|
||||
|
||||
@@ -35,13 +27,33 @@ jobs:
|
||||
run: dotnet build FictionArchive.sln --configuration Release --no-restore /p:SkipFusionBuild=true
|
||||
|
||||
- name: Run tests
|
||||
run: dotnet test FictionArchive.sln --configuration Release --no-build --verbosity normal
|
||||
run: |
|
||||
dotnet test FictionArchive.sln --configuration Release --no-build --verbosity normal \
|
||||
--logger "trx;LogFileName=test-results.trx" \
|
||||
--collect:"XPlat Code Coverage" \
|
||||
--results-directory ./TestResults
|
||||
|
||||
- name: Upload test results
|
||||
uses: christopherhx/gitea-upload-artifact@v4
|
||||
if: always()
|
||||
with:
|
||||
name: test-results
|
||||
path: ./TestResults/**/*.trx
|
||||
retention-days: 30
|
||||
|
||||
- name: Upload coverage results
|
||||
uses: christopherhx/gitea-upload-artifact@v4
|
||||
if: always()
|
||||
with:
|
||||
name: coverage-results
|
||||
path: ./TestResults/**/coverage.cobertura.xml
|
||||
retention-days: 30
|
||||
|
||||
build-frontend:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: fictionarchive-web
|
||||
working-directory: fictionarchive-web-astro
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
name: Claude PR Assistant
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
pull_request_review_comment:
|
||||
types: [created]
|
||||
issues:
|
||||
types: [opened, assigned]
|
||||
pull_request_review:
|
||||
types: [submitted]
|
||||
|
||||
jobs:
|
||||
claude-code-action:
|
||||
if: |
|
||||
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
|
||||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
|
||||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
|
||||
(github.event_name == 'issues' && contains(github.event.issue.body, '@claude'))
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
issues: write
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
- name: Run Claude PR Action
|
||||
uses: anthropics/claude-code-action@beta
|
||||
with:
|
||||
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
|
||||
gitea_token: ${{ secrets.CLAUDE_GITEA_TOKEN }}
|
||||
# Or use OAuth token instead:
|
||||
# claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
|
||||
timeout_minutes: "60"
|
||||
# mode: tag # Default: responds to @claude mentions
|
||||
# Optional: Restrict network access to specific domains only
|
||||
# experimental_allowed_domains: |
|
||||
# .anthropic.com
|
||||
# .github.com
|
||||
# api.github.com
|
||||
# .githubusercontent.com
|
||||
# bun.sh
|
||||
# registry.npmjs.org
|
||||
# .blob.core.windows.net
|
||||
@@ -15,8 +15,6 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
service:
|
||||
- name: api
|
||||
dockerfile: FictionArchive.API/Dockerfile
|
||||
- name: novel-service
|
||||
dockerfile: FictionArchive.Service.NovelService/Dockerfile
|
||||
- name: user-service
|
||||
@@ -29,6 +27,8 @@ jobs:
|
||||
dockerfile: FictionArchive.Service.SchedulerService/Dockerfile
|
||||
- name: authentication-service
|
||||
dockerfile: FictionArchive.Service.AuthenticationService/Dockerfile
|
||||
- name: usernoveldata-service
|
||||
dockerfile: FictionArchive.Service.UserNovelDataService/Dockerfile
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
@@ -40,6 +40,10 @@ jobs:
|
||||
id: version
|
||||
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Extract registry hostname
|
||||
id: registry
|
||||
run: echo "HOST=$(echo '${{ gitea.server_url }}' | sed 's|https\?://||')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Log in to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
@@ -54,8 +58,8 @@ jobs:
|
||||
file: ${{ matrix.service.dockerfile }}
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}-${{ matrix.service.name }}:${{ steps.version.outputs.VERSION }}
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}-${{ matrix.service.name }}:latest
|
||||
${{ steps.registry.outputs.HOST }}/${{ env.IMAGE_PREFIX }}-${{ matrix.service.name }}:${{ steps.version.outputs.VERSION }}
|
||||
${{ steps.registry.outputs.HOST }}/${{ env.IMAGE_PREFIX }}-${{ matrix.service.name }}:latest
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
@@ -72,6 +76,10 @@ jobs:
|
||||
id: version
|
||||
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Extract registry hostname
|
||||
id: registry
|
||||
run: echo "HOST=$(echo '${{ gitea.server_url }}' | sed 's|https\?://||')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Log in to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
@@ -82,17 +90,18 @@ jobs:
|
||||
- name: Build and push frontend Docker image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ./fictionarchive-web
|
||||
file: fictionarchive-web/Dockerfile
|
||||
context: ./fictionarchive-web-astro
|
||||
file: fictionarchive-web-astro/Dockerfile
|
||||
push: true
|
||||
build-args: |
|
||||
VITE_GRAPHQL_URI=${{ vars.VITE_GRAPHQL_URI }}
|
||||
VITE_OIDC_AUTHORITY=${{ vars.VITE_OIDC_AUTHORITY }}
|
||||
VITE_OIDC_CLIENT_ID=${{ vars.VITE_OIDC_CLIENT_ID }}
|
||||
VITE_OIDC_REDIRECT_URI=${{ vars.VITE_OIDC_REDIRECT_URI }}
|
||||
VITE_OIDC_POST_LOGOUT_REDIRECT_URI=${{ vars.VITE_OIDC_POST_LOGOUT_REDIRECT_URI }}
|
||||
PUBLIC_GRAPHQL_URI=${{ vars.PUBLIC_GRAPHQL_URI }}
|
||||
PUBLIC_OIDC_AUTHORITY=${{ vars.PUBLIC_OIDC_AUTHORITY }}
|
||||
PUBLIC_OIDC_CLIENT_ID=${{ vars.PUBLIC_OIDC_CLIENT_ID }}
|
||||
PUBLIC_OIDC_REDIRECT_URI=${{ vars.PUBLIC_OIDC_REDIRECT_URI }}
|
||||
PUBLIC_OIDC_POST_LOGOUT_REDIRECT_URI=${{ vars.PUBLIC_OIDC_POST_LOGOUT_REDIRECT_URI }}
|
||||
PUBLIC_OIDC_SCOPE=${{ vars.PUBLIC_OIDC_SCOPE }}
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}-frontend:${{ steps.version.outputs.VERSION }}
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}-frontend:latest
|
||||
${{ steps.registry.outputs.HOST }}/${{ env.IMAGE_PREFIX }}-frontend:${{ steps.version.outputs.VERSION }}
|
||||
${{ steps.registry.outputs.HOST }}/${{ env.IMAGE_PREFIX }}-frontend:latest
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -140,3 +140,6 @@ appsettings.Local.json
|
||||
schema.graphql
|
||||
*.fsp
|
||||
gateway.fgp
|
||||
|
||||
# Git worktrees
|
||||
.worktrees/
|
||||
@@ -7,9 +7,9 @@ This document describes the CI/CD pipeline configuration for FictionArchive usin
|
||||
| Workflow | File | Trigger | Purpose |
|
||||
|----------|------|---------|---------|
|
||||
| CI | `build.yml` | Push/PR to master | Build and test all projects |
|
||||
| Build Subgraphs | `build-subgraphs.yml` | Push to master (service changes) | Build GraphQL subgraph packages |
|
||||
| Build Gateway | `build-gateway.yml` | Manual or triggered by subgraphs | Compose gateway and build Docker image |
|
||||
| Build Gateway | `build-gateway.yml` | Tag `v*.*.*` or manual | Build subgraphs, compose gateway, push API image |
|
||||
| Release | `release.yml` | Tag `v*.*.*` | Build and push all Docker images |
|
||||
| Claude PR Assistant | `claude_assistant.yml` | Issue/PR comments with @claude | AI-assisted code review and issue handling |
|
||||
|
||||
## Pipeline Architecture
|
||||
|
||||
@@ -18,27 +18,32 @@ This document describes the CI/CD pipeline configuration for FictionArchive usin
|
||||
│ Push to master │
|
||||
└─────────────────────────────┬───────────────────────────────────────┘
|
||||
│
|
||||
┌───────────────┴───────────────┐
|
||||
▼ ▼
|
||||
┌─────────────────────────┐ ┌─────────────────────────┐
|
||||
│ build.yml │ │ build-subgraphs.yml │
|
||||
│ (CI checks - always) │ │ (if service changes) │
|
||||
└─────────────────────────┘ └────────────┬────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────┐
|
||||
│ build-gateway.yml │
|
||||
│ (compose & push API) │
|
||||
│ build.yml │
|
||||
│ (CI checks) │
|
||||
└─────────────────────────┘
|
||||
|
||||
┌─────────────────────────────────────────────────────────────────────┐
|
||||
│ Push tag v*.*.* │
|
||||
└─────────────────────────────┬───────────────────────────────────────┘
|
||||
│
|
||||
┌───────────────┴───────────────┐
|
||||
▼ ▼
|
||||
┌─────────────────────────┐ ┌─────────────────────────┐
|
||||
│ release.yml │ │ build-gateway.yml │
|
||||
│ (build & push all │ │ (build subgraphs & │
|
||||
│ backend + frontend) │ │ push API gateway) │
|
||||
└─────────────────────────┘ └─────────────────────────┘
|
||||
|
||||
┌─────────────────────────────────────────────────────────────────────┐
|
||||
│ Issue/PR comment containing @claude │
|
||||
└─────────────────────────────┬───────────────────────────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────────────┐
|
||||
│ release.yml │
|
||||
│ (build & push all) │
|
||||
│ claude_assistant.yml │
|
||||
│ (AI code assistance) │
|
||||
└─────────────────────────┘
|
||||
```
|
||||
|
||||
@@ -51,14 +56,15 @@ Configure these in **Settings → Actions → Secrets**:
|
||||
| Secret | Description | Required By |
|
||||
|--------|-------------|-------------|
|
||||
| `REGISTRY_TOKEN` | Gitea access token with `write:package` scope | `release.yml`, `build-gateway.yml` |
|
||||
| `GITEA_TOKEN` | Gitea access token for API calls | `build-subgraphs.yml` |
|
||||
| `CLAUDE_CODE_OAUTH_TOKEN` | Claude Code OAuth token | `claude_assistant.yml` |
|
||||
| `CLAUDE_GITEA_TOKEN` | Gitea token for Claude assistant | `claude_assistant.yml` |
|
||||
|
||||
#### Creating Access Tokens
|
||||
|
||||
1. Go to **Settings → Applications → Access Tokens**
|
||||
2. Create a new token with the following scopes:
|
||||
- `write:package` - Push container images
|
||||
- `write:repository` - Trigger workflows via API
|
||||
- `write:repository` - For Claude assistant to push commits
|
||||
3. Copy the token and add it as a repository secret
|
||||
|
||||
### Repository Variables
|
||||
@@ -85,42 +91,62 @@ Configure these in **Settings → Actions → Variables**:
|
||||
|
||||
**Requirements:**
|
||||
- .NET 8.0 SDK
|
||||
- Python 3.12
|
||||
- Node.js 20
|
||||
- HotChocolate Fusion CLI
|
||||
|
||||
### Build Subgraphs (`build-subgraphs.yml`)
|
||||
**Steps (Backend):**
|
||||
1. Checkout repository
|
||||
2. Setup .NET 8.0
|
||||
3. Restore dependencies
|
||||
4. Build solution (Release, with `SkipFusionBuild=true`)
|
||||
5. Run tests
|
||||
|
||||
**Trigger:** Push to `master` with changes in:
|
||||
- `FictionArchive.Service.*/**`
|
||||
- `FictionArchive.Common/**`
|
||||
- `FictionArchive.Service.Shared/**`
|
||||
|
||||
**Jobs:**
|
||||
1. `build-subgraphs` - Matrix job building each service's `.fsp` package
|
||||
2. `trigger-gateway` - Triggers gateway rebuild via API
|
||||
|
||||
**Subgraphs Built:**
|
||||
- Novel Service
|
||||
- Translation Service
|
||||
- Scheduler Service
|
||||
- User Service
|
||||
- File Service
|
||||
|
||||
**Artifacts:** Each subgraph produces a `.fsp` file retained for 30 days.
|
||||
**Steps (Frontend):**
|
||||
1. Checkout repository
|
||||
2. Setup Node.js 20
|
||||
3. Install dependencies (`npm ci`)
|
||||
4. Run linter (`npm run lint`)
|
||||
5. Build application (`npm run build`)
|
||||
|
||||
### Build Gateway (`build-gateway.yml`)
|
||||
|
||||
**Trigger:**
|
||||
- Manual dispatch (`workflow_dispatch`)
|
||||
- Push to `master` with changes in `FictionArchive.API/**`
|
||||
- Triggered by `build-subgraphs.yml` completion
|
||||
- Push tag matching `v*.*.*`
|
||||
|
||||
**Process:**
|
||||
1. Downloads all subgraph `.fsp` artifacts
|
||||
2. Configures Docker-internal URLs for each subgraph
|
||||
3. Composes gateway schema using Fusion CLI
|
||||
4. Builds and pushes API Docker image
|
||||
**Jobs:**
|
||||
|
||||
#### 1. `build-subgraphs` (Matrix Job)
|
||||
Builds GraphQL subgraph packages for each service:
|
||||
|
||||
| Service | Project | Subgraph Name |
|
||||
|---------|---------|---------------|
|
||||
| novel-service | FictionArchive.Service.NovelService | Novel |
|
||||
| translation-service | FictionArchive.Service.TranslationService | Translation |
|
||||
| scheduler-service | FictionArchive.Service.SchedulerService | Scheduler |
|
||||
| user-service | FictionArchive.Service.UserService | User |
|
||||
|
||||
**Note:** File Service and Authentication Service are not subgraphs (no GraphQL schema).
|
||||
|
||||
**Steps:**
|
||||
1. Checkout repository
|
||||
2. Setup .NET 8.0
|
||||
3. Install HotChocolate Fusion CLI
|
||||
4. Restore and build service project
|
||||
5. Export GraphQL schema (`schema export`)
|
||||
6. Pack subgraph into `.fsp` file
|
||||
7. Upload artifact (retained 30 days)
|
||||
|
||||
#### 2. `build-gateway` (Depends on `build-subgraphs`)
|
||||
Composes the API gateway from subgraph packages.
|
||||
|
||||
**Steps:**
|
||||
1. Checkout repository
|
||||
2. Setup .NET 8.0 and Fusion CLI
|
||||
3. Download all subgraph artifacts
|
||||
4. Configure Docker-internal URLs (`http://{service}-service:8080/graphql`)
|
||||
5. Compose gateway schema using Fusion CLI
|
||||
6. Build gateway project
|
||||
7. Build and push Docker image
|
||||
|
||||
**Image Tags:**
|
||||
- `<registry>/<owner>/fictionarchive-api:latest`
|
||||
@@ -131,23 +157,54 @@ Configure these in **Settings → Actions → Variables**:
|
||||
**Trigger:** Push tag matching `v*.*.*` (e.g., `v1.0.0`)
|
||||
|
||||
**Jobs:**
|
||||
1. `build-and-push` - Matrix job building all backend service images
|
||||
2. `build-frontend` - Builds and pushes frontend image
|
||||
|
||||
**Services Built:**
|
||||
- `fictionarchive-api`
|
||||
- `fictionarchive-novel-service`
|
||||
- `fictionarchive-user-service`
|
||||
- `fictionarchive-translation-service`
|
||||
- `fictionarchive-file-service`
|
||||
- `fictionarchive-scheduler-service`
|
||||
- `fictionarchive-authentication-service`
|
||||
- `fictionarchive-frontend`
|
||||
#### 1. `build-and-push` (Matrix Job)
|
||||
Builds and pushes all backend service images:
|
||||
|
||||
| Service | Dockerfile |
|
||||
|---------|------------|
|
||||
| novel-service | FictionArchive.Service.NovelService/Dockerfile |
|
||||
| user-service | FictionArchive.Service.UserService/Dockerfile |
|
||||
| translation-service | FictionArchive.Service.TranslationService/Dockerfile |
|
||||
| file-service | FictionArchive.Service.FileService/Dockerfile |
|
||||
| scheduler-service | FictionArchive.Service.SchedulerService/Dockerfile |
|
||||
| authentication-service | FictionArchive.Service.AuthenticationService/Dockerfile |
|
||||
|
||||
#### 2. `build-frontend`
|
||||
Builds and pushes the frontend image with environment-specific build arguments.
|
||||
|
||||
**Build Args:**
|
||||
- `VITE_GRAPHQL_URI`
|
||||
- `VITE_OIDC_AUTHORITY`
|
||||
- `VITE_OIDC_CLIENT_ID`
|
||||
- `VITE_OIDC_REDIRECT_URI`
|
||||
- `VITE_OIDC_POST_LOGOUT_REDIRECT_URI`
|
||||
|
||||
**Image Tags:**
|
||||
- `<registry>/<owner>/fictionarchive-<service>:<version>`
|
||||
- `<registry>/<owner>/fictionarchive-<service>:latest`
|
||||
|
||||
### Claude PR Assistant (`claude_assistant.yml`)
|
||||
|
||||
**Trigger:** Comments or issues containing `@claude`:
|
||||
- Issue comments
|
||||
- Pull request review comments
|
||||
- Pull request reviews
|
||||
- New issues (opened or assigned)
|
||||
|
||||
**Permissions Required:**
|
||||
- `contents: write`
|
||||
- `pull-requests: write`
|
||||
- `issues: write`
|
||||
- `id-token: write`
|
||||
|
||||
**Usage:**
|
||||
Mention `@claude` in any issue or PR comment to invoke the AI assistant for:
|
||||
- Code review assistance
|
||||
- Bug analysis
|
||||
- Implementation suggestions
|
||||
- Documentation help
|
||||
|
||||
## Container Registry
|
||||
|
||||
Images are pushed to the Gitea Container Registry at:
|
||||
@@ -155,6 +212,19 @@ Images are pushed to the Gitea Container Registry at:
|
||||
<gitea-server-url>/<repository-owner>/fictionarchive-<service>:<tag>
|
||||
```
|
||||
|
||||
### Image Naming Convention
|
||||
|
||||
| Image | Description |
|
||||
|-------|-------------|
|
||||
| `fictionarchive-api` | API Gateway (GraphQL Federation) |
|
||||
| `fictionarchive-novel-service` | Novel Service |
|
||||
| `fictionarchive-user-service` | User Service |
|
||||
| `fictionarchive-translation-service` | Translation Service |
|
||||
| `fictionarchive-file-service` | File Service |
|
||||
| `fictionarchive-scheduler-service` | Scheduler Service |
|
||||
| `fictionarchive-authentication-service` | Authentication Service |
|
||||
| `fictionarchive-frontend` | Web Frontend |
|
||||
|
||||
### Pulling Images
|
||||
|
||||
```bash
|
||||
@@ -184,13 +254,13 @@ docker pull <gitea-server-url>/<owner>/fictionarchive-api:latest
|
||||
- Ensure the `REGISTRY_TOKEN` secret is configured in repository settings
|
||||
- Verify the token has `write:package` scope
|
||||
|
||||
**"Failed to trigger gateway workflow"**
|
||||
- Ensure `GITEA_TOKEN` secret is configured
|
||||
- Verify the token has `write:repository` scope
|
||||
|
||||
**"No subgraph artifacts found"**
|
||||
- The gateway build requires subgraph artifacts from a previous `build-subgraphs` run
|
||||
- Trigger `build-subgraphs.yml` manually or push a change to a service
|
||||
- The gateway build requires subgraph artifacts from the `build-subgraphs` job
|
||||
- If subgraph builds failed, check the matrix job logs for errors
|
||||
|
||||
**"Schema export failed"**
|
||||
- Ensure the service project has a valid `subgraph-config.json`
|
||||
- Check that the service starts correctly for schema export
|
||||
|
||||
### Frontend Build Failures
|
||||
|
||||
@@ -204,6 +274,13 @@ docker pull <gitea-server-url>/<owner>/fictionarchive-api:latest
|
||||
- Verify `REGISTRY_TOKEN` has correct permissions
|
||||
- Check that the token hasn't expired
|
||||
|
||||
### Claude Assistant Failures
|
||||
|
||||
**"Claude assistant not responding"**
|
||||
- Verify `CLAUDE_CODE_OAUTH_TOKEN` is configured
|
||||
- Verify `CLAUDE_GITEA_TOKEN` is configured and has write permissions
|
||||
- Check that the comment contains `@claude` mention
|
||||
|
||||
## Local Testing
|
||||
|
||||
To test workflows locally before pushing:
|
||||
|
||||
9977
Documentation/sample_novel_page.html
Normal file
9977
Documentation/sample_novel_page.html
Normal file
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,8 @@ RUN dotnet build "./FictionArchive.API.csproj" -c $BUILD_CONFIGURATION -o /app/b
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./FictionArchive.API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:SkipFusionBuild=true
|
||||
# Copy pre-composed gateway.fgp from CI build
|
||||
COPY FictionArchive.API/gateway.fgp /app/publish/
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="15.1.11" />
|
||||
<PackageReference Include="HotChocolate.Fusion" Version="15.1.11" />
|
||||
<PackageReference Include="HotChocolate.Types.Scalars" Version="15.1.11" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.HeaderPropagation" Version="8.0.22" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.11">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
@@ -20,6 +21,7 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.11" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.7" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Builds the Fusion graph file before building the application itself (skipped in CI) -->
|
||||
|
||||
@@ -12,7 +12,13 @@ public class Program
|
||||
|
||||
#region Fusion Gateway
|
||||
|
||||
builder.Services.AddHttpClient("Fusion");
|
||||
// Register header propagation service to forward Authorization header to subgraphs
|
||||
builder.Services.AddHttpClient("Fusion")
|
||||
.AddHeaderPropagation();
|
||||
builder.Services.AddHeaderPropagation(opt =>
|
||||
{
|
||||
opt.Headers.Add("Authorization");
|
||||
});
|
||||
|
||||
builder.Services
|
||||
.AddFusionGatewayServer()
|
||||
@@ -21,23 +27,27 @@ public class Program
|
||||
|
||||
#endregion
|
||||
|
||||
var allowedOrigin = builder.Configuration["Cors:AllowedOrigin"] ?? "http://localhost:4321";
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAllOrigins",
|
||||
builder =>
|
||||
options.AddPolicy("AllowFictionArchiveOrigins",
|
||||
policyBuilder =>
|
||||
{
|
||||
builder.AllowAnyOrigin()
|
||||
policyBuilder.WithOrigins(allowedOrigin)
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader();
|
||||
.AllowAnyHeader()
|
||||
.AllowCredentials();
|
||||
});
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseCors("AllowAllOrigins");
|
||||
app.UseCors("AllowFictionArchiveOrigins");
|
||||
|
||||
app.MapHealthChecks("/healthz");
|
||||
|
||||
app.UseHeaderPropagation();
|
||||
|
||||
app.MapGraphQL();
|
||||
|
||||
app.RunWithGraphQLCommands(args);
|
||||
|
||||
@@ -5,5 +5,18 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"Cors": {
|
||||
"AllowedOrigin": "http://localhost:4321"
|
||||
},
|
||||
"OIDC": {
|
||||
"Authority": "https://auth.orfl.xyz/application/o/fiction-archive/",
|
||||
"ClientId": "ldi5IpEidq2WW0Ka1lehVskb2SOBjnYRaZCpEyBh",
|
||||
"Audience": "ldi5IpEidq2WW0Ka1lehVskb2SOBjnYRaZCpEyBh",
|
||||
"ValidIssuer": "https://auth.orfl.xyz/application/o/fiction-archive/",
|
||||
"ValidateIssuer": true,
|
||||
"ValidateAudience": true,
|
||||
"ValidateLifetime": true,
|
||||
"ValidateIssuerSigningKey": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
using FictionArchive.Service.AuthenticationService.Models.Requests;
|
||||
using FictionArchive.Service.AuthenticationService.Models.IntegrationEvents;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace FictionArchive.Service.AuthenticationService.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class AuthenticationWebhookController : ControllerBase
|
||||
{
|
||||
private readonly IEventBus _eventBus;
|
||||
|
||||
public AuthenticationWebhookController(IEventBus eventBus)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
}
|
||||
|
||||
[HttpPost(nameof(UserRegistered))]
|
||||
public async Task<ActionResult> UserRegistered([FromBody] UserRegisteredWebhookPayload payload)
|
||||
{
|
||||
var authUserAddedEvent = new AuthUserAddedEvent
|
||||
{
|
||||
OAuthProviderId = payload.OAuthProviderId,
|
||||
InviterOAuthProviderId = payload.InviterOAuthProviderId,
|
||||
EventUserEmail = payload.EventUserEmail,
|
||||
EventUserUsername = payload.EventUserUsername
|
||||
};
|
||||
|
||||
await _eventBus.Publish(authUserAddedEvent);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["FictionArchive.Service.AuthenticationService/FictionArchive.Service.AuthenticationService.csproj", "FictionArchive.Service.AuthenticationService/"]
|
||||
RUN dotnet restore "FictionArchive.Service.AuthenticationService/FictionArchive.Service.AuthenticationService.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/FictionArchive.Service.AuthenticationService"
|
||||
RUN dotnet build "./FictionArchive.Service.AuthenticationService.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./FictionArchive.Service.AuthenticationService.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "FictionArchive.Service.AuthenticationService.dll"]
|
||||
@@ -1,6 +0,0 @@
|
||||
@FictionArchive.Service.AuthenticationService_HostAddress = http://localhost:5091
|
||||
|
||||
GET {{FictionArchive.Service.AuthenticationService_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
@@ -1,16 +0,0 @@
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.AuthenticationService.Models.IntegrationEvents;
|
||||
|
||||
public class AuthUserAddedEvent : IIntegrationEvent
|
||||
{
|
||||
public string OAuthProviderId { get; set; }
|
||||
|
||||
public string InviterOAuthProviderId { get; set; }
|
||||
|
||||
// The email of the user that created the event
|
||||
public string EventUserEmail { get; set; }
|
||||
|
||||
// The username of the user that created the event
|
||||
public string EventUserUsername { get; set; }
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace FictionArchive.Service.AuthenticationService.Models.Requests;
|
||||
|
||||
public class UserRegisteredWebhookPayload
|
||||
{
|
||||
// The body of the notification message
|
||||
public string Body { get; set; }
|
||||
|
||||
public string OAuthProviderId { get; set; }
|
||||
|
||||
public string InviterOAuthProviderId { get; set; }
|
||||
|
||||
// The email of the user that created the event
|
||||
public string EventUserEmail { get; set; }
|
||||
|
||||
// The username of the user that created the event
|
||||
public string EventUserUsername { get; set; }
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
using FictionArchive.Service.Shared;
|
||||
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
||||
|
||||
namespace FictionArchive.Service.AuthenticationService;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
#region Event Bus
|
||||
|
||||
builder.Services.AddRabbitMQ(opt =>
|
||||
{
|
||||
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.MapHealthChecks("/healthz");
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"RabbitMQ": {
|
||||
"ConnectionString": "amqp://localhost",
|
||||
"ClientIdentifier": "AuthenticationService"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using Amazon.S3;
|
||||
using Amazon.S3.Model;
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.FileService.Models;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace FictionArchive.Service.FileService.Consumers;
|
||||
|
||||
public class FileUploadRequestCreatedConsumer : IConsumer<IFileUploadRequestCreated>
|
||||
{
|
||||
private readonly ILogger<FileUploadRequestCreatedConsumer> _logger;
|
||||
private readonly AmazonS3Client _amazonS3Client;
|
||||
private readonly IPublishEndpoint _publishEndpoint;
|
||||
private readonly S3Configuration _s3Configuration;
|
||||
private readonly ProxyConfiguration _proxyConfiguration;
|
||||
|
||||
public FileUploadRequestCreatedConsumer(
|
||||
ILogger<FileUploadRequestCreatedConsumer> logger,
|
||||
AmazonS3Client amazonS3Client,
|
||||
IPublishEndpoint publishEndpoint,
|
||||
IOptions<S3Configuration> s3Configuration,
|
||||
IOptions<ProxyConfiguration> proxyConfiguration)
|
||||
{
|
||||
_logger = logger;
|
||||
_amazonS3Client = amazonS3Client;
|
||||
_publishEndpoint = publishEndpoint;
|
||||
_s3Configuration = s3Configuration.Value;
|
||||
_proxyConfiguration = proxyConfiguration.Value;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<IFileUploadRequestCreated> context)
|
||||
{
|
||||
var message = context.Message;
|
||||
|
||||
var putObjectRequest = new PutObjectRequest
|
||||
{
|
||||
BucketName = _s3Configuration.Bucket,
|
||||
Key = message.FilePath
|
||||
};
|
||||
|
||||
using var memoryStream = new MemoryStream(message.FileData);
|
||||
putObjectRequest.InputStream = memoryStream;
|
||||
|
||||
var s3Response = await _amazonS3Client.PutObjectAsync(putObjectRequest);
|
||||
|
||||
if (s3Response.HttpStatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
_logger.LogError("Failed to upload file {FilePath} to S3", message.FilePath);
|
||||
|
||||
await _publishEndpoint.Publish<IFileUploadRequestStatusUpdate>(
|
||||
new FileUploadRequestStatusUpdate(
|
||||
ImportId: message.ImportId,
|
||||
RequestId: message.RequestId,
|
||||
Status: RequestStatus.Failed,
|
||||
FileAccessUrl: null,
|
||||
ErrorMessage: "An error occurred while uploading file to S3."));
|
||||
return;
|
||||
}
|
||||
|
||||
var fileAccessUrl = _proxyConfiguration.BaseUrl + "/" + message.FilePath;
|
||||
|
||||
_logger.LogInformation("Successfully uploaded file {FilePath} to S3", message.FilePath);
|
||||
|
||||
await _publishEndpoint.Publish<IFileUploadRequestStatusUpdate>(
|
||||
new FileUploadRequestStatusUpdate(
|
||||
ImportId: message.ImportId,
|
||||
RequestId: message.RequestId,
|
||||
Status: RequestStatus.Success,
|
||||
FileAccessUrl: fileAccessUrl,
|
||||
ErrorMessage: null));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Web;
|
||||
using Amazon.S3;
|
||||
using Amazon.S3.Model;
|
||||
using FictionArchive.Service.FileService.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -10,6 +11,7 @@ namespace FictionArchive.Service.FileService.Controllers
|
||||
{
|
||||
[Route("api/{*path}")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class S3ProxyController : ControllerBase
|
||||
{
|
||||
private readonly AmazonS3Client _amazonS3Client;
|
||||
@@ -34,7 +36,15 @@ namespace FictionArchive.Service.FileService.Controllers
|
||||
Key = decodedPath
|
||||
});
|
||||
|
||||
return new FileStreamResult(s3Response.ResponseStream, s3Response.Headers.ContentType);
|
||||
Response.Headers.CacheControl = "public, max-age=604800"; // 7 days
|
||||
Response.Headers.LastModified = s3Response.LastModified?.ToString("R");
|
||||
|
||||
if (!string.IsNullOrEmpty(s3Response.ETag))
|
||||
{
|
||||
Response.Headers.ETag = s3Response.ETag;
|
||||
}
|
||||
|
||||
return File(s3Response.ResponseStream, s3Response.Headers.ContentType);
|
||||
}
|
||||
catch (AmazonS3Exception e)
|
||||
{
|
||||
|
||||
@@ -7,17 +7,17 @@ EXPOSE 8081
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["FictionArchive.Service.ImageService/FictionArchive.Service.ImageService.csproj", "FictionArchive.Service.ImageService/"]
|
||||
RUN dotnet restore "FictionArchive.Service.ImageService/FictionArchive.Service.ImageService.csproj"
|
||||
COPY ["FictionArchive.Service.FileService/FictionArchive.Service.FileService.csproj", "FictionArchive.Service.FileService/"]
|
||||
RUN dotnet restore "FictionArchive.Service.FileService/FictionArchive.Service.FileService.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/FictionArchive.Service.ImageService"
|
||||
RUN dotnet build "./FictionArchive.Service.ImageService.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
WORKDIR "/src/FictionArchive.Service.FileService"
|
||||
RUN dotnet build "./FictionArchive.Service.FileService.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./FictionArchive.Service.ImageService.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
RUN dotnet publish "./FictionArchive.Service.FileService.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "FictionArchive.Service.ImageService.dll"]
|
||||
ENTRYPOINT ["dotnet", "FictionArchive.Service.FileService.dll"]
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<PackageReference Include="AWSSDK.S3" Version="4.0.13.1" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.FileService.Models.IntegrationEvents;
|
||||
|
||||
public class FileUploadRequestCreatedEvent : IIntegrationEvent
|
||||
{
|
||||
public Guid RequestId { get; set; }
|
||||
public string FilePath { get; set; }
|
||||
public byte[] FileData { get; set; }
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.FileService.Models.IntegrationEvents;
|
||||
|
||||
public class FileUploadRequestStatusUpdateEvent : IIntegrationEvent
|
||||
{
|
||||
public Guid RequestId { get; set; }
|
||||
public RequestStatus Status { get; set; }
|
||||
|
||||
#region Success
|
||||
|
||||
public string? FileAccessUrl { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Failure
|
||||
|
||||
public string? ErrorMessage { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
using Amazon.Runtime;
|
||||
using Amazon.S3;
|
||||
using FictionArchive.Common.Extensions;
|
||||
using FictionArchive.Service.FileService.Consumers;
|
||||
using FictionArchive.Service.FileService.Models;
|
||||
using FictionArchive.Service.FileService.Models.IntegrationEvents;
|
||||
using FictionArchive.Service.FileService.Services.EventHandlers;
|
||||
using FictionArchive.Service.Shared.Extensions;
|
||||
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace FictionArchive.Service.FileService;
|
||||
@@ -24,16 +22,21 @@ public class Program
|
||||
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
#region Event Bus
|
||||
#region MassTransit
|
||||
|
||||
builder.Services.AddRabbitMQ(opt =>
|
||||
builder.Services.AddFictionArchiveMassTransit(
|
||||
builder.Configuration,
|
||||
x =>
|
||||
{
|
||||
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
||||
})
|
||||
.Subscribe<FileUploadRequestCreatedEvent, FileUploadRequestCreatedEventHandler>();
|
||||
x.AddConsumer<FileUploadRequestCreatedConsumer>();
|
||||
});
|
||||
|
||||
#endregion
|
||||
|
||||
// Add authentication with cookie support
|
||||
builder.Services.AddOidcCookieAuthentication(builder.Configuration);
|
||||
builder.Services.AddFictionArchiveAuthorization();
|
||||
|
||||
builder.Services.Configure<ProxyConfiguration>(builder.Configuration.GetSection("ProxyConfiguration"));
|
||||
|
||||
// Add S3 Client
|
||||
@@ -60,6 +63,9 @@ public class Program
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapHealthChecks("/healthz");
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
using Amazon.S3;
|
||||
using Amazon.S3.Model;
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.FileService.Models;
|
||||
using FictionArchive.Service.FileService.Models.IntegrationEvents;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace FictionArchive.Service.FileService.Services.EventHandlers;
|
||||
|
||||
public class FileUploadRequestCreatedEventHandler : IIntegrationEventHandler<FileUploadRequestCreatedEvent>
|
||||
{
|
||||
private readonly ILogger<FileUploadRequestCreatedEventHandler> _logger;
|
||||
private readonly AmazonS3Client _amazonS3Client;
|
||||
private readonly IEventBus _eventBus;
|
||||
private readonly S3Configuration _s3Configuration;
|
||||
private readonly ProxyConfiguration _proxyConfiguration;
|
||||
|
||||
public FileUploadRequestCreatedEventHandler(ILogger<FileUploadRequestCreatedEventHandler> logger, AmazonS3Client amazonS3Client, IEventBus eventBus, IOptions<S3Configuration> s3Configuration, IOptions<ProxyConfiguration> proxyConfiguration)
|
||||
{
|
||||
_logger = logger;
|
||||
_amazonS3Client = amazonS3Client;
|
||||
_eventBus = eventBus;
|
||||
_proxyConfiguration = proxyConfiguration.Value;
|
||||
_s3Configuration = s3Configuration.Value;
|
||||
}
|
||||
|
||||
public async Task Handle(FileUploadRequestCreatedEvent @event)
|
||||
{
|
||||
var putObjectRequest = new PutObjectRequest();
|
||||
putObjectRequest.BucketName = _s3Configuration.Bucket;
|
||||
putObjectRequest.Key = @event.FilePath;
|
||||
putObjectRequest.UseChunkEncoding = false; // Needed to avoid an error with Garage
|
||||
|
||||
using MemoryStream memoryStream = new MemoryStream(@event.FileData);
|
||||
putObjectRequest.InputStream = memoryStream;
|
||||
|
||||
var s3Response = await _amazonS3Client.PutObjectAsync(putObjectRequest);
|
||||
if (s3Response.HttpStatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
_logger.LogError("An error occurred while uploading file to S3. Response code: {responsecode}", s3Response.HttpStatusCode);
|
||||
await _eventBus.Publish(new FileUploadRequestStatusUpdateEvent()
|
||||
{
|
||||
RequestId = @event.RequestId,
|
||||
Status = RequestStatus.Failed,
|
||||
ErrorMessage = "An error occurred while uploading file to S3."
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await _eventBus.Publish(new FileUploadRequestStatusUpdateEvent()
|
||||
{
|
||||
Status = RequestStatus.Success,
|
||||
RequestId = @event.RequestId,
|
||||
FileAccessUrl = _proxyConfiguration.BaseUrl + "/" + @event.FilePath
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ProxyConfiguration": {
|
||||
@@ -18,5 +19,15 @@
|
||||
"AccessKey": "REPLACE_ME",
|
||||
"SecretKey": "REPLACE_ME"
|
||||
},
|
||||
"OIDC": {
|
||||
"Authority": "https://auth.orfl.xyz/application/o/fiction-archive/",
|
||||
"ClientId": "ldi5IpEidq2WW0Ka1lehVskb2SOBjnYRaZCpEyBh",
|
||||
"Audience": "ldi5IpEidq2WW0Ka1lehVskb2SOBjnYRaZCpEyBh",
|
||||
"ValidIssuer": "https://auth.orfl.xyz/application/o/fiction-archive/",
|
||||
"ValidateIssuer": true,
|
||||
"ValidateAudience": true,
|
||||
"ValidateLifetime": true,
|
||||
"ValidateIssuerSigningKey": true
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="MassTransit" Version="8.5.7" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.11" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="NodaTime.Testing" Version="3.3.0" />
|
||||
<PackageReference Include="NSubstitute" Version="5.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.FileService.IntegrationEvents;
|
||||
using FictionArchive.Service.NovelService.Models.Configuration;
|
||||
using FictionArchive.Service.NovelService.Models.Enums;
|
||||
using FictionArchive.Service.NovelService.Models.Images;
|
||||
@@ -8,12 +7,14 @@ using FictionArchive.Service.NovelService.Models.Novels;
|
||||
using FictionArchive.Service.NovelService.Models.SourceAdapters;
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using FluentAssertions;
|
||||
using HtmlAgilityPack;
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NodaTime;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
@@ -42,6 +43,13 @@ public class NovelUpdateServiceTests
|
||||
Images = new List<Image>()
|
||||
};
|
||||
|
||||
var volume = new Volume
|
||||
{
|
||||
Order = 1,
|
||||
Name = LocalizationKey.CreateFromText("Main Story", Language.En),
|
||||
Chapters = new List<Chapter> { chapter }
|
||||
};
|
||||
|
||||
var novel = new Novel
|
||||
{
|
||||
Url = "http://demo/novel",
|
||||
@@ -52,20 +60,20 @@ public class NovelUpdateServiceTests
|
||||
Source = source,
|
||||
Name = LocalizationKey.CreateFromText("Demo Novel", Language.En),
|
||||
Description = LocalizationKey.CreateFromText("Description", Language.En),
|
||||
Chapters = new List<Chapter> { chapter },
|
||||
Volumes = new List<Volume> { volume },
|
||||
Tags = new List<NovelTag>()
|
||||
};
|
||||
|
||||
dbContext.Novels.Add(novel);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
return new NovelCreateResult(novel, chapter);
|
||||
return new NovelCreateResult(novel, volume, chapter);
|
||||
}
|
||||
|
||||
private static NovelUpdateService CreateService(
|
||||
NovelServiceDbContext dbContext,
|
||||
ISourceAdapter adapter,
|
||||
IEventBus eventBus,
|
||||
IPublishEndpoint publishEndpoint,
|
||||
string pendingImageUrl = "https://pending/placeholder.jpg")
|
||||
{
|
||||
var options = Options.Create(new NovelUpdateServiceConfiguration
|
||||
@@ -73,7 +81,10 @@ public class NovelUpdateServiceTests
|
||||
PendingImageUrl = pendingImageUrl
|
||||
});
|
||||
|
||||
return new NovelUpdateService(dbContext, NullLogger<NovelUpdateService>.Instance, new[] { adapter }, eventBus, options);
|
||||
var clock = Substitute.For<IClock>();
|
||||
clock.GetCurrentInstant().Returns(Instant.FromUnixTimeSeconds(0));
|
||||
|
||||
return new NovelUpdateService(dbContext, NullLogger<NovelUpdateService>.Instance, new[] { adapter }, publishEndpoint, options, clock);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -81,7 +92,7 @@ public class NovelUpdateServiceTests
|
||||
{
|
||||
using var dbContext = CreateDbContext();
|
||||
var source = new Source { Name = "Demo", Key = "demo", Url = "http://demo" };
|
||||
var (novel, chapter) = CreateNovelWithSingleChapter(dbContext, source);
|
||||
var (novel, volume, chapter) = CreateNovelWithSingleChapter(dbContext, source);
|
||||
|
||||
var rawHtml = "<p>Hello</p><img src=\"http://img/x1.jpg\" alt=\"first\" /><img src=\"http://img/x2.jpg\" alt=\"second\" />";
|
||||
var image1 = new ImageData { Url = "http://img/x1.jpg", Data = new byte[] { 1, 2, 3 } };
|
||||
@@ -95,16 +106,18 @@ public class NovelUpdateServiceTests
|
||||
ImageData = new List<ImageData> { image1, image2 }
|
||||
}));
|
||||
|
||||
var publishedEvents = new List<FileUploadRequestCreatedEvent>();
|
||||
var eventBus = Substitute.For<IEventBus>();
|
||||
eventBus.Publish(Arg.Do<FileUploadRequestCreatedEvent>(publishedEvents.Add)).Returns(Task.CompletedTask);
|
||||
eventBus.Publish(Arg.Any<object>(), Arg.Any<string>()).Returns(Task.CompletedTask);
|
||||
var publishedEvents = new List<IFileUploadRequestCreated>();
|
||||
var publishEndpoint = Substitute.For<IPublishEndpoint>();
|
||||
publishEndpoint.Publish(Arg.Do<IFileUploadRequestCreated>(e => publishedEvents.Add(e)), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var pendingImageUrl = "https://pending/placeholder.jpg";
|
||||
var service = CreateService(dbContext, adapter, eventBus, pendingImageUrl);
|
||||
var service = CreateService(dbContext, adapter, publishEndpoint, pendingImageUrl);
|
||||
|
||||
var updatedChapter = await service.PullChapterContents(novel.Id, chapter.Order);
|
||||
var importId = Guid.NewGuid();
|
||||
var (updatedChapter, imageCount) = await service.PullChapterContents(importId, novel.Id, volume.Id, chapter.Order);
|
||||
|
||||
imageCount.Should().Be(2);
|
||||
updatedChapter.Images.Should().HaveCount(2);
|
||||
updatedChapter.Images.Select(i => i.OriginalPath).Should().BeEquivalentTo(new[] { image1.Url, image2.Url });
|
||||
updatedChapter.Images.All(i => i.Id != Guid.Empty).Should().BeTrue();
|
||||
@@ -121,9 +134,10 @@ public class NovelUpdateServiceTests
|
||||
.BeEquivalentTo(updatedChapter.Images.Select(img => img.Id.ToString()));
|
||||
|
||||
publishedEvents.Should().HaveCount(2);
|
||||
publishedEvents.Should().OnlyContain(e => e.ImportId == importId);
|
||||
publishedEvents.Select(e => e.RequestId).Should().BeEquivalentTo(updatedChapter.Images.Select(i => i.Id));
|
||||
publishedEvents.Select(e => e.FileData).Should().BeEquivalentTo(new[] { image1.Data, image2.Data });
|
||||
publishedEvents.Should().OnlyContain(e => e.FilePath.StartsWith($"{novel.Id}/Images/Chapter-{updatedChapter.Id}/"));
|
||||
publishedEvents.Should().OnlyContain(e => e.FilePath.StartsWith($"Novels/{novel.Id}/Images/Chapter-{updatedChapter.Id}/"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -131,7 +145,7 @@ public class NovelUpdateServiceTests
|
||||
{
|
||||
using var dbContext = CreateDbContext();
|
||||
var source = new Source { Name = "Demo", Key = "demo", Url = "http://demo" };
|
||||
var (novel, chapter) = CreateNovelWithSingleChapter(dbContext, source);
|
||||
var (novel, volume, chapter) = CreateNovelWithSingleChapter(dbContext, source);
|
||||
|
||||
var rawHtml = "<p>Hi</p><img src=\"http://img/x1.jpg\">";
|
||||
var image = new ImageData { Url = "http://img/x1.jpg", Data = new byte[] { 7, 8, 9 } };
|
||||
@@ -144,14 +158,14 @@ public class NovelUpdateServiceTests
|
||||
ImageData = new List<ImageData> { image }
|
||||
}));
|
||||
|
||||
var eventBus = Substitute.For<IEventBus>();
|
||||
eventBus.Publish(Arg.Any<FileUploadRequestCreatedEvent>()).Returns(Task.CompletedTask);
|
||||
eventBus.Publish(Arg.Any<object>(), Arg.Any<string>()).Returns(Task.CompletedTask);
|
||||
var publishEndpoint = Substitute.For<IPublishEndpoint>();
|
||||
|
||||
var service = CreateService(dbContext, adapter, eventBus);
|
||||
var service = CreateService(dbContext, adapter, publishEndpoint);
|
||||
|
||||
var updatedChapter = await service.PullChapterContents(novel.Id, chapter.Order);
|
||||
var importId = Guid.NewGuid();
|
||||
var (updatedChapter, imageCount) = await service.PullChapterContents(importId, novel.Id, volume.Id, chapter.Order);
|
||||
|
||||
imageCount.Should().Be(1);
|
||||
var storedHtml = updatedChapter.Body.Texts.Single().Text;
|
||||
var doc = new HtmlDocument();
|
||||
doc.LoadHtml(storedHtml);
|
||||
@@ -161,5 +175,139 @@ public class NovelUpdateServiceTests
|
||||
imgNode.GetAttributeValue("src", string.Empty).Should().Be("https://pending/placeholder.jpg");
|
||||
}
|
||||
|
||||
private record NovelCreateResult(Novel Novel, Chapter Chapter);
|
||||
private record NovelCreateResult(Novel Novel, Volume Volume, Chapter Chapter);
|
||||
|
||||
#region UpdateImage Tests
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateImage_sets_NewPath_on_image_without_chapter()
|
||||
{
|
||||
// Arrange
|
||||
using var dbContext = CreateDbContext();
|
||||
var image = new Image
|
||||
{
|
||||
OriginalPath = "http://original/cover.jpg",
|
||||
NewPath = null
|
||||
};
|
||||
dbContext.Images.Add(image);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
var adapter = Substitute.For<ISourceAdapter>();
|
||||
var publishEndpoint = Substitute.For<IPublishEndpoint>();
|
||||
var service = CreateService(dbContext, adapter, publishEndpoint);
|
||||
|
||||
var newUrl = "https://cdn.example.com/uploaded/cover.jpg";
|
||||
|
||||
// Act
|
||||
await service.UpdateImage(image.Id, newUrl);
|
||||
|
||||
// Assert
|
||||
var updatedImage = await dbContext.Images.FindAsync(image.Id);
|
||||
updatedImage!.NewPath.Should().Be(newUrl);
|
||||
updatedImage.OriginalPath.Should().Be("http://original/cover.jpg");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateImage_updates_chapter_body_html_with_new_url()
|
||||
{
|
||||
// Arrange
|
||||
using var dbContext = CreateDbContext();
|
||||
var source = new Source { Name = "Demo", Key = "demo", Url = "http://demo" };
|
||||
var (novel, _, chapter) = CreateNovelWithSingleChapter(dbContext, source);
|
||||
|
||||
var image = new Image
|
||||
{
|
||||
OriginalPath = "http://original/image.jpg",
|
||||
NewPath = null,
|
||||
Chapter = chapter
|
||||
};
|
||||
chapter.Images.Add(image);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
// Set up the chapter body with an img tag referencing the image by ID (as PullChapterContents does)
|
||||
var pendingUrl = "https://pending/placeholder.jpg";
|
||||
var bodyHtml = $"<p>Content</p><img src=\"{pendingUrl}\" alt=\"{image.Id}\" />";
|
||||
chapter.Body.Texts.Add(new LocalizationText
|
||||
{
|
||||
Language = Language.En,
|
||||
Text = bodyHtml
|
||||
});
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
var adapter = Substitute.For<ISourceAdapter>();
|
||||
var publishEndpoint = Substitute.For<IPublishEndpoint>();
|
||||
var service = CreateService(dbContext, adapter, publishEndpoint, pendingUrl);
|
||||
|
||||
var newUrl = "https://cdn.example.com/uploaded/image.jpg";
|
||||
|
||||
// Act
|
||||
await service.UpdateImage(image.Id, newUrl);
|
||||
|
||||
// Assert
|
||||
var updatedImage = await dbContext.Images
|
||||
.Include(i => i.Chapter)
|
||||
.ThenInclude(c => c.Body)
|
||||
.ThenInclude(b => b.Texts)
|
||||
.FirstAsync(i => i.Id == image.Id);
|
||||
|
||||
updatedImage.NewPath.Should().Be(newUrl);
|
||||
|
||||
var updatedBodyText = updatedImage.Chapter!.Body.Texts.Single().Text;
|
||||
var doc = new HtmlDocument();
|
||||
doc.LoadHtml(updatedBodyText);
|
||||
var imgNode = doc.DocumentNode.SelectSingleNode("//img");
|
||||
imgNode.Should().NotBeNull();
|
||||
imgNode!.GetAttributeValue("src", string.Empty).Should().Be(newUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateImage_does_not_modify_other_images_in_chapter_body()
|
||||
{
|
||||
// Arrange
|
||||
using var dbContext = CreateDbContext();
|
||||
var source = new Source { Name = "Demo", Key = "demo", Url = "http://demo" };
|
||||
var (_, _, chapter) = CreateNovelWithSingleChapter(dbContext, source);
|
||||
|
||||
var image1 = new Image { OriginalPath = "http://original/img1.jpg", Chapter = chapter };
|
||||
var image2 = new Image { OriginalPath = "http://original/img2.jpg", Chapter = chapter };
|
||||
chapter.Images.Add(image1);
|
||||
chapter.Images.Add(image2);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
var pendingUrl = "https://pending/placeholder.jpg";
|
||||
var bodyHtml = $"<p>Content</p><img src=\"{pendingUrl}\" alt=\"{image1.Id}\" /><img src=\"{pendingUrl}\" alt=\"{image2.Id}\" />";
|
||||
chapter.Body.Texts.Add(new LocalizationText
|
||||
{
|
||||
Language = Language.En,
|
||||
Text = bodyHtml
|
||||
});
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
var adapter = Substitute.For<ISourceAdapter>();
|
||||
var publishEndpoint = Substitute.For<IPublishEndpoint>();
|
||||
var service = CreateService(dbContext, adapter, publishEndpoint, pendingUrl);
|
||||
|
||||
var newUrl = "https://cdn.example.com/uploaded/img1.jpg";
|
||||
|
||||
// Act - only update image1
|
||||
await service.UpdateImage(image1.Id, newUrl);
|
||||
|
||||
// Assert
|
||||
var updatedChapter = await dbContext.Chapters
|
||||
.Include(c => c.Body)
|
||||
.ThenInclude(b => b.Texts)
|
||||
.FirstAsync(c => c.Id == chapter.Id);
|
||||
|
||||
var updatedBodyText = updatedChapter.Body.Texts.Single().Text;
|
||||
var doc = new HtmlDocument();
|
||||
doc.LoadHtml(updatedBodyText);
|
||||
|
||||
var img1Node = doc.DocumentNode.SelectSingleNode($"//img[@alt='{image1.Id}']");
|
||||
var img2Node = doc.DocumentNode.SelectSingleNode($"//img[@alt='{image2.Id}']");
|
||||
|
||||
img1Node!.GetAttributeValue("src", string.Empty).Should().Be(newUrl);
|
||||
img2Node!.GetAttributeValue("src", string.Empty).Should().Be(pendingUrl);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.NovelService.Sagas;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using FluentAssertions;
|
||||
using MassTransit;
|
||||
using MassTransit.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NodaTime;
|
||||
using NodaTime.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Tests.Sagas;
|
||||
|
||||
public class NovelImportSagaTests
|
||||
{
|
||||
private readonly FakeClock _clock = new(Instant.FromUtc(2026, 1, 27, 12, 0, 0));
|
||||
|
||||
[Fact]
|
||||
public async Task Should_transition_to_importing_on_import_requested()
|
||||
{
|
||||
await using var provider = CreateTestProvider();
|
||||
var harness = provider.GetRequiredService<ITestHarness>();
|
||||
await harness.Start();
|
||||
|
||||
var importId = Guid.NewGuid();
|
||||
await harness.Bus.Publish<INovelImportRequested>(new NovelImportRequested(importId, "https://example.com/novel"));
|
||||
|
||||
var sagaHarness = harness.GetSagaStateMachineHarness<NovelImportSaga, NovelImportSagaState>();
|
||||
(await sagaHarness.Exists(importId, x => x.Importing)).HasValue.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_transition_to_completed_when_no_chapters()
|
||||
{
|
||||
await using var provider = CreateTestProvider();
|
||||
var harness = provider.GetRequiredService<ITestHarness>();
|
||||
await harness.Start();
|
||||
|
||||
var importId = Guid.NewGuid();
|
||||
await harness.Bus.Publish<INovelImportRequested>(new NovelImportRequested(importId, "https://example.com/novel"));
|
||||
await harness.Bus.Publish<INovelMetadataImported>(new NovelMetadataImported(importId, 1, 0));
|
||||
|
||||
var sagaHarness = harness.GetSagaStateMachineHarness<NovelImportSaga, NovelImportSagaState>();
|
||||
(await sagaHarness.Exists(importId, x => x.Completed)).HasValue.Should().BeTrue();
|
||||
|
||||
(await harness.Published.Any<INovelImportCompleted>(x =>
|
||||
x.Context.Message.ImportId == importId && x.Context.Message.Success)).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_transition_to_processing_when_chapters_pending()
|
||||
{
|
||||
await using var provider = CreateTestProvider();
|
||||
var harness = provider.GetRequiredService<ITestHarness>();
|
||||
await harness.Start();
|
||||
|
||||
var importId = Guid.NewGuid();
|
||||
await harness.Bus.Publish<INovelImportRequested>(new NovelImportRequested(importId, "https://example.com/novel"));
|
||||
await harness.Bus.Publish<INovelMetadataImported>(new NovelMetadataImported(importId, 1, 2));
|
||||
|
||||
var sagaHarness = harness.GetSagaStateMachineHarness<NovelImportSaga, NovelImportSagaState>();
|
||||
(await sagaHarness.Exists(importId, x => x.Processing)).HasValue.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Should_complete_when_all_chapters_pulled_and_images_uploaded()
|
||||
{
|
||||
await using var provider = CreateTestProvider();
|
||||
var harness = provider.GetRequiredService<ITestHarness>();
|
||||
await harness.Start();
|
||||
|
||||
var importId = Guid.NewGuid();
|
||||
await harness.Bus.Publish<INovelImportRequested>(new NovelImportRequested(importId, "https://example.com/novel"));
|
||||
await harness.Bus.Publish<INovelMetadataImported>(new NovelMetadataImported(importId, 1, 2));
|
||||
await harness.Bus.Publish<IChapterPullCompleted>(new ChapterPullCompleted(importId, 1, 1));
|
||||
await harness.Bus.Publish<IChapterPullCompleted>(new ChapterPullCompleted(importId, 2, 0));
|
||||
await harness.Bus.Publish<IFileUploadRequestStatusUpdate>(new FileUploadRequestStatusUpdate(
|
||||
importId, Guid.NewGuid(), RequestStatus.Success, "https://cdn.example.com/image.jpg", null));
|
||||
|
||||
var sagaHarness = harness.GetSagaStateMachineHarness<NovelImportSaga, NovelImportSagaState>();
|
||||
(await sagaHarness.Exists(importId, x => x.Completed)).HasValue.Should().BeTrue();
|
||||
}
|
||||
|
||||
private ServiceProvider CreateTestProvider()
|
||||
{
|
||||
return new ServiceCollection()
|
||||
.AddSingleton<IClock>(_clock)
|
||||
.AddMassTransitTestHarness(cfg =>
|
||||
{
|
||||
cfg.AddSagaStateMachine<NovelImportSaga, NovelImportSagaState>()
|
||||
.InMemoryRepository();
|
||||
})
|
||||
.BuildServiceProvider(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Consumers;
|
||||
|
||||
public class ChapterPullRequestedConsumer : IConsumer<IChapterPullRequested>
|
||||
{
|
||||
private readonly ILogger<ChapterPullRequestedConsumer> _logger;
|
||||
private readonly NovelUpdateService _novelUpdateService;
|
||||
|
||||
public ChapterPullRequestedConsumer(
|
||||
ILogger<ChapterPullRequestedConsumer> logger,
|
||||
NovelUpdateService novelUpdateService)
|
||||
{
|
||||
_logger = logger;
|
||||
_novelUpdateService = novelUpdateService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<IChapterPullRequested> context)
|
||||
{
|
||||
var message = context.Message;
|
||||
|
||||
var (chapter, imageCount) = await _novelUpdateService.PullChapterContents(
|
||||
message.ImportId,
|
||||
message.NovelId,
|
||||
message.VolumeId,
|
||||
message.ChapterOrder);
|
||||
|
||||
await context.Publish<IChapterPullCompleted>(new ChapterPullCompleted(
|
||||
message.ImportId,
|
||||
chapter.Id,
|
||||
imageCount
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Consumers;
|
||||
|
||||
public class FileUploadRequestStatusUpdateConsumer : IConsumer<IFileUploadRequestStatusUpdate>
|
||||
{
|
||||
private readonly ILogger<FileUploadRequestStatusUpdateConsumer> _logger;
|
||||
private readonly NovelServiceDbContext _dbContext;
|
||||
private readonly NovelUpdateService _novelUpdateService;
|
||||
|
||||
public FileUploadRequestStatusUpdateConsumer(
|
||||
ILogger<FileUploadRequestStatusUpdateConsumer> logger,
|
||||
NovelServiceDbContext dbContext,
|
||||
NovelUpdateService novelUpdateService)
|
||||
{
|
||||
_logger = logger;
|
||||
_dbContext = dbContext;
|
||||
_novelUpdateService = novelUpdateService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<IFileUploadRequestStatusUpdate> context)
|
||||
{
|
||||
var message = context.Message;
|
||||
|
||||
var image = await _dbContext.Images.FindAsync(message.RequestId);
|
||||
if (image == null)
|
||||
{
|
||||
// Not a request we care about.
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.Status == RequestStatus.Failed)
|
||||
{
|
||||
_logger.LogError("Image upload failed for image with id {imageId}", image.Id);
|
||||
return;
|
||||
}
|
||||
else if (message.Status == RequestStatus.Success)
|
||||
{
|
||||
_logger.LogInformation("Image upload succeeded for image with id {imageId}", image.Id);
|
||||
await _novelUpdateService.UpdateImage(image.Id, message.FileAccessUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Consumers;
|
||||
|
||||
public class NovelImportCompletedConsumer : IConsumer<INovelImportCompleted>
|
||||
{
|
||||
private readonly ILogger<NovelImportCompletedConsumer> _logger;
|
||||
private readonly NovelServiceDbContext _dbContext;
|
||||
|
||||
public NovelImportCompletedConsumer(
|
||||
ILogger<NovelImportCompletedConsumer> logger,
|
||||
NovelServiceDbContext dbContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<INovelImportCompleted> context)
|
||||
{
|
||||
var message = context.Message;
|
||||
|
||||
_logger.LogInformation(
|
||||
"Novel import {ImportId} completed. Success: {Success}, NovelId: {NovelId}, Error: {Error}",
|
||||
message.ImportId,
|
||||
message.Success,
|
||||
message.NovelId,
|
||||
message.ErrorMessage);
|
||||
|
||||
// Remove from ActiveImports to allow future imports
|
||||
var activeImport = await _dbContext.ActiveImports
|
||||
.FirstOrDefaultAsync(a => a.ImportId == message.ImportId);
|
||||
|
||||
if (activeImport != null)
|
||||
{
|
||||
_dbContext.ActiveImports.Remove(activeImport);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using MassTransit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Consumers;
|
||||
|
||||
public class NovelImportRequestedConsumer : IConsumer<INovelImportRequested>
|
||||
{
|
||||
private readonly ILogger<NovelImportRequestedConsumer> _logger;
|
||||
private readonly NovelUpdateService _novelUpdateService;
|
||||
|
||||
public NovelImportRequestedConsumer(
|
||||
ILogger<NovelImportRequestedConsumer> logger,
|
||||
NovelUpdateService novelUpdateService)
|
||||
{
|
||||
_logger = logger;
|
||||
_novelUpdateService = novelUpdateService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<INovelImportRequested> context)
|
||||
{
|
||||
var message = context.Message;
|
||||
_logger.LogInformation("Starting novel import for {NovelUrl} with ImportId {ImportId}",
|
||||
message.NovelUrl, message.ImportId);
|
||||
|
||||
await _novelUpdateService.ImportNovel(message.ImportId, message.NovelUrl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using FictionArchive.Service.NovelService.Models.Localization;
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Consumers;
|
||||
|
||||
public class TranslationRequestCompletedConsumer : IConsumer<ITranslationRequestCompleted>
|
||||
{
|
||||
private readonly ILogger<TranslationRequestCompletedConsumer> _logger;
|
||||
private readonly NovelServiceDbContext _dbContext;
|
||||
|
||||
public TranslationRequestCompletedConsumer(
|
||||
ILogger<TranslationRequestCompletedConsumer> logger,
|
||||
NovelServiceDbContext dbContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<ITranslationRequestCompleted> context)
|
||||
{
|
||||
var message = context.Message;
|
||||
|
||||
var localizationRequest = await _dbContext.LocalizationRequests
|
||||
.Include(r => r.KeyRequestedForTranslation)
|
||||
.ThenInclude(lk => lk.Texts)
|
||||
.FirstOrDefaultAsync(lk => lk.Id == message.TranslationRequestId);
|
||||
|
||||
if (localizationRequest == null)
|
||||
{
|
||||
// Not one of our requests, discard it
|
||||
return;
|
||||
}
|
||||
|
||||
localizationRequest.KeyRequestedForTranslation.Texts.Add(new LocalizationText
|
||||
{
|
||||
Language = localizationRequest.TranslateTo,
|
||||
Text = message.TranslatedText,
|
||||
TranslationEngine = localizationRequest.Engine
|
||||
});
|
||||
|
||||
_dbContext.LocalizationRequests.Remove(localizationRequest);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Contracts;
|
||||
|
||||
public record ChapterCreated(
|
||||
uint ChapterId,
|
||||
uint NovelId,
|
||||
uint VolumeId,
|
||||
uint VolumeOrder,
|
||||
uint ChapterOrder,
|
||||
string ChapterTitle) : IChapterCreated;
|
||||
@@ -0,0 +1,11 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Contracts;
|
||||
|
||||
public record NovelCreated(
|
||||
uint NovelId,
|
||||
string Title,
|
||||
Language OriginalLanguage,
|
||||
string Source,
|
||||
string AuthorName) : INovelCreated;
|
||||
@@ -0,0 +1,11 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Contracts;
|
||||
|
||||
public record TranslationRequestCreated(
|
||||
Guid TranslationRequestId,
|
||||
Language From,
|
||||
Language To,
|
||||
string Body,
|
||||
string TranslationEngineKey) : ITranslationRequestCreated;
|
||||
@@ -10,11 +10,12 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HotChocolate.AspNetCore.CommandLine" Version="15.1.11" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.12.4" />
|
||||
<PackageReference Include="MassTransit.EntityFrameworkCore" Version="8.5.7" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.11">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,37 +1,42 @@
|
||||
using FictionArchive.Service.NovelService.Contracts;
|
||||
using FictionArchive.Service.NovelService.Models.Enums;
|
||||
using FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||
using FictionArchive.Service.NovelService.Models.Localization;
|
||||
using FictionArchive.Service.NovelService.Models.Novels;
|
||||
using FictionArchive.Service.NovelService.Models.SourceAdapters;
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using HotChocolate.Authorization;
|
||||
using HotChocolate.Types;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.GraphQL;
|
||||
|
||||
public class Mutation
|
||||
{
|
||||
public async Task<NovelUpdateRequestedEvent> ImportNovel(string novelUrl, IEventBus eventBus)
|
||||
[Error<InvalidOperationException>]
|
||||
[Authorize]
|
||||
public async Task<NovelImportRequested> ImportNovel(string novelUrl, NovelUpdateService service)
|
||||
{
|
||||
var importNovelRequestEvent = new NovelUpdateRequestedEvent()
|
||||
{
|
||||
NovelUrl = novelUrl
|
||||
};
|
||||
await eventBus.Publish(importNovelRequestEvent);
|
||||
return importNovelRequestEvent;
|
||||
return await service.QueueNovelImport(novelUrl);
|
||||
}
|
||||
|
||||
public async Task<ChapterPullRequestedEvent> FetchChapterContents(uint novelId,
|
||||
uint chapterNumber,
|
||||
IEventBus eventBus)
|
||||
[Authorize]
|
||||
public async Task<ChapterPullRequested> FetchChapterContents(
|
||||
Guid importId,
|
||||
uint novelId,
|
||||
uint volumeId,
|
||||
uint chapterOrder,
|
||||
NovelUpdateService service)
|
||||
{
|
||||
var chapterPullEvent = new ChapterPullRequestedEvent()
|
||||
return await service.QueueChapterPull(importId, novelId, volumeId, chapterOrder);
|
||||
}
|
||||
|
||||
[Error<KeyNotFoundException>]
|
||||
[Authorize]
|
||||
public async Task<bool> DeleteNovel(uint novelId, NovelUpdateService service)
|
||||
{
|
||||
NovelId = novelId,
|
||||
ChapterNumber = chapterNumber
|
||||
};
|
||||
await eventBus.Publish(chapterPullEvent);
|
||||
return chapterPullEvent;
|
||||
await service.DeleteNovel(novelId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using FictionArchive.Service.NovelService.Models.Novels;
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.NovelService.Models.DTOs;
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using HotChocolate.Authorization;
|
||||
using HotChocolate.Data;
|
||||
using HotChocolate.Types;
|
||||
|
||||
@@ -7,12 +9,255 @@ namespace FictionArchive.Service.NovelService.GraphQL;
|
||||
|
||||
public class Query
|
||||
{
|
||||
[Authorize]
|
||||
[UsePaging]
|
||||
[UseProjection]
|
||||
[UseFiltering]
|
||||
[UseSorting]
|
||||
public IQueryable<Novel> GetNovels(NovelServiceDbContext dbContext)
|
||||
public IQueryable<NovelDto> GetNovels(
|
||||
NovelServiceDbContext dbContext,
|
||||
Language preferredLanguage = Language.En)
|
||||
{
|
||||
return dbContext.Novels.AsQueryable();
|
||||
return dbContext.Novels.Select(novel => new NovelDto
|
||||
{
|
||||
Id = novel.Id,
|
||||
CreatedTime = novel.CreatedTime,
|
||||
LastUpdatedTime = novel.LastUpdatedTime,
|
||||
Url = novel.Url,
|
||||
RawLanguage = novel.RawLanguage,
|
||||
RawStatus = novel.RawStatus,
|
||||
StatusOverride = novel.StatusOverride,
|
||||
ExternalId = novel.ExternalId,
|
||||
|
||||
Name = novel.Name.Texts
|
||||
.Where(t => t.Language == preferredLanguage)
|
||||
.Select(t => t.Text)
|
||||
.FirstOrDefault()
|
||||
?? novel.Name.Texts.Select(t => t.Text).FirstOrDefault()
|
||||
?? "",
|
||||
|
||||
Description = novel.Description.Texts
|
||||
.Where(t => t.Language == preferredLanguage)
|
||||
.Select(t => t.Text)
|
||||
.FirstOrDefault()
|
||||
?? novel.Description.Texts.Select(t => t.Text).FirstOrDefault()
|
||||
?? "",
|
||||
|
||||
Author = new PersonDto
|
||||
{
|
||||
Id = novel.Author.Id,
|
||||
CreatedTime = novel.Author.CreatedTime,
|
||||
LastUpdatedTime = novel.Author.LastUpdatedTime,
|
||||
Name = novel.Author.Name.Texts
|
||||
.Where(t => t.Language == preferredLanguage)
|
||||
.Select(t => t.Text)
|
||||
.FirstOrDefault()
|
||||
?? novel.Author.Name.Texts.Select(t => t.Text).FirstOrDefault()
|
||||
?? "",
|
||||
ExternalUrl = novel.Author.ExternalUrl
|
||||
},
|
||||
|
||||
Source = new SourceDto
|
||||
{
|
||||
Id = novel.Source.Id,
|
||||
CreatedTime = novel.Source.CreatedTime,
|
||||
LastUpdatedTime = novel.Source.LastUpdatedTime,
|
||||
Name = novel.Source.Name,
|
||||
Key = novel.Source.Key,
|
||||
Url = novel.Source.Url
|
||||
},
|
||||
|
||||
CoverImage = novel.CoverImage != null
|
||||
? new ImageDto
|
||||
{
|
||||
Id = novel.CoverImage.Id,
|
||||
CreatedTime = novel.CoverImage.CreatedTime,
|
||||
LastUpdatedTime = novel.CoverImage.LastUpdatedTime,
|
||||
NewPath = novel.CoverImage.NewPath
|
||||
}
|
||||
: null,
|
||||
|
||||
Volumes = novel.Volumes.OrderBy(v => v.Order).Select(volume => new VolumeDto
|
||||
{
|
||||
Id = volume.Id,
|
||||
CreatedTime = volume.CreatedTime,
|
||||
LastUpdatedTime = volume.LastUpdatedTime,
|
||||
Order = volume.Order,
|
||||
Name = volume.Name.Texts
|
||||
.Where(t => t.Language == preferredLanguage)
|
||||
.Select(t => t.Text)
|
||||
.FirstOrDefault()
|
||||
?? volume.Name.Texts.Select(t => t.Text).FirstOrDefault()
|
||||
?? "",
|
||||
Chapters = volume.Chapters.OrderBy(c => c.Order).Select(chapter => new ChapterDto
|
||||
{
|
||||
Id = chapter.Id,
|
||||
CreatedTime = chapter.CreatedTime,
|
||||
LastUpdatedTime = chapter.LastUpdatedTime,
|
||||
Revision = chapter.Revision,
|
||||
Order = chapter.Order,
|
||||
Url = chapter.Url,
|
||||
Name = chapter.Name.Texts
|
||||
.Where(t => t.Language == preferredLanguage)
|
||||
.Select(t => t.Text)
|
||||
.FirstOrDefault()
|
||||
?? chapter.Name.Texts.Select(t => t.Text).FirstOrDefault()
|
||||
?? "",
|
||||
Body = chapter.Body.Texts
|
||||
.Where(t => t.Language == preferredLanguage)
|
||||
.Select(t => t.Text)
|
||||
.FirstOrDefault()
|
||||
?? chapter.Body.Texts.Select(t => t.Text).FirstOrDefault()
|
||||
?? "",
|
||||
Images = chapter.Images.Select(image => new ImageDto
|
||||
{
|
||||
Id = image.Id,
|
||||
CreatedTime = image.CreatedTime,
|
||||
LastUpdatedTime = image.LastUpdatedTime,
|
||||
NewPath = image.NewPath
|
||||
}).ToList()
|
||||
}).ToList()
|
||||
}).ToList(),
|
||||
|
||||
Tags = novel.Tags.Select(tag => new NovelTagDto
|
||||
{
|
||||
Id = tag.Id,
|
||||
CreatedTime = tag.CreatedTime,
|
||||
LastUpdatedTime = tag.LastUpdatedTime,
|
||||
Key = tag.Key,
|
||||
TagType = tag.TagType,
|
||||
DisplayName = tag.DisplayName.Texts
|
||||
.Where(t => t.Language == preferredLanguage)
|
||||
.Select(t => t.Text)
|
||||
.FirstOrDefault()
|
||||
?? tag.DisplayName.Texts.Select(t => t.Text).FirstOrDefault()
|
||||
?? "",
|
||||
Source = tag.Source != null
|
||||
? new SourceDto
|
||||
{
|
||||
Id = tag.Source.Id,
|
||||
CreatedTime = tag.Source.CreatedTime,
|
||||
LastUpdatedTime = tag.Source.LastUpdatedTime,
|
||||
Name = tag.Source.Name,
|
||||
Key = tag.Source.Key,
|
||||
Url = tag.Source.Url
|
||||
}
|
||||
: null
|
||||
}).ToList()
|
||||
});
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[UseFirstOrDefault]
|
||||
[UseProjection]
|
||||
public IQueryable<ChapterReaderDto> GetChapter(
|
||||
NovelServiceDbContext dbContext,
|
||||
uint novelId,
|
||||
uint volumeOrder,
|
||||
uint chapterOrder,
|
||||
Language preferredLanguage = Language.En)
|
||||
{
|
||||
return dbContext.Chapters
|
||||
.Where(c => c.Volume.Novel.Id == novelId && c.Volume.Order == volumeOrder && c.Order == chapterOrder)
|
||||
.Select(chapter => new ChapterReaderDto
|
||||
{
|
||||
Id = chapter.Id,
|
||||
CreatedTime = chapter.CreatedTime,
|
||||
LastUpdatedTime = chapter.LastUpdatedTime,
|
||||
Revision = chapter.Revision,
|
||||
Order = chapter.Order,
|
||||
Url = chapter.Url,
|
||||
|
||||
Name = chapter.Name.Texts
|
||||
.Where(t => t.Language == preferredLanguage)
|
||||
.Select(t => t.Text)
|
||||
.FirstOrDefault()
|
||||
?? chapter.Name.Texts.Select(t => t.Text).FirstOrDefault()
|
||||
?? "",
|
||||
|
||||
Body = chapter.Body.Texts
|
||||
.Where(t => t.Language == preferredLanguage)
|
||||
.Select(t => t.Text)
|
||||
.FirstOrDefault()
|
||||
?? chapter.Body.Texts.Select(t => t.Text).FirstOrDefault()
|
||||
?? "",
|
||||
|
||||
Images = chapter.Images.Select(image => new ImageDto
|
||||
{
|
||||
Id = image.Id,
|
||||
CreatedTime = image.CreatedTime,
|
||||
LastUpdatedTime = image.LastUpdatedTime,
|
||||
NewPath = image.NewPath
|
||||
}).ToList(),
|
||||
|
||||
NovelId = chapter.Volume.Novel.Id,
|
||||
NovelName = chapter.Volume.Novel.Name.Texts
|
||||
.Where(t => t.Language == preferredLanguage)
|
||||
.Select(t => t.Text)
|
||||
.FirstOrDefault()
|
||||
?? chapter.Volume.Novel.Name.Texts.Select(t => t.Text).FirstOrDefault()
|
||||
?? "",
|
||||
|
||||
// Volume context
|
||||
VolumeId = chapter.Volume.Id,
|
||||
VolumeName = chapter.Volume.Name.Texts
|
||||
.Where(t => t.Language == preferredLanguage)
|
||||
.Select(t => t.Text)
|
||||
.FirstOrDefault()
|
||||
?? chapter.Volume.Name.Texts.Select(t => t.Text).FirstOrDefault()
|
||||
?? "",
|
||||
VolumeOrder = chapter.Volume.Order,
|
||||
TotalChaptersInVolume = chapter.Volume.Chapters.Count,
|
||||
|
||||
// Previous chapter: first try same volume, then last chapter of previous volume
|
||||
PrevChapterVolumeOrder = chapter.Volume.Chapters
|
||||
.Where(c => c.Order < chapterOrder)
|
||||
.OrderByDescending(c => c.Order)
|
||||
.Select(c => (int?)chapter.Volume.Order)
|
||||
.FirstOrDefault()
|
||||
?? chapter.Volume.Novel.Volumes
|
||||
.Where(v => v.Order < chapter.Volume.Order)
|
||||
.OrderByDescending(v => v.Order)
|
||||
.SelectMany(v => v.Chapters.OrderByDescending(c => c.Order).Take(1))
|
||||
.Select(c => (int?)c.Volume.Order)
|
||||
.FirstOrDefault(),
|
||||
|
||||
PrevChapterOrder = chapter.Volume.Chapters
|
||||
.Where(c => c.Order < chapterOrder)
|
||||
.OrderByDescending(c => c.Order)
|
||||
.Select(c => (uint?)c.Order)
|
||||
.FirstOrDefault()
|
||||
?? chapter.Volume.Novel.Volumes
|
||||
.Where(v => v.Order < chapter.Volume.Order)
|
||||
.OrderByDescending(v => v.Order)
|
||||
.SelectMany(v => v.Chapters.OrderByDescending(c => c.Order).Take(1))
|
||||
.Select(c => (uint?)c.Order)
|
||||
.FirstOrDefault(),
|
||||
|
||||
// Next chapter: first try same volume, then first chapter of next volume
|
||||
NextChapterVolumeOrder = chapter.Volume.Chapters
|
||||
.Where(c => c.Order > chapterOrder)
|
||||
.OrderBy(c => c.Order)
|
||||
.Select(c => (int?)chapter.Volume.Order)
|
||||
.FirstOrDefault()
|
||||
?? chapter.Volume.Novel.Volumes
|
||||
.Where(v => v.Order > chapter.Volume.Order)
|
||||
.OrderBy(v => v.Order)
|
||||
.SelectMany(v => v.Chapters.OrderBy(c => c.Order).Take(1))
|
||||
.Select(c => (int?)c.Volume.Order)
|
||||
.FirstOrDefault(),
|
||||
|
||||
NextChapterOrder = chapter.Volume.Chapters
|
||||
.Where(c => c.Order > chapterOrder)
|
||||
.OrderBy(c => c.Order)
|
||||
.Select(c => (uint?)c.Order)
|
||||
.FirstOrDefault()
|
||||
?? chapter.Volume.Novel.Volumes
|
||||
.Where(v => v.Order > chapter.Volume.Order)
|
||||
.OrderBy(v => v.Order)
|
||||
.SelectMany(v => v.Chapters.OrderBy(c => c.Order).Take(1))
|
||||
.Select(c => (uint?)c.Order)
|
||||
.FirstOrDefault()
|
||||
});
|
||||
}
|
||||
}
|
||||
547
FictionArchive.Service.NovelService/Migrations/20251208230154_FA-misc_NovelConstraint.Designer.cs
generated
Normal file
547
FictionArchive.Service.NovelService/Migrations/20251208230154_FA-misc_NovelConstraint.Designer.cs
generated
Normal file
@@ -0,0 +1,547 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using NodaTime;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Migrations
|
||||
{
|
||||
[DbContext(typeof(NovelServiceDbContext))]
|
||||
[Migration("20251208230154_FA-misc_NovelConstraint")]
|
||||
partial class FAmisc_NovelConstraint
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.11")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Images.Image", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<long?>("ChapterId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("NewPath")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("OriginalPath")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ChapterId");
|
||||
|
||||
b.ToTable("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("LocalizationKeys");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationRequest", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<long>("EngineId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<Guid>("KeyRequestedForTranslationId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("TranslateTo")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EngineId");
|
||||
|
||||
b.HasIndex("KeyRequestedForTranslationId");
|
||||
|
||||
b.ToTable("LocalizationRequests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationText", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("Language")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid?>("LocalizationKeyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<long?>("TranslationEngineId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("LocalizationKeyId");
|
||||
|
||||
b.HasIndex("TranslationEngineId");
|
||||
|
||||
b.ToTable("LocalizationText");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Guid>("BodyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<long>("NovelId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<long>("Order")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<long>("Revision")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BodyId");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.HasIndex("NovelId");
|
||||
|
||||
b.ToTable("Chapter");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<long>("AuthorId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<Guid?>("CoverImageId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("DescriptionId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("ExternalId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("RawLanguage")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RawStatus")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<long>("SourceId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int?>("StatusOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AuthorId");
|
||||
|
||||
b.HasIndex("CoverImageId");
|
||||
|
||||
b.HasIndex("DescriptionId");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.HasIndex("SourceId");
|
||||
|
||||
b.HasIndex("ExternalId", "SourceId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.NovelTag", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("DisplayNameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<long?>("SourceId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int>("TagType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DisplayNameId");
|
||||
|
||||
b.HasIndex("SourceId");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Person", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ExternalUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.ToTable("Person");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Source", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Sources");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("TranslationEngines");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelNovelTag", b =>
|
||||
{
|
||||
b.Property<long>("NovelsId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<long>("TagsId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("NovelsId", "TagsId");
|
||||
|
||||
b.HasIndex("TagsId");
|
||||
|
||||
b.ToTable("NovelNovelTag");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Images.Image", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Chapter", "Chapter")
|
||||
.WithMany("Images")
|
||||
.HasForeignKey("ChapterId");
|
||||
|
||||
b.Navigation("Chapter");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationRequest", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", "Engine")
|
||||
.WithMany()
|
||||
.HasForeignKey("EngineId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "KeyRequestedForTranslation")
|
||||
.WithMany()
|
||||
.HasForeignKey("KeyRequestedForTranslationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Engine");
|
||||
|
||||
b.Navigation("KeyRequestedForTranslation");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationText", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", null)
|
||||
.WithMany("Texts")
|
||||
.HasForeignKey("LocalizationKeyId");
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", "TranslationEngine")
|
||||
.WithMany()
|
||||
.HasForeignKey("TranslationEngineId");
|
||||
|
||||
b.Navigation("TranslationEngine");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Body")
|
||||
.WithMany()
|
||||
.HasForeignKey("BodyId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||
.WithMany()
|
||||
.HasForeignKey("NameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", "Novel")
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("NovelId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Body");
|
||||
|
||||
b.Navigation("Name");
|
||||
|
||||
b.Navigation("Novel");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Person", "Author")
|
||||
.WithMany()
|
||||
.HasForeignKey("AuthorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Images.Image", "CoverImage")
|
||||
.WithMany()
|
||||
.HasForeignKey("CoverImageId");
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Description")
|
||||
.WithMany()
|
||||
.HasForeignKey("DescriptionId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||
.WithMany()
|
||||
.HasForeignKey("NameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Source", "Source")
|
||||
.WithMany()
|
||||
.HasForeignKey("SourceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Author");
|
||||
|
||||
b.Navigation("CoverImage");
|
||||
|
||||
b.Navigation("Description");
|
||||
|
||||
b.Navigation("Name");
|
||||
|
||||
b.Navigation("Source");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.NovelTag", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "DisplayName")
|
||||
.WithMany()
|
||||
.HasForeignKey("DisplayNameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Source", "Source")
|
||||
.WithMany()
|
||||
.HasForeignKey("SourceId");
|
||||
|
||||
b.Navigation("DisplayName");
|
||||
|
||||
b.Navigation("Source");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Person", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||
.WithMany()
|
||||
.HasForeignKey("NameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Name");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelNovelTag", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.NovelTag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", b =>
|
||||
{
|
||||
b.Navigation("Texts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||
{
|
||||
b.Navigation("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FAmisc_NovelConstraint : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Chapter_Novels_NovelId",
|
||||
table: "Chapter");
|
||||
|
||||
migrationBuilder.AlterColumn<long>(
|
||||
name: "NovelId",
|
||||
table: "Chapter",
|
||||
type: "bigint",
|
||||
nullable: false,
|
||||
defaultValue: 0L,
|
||||
oldClrType: typeof(long),
|
||||
oldType: "bigint",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Novels_ExternalId_SourceId",
|
||||
table: "Novels",
|
||||
columns: new[] { "ExternalId", "SourceId" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Chapter_Novels_NovelId",
|
||||
table: "Chapter",
|
||||
column: "NovelId",
|
||||
principalTable: "Novels",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Chapter_Novels_NovelId",
|
||||
table: "Chapter");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Novels_ExternalId_SourceId",
|
||||
table: "Novels");
|
||||
|
||||
migrationBuilder.AlterColumn<long>(
|
||||
name: "NovelId",
|
||||
table: "Chapter",
|
||||
type: "bigint",
|
||||
nullable: true,
|
||||
oldClrType: typeof(long),
|
||||
oldType: "bigint");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Chapter_Novels_NovelId",
|
||||
table: "Chapter",
|
||||
column: "NovelId",
|
||||
principalTable: "Novels",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
}
|
||||
}
|
||||
605
FictionArchive.Service.NovelService/Migrations/20251229203027_AddVolumes.Designer.cs
generated
Normal file
605
FictionArchive.Service.NovelService/Migrations/20251229203027_AddVolumes.Designer.cs
generated
Normal file
@@ -0,0 +1,605 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using NodaTime;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Migrations
|
||||
{
|
||||
[DbContext(typeof(NovelServiceDbContext))]
|
||||
[Migration("20251229203027_AddVolumes")]
|
||||
partial class AddVolumes
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.11")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Images.Image", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<long?>("ChapterId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("NewPath")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("OriginalPath")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ChapterId");
|
||||
|
||||
b.ToTable("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("LocalizationKeys");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationRequest", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<long>("EngineId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<Guid>("KeyRequestedForTranslationId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("TranslateTo")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EngineId");
|
||||
|
||||
b.HasIndex("KeyRequestedForTranslationId");
|
||||
|
||||
b.ToTable("LocalizationRequests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationText", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("Language")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid?>("LocalizationKeyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<long?>("TranslationEngineId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("LocalizationKeyId");
|
||||
|
||||
b.HasIndex("TranslationEngineId");
|
||||
|
||||
b.ToTable("LocalizationText");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Guid>("BodyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<long>("Order")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<long>("Revision")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<long>("VolumeId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BodyId");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.HasIndex("VolumeId", "Order")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Chapter");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<long>("AuthorId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<Guid?>("CoverImageId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("DescriptionId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("ExternalId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("RawLanguage")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RawStatus")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<long>("SourceId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int?>("StatusOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AuthorId");
|
||||
|
||||
b.HasIndex("CoverImageId");
|
||||
|
||||
b.HasIndex("DescriptionId");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.HasIndex("SourceId");
|
||||
|
||||
b.HasIndex("ExternalId", "SourceId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.NovelTag", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("DisplayNameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<long?>("SourceId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int>("TagType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DisplayNameId");
|
||||
|
||||
b.HasIndex("SourceId");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Person", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ExternalUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.ToTable("Person");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Source", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Sources");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("TranslationEngines");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Volume", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<long>("NovelId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int>("Order")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.HasIndex("NovelId", "Order")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Volume");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelNovelTag", b =>
|
||||
{
|
||||
b.Property<long>("NovelsId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<long>("TagsId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("NovelsId", "TagsId");
|
||||
|
||||
b.HasIndex("TagsId");
|
||||
|
||||
b.ToTable("NovelNovelTag");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Images.Image", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Chapter", "Chapter")
|
||||
.WithMany("Images")
|
||||
.HasForeignKey("ChapterId");
|
||||
|
||||
b.Navigation("Chapter");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationRequest", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", "Engine")
|
||||
.WithMany()
|
||||
.HasForeignKey("EngineId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "KeyRequestedForTranslation")
|
||||
.WithMany()
|
||||
.HasForeignKey("KeyRequestedForTranslationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Engine");
|
||||
|
||||
b.Navigation("KeyRequestedForTranslation");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationText", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", null)
|
||||
.WithMany("Texts")
|
||||
.HasForeignKey("LocalizationKeyId");
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", "TranslationEngine")
|
||||
.WithMany()
|
||||
.HasForeignKey("TranslationEngineId");
|
||||
|
||||
b.Navigation("TranslationEngine");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Body")
|
||||
.WithMany()
|
||||
.HasForeignKey("BodyId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||
.WithMany()
|
||||
.HasForeignKey("NameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Volume", "Volume")
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("VolumeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Body");
|
||||
|
||||
b.Navigation("Name");
|
||||
|
||||
b.Navigation("Volume");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Person", "Author")
|
||||
.WithMany()
|
||||
.HasForeignKey("AuthorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Images.Image", "CoverImage")
|
||||
.WithMany()
|
||||
.HasForeignKey("CoverImageId");
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Description")
|
||||
.WithMany()
|
||||
.HasForeignKey("DescriptionId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||
.WithMany()
|
||||
.HasForeignKey("NameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Source", "Source")
|
||||
.WithMany()
|
||||
.HasForeignKey("SourceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Author");
|
||||
|
||||
b.Navigation("CoverImage");
|
||||
|
||||
b.Navigation("Description");
|
||||
|
||||
b.Navigation("Name");
|
||||
|
||||
b.Navigation("Source");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.NovelTag", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "DisplayName")
|
||||
.WithMany()
|
||||
.HasForeignKey("DisplayNameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Source", "Source")
|
||||
.WithMany()
|
||||
.HasForeignKey("SourceId");
|
||||
|
||||
b.Navigation("DisplayName");
|
||||
|
||||
b.Navigation("Source");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Person", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||
.WithMany()
|
||||
.HasForeignKey("NameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Name");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Volume", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||
.WithMany()
|
||||
.HasForeignKey("NameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", "Novel")
|
||||
.WithMany("Volumes")
|
||||
.HasForeignKey("NovelId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Name");
|
||||
|
||||
b.Navigation("Novel");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelNovelTag", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.NovelTag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", b =>
|
||||
{
|
||||
b.Navigation("Texts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||
{
|
||||
b.Navigation("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||
{
|
||||
b.Navigation("Volumes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Volume", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using NodaTime;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddVolumes : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// 1. Create the Volume table
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Volume",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Order = table.Column<int>(type: "integer", nullable: false),
|
||||
NameId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
NovelId = table.Column<long>(type: "bigint", nullable: false),
|
||||
CreatedTime = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
|
||||
LastUpdatedTime = table.Column<Instant>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Volume", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Volume_LocalizationKeys_NameId",
|
||||
column: x => x.NameId,
|
||||
principalTable: "LocalizationKeys",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Volume_Novels_NovelId",
|
||||
column: x => x.NovelId,
|
||||
principalTable: "Novels",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Volume_NameId",
|
||||
table: "Volume",
|
||||
column: "NameId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Volume_NovelId_Order",
|
||||
table: "Volume",
|
||||
columns: new[] { "NovelId", "Order" },
|
||||
unique: true);
|
||||
|
||||
// 2. Add nullable VolumeId column to Chapter (keep NovelId for now)
|
||||
migrationBuilder.AddColumn<long>(
|
||||
name: "VolumeId",
|
||||
table: "Chapter",
|
||||
type: "bigint",
|
||||
nullable: true);
|
||||
|
||||
// 3. Data migration: Create volumes and link chapters for each novel
|
||||
migrationBuilder.Sql(@"
|
||||
DO $$
|
||||
DECLARE
|
||||
novel_rec RECORD;
|
||||
loc_key_id uuid;
|
||||
volume_id bigint;
|
||||
BEGIN
|
||||
FOR novel_rec IN SELECT ""Id"", ""RawLanguage"" FROM ""Novels"" LOOP
|
||||
-- Create LocalizationKey for volume name
|
||||
loc_key_id := gen_random_uuid();
|
||||
INSERT INTO ""LocalizationKeys"" (""Id"", ""CreatedTime"", ""LastUpdatedTime"")
|
||||
VALUES (loc_key_id, NOW(), NOW());
|
||||
|
||||
-- Create LocalizationText for 'Main Story' in novel's raw language
|
||||
INSERT INTO ""LocalizationText"" (""Id"", ""LocalizationKeyId"", ""Language"", ""Text"", ""CreatedTime"", ""LastUpdatedTime"")
|
||||
VALUES (gen_random_uuid(), loc_key_id, novel_rec.""RawLanguage"", 'Main Story', NOW(), NOW());
|
||||
|
||||
-- Create Volume for this novel
|
||||
INSERT INTO ""Volume"" (""Order"", ""NameId"", ""NovelId"", ""CreatedTime"", ""LastUpdatedTime"")
|
||||
VALUES (1, loc_key_id, novel_rec.""Id"", NOW(), NOW())
|
||||
RETURNING ""Id"" INTO volume_id;
|
||||
|
||||
-- Link all chapters of this novel to the new volume
|
||||
UPDATE ""Chapter"" SET ""VolumeId"" = volume_id WHERE ""NovelId"" = novel_rec.""Id"";
|
||||
END LOOP;
|
||||
END $$;
|
||||
");
|
||||
|
||||
// 4. Drop old FK and index for NovelId
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Chapter_Novels_NovelId",
|
||||
table: "Chapter");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Chapter_NovelId",
|
||||
table: "Chapter");
|
||||
|
||||
// 5. Drop NovelId column from Chapter
|
||||
migrationBuilder.DropColumn(
|
||||
name: "NovelId",
|
||||
table: "Chapter");
|
||||
|
||||
// 6. Make VolumeId non-nullable
|
||||
migrationBuilder.AlterColumn<long>(
|
||||
name: "VolumeId",
|
||||
table: "Chapter",
|
||||
type: "bigint",
|
||||
nullable: false,
|
||||
oldClrType: typeof(long),
|
||||
oldType: "bigint",
|
||||
oldNullable: true);
|
||||
|
||||
// 7. Add unique index and FK for VolumeId
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Chapter_VolumeId_Order",
|
||||
table: "Chapter",
|
||||
columns: new[] { "VolumeId", "Order" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Chapter_Volume_VolumeId",
|
||||
table: "Chapter",
|
||||
column: "VolumeId",
|
||||
principalTable: "Volume",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Add back NovelId column
|
||||
migrationBuilder.AddColumn<long>(
|
||||
name: "NovelId",
|
||||
table: "Chapter",
|
||||
type: "bigint",
|
||||
nullable: true);
|
||||
|
||||
// Migrate data back: set NovelId from Volume
|
||||
migrationBuilder.Sql(@"
|
||||
UPDATE ""Chapter"" c
|
||||
SET ""NovelId"" = v.""NovelId""
|
||||
FROM ""Volume"" v
|
||||
WHERE c.""VolumeId"" = v.""Id"";
|
||||
");
|
||||
|
||||
// Make NovelId non-nullable
|
||||
migrationBuilder.AlterColumn<long>(
|
||||
name: "NovelId",
|
||||
table: "Chapter",
|
||||
type: "bigint",
|
||||
nullable: false,
|
||||
oldClrType: typeof(long),
|
||||
oldType: "bigint",
|
||||
oldNullable: true);
|
||||
|
||||
// Drop VolumeId FK and index
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Chapter_Volume_VolumeId",
|
||||
table: "Chapter");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Chapter_VolumeId_Order",
|
||||
table: "Chapter");
|
||||
|
||||
// Drop VolumeId column
|
||||
migrationBuilder.DropColumn(
|
||||
name: "VolumeId",
|
||||
table: "Chapter");
|
||||
|
||||
// Recreate NovelId index and FK
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Chapter_NovelId",
|
||||
table: "Chapter",
|
||||
column: "NovelId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Chapter_Novels_NovelId",
|
||||
table: "Chapter",
|
||||
column: "NovelId",
|
||||
principalTable: "Novels",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
// Note: Volume LocalizationKeys are not cleaned up in Down migration
|
||||
// as they may have been modified. Manual cleanup may be needed.
|
||||
migrationBuilder.DropTable(
|
||||
name: "Volume");
|
||||
}
|
||||
}
|
||||
}
|
||||
673
FictionArchive.Service.NovelService/Migrations/20260127161500_AddNovelImportSaga.Designer.cs
generated
Normal file
673
FictionArchive.Service.NovelService/Migrations/20260127161500_AddNovelImportSaga.Designer.cs
generated
Normal file
@@ -0,0 +1,673 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using NodaTime;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Migrations
|
||||
{
|
||||
[DbContext(typeof(NovelServiceDbContext))]
|
||||
[Migration("20260127161500_AddNovelImportSaga")]
|
||||
partial class AddNovelImportSaga
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.11")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.ActiveImport", b =>
|
||||
{
|
||||
b.Property<Guid>("ImportId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("StartedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("ImportId");
|
||||
|
||||
b.HasIndex("NovelUrl")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("ActiveImports");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Images.Image", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<long?>("ChapterId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("NewPath")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("OriginalPath")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ChapterId");
|
||||
|
||||
b.ToTable("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("LocalizationKeys");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationRequest", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<long>("EngineId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<Guid>("KeyRequestedForTranslationId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("TranslateTo")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EngineId");
|
||||
|
||||
b.HasIndex("KeyRequestedForTranslationId");
|
||||
|
||||
b.ToTable("LocalizationRequests");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationText", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("Language")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid?>("LocalizationKeyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<long?>("TranslationEngineId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("LocalizationKeyId");
|
||||
|
||||
b.HasIndex("TranslationEngineId");
|
||||
|
||||
b.ToTable("LocalizationText");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Guid>("BodyId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<long>("Order")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<long>("Revision")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<long>("VolumeId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BodyId");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.HasIndex("VolumeId", "Order")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Chapter");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<long>("AuthorId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<Guid?>("CoverImageId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("DescriptionId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("ExternalId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("RawLanguage")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("RawStatus")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<long>("SourceId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int?>("StatusOverride")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("AuthorId");
|
||||
|
||||
b.HasIndex("CoverImageId");
|
||||
|
||||
b.HasIndex("DescriptionId");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.HasIndex("SourceId");
|
||||
|
||||
b.HasIndex("ExternalId", "SourceId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.NovelTag", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("DisplayNameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<long?>("SourceId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int>("TagType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DisplayNameId");
|
||||
|
||||
b.HasIndex("SourceId");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Person", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ExternalUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.ToTable("Person");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Source", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Sources");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("TranslationEngines");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Volume", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<long>("NovelId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int>("Order")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.HasIndex("NovelId", "Order")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Volume");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Sagas.NovelImportSagaState", b =>
|
||||
{
|
||||
b.Property<Guid>("CorrelationId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant?>("CompletedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("CompletedChapters")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("CompletedImages")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("CurrentState")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ErrorMessage")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ExpectedChapters")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ExpectedImages")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<long?>("NovelId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("StartedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("CorrelationId");
|
||||
|
||||
b.HasIndex("CurrentState");
|
||||
|
||||
b.HasIndex("NovelUrl");
|
||||
|
||||
b.ToTable("NovelImportSagaStates");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelNovelTag", b =>
|
||||
{
|
||||
b.Property<long>("NovelsId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<long>("TagsId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("NovelsId", "TagsId");
|
||||
|
||||
b.HasIndex("TagsId");
|
||||
|
||||
b.ToTable("NovelNovelTag");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Images.Image", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Chapter", "Chapter")
|
||||
.WithMany("Images")
|
||||
.HasForeignKey("ChapterId");
|
||||
|
||||
b.Navigation("Chapter");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationRequest", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", "Engine")
|
||||
.WithMany()
|
||||
.HasForeignKey("EngineId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "KeyRequestedForTranslation")
|
||||
.WithMany()
|
||||
.HasForeignKey("KeyRequestedForTranslationId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Engine");
|
||||
|
||||
b.Navigation("KeyRequestedForTranslation");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationText", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", null)
|
||||
.WithMany("Texts")
|
||||
.HasForeignKey("LocalizationKeyId");
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.TranslationEngine", "TranslationEngine")
|
||||
.WithMany()
|
||||
.HasForeignKey("TranslationEngineId");
|
||||
|
||||
b.Navigation("TranslationEngine");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Body")
|
||||
.WithMany()
|
||||
.HasForeignKey("BodyId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||
.WithMany()
|
||||
.HasForeignKey("NameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Volume", "Volume")
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("VolumeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Body");
|
||||
|
||||
b.Navigation("Name");
|
||||
|
||||
b.Navigation("Volume");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Person", "Author")
|
||||
.WithMany()
|
||||
.HasForeignKey("AuthorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Images.Image", "CoverImage")
|
||||
.WithMany()
|
||||
.HasForeignKey("CoverImageId");
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Description")
|
||||
.WithMany()
|
||||
.HasForeignKey("DescriptionId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||
.WithMany()
|
||||
.HasForeignKey("NameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Source", "Source")
|
||||
.WithMany()
|
||||
.HasForeignKey("SourceId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Author");
|
||||
|
||||
b.Navigation("CoverImage");
|
||||
|
||||
b.Navigation("Description");
|
||||
|
||||
b.Navigation("Name");
|
||||
|
||||
b.Navigation("Source");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.NovelTag", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "DisplayName")
|
||||
.WithMany()
|
||||
.HasForeignKey("DisplayNameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Source", "Source")
|
||||
.WithMany()
|
||||
.HasForeignKey("SourceId");
|
||||
|
||||
b.Navigation("DisplayName");
|
||||
|
||||
b.Navigation("Source");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Person", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||
.WithMany()
|
||||
.HasForeignKey("NameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Name");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Volume", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||
.WithMany()
|
||||
.HasForeignKey("NameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", "Novel")
|
||||
.WithMany("Volumes")
|
||||
.HasForeignKey("NovelId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Name");
|
||||
|
||||
b.Navigation("Novel");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelNovelTag", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("NovelsId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.NovelTag", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagsId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", b =>
|
||||
{
|
||||
b.Navigation("Texts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Chapter", b =>
|
||||
{
|
||||
b.Navigation("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||
{
|
||||
b.Navigation("Volumes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Volume", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using NodaTime;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddNovelImportSaga : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ActiveImports",
|
||||
columns: table => new
|
||||
{
|
||||
ImportId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
NovelUrl = table.Column<string>(type: "text", nullable: false),
|
||||
StartedAt = table.Column<Instant>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ActiveImports", x => x.ImportId);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "NovelImportSagaStates",
|
||||
columns: table => new
|
||||
{
|
||||
CorrelationId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
CurrentState = table.Column<string>(type: "text", nullable: false),
|
||||
NovelUrl = table.Column<string>(type: "text", nullable: false),
|
||||
NovelId = table.Column<long>(type: "bigint", nullable: true),
|
||||
ExpectedChapters = table.Column<int>(type: "integer", nullable: false),
|
||||
CompletedChapters = table.Column<int>(type: "integer", nullable: false),
|
||||
ExpectedImages = table.Column<int>(type: "integer", nullable: false),
|
||||
CompletedImages = table.Column<int>(type: "integer", nullable: false),
|
||||
StartedAt = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
|
||||
CompletedAt = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
|
||||
ErrorMessage = table.Column<string>(type: "text", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_NovelImportSagaStates", x => x.CorrelationId);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ActiveImports_NovelUrl",
|
||||
table: "ActiveImports",
|
||||
column: "NovelUrl",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_NovelImportSagaStates_CurrentState",
|
||||
table: "NovelImportSagaStates",
|
||||
column: "CurrentState");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_NovelImportSagaStates_NovelUrl",
|
||||
table: "NovelImportSagaStates",
|
||||
column: "NovelUrl");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "ActiveImports");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "NovelImportSagaStates");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,27 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.ActiveImport", b =>
|
||||
{
|
||||
b.Property<Guid>("ImportId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("StartedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("ImportId");
|
||||
|
||||
b.HasIndex("NovelUrl")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("ActiveImports");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Images.Image", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -153,9 +174,6 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<long?>("NovelId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<long>("Order")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
@@ -165,13 +183,17 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
b.Property<string>("Url")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<long>("VolumeId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BodyId");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.HasIndex("NovelId");
|
||||
b.HasIndex("VolumeId", "Order")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Chapter");
|
||||
});
|
||||
@@ -234,6 +256,9 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
|
||||
b.HasIndex("SourceId");
|
||||
|
||||
b.HasIndex("ExternalId", "SourceId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Novels");
|
||||
});
|
||||
|
||||
@@ -354,6 +379,86 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
b.ToTable("TranslationEngines");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Volume", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
||||
|
||||
b.Property<Instant>("CreatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Instant>("LastUpdatedTime")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<Guid>("NameId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<long>("NovelId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int>("Order")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NameId");
|
||||
|
||||
b.HasIndex("NovelId", "Order")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Volume");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Sagas.NovelImportSagaState", b =>
|
||||
{
|
||||
b.Property<Guid>("CorrelationId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<Instant?>("CompletedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("CompletedChapters")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("CompletedImages")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("CurrentState")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ErrorMessage")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("ExpectedChapters")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("ExpectedImages")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<long?>("NovelId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("NovelUrl")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Instant>("StartedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("CorrelationId");
|
||||
|
||||
b.HasIndex("CurrentState");
|
||||
|
||||
b.HasIndex("NovelUrl");
|
||||
|
||||
b.ToTable("NovelImportSagaStates");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelNovelTag", b =>
|
||||
{
|
||||
b.Property<long>("NovelsId")
|
||||
@@ -424,13 +529,17 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", null)
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Volume", "Volume")
|
||||
.WithMany("Chapters")
|
||||
.HasForeignKey("NovelId");
|
||||
.HasForeignKey("VolumeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Body");
|
||||
|
||||
b.Navigation("Name");
|
||||
|
||||
b.Navigation("Volume");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||
@@ -502,6 +611,25 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
b.Navigation("Name");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Volume", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Localization.LocalizationKey", "Name")
|
||||
.WithMany()
|
||||
.HasForeignKey("NameId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", "Novel")
|
||||
.WithMany("Volumes")
|
||||
.HasForeignKey("NovelId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Name");
|
||||
|
||||
b.Navigation("Novel");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NovelNovelTag", b =>
|
||||
{
|
||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", null)
|
||||
@@ -528,6 +656,11 @@ namespace FictionArchive.Service.NovelService.Migrations
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||
{
|
||||
b.Navigation("Volumes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Volume", b =>
|
||||
{
|
||||
b.Navigation("Chapters");
|
||||
});
|
||||
|
||||
10
FictionArchive.Service.NovelService/Models/ActiveImport.cs
Normal file
10
FictionArchive.Service.NovelService/Models/ActiveImport.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using NodaTime;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Models;
|
||||
|
||||
public class ActiveImport
|
||||
{
|
||||
public Guid ImportId { get; set; }
|
||||
public required string NovelUrl { get; set; }
|
||||
public Instant StartedAt { get; set; }
|
||||
}
|
||||
10
FictionArchive.Service.NovelService/Models/DTOs/BaseDto.cs
Normal file
10
FictionArchive.Service.NovelService/Models/DTOs/BaseDto.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using NodaTime;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Models.DTOs;
|
||||
|
||||
public abstract class BaseDto<TKey>
|
||||
{
|
||||
public TKey Id { get; init; }
|
||||
public Instant CreatedTime { get; init; }
|
||||
public Instant LastUpdatedTime { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace FictionArchive.Service.NovelService.Models.DTOs;
|
||||
|
||||
public class ChapterDto : BaseDto<uint>
|
||||
{
|
||||
public uint Revision { get; init; }
|
||||
public uint Order { get; init; }
|
||||
public string? Url { get; init; }
|
||||
public required string Name { get; init; }
|
||||
public required string Body { get; init; }
|
||||
public required List<ImageDto> Images { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace FictionArchive.Service.NovelService.Models.DTOs;
|
||||
|
||||
public class ChapterReaderDto : BaseDto<uint>
|
||||
{
|
||||
public uint Revision { get; init; }
|
||||
public uint Order { get; init; }
|
||||
public string? Url { get; init; }
|
||||
public required string Name { get; init; }
|
||||
public required string Body { get; init; }
|
||||
public required List<ImageDto> Images { get; init; }
|
||||
|
||||
// Navigation context
|
||||
public uint NovelId { get; init; }
|
||||
public required string NovelName { get; init; }
|
||||
|
||||
// Volume context
|
||||
public uint VolumeId { get; init; }
|
||||
public required string VolumeName { get; init; }
|
||||
public int VolumeOrder { get; init; }
|
||||
public int TotalChaptersInVolume { get; init; }
|
||||
|
||||
// Cross-volume navigation (VolumeOrder + ChapterOrder identify a chapter)
|
||||
public int? PrevChapterVolumeOrder { get; init; }
|
||||
public uint? PrevChapterOrder { get; init; }
|
||||
public int? NextChapterVolumeOrder { get; init; }
|
||||
public uint? NextChapterOrder { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace FictionArchive.Service.NovelService.Models.DTOs;
|
||||
|
||||
public class ImageDto : BaseDto<Guid>
|
||||
{
|
||||
public string? NewPath { get; init; }
|
||||
}
|
||||
20
FictionArchive.Service.NovelService/Models/DTOs/NovelDto.cs
Normal file
20
FictionArchive.Service.NovelService/Models/DTOs/NovelDto.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.NovelService.Models.Enums;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Models.DTOs;
|
||||
|
||||
public class NovelDto : BaseDto<uint>
|
||||
{
|
||||
public required PersonDto Author { get; init; }
|
||||
public required string Url { get; init; }
|
||||
public Language RawLanguage { get; init; }
|
||||
public NovelStatus RawStatus { get; init; }
|
||||
public NovelStatus? StatusOverride { get; init; }
|
||||
public required SourceDto Source { get; init; }
|
||||
public required string ExternalId { get; init; }
|
||||
public required string Name { get; init; }
|
||||
public required string Description { get; init; }
|
||||
public required List<VolumeDto> Volumes { get; init; }
|
||||
public required List<NovelTagDto> Tags { get; init; }
|
||||
public ImageDto? CoverImage { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using FictionArchive.Service.NovelService.Models.Enums;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Models.DTOs;
|
||||
|
||||
public class NovelTagDto : BaseDto<uint>
|
||||
{
|
||||
public required string Key { get; init; }
|
||||
public required string DisplayName { get; init; }
|
||||
public TagType TagType { get; init; }
|
||||
public SourceDto? Source { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FictionArchive.Service.NovelService.Models.DTOs;
|
||||
|
||||
public class PersonDto : BaseDto<uint>
|
||||
{
|
||||
public required string Name { get; init; }
|
||||
public string? ExternalUrl { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FictionArchive.Service.NovelService.Models.DTOs;
|
||||
|
||||
public class SourceDto : BaseDto<uint>
|
||||
{
|
||||
public required string Name { get; init; }
|
||||
public required string Key { get; init; }
|
||||
public required string Url { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FictionArchive.Service.NovelService.Models.DTOs;
|
||||
|
||||
public class VolumeDto : BaseDto<uint>
|
||||
{
|
||||
public int Order { get; init; }
|
||||
public required string Name { get; init; }
|
||||
public required List<ChapterDto> Chapters { get; init; }
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||
|
||||
public class ChapterPullRequestedEvent : IIntegrationEvent
|
||||
{
|
||||
public uint NovelId { get; set; }
|
||||
public uint ChapterNumber { get; set; }
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.FileService.IntegrationEvents;
|
||||
|
||||
public class FileUploadRequestCreatedEvent : IIntegrationEvent
|
||||
{
|
||||
public Guid RequestId { get; set; }
|
||||
public string FilePath { get; set; }
|
||||
public byte[] FileData { get; set; }
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||
|
||||
public class FileUploadRequestStatusUpdateEvent : IIntegrationEvent
|
||||
{
|
||||
public Guid RequestId { get; set; }
|
||||
public RequestStatus Status { get; set; }
|
||||
|
||||
#region Success
|
||||
|
||||
public string? FileAccessUrl { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Failure
|
||||
|
||||
public string? ErrorMessage { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||
|
||||
public class NovelUpdateRequestedEvent : IIntegrationEvent
|
||||
{
|
||||
public string NovelUrl { get; set; }
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||
|
||||
public class TranslationRequestCompletedEvent : IIntegrationEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps this event back to a triggering request.
|
||||
/// </summary>
|
||||
public Guid? TranslationRequestId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The resulting text.
|
||||
/// </summary>
|
||||
public string? TranslatedText { get; set; }
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||
|
||||
public class TranslationRequestCreatedEvent : IIntegrationEvent
|
||||
{
|
||||
public Guid TranslationRequestId { get; set; }
|
||||
public Language From { get; set; }
|
||||
public Language To { get; set; }
|
||||
public string Body { get; set; }
|
||||
public string TranslationEngineKey { get; set; }
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using FictionArchive.Service.NovelService.Models.Images;
|
||||
using FictionArchive.Service.NovelService.Models.Localization;
|
||||
using FictionArchive.Service.Shared.Models;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Models.Novels;
|
||||
|
||||
[Table("Chapter")]
|
||||
public class Chapter : BaseEntity<uint>
|
||||
{
|
||||
public uint Revision { get; set; }
|
||||
@@ -15,4 +17,10 @@ public class Chapter : BaseEntity<uint>
|
||||
|
||||
// Images appearing in this chapter.
|
||||
public List<Image> Images { get; set; }
|
||||
|
||||
#region Navigation Properties
|
||||
|
||||
public Volume Volume { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class Novel : BaseEntity<uint>
|
||||
public LocalizationKey Name { get; set; }
|
||||
public LocalizationKey Description { get; set; }
|
||||
|
||||
public List<Chapter> Chapters { get; set; }
|
||||
public List<Volume> Volumes { get; set; }
|
||||
public List<NovelTag> Tags { get; set; }
|
||||
public Image? CoverImage { get; set; }
|
||||
}
|
||||
24
FictionArchive.Service.NovelService/Models/Novels/Volume.cs
Normal file
24
FictionArchive.Service.NovelService/Models/Novels/Volume.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using FictionArchive.Service.NovelService.Models.Localization;
|
||||
using FictionArchive.Service.Shared.Models;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Models.Novels;
|
||||
|
||||
[Table("Volume")]
|
||||
public class Volume : BaseEntity<uint>
|
||||
{
|
||||
/// <summary>
|
||||
/// Signed int to allow special ordering like -1 for "Author Notes" at top.
|
||||
/// </summary>
|
||||
public int Order { get; set; }
|
||||
|
||||
public LocalizationKey Name { get; set; }
|
||||
|
||||
public List<Chapter> Chapters { get; set; }
|
||||
|
||||
#region Navigation Properties
|
||||
|
||||
public Novel Novel { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class NovelMetadata
|
||||
public Language RawLanguage { get; set; }
|
||||
public NovelStatus RawStatus { get; set; }
|
||||
|
||||
public List<ChapterMetadata> Chapters { get; set; }
|
||||
public List<VolumeMetadata> Volumes { get; set; }
|
||||
public List<string> SourceTags { get; set; }
|
||||
public List<string> SystemTags { get; set; }
|
||||
public SourceDescriptor SourceDescriptor { get; set; }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FictionArchive.Service.NovelService.Models.SourceAdapters;
|
||||
|
||||
public class VolumeMetadata
|
||||
{
|
||||
public int Order { get; set; }
|
||||
public string Name { get; set; }
|
||||
public List<ChapterMetadata> Chapters { get; set; }
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
using FictionArchive.Common.Extensions;
|
||||
using FictionArchive.Service.NovelService.Consumers;
|
||||
using FictionArchive.Service.NovelService.GraphQL;
|
||||
using FictionArchive.Service.NovelService.Models.Configuration;
|
||||
using FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||
using FictionArchive.Service.NovelService.Sagas;
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using FictionArchive.Service.NovelService.Services.EventHandlers;
|
||||
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
||||
using FictionArchive.Service.NovelService.Services.SourceAdapters.Novelpia;
|
||||
using FictionArchive.Service.Shared;
|
||||
using FictionArchive.Service.Shared.Extensions;
|
||||
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
||||
using FictionArchive.Service.Shared.Services.GraphQL;
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NodaTime;
|
||||
|
||||
namespace FictionArchive.Service.NovelService;
|
||||
|
||||
@@ -17,33 +19,51 @@ public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var isSchemaExport = SchemaExportDetector.IsSchemaExportMode(args);
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.AddLocalAppsettings();
|
||||
|
||||
builder.Services.AddMemoryCache();
|
||||
|
||||
#region Event Bus
|
||||
#region MassTransit
|
||||
|
||||
builder.Services.AddRabbitMQ(opt =>
|
||||
if (!isSchemaExport)
|
||||
{
|
||||
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
||||
})
|
||||
.Subscribe<TranslationRequestCompletedEvent, TranslationRequestCompletedEventHandler>()
|
||||
.Subscribe<NovelUpdateRequestedEvent, NovelUpdateRequestedEventHandler>()
|
||||
.Subscribe<ChapterPullRequestedEvent, ChapterPullRequestedEventHandler>()
|
||||
.Subscribe<FileUploadRequestStatusUpdateEvent, FileUploadRequestStatusUpdateEventHandler>();
|
||||
builder.Services.AddFictionArchiveMassTransit(
|
||||
builder.Configuration,
|
||||
x =>
|
||||
{
|
||||
x.AddConsumer<TranslationRequestCompletedConsumer>();
|
||||
x.AddConsumer<FileUploadRequestStatusUpdateConsumer>();
|
||||
x.AddConsumer<ChapterPullRequestedConsumer>();
|
||||
x.AddConsumer<NovelImportRequestedConsumer>();
|
||||
x.AddConsumer<NovelImportCompletedConsumer>();
|
||||
|
||||
x.AddSagaStateMachine<NovelImportSaga, NovelImportSagaState>()
|
||||
.EntityFrameworkRepository(r =>
|
||||
{
|
||||
r.ConcurrencyMode = ConcurrencyMode.Optimistic;
|
||||
r.ExistingDbContext<NovelServiceDbContext>();
|
||||
r.UsePostgres();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GraphQL
|
||||
|
||||
builder.Services.AddDefaultGraphQl<Query, Mutation>();
|
||||
builder.Services.AddDefaultGraphQl<Query, Mutation>()
|
||||
.AddAuthorization();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Database
|
||||
|
||||
builder.Services.RegisterDbContext<NovelServiceDbContext>(builder.Configuration.GetConnectionString("DefaultConnection"));
|
||||
builder.Services.RegisterDbContext<NovelServiceDbContext>(
|
||||
builder.Configuration.GetConnectionString("DefaultConnection"),
|
||||
skipInfrastructure: isSchemaExport);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -53,25 +73,35 @@ public class Program
|
||||
builder.Services.AddHttpClient<NovelpiaAuthMessageHandler>(client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("https://novelpia.com");
|
||||
});
|
||||
})
|
||||
.AddStandardResilienceHandler();
|
||||
builder.Services.AddHttpClient<ISourceAdapter, NovelpiaAdapter>(client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("https://novelpia.com");
|
||||
})
|
||||
.AddHttpMessageHandler<NovelpiaAuthMessageHandler>();
|
||||
.AddHttpMessageHandler<NovelpiaAuthMessageHandler>()
|
||||
.AddStandardResilienceHandler();
|
||||
|
||||
builder.Services.Configure<NovelUpdateServiceConfiguration>(builder.Configuration.GetSection("UpdateService"));
|
||||
builder.Services.AddTransient<NovelUpdateService>();
|
||||
|
||||
#endregion
|
||||
|
||||
// Register IClock for saga and service use
|
||||
builder.Services.AddSingleton<IClock>(SystemClock.Instance);
|
||||
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
// Authentication & Authorization
|
||||
builder.Services.AddOidcAuthentication(builder.Configuration);
|
||||
builder.Services.AddFictionArchiveAuthorization();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Update database
|
||||
using (var scope = app.Services.CreateScope())
|
||||
// Update database (skip in schema export mode)
|
||||
if (!isSchemaExport)
|
||||
{
|
||||
using var scope = app.Services.CreateScope();
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<NovelServiceDbContext>();
|
||||
dbContext.UpdateDatabase();
|
||||
}
|
||||
@@ -80,6 +110,9 @@ public class Program
|
||||
|
||||
app.MapHealthChecks("/healthz");
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapGraphQL();
|
||||
|
||||
app.RunWithGraphQLCommands(args);
|
||||
|
||||
135
FictionArchive.Service.NovelService/Sagas/NovelImportSaga.cs
Normal file
135
FictionArchive.Service.NovelService/Sagas/NovelImportSaga.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using MassTransit;
|
||||
using NodaTime;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Sagas;
|
||||
|
||||
public class NovelImportSaga : MassTransitStateMachine<NovelImportSagaState>
|
||||
{
|
||||
public State Importing { get; private set; } = null!;
|
||||
public State Processing { get; private set; } = null!;
|
||||
public State Completed { get; private set; } = null!;
|
||||
public State Failed { get; private set; } = null!;
|
||||
|
||||
public Event<INovelImportRequested> NovelImportRequested { get; private set; } = null!;
|
||||
public Event<INovelMetadataImported> NovelMetadataImported { get; private set; } = null!;
|
||||
public Event<IChapterPullCompleted> ChapterPullCompleted { get; private set; } = null!;
|
||||
public Event<IFileUploadRequestStatusUpdate> FileUploadStatusUpdate { get; private set; } = null!;
|
||||
public Event<Fault<IChapterPullRequested>> ChapterPullFaulted { get; private set; } = null!;
|
||||
public Event<Fault<IFileUploadRequestCreated>> FileUploadFaulted { get; private set; } = null!;
|
||||
|
||||
private readonly IClock _clock;
|
||||
|
||||
public NovelImportSaga(IClock clock)
|
||||
{
|
||||
_clock = clock;
|
||||
|
||||
InstanceState(x => x.CurrentState);
|
||||
|
||||
Event(() => NovelImportRequested, x => x.CorrelateById(ctx => ctx.Message.ImportId));
|
||||
Event(() => NovelMetadataImported, x => x.CorrelateById(ctx => ctx.Message.ImportId));
|
||||
Event(() => ChapterPullCompleted, x => x.CorrelateById(ctx => ctx.Message.ImportId));
|
||||
Event(() => FileUploadStatusUpdate, x =>
|
||||
{
|
||||
x.CorrelateById(ctx => ctx.Message.ImportId ?? Guid.Empty);
|
||||
x.OnMissingInstance(m => m.Discard());
|
||||
});
|
||||
Event(() => ChapterPullFaulted, x => x.CorrelateById(ctx => ctx.Message.Message.ImportId));
|
||||
Event(() => FileUploadFaulted, x =>
|
||||
{
|
||||
x.CorrelateById(ctx => ctx.Message.Message.ImportId ?? Guid.Empty);
|
||||
x.OnMissingInstance(m => m.Discard());
|
||||
});
|
||||
|
||||
Initially(
|
||||
When(NovelImportRequested)
|
||||
.Then(ctx =>
|
||||
{
|
||||
ctx.Saga.NovelUrl = ctx.Message.NovelUrl;
|
||||
ctx.Saga.StartedAt = _clock.GetCurrentInstant();
|
||||
})
|
||||
.TransitionTo(Importing)
|
||||
);
|
||||
|
||||
During(Importing,
|
||||
When(NovelMetadataImported)
|
||||
.Then(ctx =>
|
||||
{
|
||||
ctx.Saga.NovelId = ctx.Message.NovelId;
|
||||
ctx.Saga.ExpectedChapters = ctx.Message.ChaptersPendingPull;
|
||||
})
|
||||
.IfElse(
|
||||
ctx => ctx.Saga.ExpectedChapters == 0,
|
||||
thenBinder => thenBinder
|
||||
.Then(ctx => ctx.Saga.CompletedAt = _clock.GetCurrentInstant())
|
||||
.TransitionTo(Completed)
|
||||
.PublishAsync(ctx => ctx.Init<INovelImportCompleted>(new NovelImportCompleted(
|
||||
ctx.Saga.CorrelationId,
|
||||
ctx.Saga.NovelId,
|
||||
true,
|
||||
null))),
|
||||
elseBinder => elseBinder.TransitionTo(Processing)
|
||||
)
|
||||
);
|
||||
|
||||
During(Processing,
|
||||
When(ChapterPullCompleted)
|
||||
.Then(ctx =>
|
||||
{
|
||||
ctx.Saga.CompletedChapters++;
|
||||
ctx.Saga.ExpectedImages += ctx.Message.ImagesQueued;
|
||||
})
|
||||
.If(ctx => IsComplete(ctx.Saga), ctx => ctx
|
||||
.Then(c => c.Saga.CompletedAt = _clock.GetCurrentInstant())
|
||||
.TransitionTo(Completed)
|
||||
.PublishAsync(c => c.Init<INovelImportCompleted>(new NovelImportCompleted(
|
||||
c.Saga.CorrelationId,
|
||||
c.Saga.NovelId,
|
||||
true,
|
||||
null)))),
|
||||
|
||||
When(FileUploadStatusUpdate)
|
||||
.Then(ctx => ctx.Saga.CompletedImages++)
|
||||
.If(ctx => IsComplete(ctx.Saga), ctx => ctx
|
||||
.Then(c => c.Saga.CompletedAt = _clock.GetCurrentInstant())
|
||||
.TransitionTo(Completed)
|
||||
.PublishAsync(c => c.Init<INovelImportCompleted>(new NovelImportCompleted(
|
||||
c.Saga.CorrelationId,
|
||||
c.Saga.NovelId,
|
||||
true,
|
||||
null)))),
|
||||
|
||||
When(ChapterPullFaulted)
|
||||
.Then(ctx =>
|
||||
{
|
||||
ctx.Saga.ErrorMessage = ctx.Message.Exceptions.FirstOrDefault()?.Message;
|
||||
ctx.Saga.CompletedAt = _clock.GetCurrentInstant();
|
||||
})
|
||||
.TransitionTo(Failed)
|
||||
.PublishAsync(ctx => ctx.Init<INovelImportCompleted>(new NovelImportCompleted(
|
||||
ctx.Saga.CorrelationId,
|
||||
ctx.Saga.NovelId,
|
||||
false,
|
||||
ctx.Saga.ErrorMessage))),
|
||||
|
||||
When(FileUploadFaulted)
|
||||
.Then(ctx =>
|
||||
{
|
||||
ctx.Saga.ErrorMessage = ctx.Message.Exceptions.FirstOrDefault()?.Message;
|
||||
ctx.Saga.CompletedAt = _clock.GetCurrentInstant();
|
||||
})
|
||||
.TransitionTo(Failed)
|
||||
.PublishAsync(ctx => ctx.Init<INovelImportCompleted>(new NovelImportCompleted(
|
||||
ctx.Saga.CorrelationId,
|
||||
ctx.Saga.NovelId,
|
||||
false,
|
||||
ctx.Saga.ErrorMessage)))
|
||||
);
|
||||
|
||||
SetCompletedWhenFinalized();
|
||||
}
|
||||
|
||||
private static bool IsComplete(NovelImportSagaState saga) =>
|
||||
saga.CompletedChapters >= saga.ExpectedChapters &&
|
||||
saga.CompletedImages >= saga.ExpectedImages;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using MassTransit;
|
||||
using NodaTime;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Sagas;
|
||||
|
||||
public class NovelImportSagaState : SagaStateMachineInstance
|
||||
{
|
||||
public Guid CorrelationId { get; set; }
|
||||
public string CurrentState { get; set; } = null!;
|
||||
|
||||
// Identity
|
||||
public string NovelUrl { get; set; } = null!;
|
||||
public uint? NovelId { get; set; }
|
||||
|
||||
// Chapter tracking
|
||||
public int ExpectedChapters { get; set; }
|
||||
public int CompletedChapters { get; set; }
|
||||
|
||||
// Image tracking
|
||||
public int ExpectedImages { get; set; }
|
||||
public int CompletedImages { get; set; }
|
||||
|
||||
// Timestamps
|
||||
public Instant StartedAt { get; set; }
|
||||
public Instant? CompletedAt { get; set; }
|
||||
|
||||
// Error info
|
||||
public string? ErrorMessage { get; set; }
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Services.EventHandlers;
|
||||
|
||||
public class ChapterPullRequestedEventHandler : IIntegrationEventHandler<ChapterPullRequestedEvent>
|
||||
{
|
||||
private readonly NovelUpdateService _novelUpdateService;
|
||||
|
||||
public ChapterPullRequestedEventHandler(NovelUpdateService novelUpdateService)
|
||||
{
|
||||
_novelUpdateService = novelUpdateService;
|
||||
}
|
||||
|
||||
public async Task Handle(ChapterPullRequestedEvent @event)
|
||||
{
|
||||
await _novelUpdateService.PullChapterContents(@event.NovelId, @event.ChapterNumber);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Services.EventHandlers;
|
||||
|
||||
public class FileUploadRequestStatusUpdateEventHandler : IIntegrationEventHandler<FileUploadRequestStatusUpdateEvent>
|
||||
{
|
||||
private readonly ILogger<FileUploadRequestStatusUpdateEventHandler> _logger;
|
||||
private readonly NovelServiceDbContext _context;
|
||||
private readonly NovelUpdateService _novelUpdateService;
|
||||
|
||||
public FileUploadRequestStatusUpdateEventHandler(ILogger<FileUploadRequestStatusUpdateEventHandler> logger, NovelServiceDbContext context, NovelUpdateService novelUpdateService)
|
||||
{
|
||||
_logger = logger;
|
||||
_context = context;
|
||||
_novelUpdateService = novelUpdateService;
|
||||
}
|
||||
|
||||
public async Task Handle(FileUploadRequestStatusUpdateEvent @event)
|
||||
{
|
||||
var image = await _context.Images.FindAsync(@event.RequestId);
|
||||
if (image == null)
|
||||
{
|
||||
// Not a request we care about.
|
||||
return;
|
||||
}
|
||||
if (@event.Status == RequestStatus.Failed)
|
||||
{
|
||||
_logger.LogError("Image upload failed for image with id {imageId}", image.Id);
|
||||
return;
|
||||
}
|
||||
else if (@event.Status == RequestStatus.Success)
|
||||
{
|
||||
_logger.LogInformation("Image upload succeeded for image with id {imageId}", image.Id);
|
||||
await _novelUpdateService.UpdateImage(image.Id, @event.FileAccessUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Services.EventHandlers;
|
||||
|
||||
public class NovelUpdateRequestedEventHandler : IIntegrationEventHandler<NovelUpdateRequestedEvent>
|
||||
{
|
||||
private readonly ILogger<NovelUpdateRequestedEventHandler> _logger;
|
||||
private readonly IEventBus _eventBus;
|
||||
private readonly NovelUpdateService _novelUpdateService;
|
||||
|
||||
public NovelUpdateRequestedEventHandler(ILogger<NovelUpdateRequestedEventHandler> logger, IEventBus eventBus, NovelUpdateService novelUpdateService)
|
||||
{
|
||||
_logger = logger;
|
||||
_eventBus = eventBus;
|
||||
_novelUpdateService = novelUpdateService;
|
||||
}
|
||||
|
||||
public async Task Handle(NovelUpdateRequestedEvent @event)
|
||||
{
|
||||
await _novelUpdateService.ImportNovel(@event.NovelUrl);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||
using FictionArchive.Service.NovelService.Models.Localization;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Services.EventHandlers;
|
||||
|
||||
public class TranslationRequestCompletedEventHandler : IIntegrationEventHandler<TranslationRequestCompletedEvent>
|
||||
{
|
||||
private readonly ILogger<TranslationRequestCompletedEventHandler> _logger;
|
||||
private readonly NovelServiceDbContext _dbContext;
|
||||
|
||||
public TranslationRequestCompletedEventHandler(ILogger<TranslationRequestCompletedEventHandler> logger, NovelServiceDbContext dbContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task Handle(TranslationRequestCompletedEvent @event)
|
||||
{
|
||||
var localizationRequest = await _dbContext.LocalizationRequests.Include(r => r.KeyRequestedForTranslation)
|
||||
.ThenInclude(lk => lk.Texts)
|
||||
.FirstOrDefaultAsync(lk => lk.Id == @event.TranslationRequestId);
|
||||
if (localizationRequest == null)
|
||||
{
|
||||
// Not one of our requests, discard it
|
||||
return;
|
||||
}
|
||||
|
||||
localizationRequest.KeyRequestedForTranslation.Texts.Add(new LocalizationText()
|
||||
{
|
||||
Language = localizationRequest.TranslateTo,
|
||||
Text = @event.TranslatedText,
|
||||
TranslationEngine = localizationRequest.Engine
|
||||
});
|
||||
_dbContext.LocalizationRequests.Remove(localizationRequest);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using FictionArchive.Service.NovelService.Models;
|
||||
using FictionArchive.Service.NovelService.Models.Images;
|
||||
using FictionArchive.Service.NovelService.Models.Localization;
|
||||
using FictionArchive.Service.NovelService.Models.Novels;
|
||||
using FictionArchive.Service.NovelService.Sagas;
|
||||
using FictionArchive.Service.Shared.Services.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -10,10 +12,46 @@ public class NovelServiceDbContext(DbContextOptions options, ILogger<NovelServic
|
||||
: FictionArchiveDbContext(options, logger)
|
||||
{
|
||||
public DbSet<Novel> Novels { get; set; }
|
||||
public DbSet<Volume> Volumes { get; set; }
|
||||
public DbSet<Chapter> Chapters { get; set; }
|
||||
public DbSet<Source> Sources { get; set; }
|
||||
public DbSet<TranslationEngine> TranslationEngines { get; set; }
|
||||
public DbSet<NovelTag> Tags { get; set; }
|
||||
public DbSet<LocalizationKey> LocalizationKeys { get; set; }
|
||||
public DbSet<LocalizationRequest> LocalizationRequests { get; set; }
|
||||
public DbSet<Image> Images { get; set; }
|
||||
public DbSet<ActiveImport> ActiveImports { get; set; }
|
||||
public DbSet<NovelImportSagaState> NovelImportSagaStates { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<Novel>()
|
||||
.HasIndex("ExternalId", "SourceId")
|
||||
.IsUnique();
|
||||
|
||||
// Volume.Order is unique per Novel
|
||||
modelBuilder.Entity<Volume>()
|
||||
.HasIndex("NovelId", "Order")
|
||||
.IsUnique();
|
||||
|
||||
// Chapter.Order is unique per Volume
|
||||
modelBuilder.Entity<Chapter>()
|
||||
.HasIndex("VolumeId", "Order")
|
||||
.IsUnique();
|
||||
|
||||
modelBuilder.Entity<ActiveImport>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.ImportId);
|
||||
entity.HasIndex(e => e.NovelUrl).IsUnique();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<NovelImportSagaState>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.CorrelationId);
|
||||
entity.HasIndex(e => e.NovelUrl);
|
||||
entity.HasIndex(e => e.CurrentState);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using FictionArchive.Service.FileService.IntegrationEvents;
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.NovelService.Contracts;
|
||||
using FictionArchive.Service.NovelService.Models;
|
||||
using FictionArchive.Service.NovelService.Models.Configuration;
|
||||
using FictionArchive.Service.NovelService.Models.Enums;
|
||||
using FictionArchive.Service.NovelService.Models.Images;
|
||||
@@ -6,10 +8,12 @@ using FictionArchive.Service.NovelService.Models.Localization;
|
||||
using FictionArchive.Service.NovelService.Models.Novels;
|
||||
using FictionArchive.Service.NovelService.Models.SourceAdapters;
|
||||
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using HtmlAgilityPack;
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NodaTime;
|
||||
|
||||
namespace FictionArchive.Service.NovelService.Services;
|
||||
|
||||
@@ -18,26 +22,297 @@ public class NovelUpdateService
|
||||
private readonly NovelServiceDbContext _dbContext;
|
||||
private readonly ILogger<NovelUpdateService> _logger;
|
||||
private readonly IEnumerable<ISourceAdapter> _sourceAdapters;
|
||||
private readonly IEventBus _eventBus;
|
||||
private readonly IPublishEndpoint _publishEndpoint;
|
||||
private readonly NovelUpdateServiceConfiguration _novelUpdateServiceConfiguration;
|
||||
private readonly IClock _clock;
|
||||
|
||||
public NovelUpdateService(NovelServiceDbContext dbContext, ILogger<NovelUpdateService> logger, IEnumerable<ISourceAdapter> sourceAdapters, IEventBus eventBus, IOptions<NovelUpdateServiceConfiguration> novelUpdateServiceConfiguration)
|
||||
public NovelUpdateService(NovelServiceDbContext dbContext, ILogger<NovelUpdateService> logger, IEnumerable<ISourceAdapter> sourceAdapters, IPublishEndpoint publishEndpoint, IOptions<NovelUpdateServiceConfiguration> novelUpdateServiceConfiguration, IClock clock)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_logger = logger;
|
||||
_sourceAdapters = sourceAdapters;
|
||||
_eventBus = eventBus;
|
||||
_publishEndpoint = publishEndpoint;
|
||||
_novelUpdateServiceConfiguration = novelUpdateServiceConfiguration.Value;
|
||||
_clock = clock;
|
||||
}
|
||||
|
||||
public async Task<Novel> ImportNovel(string novelUrl)
|
||||
#region Helper Methods
|
||||
|
||||
private async Task<Source> GetOrCreateSource(SourceDescriptor descriptor)
|
||||
{
|
||||
var existingSource = await _dbContext.Sources
|
||||
.FirstOrDefaultAsync(s => s.Key == descriptor.Key);
|
||||
|
||||
if (existingSource != null)
|
||||
{
|
||||
return existingSource;
|
||||
}
|
||||
|
||||
return new Source
|
||||
{
|
||||
Name = descriptor.Name,
|
||||
Url = descriptor.Url,
|
||||
Key = descriptor.Key
|
||||
};
|
||||
}
|
||||
|
||||
private Person GetOrCreateAuthor(
|
||||
string authorName,
|
||||
string? authorUrl,
|
||||
Language rawLanguage,
|
||||
Person? existingAuthor)
|
||||
{
|
||||
// Case 1: No existing author - create new
|
||||
if (existingAuthor == null)
|
||||
{
|
||||
return new Person
|
||||
{
|
||||
Name = LocalizationKey.CreateFromText(authorName, rawLanguage),
|
||||
ExternalUrl = authorUrl
|
||||
};
|
||||
}
|
||||
|
||||
// Case 2: ExternalUrl differs - create new Person
|
||||
if (existingAuthor.ExternalUrl != authorUrl)
|
||||
{
|
||||
return new Person
|
||||
{
|
||||
Name = LocalizationKey.CreateFromText(authorName, rawLanguage),
|
||||
ExternalUrl = authorUrl
|
||||
};
|
||||
}
|
||||
|
||||
// Case 3: Same URL - update name if different
|
||||
UpdateLocalizationKey(existingAuthor.Name, authorName, rawLanguage);
|
||||
return existingAuthor;
|
||||
}
|
||||
|
||||
private static void UpdateLocalizationKey(LocalizationKey key, string newText, Language language)
|
||||
{
|
||||
var existingText = key.Texts.FirstOrDefault(t => t.Language == language);
|
||||
if (existingText != null)
|
||||
{
|
||||
existingText.Text = newText;
|
||||
}
|
||||
else
|
||||
{
|
||||
key.Texts.Add(new LocalizationText
|
||||
{
|
||||
Language = language,
|
||||
Text = newText
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateNovelMetadata(Novel novel, NovelMetadata metadata)
|
||||
{
|
||||
UpdateLocalizationKey(novel.Name, metadata.Name, metadata.RawLanguage);
|
||||
UpdateLocalizationKey(novel.Description, metadata.Description, metadata.RawLanguage);
|
||||
novel.RawStatus = metadata.RawStatus;
|
||||
novel.Url = metadata.Url;
|
||||
}
|
||||
|
||||
private async Task<List<NovelTag>> SynchronizeTags(
|
||||
List<string> sourceTags,
|
||||
List<string> systemTags,
|
||||
Language rawLanguage)
|
||||
{
|
||||
var allTagKeys = sourceTags.Concat(systemTags).ToHashSet();
|
||||
|
||||
// Query existing tags from DB by Key
|
||||
var existingTagsInDb = await _dbContext.Tags
|
||||
.Where(t => allTagKeys.Contains(t.Key))
|
||||
.ToListAsync();
|
||||
|
||||
var existingTagKeyMap = existingTagsInDb.ToDictionary(t => t.Key);
|
||||
var result = new List<NovelTag>();
|
||||
|
||||
// Process source tags
|
||||
foreach (var tagKey in sourceTags)
|
||||
{
|
||||
if (existingTagKeyMap.TryGetValue(tagKey, out var existingTag))
|
||||
{
|
||||
result.Add(existingTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(new NovelTag
|
||||
{
|
||||
Key = tagKey,
|
||||
DisplayName = LocalizationKey.CreateFromText(tagKey, rawLanguage),
|
||||
TagType = TagType.External
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Process system tags
|
||||
foreach (var tagKey in systemTags)
|
||||
{
|
||||
if (existingTagKeyMap.TryGetValue(tagKey, out var existingTag))
|
||||
{
|
||||
result.Add(existingTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(new NovelTag
|
||||
{
|
||||
Key = tagKey,
|
||||
DisplayName = LocalizationKey.CreateFromText(tagKey, rawLanguage),
|
||||
TagType = TagType.System
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Chapter> SynchronizeChapters(
|
||||
List<ChapterMetadata> metadataChapters,
|
||||
Language rawLanguage,
|
||||
List<Chapter>? existingChapters)
|
||||
{
|
||||
existingChapters ??= new List<Chapter>();
|
||||
var existingOrderSet = existingChapters.Select(c => c.Order).ToHashSet();
|
||||
|
||||
// Only add chapters that don't already exist (by Order)
|
||||
var newChapters = metadataChapters
|
||||
.Where(mc => !existingOrderSet.Contains(mc.Order))
|
||||
.Select(mc => new Chapter
|
||||
{
|
||||
Order = mc.Order,
|
||||
Url = mc.Url,
|
||||
Revision = mc.Revision,
|
||||
Name = LocalizationKey.CreateFromText(mc.Name, rawLanguage),
|
||||
Body = new LocalizationKey
|
||||
{
|
||||
Texts = new List<LocalizationText>()
|
||||
}
|
||||
})
|
||||
.ToList();
|
||||
|
||||
// Combine existing chapters with new ones
|
||||
return existingChapters.Concat(newChapters).ToList();
|
||||
}
|
||||
|
||||
private static List<Volume> SynchronizeVolumes(
|
||||
List<VolumeMetadata> metadataVolumes,
|
||||
Language rawLanguage,
|
||||
List<Volume>? existingVolumes)
|
||||
{
|
||||
existingVolumes ??= new List<Volume>();
|
||||
var result = new List<Volume>();
|
||||
|
||||
foreach (var metaVolume in metadataVolumes)
|
||||
{
|
||||
// Match volumes by Order (unique per novel)
|
||||
var existingVolume = existingVolumes.FirstOrDefault(v => v.Order == metaVolume.Order);
|
||||
|
||||
if (existingVolume != null)
|
||||
{
|
||||
// Volume exists - sync its chapters
|
||||
existingVolume.Chapters = SynchronizeChapters(
|
||||
metaVolume.Chapters,
|
||||
rawLanguage,
|
||||
existingVolume.Chapters);
|
||||
result.Add(existingVolume);
|
||||
}
|
||||
else
|
||||
{
|
||||
// New volume - create it with synced chapters
|
||||
var newVolume = new Volume
|
||||
{
|
||||
Order = metaVolume.Order,
|
||||
Name = LocalizationKey.CreateFromText(metaVolume.Name, rawLanguage),
|
||||
Chapters = SynchronizeChapters(metaVolume.Chapters, rawLanguage, null)
|
||||
};
|
||||
result.Add(newVolume);
|
||||
}
|
||||
}
|
||||
|
||||
// Keep existing volumes not in metadata (user-created volumes)
|
||||
var metaOrders = metadataVolumes.Select(v => v.Order).ToHashSet();
|
||||
result.AddRange(existingVolumes.Where(v => !metaOrders.Contains(v.Order)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static (Image? image, bool shouldPublishEvent) HandleCoverImage(
|
||||
ImageData? newCoverData,
|
||||
Image? existingCoverImage)
|
||||
{
|
||||
// Case 1: No new cover image - keep existing or null
|
||||
if (newCoverData == null)
|
||||
{
|
||||
return (existingCoverImage, false);
|
||||
}
|
||||
|
||||
// Case 2: New cover, no existing
|
||||
if (existingCoverImage == null)
|
||||
{
|
||||
var newImage = new Image { OriginalPath = newCoverData.Url };
|
||||
return (newImage, true);
|
||||
}
|
||||
|
||||
// Case 3: Both exist - check if URL changed
|
||||
if (existingCoverImage.OriginalPath != newCoverData.Url)
|
||||
{
|
||||
existingCoverImage.OriginalPath = newCoverData.Url;
|
||||
existingCoverImage.NewPath = null; // Reset uploaded path
|
||||
return (existingCoverImage, true);
|
||||
}
|
||||
|
||||
// Case 4: Same cover URL - no change needed
|
||||
return (existingCoverImage, false);
|
||||
}
|
||||
|
||||
private async Task<Novel> CreateNewNovel(NovelMetadata metadata, Source source)
|
||||
{
|
||||
var author = new Person
|
||||
{
|
||||
Name = LocalizationKey.CreateFromText(metadata.AuthorName, metadata.RawLanguage),
|
||||
ExternalUrl = metadata.AuthorUrl
|
||||
};
|
||||
|
||||
var tags = await SynchronizeTags(
|
||||
metadata.SourceTags,
|
||||
metadata.SystemTags,
|
||||
metadata.RawLanguage);
|
||||
|
||||
var volumes = SynchronizeVolumes(metadata.Volumes, metadata.RawLanguage, null);
|
||||
|
||||
var novel = new Novel
|
||||
{
|
||||
Author = author,
|
||||
RawLanguage = metadata.RawLanguage,
|
||||
Url = metadata.Url,
|
||||
ExternalId = metadata.ExternalId,
|
||||
CoverImage = metadata.CoverImage != null
|
||||
? new Image { OriginalPath = metadata.CoverImage.Url }
|
||||
: null,
|
||||
Volumes = volumes,
|
||||
Description = LocalizationKey.CreateFromText(metadata.Description, metadata.RawLanguage),
|
||||
Name = LocalizationKey.CreateFromText(metadata.Name, metadata.RawLanguage),
|
||||
RawStatus = metadata.RawStatus,
|
||||
Tags = tags,
|
||||
Source = source
|
||||
};
|
||||
|
||||
_dbContext.Novels.Add(novel);
|
||||
return novel;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task<Novel> ImportNovel(Guid importId, string novelUrl)
|
||||
{
|
||||
// Step 1: Get metadata from source adapter
|
||||
NovelMetadata? metadata = null;
|
||||
foreach (ISourceAdapter sourceAdapter in _sourceAdapters)
|
||||
{
|
||||
if (await sourceAdapter.CanProcessNovel(novelUrl))
|
||||
{
|
||||
metadata = await sourceAdapter.GetMetadata(novelUrl);
|
||||
break; // Stop after finding adapter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,91 +321,182 @@ public class NovelUpdateService
|
||||
throw new NotSupportedException("The provided novel url is currently unsupported.");
|
||||
}
|
||||
|
||||
var systemTags = metadata.SystemTags.Select(tag => new NovelTag()
|
||||
{
|
||||
Key = tag,
|
||||
DisplayName = LocalizationKey.CreateFromText(tag, metadata.RawLanguage),
|
||||
TagType = TagType.System
|
||||
});
|
||||
var sourceTags = metadata.SourceTags.Select(tag => new NovelTag()
|
||||
{
|
||||
Key = tag,
|
||||
DisplayName = LocalizationKey.CreateFromText(tag, metadata.RawLanguage),
|
||||
TagType = TagType.External
|
||||
});
|
||||
// Step 2: Resolve or create Source
|
||||
var source = await GetOrCreateSource(metadata.SourceDescriptor);
|
||||
|
||||
var addedNovel = _dbContext.Novels.Add(new Novel()
|
||||
// Step 3: Check for existing novel by ExternalId + Source.Key
|
||||
var existingNovel = await _dbContext.Novels
|
||||
.Include(n => n.Author)
|
||||
.ThenInclude(a => a.Name)
|
||||
.ThenInclude(lk => lk.Texts)
|
||||
.Include(n => n.Source)
|
||||
.Include(n => n.Name)
|
||||
.ThenInclude(lk => lk.Texts)
|
||||
.Include(n => n.Description)
|
||||
.ThenInclude(lk => lk.Texts)
|
||||
.Include(n => n.Tags)
|
||||
.Include(n => n.Volumes)
|
||||
.ThenInclude(volume => volume.Chapters)
|
||||
.ThenInclude(chapter => chapter.Body)
|
||||
.ThenInclude(localizationKey => localizationKey.Texts)
|
||||
.Include(n => n.CoverImage).Include(novel => novel.Volumes).ThenInclude(volume => volume.Chapters)
|
||||
.ThenInclude(chapter => chapter.Name)
|
||||
.FirstOrDefaultAsync(n =>
|
||||
n.ExternalId == metadata.ExternalId &&
|
||||
n.Source.Key == metadata.SourceDescriptor.Key);
|
||||
|
||||
Novel novel;
|
||||
bool shouldPublishCoverEvent;
|
||||
|
||||
// Capture existing chapter IDs to detect new chapters later
|
||||
var existingChapterIds = existingNovel?.Volumes
|
||||
.SelectMany(v => v.Chapters)
|
||||
.Select(c => c.Id)
|
||||
.ToHashSet() ?? new HashSet<uint>();
|
||||
|
||||
if (existingNovel == null)
|
||||
{
|
||||
Author = new Person()
|
||||
{
|
||||
Name = LocalizationKey.CreateFromText(metadata.AuthorName, metadata.RawLanguage),
|
||||
ExternalUrl = metadata.AuthorUrl,
|
||||
},
|
||||
RawLanguage = metadata.RawLanguage,
|
||||
Url = metadata.Url,
|
||||
ExternalId = metadata.ExternalId,
|
||||
CoverImage = metadata.CoverImage != null ? new Image()
|
||||
{
|
||||
OriginalPath = metadata.CoverImage.Url,
|
||||
} : null,
|
||||
Chapters = metadata.Chapters.Select(chapter =>
|
||||
{
|
||||
return new Chapter()
|
||||
{
|
||||
Order = chapter.Order,
|
||||
Url = chapter.Url,
|
||||
Revision = chapter.Revision,
|
||||
Name = LocalizationKey.CreateFromText(chapter.Name, metadata.RawLanguage),
|
||||
Body = new LocalizationKey()
|
||||
{
|
||||
Texts = new List<LocalizationText>()
|
||||
// CREATE PATH: New novel
|
||||
novel = await CreateNewNovel(metadata, source);
|
||||
shouldPublishCoverEvent = novel.CoverImage != null;
|
||||
}
|
||||
};
|
||||
}).ToList(),
|
||||
Description = LocalizationKey.CreateFromText(metadata.Description, metadata.RawLanguage),
|
||||
Name = LocalizationKey.CreateFromText(metadata.Name, metadata.RawLanguage),
|
||||
RawStatus = metadata.RawStatus,
|
||||
Tags = sourceTags.Concat(systemTags).ToList(),
|
||||
Source = new Source()
|
||||
else
|
||||
{
|
||||
Name = metadata.SourceDescriptor.Name,
|
||||
Url = metadata.SourceDescriptor.Url,
|
||||
Key = metadata.SourceDescriptor.Key,
|
||||
// UPDATE PATH: Existing novel
|
||||
novel = existingNovel;
|
||||
|
||||
// Update author
|
||||
novel.Author = GetOrCreateAuthor(
|
||||
metadata.AuthorName,
|
||||
metadata.AuthorUrl,
|
||||
metadata.RawLanguage,
|
||||
existingNovel.Author);
|
||||
|
||||
// Update metadata (Name, Description, RawStatus)
|
||||
UpdateNovelMetadata(novel, metadata);
|
||||
|
||||
// Synchronize tags (remove old, add new, reuse existing)
|
||||
novel.Tags = await SynchronizeTags(
|
||||
metadata.SourceTags,
|
||||
metadata.SystemTags,
|
||||
metadata.RawLanguage);
|
||||
|
||||
// Synchronize volumes (and their chapters)
|
||||
novel.Volumes = SynchronizeVolumes(
|
||||
metadata.Volumes,
|
||||
metadata.RawLanguage,
|
||||
existingNovel.Volumes);
|
||||
|
||||
// Handle cover image
|
||||
(novel.CoverImage, shouldPublishCoverEvent) = HandleCoverImage(
|
||||
metadata.CoverImage,
|
||||
existingNovel.CoverImage);
|
||||
}
|
||||
});
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
// Signal request for cover image if present
|
||||
if (addedNovel.Entity.CoverImage != null)
|
||||
// Publish novel created event for new novels
|
||||
if (existingNovel == null)
|
||||
{
|
||||
await _eventBus.Publish(new FileUploadRequestCreatedEvent()
|
||||
{
|
||||
RequestId = addedNovel.Entity.CoverImage.Id,
|
||||
FileData = metadata.CoverImage.Data,
|
||||
FilePath = $"Novels/{addedNovel.Entity.Id}/Images/cover.jpg"
|
||||
});
|
||||
await _publishEndpoint.Publish<INovelCreated>(new NovelCreated(
|
||||
novel.Id,
|
||||
novel.Name.Texts.First(t => t.Language == novel.RawLanguage).Text,
|
||||
novel.RawLanguage,
|
||||
novel.Source.Key,
|
||||
novel.Author.Name.Texts.First(t => t.Language == novel.RawLanguage).Text));
|
||||
}
|
||||
|
||||
return addedNovel.Entity;
|
||||
// Publish chapter created events for new chapters
|
||||
foreach (var volume in novel.Volumes)
|
||||
{
|
||||
foreach (var chapter in volume.Chapters.Where(c => !existingChapterIds.Contains(c.Id)))
|
||||
{
|
||||
await _publishEndpoint.Publish<IChapterCreated>(new ChapterCreated(
|
||||
chapter.Id,
|
||||
novel.Id,
|
||||
volume.Id,
|
||||
(uint)volume.Order,
|
||||
chapter.Order,
|
||||
chapter.Name.Texts.First(t => t.Language == novel.RawLanguage).Text));
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Chapter> PullChapterContents(uint novelId, uint chapterNumber)
|
||||
// Count chapters that need pulling
|
||||
var chaptersNeedingPull = novel.Volumes
|
||||
.SelectMany(v => v.Chapters)
|
||||
.Where(c => c.Body?.Texts == null || !c.Body.Texts.Any())
|
||||
.ToList();
|
||||
|
||||
// Publish metadata imported event for saga
|
||||
await _publishEndpoint.Publish<INovelMetadataImported>(new NovelMetadataImported(
|
||||
importId,
|
||||
novel.Id,
|
||||
chaptersNeedingPull.Count
|
||||
));
|
||||
|
||||
// Publish cover image event if needed
|
||||
if (shouldPublishCoverEvent && novel.CoverImage != null && metadata.CoverImage != null)
|
||||
{
|
||||
await _publishEndpoint.Publish<IFileUploadRequestCreated>(new FileUploadRequestCreated(
|
||||
importId,
|
||||
novel.CoverImage.Id,
|
||||
$"Novels/{novel.Id}/Images/cover.jpg",
|
||||
metadata.CoverImage.Data));
|
||||
}
|
||||
|
||||
// Publish chapter pull events for chapters without body content
|
||||
foreach (var volume in novel.Volumes)
|
||||
{
|
||||
var volumeChaptersNeedingPull = volume.Chapters
|
||||
.Where(c => c.Body?.Texts == null || !c.Body.Texts.Any())
|
||||
.ToList();
|
||||
|
||||
foreach (var chapter in volumeChaptersNeedingPull)
|
||||
{
|
||||
await _publishEndpoint.Publish<IChapterPullRequested>(new ChapterPullRequested(
|
||||
importId,
|
||||
novel.Id,
|
||||
volume.Id,
|
||||
chapter.Order));
|
||||
}
|
||||
}
|
||||
|
||||
return novel;
|
||||
}
|
||||
|
||||
public async Task<(Chapter chapter, int imageCount)> PullChapterContents(Guid importId, uint novelId, uint volumeId, uint chapterOrder)
|
||||
{
|
||||
var novel = await _dbContext.Novels.Where(novel => novel.Id == novelId)
|
||||
.Include(novel => novel.Chapters)
|
||||
.Include(novel => novel.Volumes)
|
||||
.ThenInclude(volume => volume.Chapters)
|
||||
.ThenInclude(chapter => chapter.Body)
|
||||
.ThenInclude(body => body.Texts)
|
||||
.Include(novel => novel.Source).Include(novel => novel.Chapters).ThenInclude(chapter => chapter.Images)
|
||||
.Include(novel => novel.Source)
|
||||
.Include(novel => novel.Volumes)
|
||||
.ThenInclude(volume => volume.Chapters)
|
||||
.ThenInclude(chapter => chapter.Images)
|
||||
.FirstOrDefaultAsync();
|
||||
var chapter = novel.Chapters.Where(chapter => chapter.Order == chapterNumber).FirstOrDefault();
|
||||
var volume = novel.Volumes.FirstOrDefault(v => v.Id == volumeId);
|
||||
var chapter = volume.Chapters.FirstOrDefault(c => c.Order == chapterOrder);
|
||||
var adapter = _sourceAdapters.FirstOrDefault(adapter => adapter.SourceDescriptor.Key == novel.Source.Key);
|
||||
var rawChapter = await adapter.GetRawChapter(chapter.Url);
|
||||
var localizationText = new LocalizationText()
|
||||
|
||||
// If we already have the raw for this, overwrite it for now. Revisions will come later.
|
||||
var localizationText = chapter.Body.Texts.FirstOrDefault(text => text.Language == novel.RawLanguage);
|
||||
if (localizationText == null)
|
||||
{
|
||||
localizationText = new LocalizationText()
|
||||
{
|
||||
Text = rawChapter.Text,
|
||||
Language = novel.RawLanguage
|
||||
};
|
||||
chapter.Body.Texts.Add(localizationText);
|
||||
}
|
||||
else
|
||||
{
|
||||
localizationText.Text = rawChapter.Text;
|
||||
}
|
||||
|
||||
chapter.Images = rawChapter.ImageData.Select(img => new Image()
|
||||
{
|
||||
OriginalPath = img.Url
|
||||
@@ -164,15 +530,14 @@ public class NovelUpdateService
|
||||
foreach (var image in chapter.Images)
|
||||
{
|
||||
var data = rawChapter.ImageData.FirstOrDefault(img => img.Url == image.OriginalPath);
|
||||
await _eventBus.Publish(new FileUploadRequestCreatedEvent()
|
||||
{
|
||||
FileData = data.Data,
|
||||
FilePath = $"{novel.Id}/Images/Chapter-{chapter.Id}/{imgCount++}.jpg",
|
||||
RequestId = image.Id
|
||||
});
|
||||
await _publishEndpoint.Publish<IFileUploadRequestCreated>(new FileUploadRequestCreated(
|
||||
importId,
|
||||
image.Id,
|
||||
$"Novels/{novel.Id}/Images/Chapter-{chapter.Id}/{imgCount++}.jpg",
|
||||
data.Data));
|
||||
}
|
||||
|
||||
return chapter;
|
||||
return (chapter, chapter.Images.Count);
|
||||
}
|
||||
|
||||
public async Task UpdateImage(Guid imageId, string newUrl)
|
||||
@@ -195,10 +560,100 @@ public class NovelUpdateService
|
||||
if (match != null)
|
||||
{
|
||||
match.Attributes["src"].Value = newUrl;
|
||||
bodyText.Text = chapterDoc.DocumentNode.OuterHtml;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<NovelImportRequested> QueueNovelImport(string novelUrl)
|
||||
{
|
||||
var importId = Guid.NewGuid();
|
||||
var activeImport = new ActiveImport
|
||||
{
|
||||
ImportId = importId,
|
||||
NovelUrl = novelUrl,
|
||||
StartedAt = _clock.GetCurrentInstant()
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
await _dbContext.ActiveImports.AddAsync(activeImport);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
throw new InvalidOperationException($"An import is already in progress for {novelUrl}");
|
||||
}
|
||||
|
||||
var importNovelRequestEvent = new NovelImportRequested(importId, novelUrl);
|
||||
await _publishEndpoint.Publish<INovelImportRequested>(importNovelRequestEvent);
|
||||
return importNovelRequestEvent;
|
||||
}
|
||||
|
||||
public async Task<ChapterPullRequested> QueueChapterPull(Guid importId, uint novelId, uint volumeId, uint chapterOrder)
|
||||
{
|
||||
var chapterPullEvent = new ChapterPullRequested(importId, novelId, volumeId, chapterOrder);
|
||||
await _publishEndpoint.Publish<IChapterPullRequested>(chapterPullEvent);
|
||||
return chapterPullEvent;
|
||||
}
|
||||
|
||||
public async Task DeleteNovel(uint novelId)
|
||||
{
|
||||
var novel = await _dbContext.Novels
|
||||
.Include(n => n.CoverImage)
|
||||
.Include(n => n.Name).ThenInclude(k => k.Texts)
|
||||
.Include(n => n.Description).ThenInclude(k => k.Texts)
|
||||
.Include(n => n.Volumes).ThenInclude(v => v.Name).ThenInclude(k => k.Texts)
|
||||
.Include(n => n.Volumes).ThenInclude(v => v.Chapters).ThenInclude(c => c.Images)
|
||||
.Include(n => n.Volumes).ThenInclude(v => v.Chapters).ThenInclude(c => c.Name).ThenInclude(k => k.Texts)
|
||||
.Include(n => n.Volumes).ThenInclude(v => v.Chapters).ThenInclude(c => c.Body).ThenInclude(k => k.Texts)
|
||||
.FirstOrDefaultAsync(n => n.Id == novelId);
|
||||
|
||||
if (novel == null)
|
||||
throw new KeyNotFoundException($"Novel with ID '{novelId}' not found");
|
||||
|
||||
// Collect all LocalizationKey IDs for cleanup
|
||||
var locKeyIds = new List<Guid> { novel.Name.Id, novel.Description.Id };
|
||||
foreach (var volume in novel.Volumes)
|
||||
{
|
||||
locKeyIds.Add(volume.Name.Id);
|
||||
locKeyIds.AddRange(volume.Chapters.Select(c => c.Name.Id));
|
||||
locKeyIds.AddRange(volume.Chapters.Select(c => c.Body.Id));
|
||||
}
|
||||
|
||||
// 1. Remove LocalizationRequests referencing these keys
|
||||
var locRequests = await _dbContext.LocalizationRequests
|
||||
.Where(r => locKeyIds.Contains(r.KeyRequestedForTranslation.Id))
|
||||
.ToListAsync();
|
||||
_dbContext.LocalizationRequests.RemoveRange(locRequests);
|
||||
|
||||
// 2. Remove LocalizationTexts (NO ACTION FK - won't cascade)
|
||||
_dbContext.RemoveRange(novel.Name.Texts);
|
||||
_dbContext.RemoveRange(novel.Description.Texts);
|
||||
foreach (var volume in novel.Volumes)
|
||||
{
|
||||
_dbContext.RemoveRange(volume.Name.Texts);
|
||||
foreach (var chapter in volume.Chapters)
|
||||
{
|
||||
_dbContext.RemoveRange(chapter.Name.Texts);
|
||||
_dbContext.RemoveRange(chapter.Body.Texts);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Remove Images (NO ACTION FK - won't cascade)
|
||||
if (novel.CoverImage != null)
|
||||
_dbContext.Images.Remove(novel.CoverImage);
|
||||
foreach (var volume in novel.Volumes)
|
||||
{
|
||||
foreach (var chapter in volume.Chapters)
|
||||
_dbContext.Images.RemoveRange(chapter.Images);
|
||||
}
|
||||
|
||||
// 4. Remove novel - cascades: volumes, chapters, localization keys, tag mappings
|
||||
_dbContext.Novels.Remove(novel);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class NovelpiaAdapter : ISourceAdapter
|
||||
ExternalId = novelId.ToString(),
|
||||
SystemTags = new List<string>(),
|
||||
SourceTags = new List<string>(),
|
||||
Chapters = new List<ChapterMetadata>(),
|
||||
Volumes = new List<VolumeMetadata>(),
|
||||
SourceDescriptor = SourceDescriptor
|
||||
};
|
||||
|
||||
@@ -133,15 +133,16 @@ public class NovelpiaAdapter : ISourceAdapter
|
||||
novel.SourceTags.Add(tag);
|
||||
}
|
||||
|
||||
// Author's posts (from notice_table in the page HTML)
|
||||
var authorsPosts = ParseAuthorsPosts(novelData);
|
||||
|
||||
// Chapters
|
||||
uint page = 0;
|
||||
List<ChapterMetadata> chapters = new List<ChapterMetadata>();
|
||||
List<uint> seenChapterIds = new List<uint>();
|
||||
uint chapterOrder = 0;
|
||||
uint chapterOrder = 1;
|
||||
while (true)
|
||||
{
|
||||
await Task.Delay(500);
|
||||
_logger.LogInformation("Next chapter batch");
|
||||
var response = await _httpClient.PostAsync(EpisodeListEndpoint, new FormUrlEncodedContent(new Dictionary<string, string>
|
||||
{
|
||||
{"novel_no", novelId.ToString()},
|
||||
@@ -170,7 +171,25 @@ public class NovelpiaAdapter : ISourceAdapter
|
||||
}
|
||||
page++;
|
||||
}
|
||||
novel.Chapters = chapters;
|
||||
|
||||
// Add Author's Posts volume if there are any
|
||||
if (authorsPosts.Count > 0)
|
||||
{
|
||||
novel.Volumes.Add(new VolumeMetadata
|
||||
{
|
||||
Order = 0,
|
||||
Name = "Author's Posts",
|
||||
Chapters = authorsPosts
|
||||
});
|
||||
}
|
||||
|
||||
// Main Story volume
|
||||
novel.Volumes.Add(new VolumeMetadata
|
||||
{
|
||||
Order = 1,
|
||||
Name = "Main Story",
|
||||
Chapters = chapters
|
||||
});
|
||||
|
||||
return novel;
|
||||
}
|
||||
@@ -243,4 +262,40 @@ public class NovelpiaAdapter : ISourceAdapter
|
||||
}
|
||||
return await image.Content.ReadAsByteArrayAsync();
|
||||
}
|
||||
|
||||
private List<ChapterMetadata> ParseAuthorsPosts(string novelHtml)
|
||||
{
|
||||
var posts = new List<ChapterMetadata>();
|
||||
|
||||
// Find the notice_table section
|
||||
var noticeTableMatch = Regex.Match(novelHtml,
|
||||
@"(?s)<table[^>]*class=""notice_table[^""]*""[^>]*>(.*?)</table>");
|
||||
if (!noticeTableMatch.Success)
|
||||
return posts;
|
||||
|
||||
var tableContent = noticeTableMatch.Groups[1].Value;
|
||||
|
||||
// Find all td elements with onclick containing viewer URL and extract title from <b>
|
||||
// HTML structure: <td ... onclick="...location='/viewer/3330612';"><b>Title</b>
|
||||
var postMatches = Regex.Matches(tableContent,
|
||||
@"onclick=""[^""]*location='/viewer/(\d+)'[^""]*""[^>]*><b>([^<]+)</b>");
|
||||
|
||||
uint order = 1;
|
||||
foreach (Match match in postMatches)
|
||||
{
|
||||
string viewerId = match.Groups[1].Value;
|
||||
string title = WebUtility.HtmlDecode(match.Groups[2].Value.Trim());
|
||||
|
||||
posts.Add(new ChapterMetadata
|
||||
{
|
||||
Revision = 0,
|
||||
Order = order,
|
||||
Url = $"https://novelpia.com/viewer/{viewerId}",
|
||||
Name = title
|
||||
});
|
||||
order++;
|
||||
}
|
||||
|
||||
return posts;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore": "Warning"
|
||||
}
|
||||
},
|
||||
"Novelpia": {
|
||||
@@ -19,5 +20,15 @@
|
||||
"ConnectionString": "amqp://localhost",
|
||||
"ClientIdentifier": "NovelService"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"OIDC": {
|
||||
"Authority": "https://auth.orfl.xyz/application/o/fiction-archive/",
|
||||
"ClientId": "ldi5IpEidq2WW0Ka1lehVskb2SOBjnYRaZCpEyBh",
|
||||
"Audience": "ldi5IpEidq2WW0Ka1lehVskb2SOBjnYRaZCpEyBh",
|
||||
"ValidIssuer": "https://auth.orfl.xyz/application/o/fiction-archive/",
|
||||
"ValidateIssuer": true,
|
||||
"ValidateAudience": true,
|
||||
"ValidateLifetime": true,
|
||||
"ValidateIssuerSigningKey": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"subgraph": "Novels",
|
||||
"http": {
|
||||
"baseAddress": "http://localhost:5101/graphql"
|
||||
"baseAddress": "https://localhost:7208/graphql"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Data;
|
||||
using FictionArchive.Service.SchedulerService.Models;
|
||||
using FictionArchive.Service.SchedulerService.Services;
|
||||
using FictionArchive.Service.Shared.Constants;
|
||||
using HotChocolate.Authorization;
|
||||
using HotChocolate.Types;
|
||||
using Quartz;
|
||||
|
||||
@@ -10,18 +12,21 @@ public class Mutation
|
||||
{
|
||||
[Error<DuplicateNameException>]
|
||||
[Error<FormatException>]
|
||||
[Authorize(Roles = [AuthorizationConstants.Roles.Admin])]
|
||||
public async Task<SchedulerJob> ScheduleEventJob(string key, string description, string eventType, string eventData, string cronSchedule, JobManagerService jobManager)
|
||||
{
|
||||
return await jobManager.ScheduleEventJob(key, description, eventType, eventData, cronSchedule);
|
||||
}
|
||||
|
||||
[Error<JobPersistenceException>]
|
||||
[Authorize(Roles = [AuthorizationConstants.Roles.Admin])]
|
||||
public async Task<bool> RunJob(string jobKey, JobManagerService jobManager)
|
||||
{
|
||||
return await jobManager.TriggerJob(jobKey);
|
||||
}
|
||||
|
||||
[Error<KeyNotFoundException>]
|
||||
[Authorize(Roles = [AuthorizationConstants.Roles.Admin])]
|
||||
public async Task<bool> DeleteJob(string jobKey, JobManagerService jobManager)
|
||||
{
|
||||
bool deleted = await jobManager.DeleteJob(jobKey);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using MassTransit;
|
||||
using Newtonsoft.Json;
|
||||
using Quartz;
|
||||
|
||||
@@ -6,15 +6,15 @@ namespace FictionArchive.Service.SchedulerService.Models.JobTemplates;
|
||||
|
||||
public class EventJobTemplate : IJob
|
||||
{
|
||||
private readonly IEventBus _eventBus;
|
||||
private readonly IBus _bus;
|
||||
private readonly ILogger<EventJobTemplate> _logger;
|
||||
|
||||
public const string EventTypeParameter = "RoutingKey";
|
||||
public const string EventDataParameter = "MessageData";
|
||||
|
||||
public EventJobTemplate(IEventBus eventBus, ILogger<EventJobTemplate> logger)
|
||||
public EventJobTemplate(IBus bus, ILogger<EventJobTemplate> logger)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
_bus = bus;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class EventJobTemplate : IJob
|
||||
var eventData = context.MergedJobDataMap.GetString(EventDataParameter);
|
||||
var eventType = context.MergedJobDataMap.GetString(EventTypeParameter);
|
||||
var eventObject = JsonConvert.DeserializeObject(eventData);
|
||||
await _eventBus.Publish(eventObject, eventType);
|
||||
await _bus.Publish(eventObject);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using FictionArchive.Service.SchedulerService.GraphQL;
|
||||
using FictionArchive.Service.SchedulerService.Services;
|
||||
using FictionArchive.Service.Shared;
|
||||
using FictionArchive.Service.Shared.Extensions;
|
||||
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
||||
using Quartz;
|
||||
using Quartz.Impl.AdoJobStore;
|
||||
|
||||
@@ -11,30 +11,49 @@ public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var isSchemaExport = SchemaExportDetector.IsSchemaExportMode(args);
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Services
|
||||
builder.Services.AddDefaultGraphQl<Query, Mutation>();
|
||||
builder.Services.AddDefaultGraphQl<Query, Mutation>()
|
||||
.AddAuthorization();
|
||||
builder.Services.AddHealthChecks();
|
||||
builder.Services.AddTransient<JobManagerService>();
|
||||
|
||||
// Authentication & Authorization
|
||||
builder.Services.AddOidcAuthentication(builder.Configuration);
|
||||
builder.Services.AddFictionArchiveAuthorization();
|
||||
|
||||
#region Database
|
||||
|
||||
builder.Services.RegisterDbContext<SchedulerServiceDbContext>(builder.Configuration.GetConnectionString("DefaultConnection"));
|
||||
builder.Services.RegisterDbContext<SchedulerServiceDbContext>(
|
||||
builder.Configuration.GetConnectionString("DefaultConnection"),
|
||||
skipInfrastructure: isSchemaExport);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Bus
|
||||
|
||||
builder.Services.AddRabbitMQ(opt =>
|
||||
if (!isSchemaExport)
|
||||
{
|
||||
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
||||
});
|
||||
builder.Services.AddFictionArchiveMassTransit(builder.Configuration);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Quartz
|
||||
|
||||
if (isSchemaExport)
|
||||
{
|
||||
// Schema export mode: use in-memory store (no DB connection needed)
|
||||
builder.Services.AddQuartz(opt =>
|
||||
{
|
||||
opt.UseInMemoryStore();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Services.AddQuartz(opt =>
|
||||
{
|
||||
opt.UsePersistentStore(pso =>
|
||||
@@ -52,13 +71,16 @@ public class Program
|
||||
{
|
||||
opt.WaitForJobsToComplete = true;
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
// Update database (skip in schema export mode)
|
||||
if (!isSchemaExport)
|
||||
{
|
||||
using var scope = app.Services.CreateScope();
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<SchedulerServiceDbContext>();
|
||||
dbContext.UpdateDatabase();
|
||||
}
|
||||
@@ -67,6 +89,9 @@ public class Program
|
||||
|
||||
app.MapHealthChecks("/healthz");
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapGraphQL();
|
||||
|
||||
app.RunWithGraphQLCommands(args);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Data;
|
||||
using FictionArchive.Service.SchedulerService.Models;
|
||||
using FictionArchive.Service.SchedulerService.Models.JobTemplates;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using Quartz;
|
||||
using Quartz.Impl.Matchers;
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore": "Warning"
|
||||
}
|
||||
},
|
||||
"RabbitMQ": {
|
||||
@@ -12,5 +13,15 @@
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=localhost;Database=FictionArchive_SchedulerService;Username=postgres;password=postgres"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"OIDC": {
|
||||
"Authority": "https://auth.orfl.xyz/application/o/fiction-archive/",
|
||||
"ClientId": "ldi5IpEidq2WW0Ka1lehVskb2SOBjnYRaZCpEyBh",
|
||||
"Audience": "ldi5IpEidq2WW0Ka1lehVskb2SOBjnYRaZCpEyBh",
|
||||
"ValidIssuer": "https://auth.orfl.xyz/application/o/fiction-archive/",
|
||||
"ValidateIssuer": true,
|
||||
"ValidateAudience": true,
|
||||
"ValidateLifetime": true,
|
||||
"ValidateIssuerSigningKey": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace FictionArchive.Service.Shared.Constants;
|
||||
|
||||
public static class AuthorizationConstants
|
||||
{
|
||||
public static class Roles
|
||||
{
|
||||
public const string Admin = "admin";
|
||||
}
|
||||
|
||||
public static class Policies
|
||||
{
|
||||
public const string Admin = "Admin";
|
||||
public const string User = "User";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
public interface IChapterCreated
|
||||
{
|
||||
uint ChapterId { get; }
|
||||
uint NovelId { get; }
|
||||
uint VolumeId { get; }
|
||||
uint VolumeOrder { get; }
|
||||
uint ChapterOrder { get; }
|
||||
string ChapterTitle { get; }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
public interface IChapterPullCompleted
|
||||
{
|
||||
Guid ImportId { get; }
|
||||
uint ChapterId { get; }
|
||||
int ImagesQueued { get; }
|
||||
}
|
||||
|
||||
public record ChapterPullCompleted(Guid ImportId, uint ChapterId, int ImagesQueued) : IChapterPullCompleted;
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
public interface IChapterPullRequested
|
||||
{
|
||||
Guid ImportId { get; }
|
||||
uint NovelId { get; }
|
||||
uint VolumeId { get; }
|
||||
uint ChapterOrder { get; }
|
||||
}
|
||||
|
||||
public record ChapterPullRequested(Guid ImportId, uint NovelId, uint VolumeId, uint ChapterOrder) : IChapterPullRequested;
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
public interface IFileUploadRequestCreated
|
||||
{
|
||||
Guid? ImportId { get; }
|
||||
Guid RequestId { get; }
|
||||
string FilePath { get; }
|
||||
byte[] FileData { get; }
|
||||
}
|
||||
|
||||
public record FileUploadRequestCreated(Guid? ImportId, Guid RequestId, string FilePath, byte[] FileData) : IFileUploadRequestCreated;
|
||||
@@ -0,0 +1,14 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
|
||||
namespace FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
public interface IFileUploadRequestStatusUpdate
|
||||
{
|
||||
Guid? ImportId { get; }
|
||||
Guid RequestId { get; }
|
||||
RequestStatus Status { get; }
|
||||
string? FileAccessUrl { get; }
|
||||
string? ErrorMessage { get; }
|
||||
}
|
||||
|
||||
public record FileUploadRequestStatusUpdate(Guid? ImportId, Guid RequestId, RequestStatus Status, string? FileAccessUrl, string? ErrorMessage) : IFileUploadRequestStatusUpdate;
|
||||
@@ -0,0 +1,12 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
|
||||
namespace FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
public interface INovelCreated
|
||||
{
|
||||
uint NovelId { get; }
|
||||
string Title { get; }
|
||||
Language OriginalLanguage { get; }
|
||||
string Source { get; }
|
||||
string AuthorName { get; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
public interface INovelImportCompleted
|
||||
{
|
||||
Guid ImportId { get; }
|
||||
uint? NovelId { get; }
|
||||
bool Success { get; }
|
||||
string? ErrorMessage { get; }
|
||||
}
|
||||
|
||||
public record NovelImportCompleted(Guid ImportId, uint? NovelId, bool Success, string? ErrorMessage) : INovelImportCompleted;
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
public interface INovelImportRequested
|
||||
{
|
||||
Guid ImportId { get; }
|
||||
string NovelUrl { get; }
|
||||
}
|
||||
|
||||
public record NovelImportRequested(Guid ImportId, string NovelUrl) : INovelImportRequested;
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
public interface INovelMetadataImported
|
||||
{
|
||||
Guid ImportId { get; }
|
||||
uint NovelId { get; }
|
||||
int ChaptersPendingPull { get; }
|
||||
}
|
||||
|
||||
public record NovelMetadataImported(Guid ImportId, uint NovelId, int ChaptersPendingPull) : INovelMetadataImported;
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
public interface ITranslationRequestCompleted
|
||||
{
|
||||
Guid? TranslationRequestId { get; }
|
||||
string? TranslatedText { get; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
|
||||
namespace FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
public interface ITranslationRequestCreated
|
||||
{
|
||||
Guid TranslationRequestId { get; }
|
||||
Language From { get; }
|
||||
Language To { get; }
|
||||
string Body { get; }
|
||||
string TranslationEngineKey { get; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace FictionArchive.Service.Shared.Contracts.Events;
|
||||
|
||||
public interface IUserInvited
|
||||
{
|
||||
string InvitedUserId { get; }
|
||||
string InvitedUsername { get; }
|
||||
string InvitedEmail { get; }
|
||||
string InvitedOAuthProviderId { get; }
|
||||
string InviterId { get; }
|
||||
string InviterUsername { get; }
|
||||
string InviterOAuthProviderId { get; }
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user