Compare commits
104 Commits
feature/FA
...
feature/FA
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | |||
| 30cc89242d | |||
| 84294455f9 | |||
| be62af98d3 | |||
|
|
15a8185621 | ||
|
|
0180a58084 | ||
|
|
573f3fc7b0 | ||
|
|
cdc2176e35 | ||
|
|
e9eaf1569b | ||
|
|
ba99642e97 | ||
|
|
c6d794aabc | ||
|
|
62e7e20f94 | ||
| aff1396c6a | |||
| 9e1792e4d0 | |||
|
|
747a212fb0 | ||
|
|
200bdaabed | ||
|
|
caa36648e2 | ||
| 6f2454329d | |||
|
|
fdf2ff7c1b | ||
|
|
e8596b67c4 | ||
| a01250696f |
175
.gitea/workflows/build-gateway.yml
Normal file
175
.gitea/workflows/build-gateway.yml
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
name: Build Gateway
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*.*.*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ${{ gitea.server_url }}
|
||||||
|
IMAGE_NAME: ${{ gitea.repository_owner }}/fictionarchive-api
|
||||||
|
|
||||||
|
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: usernoveldata-service
|
||||||
|
project: FictionArchive.Service.UserNovelDataService
|
||||||
|
subgraph: UserNovelData
|
||||||
|
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: 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
|
||||||
|
|
||||||
|
- name: Download Novel Service subgraph
|
||||||
|
uses: christopherhx/gitea-download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: novel-service-subgraph
|
||||||
|
path: subgraphs/novel
|
||||||
|
|
||||||
|
- name: Download Translation Service subgraph
|
||||||
|
uses: christopherhx/gitea-download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: translation-service-subgraph
|
||||||
|
path: subgraphs/translation
|
||||||
|
|
||||||
|
- name: Download Scheduler Service subgraph
|
||||||
|
uses: christopherhx/gitea-download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: scheduler-service-subgraph
|
||||||
|
path: subgraphs/scheduler
|
||||||
|
|
||||||
|
- name: Download User Service subgraph
|
||||||
|
uses: christopherhx/gitea-download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: user-service-subgraph
|
||||||
|
path: subgraphs/user
|
||||||
|
|
||||||
|
- name: Download UserNovelData Service subgraph
|
||||||
|
uses: christopherhx/gitea-download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: usernoveldata-service-subgraph
|
||||||
|
path: subgraphs/usernoveldata
|
||||||
|
|
||||||
|
- name: Configure subgraph URLs for Docker
|
||||||
|
run: |
|
||||||
|
for fsp in subgraphs/*/*.fsp; do
|
||||||
|
if [ -f "$fsp" ]; then
|
||||||
|
dir=$(dirname "$fsp")
|
||||||
|
name=$(basename "$dir")
|
||||||
|
url="http://${name}-service:8080/graphql"
|
||||||
|
echo "Setting $name URL to $url"
|
||||||
|
fusion subgraph config set http --url "$url" -c "$fsp"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Compose gateway
|
||||||
|
run: |
|
||||||
|
cd FictionArchive.API
|
||||||
|
rm -f gateway.fgp
|
||||||
|
for fsp in ../subgraphs/*/*.fsp; do
|
||||||
|
if [ -f "$fsp" ]; then
|
||||||
|
echo "Composing: $fsp"
|
||||||
|
fusion compose -p gateway.fgp -s "$fsp"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Restore dependencies
|
||||||
|
run: dotnet restore FictionArchive.API/FictionArchive.API.csproj
|
||||||
|
|
||||||
|
- name: Build gateway
|
||||||
|
run: dotnet build FictionArchive.API/FictionArchive.API.csproj -c Release --no-restore -p:SkipFusionBuild=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:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ gitea.actor }}
|
||||||
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: FictionArchive.API/Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
${{ 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
|
||||||
74
.gitea/workflows/build.yml
Normal file
74
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-backend:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup .NET
|
||||||
|
uses: actions/setup-dotnet@v4
|
||||||
|
with:
|
||||||
|
dotnet-version: '8.0.x'
|
||||||
|
|
||||||
|
- name: Restore dependencies
|
||||||
|
run: dotnet restore FictionArchive.sln
|
||||||
|
|
||||||
|
- name: Build solution
|
||||||
|
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 \
|
||||||
|
--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-astro
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v6.0.0
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
package-manager-cache: false
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: npm run lint
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: npm run build
|
||||||
107
.gitea/workflows/release.yml
Normal file
107
.gitea/workflows/release.yml
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*.*.*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ${{ gitea.server_url }}
|
||||||
|
IMAGE_PREFIX: ${{ gitea.repository_owner }}/fictionarchive
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
service:
|
||||||
|
- name: novel-service
|
||||||
|
dockerfile: FictionArchive.Service.NovelService/Dockerfile
|
||||||
|
- name: user-service
|
||||||
|
dockerfile: FictionArchive.Service.UserService/Dockerfile
|
||||||
|
- name: translation-service
|
||||||
|
dockerfile: FictionArchive.Service.TranslationService/Dockerfile
|
||||||
|
- name: file-service
|
||||||
|
dockerfile: FictionArchive.Service.FileService/Dockerfile
|
||||||
|
- name: scheduler-service
|
||||||
|
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
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Extract version from tag
|
||||||
|
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:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ gitea.actor }}
|
||||||
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ${{ matrix.service.dockerfile }}
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
${{ 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
|
||||||
|
|
||||||
|
build-frontend:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Extract version from tag
|
||||||
|
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:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ gitea.actor }}
|
||||||
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push frontend Docker image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: ./fictionarchive-web-astro
|
||||||
|
file: fictionarchive-web-astro/Dockerfile
|
||||||
|
push: true
|
||||||
|
build-args: |
|
||||||
|
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: |
|
||||||
|
${{ 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
|
schema.graphql
|
||||||
*.fsp
|
*.fsp
|
||||||
gateway.fgp
|
gateway.fgp
|
||||||
|
|
||||||
|
# Git worktrees
|
||||||
|
.worktrees/
|
||||||
405
Documentation/ARCHITECTURE.md
Normal file
405
Documentation/ARCHITECTURE.md
Normal file
@@ -0,0 +1,405 @@
|
|||||||
|
# FictionArchive Architecture Overview
|
||||||
|
|
||||||
|
## High-Level Architecture
|
||||||
|
|
||||||
|
```
|
||||||
|
┌────────────────────────────────────────────────────────────────┐
|
||||||
|
│ React 19 Frontend │
|
||||||
|
│ (Apollo Client, TailwindCSS, OIDC Auth) │
|
||||||
|
└───────────────────────────┬────────────────────────────────────┘
|
||||||
|
│ GraphQL
|
||||||
|
▼
|
||||||
|
┌────────────────────────────────────────────────────────────────┐
|
||||||
|
│ Hot Chocolate Fusion Gateway │
|
||||||
|
│ (FictionArchive.API) │
|
||||||
|
└──────┬────────┬────────┬────────┬────────┬─────────────────────┘
|
||||||
|
│ │ │ │ │
|
||||||
|
▼ ▼ ▼ ▼ ▼
|
||||||
|
┌──────────┐┌──────────┐┌───────────┐┌──────────┐┌──────────────┐
|
||||||
|
│ Novel ││ User ││Translation││Scheduler ││ File │
|
||||||
|
│ Service ││ Service ││ Service ││ Service ││ Service │
|
||||||
|
└────┬─────┘└────┬─────┘└─────┬─────┘└────┬─────┘└──────┬───────┘
|
||||||
|
│ │ │ │ │
|
||||||
|
└───────────┴────────────┴───────────┴─────────────┘
|
||||||
|
│
|
||||||
|
┌────────┴────────┐
|
||||||
|
│ RabbitMQ │
|
||||||
|
│ (Event Bus) │
|
||||||
|
└─────────────────┘
|
||||||
|
│
|
||||||
|
┌────────┴────────┐
|
||||||
|
│ PostgreSQL │
|
||||||
|
│ (per service) │
|
||||||
|
└─────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## Technology Stack
|
||||||
|
|
||||||
|
| Layer | Technology | Version |
|
||||||
|
|-------|------------|---------|
|
||||||
|
| Runtime | .NET | 8.0 |
|
||||||
|
| GraphQL | Hot Chocolate / Fusion | 13+ |
|
||||||
|
| Database | PostgreSQL | 12+ |
|
||||||
|
| ORM | Entity Framework Core | 8.0 |
|
||||||
|
| Message Broker | RabbitMQ | 3.12+ |
|
||||||
|
| Job Scheduler | Quartz.NET | Latest |
|
||||||
|
| Object Storage | AWS S3 / Garage | - |
|
||||||
|
| Date/Time | NodaTime | Latest |
|
||||||
|
| Frontend | React | 19.2 |
|
||||||
|
| Frontend Build | Vite | 7.2 |
|
||||||
|
| GraphQL Client | Apollo Client | 4.0 |
|
||||||
|
| Auth | OIDC Client TS | 3.4 |
|
||||||
|
| Styling | TailwindCSS | 3.4 |
|
||||||
|
| UI Components | Radix UI | Latest |
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
FictionArchive.sln
|
||||||
|
├── FictionArchive.Common # Shared enums and extensions
|
||||||
|
├── FictionArchive.API # GraphQL Fusion Gateway
|
||||||
|
├── FictionArchive.Service.Shared # Shared infrastructure
|
||||||
|
├── FictionArchive.Service.NovelService
|
||||||
|
├── FictionArchive.Service.UserService
|
||||||
|
├── FictionArchive.Service.TranslationService
|
||||||
|
├── FictionArchive.Service.FileService
|
||||||
|
├── FictionArchive.Service.SchedulerService
|
||||||
|
├── FictionArchive.Service.AuthenticationService
|
||||||
|
├── FictionArchive.Service.NovelService.Tests
|
||||||
|
└── fictionarchive-web # React frontend
|
||||||
|
```
|
||||||
|
|
||||||
|
## Services
|
||||||
|
|
||||||
|
### FictionArchive.API - GraphQL Fusion Gateway
|
||||||
|
|
||||||
|
- **Role**: Single entry point for all GraphQL queries
|
||||||
|
- **Port**: 5001 (HTTPS)
|
||||||
|
- **Endpoints**:
|
||||||
|
- `/graphql` - GraphQL endpoint
|
||||||
|
- `/healthz` - Health check
|
||||||
|
- **Responsibilities**:
|
||||||
|
- Compose GraphQL schemas from all subgraphs
|
||||||
|
- Route queries to appropriate services
|
||||||
|
- CORS policy management
|
||||||
|
|
||||||
|
### FictionArchive.Service.NovelService
|
||||||
|
|
||||||
|
- **Role**: Novel/fiction content management
|
||||||
|
- **Port**: 8081 (HTTPS)
|
||||||
|
- **Database**: `FictionArchive_NovelService`
|
||||||
|
- **GraphQL Operations**:
|
||||||
|
- `GetNovels` - Paginated, filterable novel listing
|
||||||
|
- `ImportNovel` - Trigger novel import
|
||||||
|
- `FetchChapterContents` - Fetch chapter content
|
||||||
|
- **Models**: Novel, Chapter, Source, NovelTag, Image, LocalizationKey
|
||||||
|
- **External Integration**: Novelpia adapter
|
||||||
|
- **Events Published**: `TranslationRequestCreatedEvent`, `FileUploadRequestCreatedEvent`
|
||||||
|
- **Events Subscribed**: `TranslationRequestCompletedEvent`, `NovelUpdateRequestedEvent`, `ChapterPullRequestedEvent`, `FileUploadRequestStatusUpdateEvent`
|
||||||
|
|
||||||
|
### FictionArchive.Service.UserService
|
||||||
|
|
||||||
|
- **Role**: User identity and profile management
|
||||||
|
- **Port**: 8081 (HTTPS)
|
||||||
|
- **Database**: `FictionArchive_UserService`
|
||||||
|
- **Models**: User (with OAuth provider linking)
|
||||||
|
- **Events Subscribed**: `AuthUserAddedEvent`
|
||||||
|
|
||||||
|
### FictionArchive.Service.TranslationService
|
||||||
|
|
||||||
|
- **Role**: Text translation orchestration
|
||||||
|
- **Port**: 8081 (HTTPS)
|
||||||
|
- **Database**: `FictionArchive_TranslationService`
|
||||||
|
- **External Integration**: DeepL API
|
||||||
|
- **Models**: TranslationRequest
|
||||||
|
- **Events Published**: `TranslationRequestCompletedEvent`
|
||||||
|
- **Events Subscribed**: `TranslationRequestCreatedEvent`
|
||||||
|
|
||||||
|
### FictionArchive.Service.FileService
|
||||||
|
|
||||||
|
- **Role**: File storage and S3 proxy
|
||||||
|
- **Port**: 8080 (HTTP)
|
||||||
|
- **Protocol**: REST only (not GraphQL)
|
||||||
|
- **Endpoints**: `GET /api/{*path}` - S3 file proxy
|
||||||
|
- **External Integration**: S3-compatible storage (AWS S3 / Garage)
|
||||||
|
- **Events Published**: `FileUploadRequestStatusUpdateEvent`
|
||||||
|
- **Events Subscribed**: `FileUploadRequestCreatedEvent`
|
||||||
|
|
||||||
|
### FictionArchive.Service.SchedulerService
|
||||||
|
|
||||||
|
- **Role**: Job scheduling and automation
|
||||||
|
- **Port**: 8081 (HTTPS)
|
||||||
|
- **Database**: `FictionArchive_SchedulerService`
|
||||||
|
- **Scheduler**: Quartz.NET with persistent job store
|
||||||
|
- **GraphQL Operations**: `ScheduleEventJob`, `GetScheduledJobs`
|
||||||
|
- **Models**: SchedulerJob, EventJobTemplate
|
||||||
|
|
||||||
|
### FictionArchive.Service.AuthenticationService
|
||||||
|
|
||||||
|
- **Role**: OAuth/OIDC webhook receiver
|
||||||
|
- **Port**: 8080 (HTTP)
|
||||||
|
- **Protocol**: REST only
|
||||||
|
- **Endpoints**: `POST /api/AuthenticationWebhook/UserRegistered`
|
||||||
|
- **Events Published**: `AuthUserAddedEvent`
|
||||||
|
- **No Database** - Stateless webhook handler
|
||||||
|
|
||||||
|
## Communication Patterns
|
||||||
|
|
||||||
|
### GraphQL Federation
|
||||||
|
|
||||||
|
- Hot Chocolate Fusion Gateway composes subgraph schemas
|
||||||
|
- Schema export automated via `build_gateway.py`
|
||||||
|
- Each service defines its own Query/Mutation types
|
||||||
|
|
||||||
|
### Event-Driven Architecture (RabbitMQ)
|
||||||
|
|
||||||
|
- Direct exchange: `fiction-archive-event-bus`
|
||||||
|
- Per-service queues based on `ClientIdentifier`
|
||||||
|
- Routing key = event class name
|
||||||
|
- Headers: `X-Created-At`, `X-Event-Id`
|
||||||
|
- NodaTime JSON serialization
|
||||||
|
|
||||||
|
### Event Flow Examples
|
||||||
|
|
||||||
|
**Novel Import:**
|
||||||
|
```
|
||||||
|
1. Frontend → importNovel mutation
|
||||||
|
2. NovelService publishes NovelUpdateRequestedEvent
|
||||||
|
3. NovelUpdateRequestedEventHandler processes
|
||||||
|
4. Fetches metadata via NovelpiaAdapter
|
||||||
|
5. Publishes FileUploadRequestCreatedEvent (for cover)
|
||||||
|
6. FileService uploads to S3
|
||||||
|
7. FileService publishes FileUploadRequestStatusUpdateEvent
|
||||||
|
8. NovelService updates image path
|
||||||
|
```
|
||||||
|
|
||||||
|
**Translation:**
|
||||||
|
```
|
||||||
|
1. NovelService publishes TranslationRequestCreatedEvent
|
||||||
|
2. TranslationService translates via DeepL
|
||||||
|
3. TranslationService publishes TranslationRequestCompletedEvent
|
||||||
|
4. NovelService updates chapter translation
|
||||||
|
```
|
||||||
|
|
||||||
|
## Data Storage
|
||||||
|
|
||||||
|
### Database Pattern
|
||||||
|
- Database per service (PostgreSQL)
|
||||||
|
- Connection string format: `Host=localhost;Database=FictionArchive_{ServiceName};...`
|
||||||
|
- Auto-migration on startup via `dbContext.UpdateDatabase()`
|
||||||
|
|
||||||
|
### Audit Trail
|
||||||
|
- `AuditInterceptor` auto-sets `CreatedTime` and `LastUpdatedTime`
|
||||||
|
- `IAuditable` interface with NodaTime `Instant` fields
|
||||||
|
- `BaseEntity<TKey>` abstract base class
|
||||||
|
|
||||||
|
### Object Storage
|
||||||
|
- S3-compatible (AWS S3 or Garage)
|
||||||
|
- Path-style URLs for Garage compatibility
|
||||||
|
- Proxied through FileService
|
||||||
|
|
||||||
|
## Frontend Architecture
|
||||||
|
|
||||||
|
### Structure
|
||||||
|
```
|
||||||
|
fictionarchive-web/
|
||||||
|
├── src/
|
||||||
|
│ ├── auth/ # OIDC authentication
|
||||||
|
│ ├── components/ # React components
|
||||||
|
│ │ └── ui/ # Radix-based primitives
|
||||||
|
│ ├── pages/ # Route pages
|
||||||
|
│ ├── layouts/ # Layout components
|
||||||
|
│ ├── graphql/ # GraphQL queries
|
||||||
|
│ ├── __generated__/ # Codegen output
|
||||||
|
│ └── lib/ # Utilities
|
||||||
|
└── codegen.ts # GraphQL Codegen config
|
||||||
|
```
|
||||||
|
|
||||||
|
### Authentication
|
||||||
|
- OIDC via `oidc-client-ts`
|
||||||
|
- Environment variables for configuration
|
||||||
|
- `useAuth` hook for state access
|
||||||
|
|
||||||
|
### State Management
|
||||||
|
- Apollo Client for GraphQL state
|
||||||
|
- React Context for auth state
|
||||||
|
|
||||||
|
## Infrastructure
|
||||||
|
|
||||||
|
### Docker
|
||||||
|
- Multi-stage builds
|
||||||
|
- Base: `mcr.microsoft.com/dotnet/aspnet:8.0`
|
||||||
|
- Non-root user for security
|
||||||
|
- Ports: 8080 (HTTP) or 8081 (HTTPS)
|
||||||
|
|
||||||
|
### Health Checks
|
||||||
|
- All services expose `/healthz`
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
- `appsettings.json` - Default settings
|
||||||
|
- `appsettings.Development.json` - Dev overrides
|
||||||
|
- `appsettings.Local.json` - Local secrets (not committed)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Improvement Recommendations
|
||||||
|
|
||||||
|
## Critical
|
||||||
|
|
||||||
|
### 1. Event Bus - No Dead Letter Queue or Retry Logic
|
||||||
|
**Location**: `FictionArchive.Service.Shared/Services/EventBus/Implementations/RabbitMQEventBus.cs:126-133`
|
||||||
|
|
||||||
|
**Issue**: Events are always ACK'd even on failure. No DLQ configuration for poison messages. Failed events are lost forever.
|
||||||
|
|
||||||
|
**Recommendation**: Implement retry with exponential backoff, dead-letter exchange, and poison message handling.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// Example: Add retry and DLQ
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "Error handling event");
|
||||||
|
if (retryCount < maxRetries)
|
||||||
|
{
|
||||||
|
await channel.BasicNackAsync(@event.DeliveryTag, false, true); // requeue
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Send to DLQ
|
||||||
|
await channel.BasicNackAsync(@event.DeliveryTag, false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. CORS Configuration is Insecure
|
||||||
|
**Location**: `FictionArchive.API/Program.cs:24-33`
|
||||||
|
|
||||||
|
**Issue**: `AllowAnyOrigin()` allows requests from any domain, unsuitable for production.
|
||||||
|
|
||||||
|
**Recommendation**: Configure specific allowed origins via appsettings:
|
||||||
|
```csharp
|
||||||
|
builder.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy("Production", policy =>
|
||||||
|
{
|
||||||
|
policy.WithOrigins(builder.Configuration.GetSection("Cors:AllowedOrigins").Get<string[]>())
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowAnyHeader();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Auto-Migration on Startup
|
||||||
|
**Location**: `FictionArchive.Service.Shared/Services/Database/FictionArchiveDbContext.cs:23-38`
|
||||||
|
|
||||||
|
**Issue**: Running migrations at startup can cause race conditions with multiple instances and potential data corruption during rolling deployments.
|
||||||
|
|
||||||
|
**Recommendation**: Use a migration job, init container, or CLI tool instead of startup code.
|
||||||
|
|
||||||
|
## Important
|
||||||
|
|
||||||
|
### 4. No Circuit Breaker Pattern
|
||||||
|
**Issue**: External service calls (DeepL, Novelpia, S3) lack resilience patterns.
|
||||||
|
|
||||||
|
**Recommendation**: Add Polly for circuit breaker, retry, and timeout policies:
|
||||||
|
```csharp
|
||||||
|
builder.Services.AddHttpClient<ISourceAdapter, NovelpiaAdapter>()
|
||||||
|
.AddPolicyHandler(GetRetryPolicy())
|
||||||
|
.AddPolicyHandler(GetCircuitBreakerPolicy());
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Missing Request Validation/Rate Limiting
|
||||||
|
**Issue**: No visible rate limiting on GraphQL mutations. `ImportNovel` could be abused.
|
||||||
|
|
||||||
|
**Recommendation**: Add rate limiting middleware and input validation.
|
||||||
|
|
||||||
|
### 6. Hardcoded Exchange Name
|
||||||
|
**Location**: `RabbitMQEventBus.cs:24`
|
||||||
|
|
||||||
|
**Issue**: `fiction-archive-event-bus` is hardcoded.
|
||||||
|
|
||||||
|
**Recommendation**: Move to configuration for environment flexibility.
|
||||||
|
|
||||||
|
### 7. No Distributed Tracing
|
||||||
|
**Issue**: Event correlation exists (`X-Event-Id` header) but not integrated with tracing.
|
||||||
|
|
||||||
|
**Recommendation**: Add OpenTelemetry for end-to-end request tracing across services.
|
||||||
|
|
||||||
|
### 8. Singleton AuditInterceptor
|
||||||
|
**Location**: `FictionArchiveDbContext.cs:20`
|
||||||
|
|
||||||
|
**Issue**: `new AuditInterceptor()` created per DbContext instance.
|
||||||
|
|
||||||
|
**Recommendation**: Register as singleton in DI and inject.
|
||||||
|
|
||||||
|
## Minor / Code Quality
|
||||||
|
|
||||||
|
### 9. Limited Test Coverage
|
||||||
|
**Issue**: Only `NovelService.Tests` exists. No integration tests for event handlers.
|
||||||
|
|
||||||
|
**Recommendation**: Add unit and integration tests for each service, especially event handlers.
|
||||||
|
|
||||||
|
### 10. Inconsistent Port Configuration
|
||||||
|
**Issue**: Some services use 8080 (HTTP), others 8081 (HTTPS).
|
||||||
|
|
||||||
|
**Recommendation**: Standardize on HTTPS with proper cert management.
|
||||||
|
|
||||||
|
### 11. No API Versioning
|
||||||
|
**Issue**: GraphQL schemas have no versioning strategy.
|
||||||
|
|
||||||
|
**Recommendation**: Consider schema versioning or deprecation annotations for breaking changes.
|
||||||
|
|
||||||
|
### 12. Frontend - No Error Boundary
|
||||||
|
**Issue**: React app lacks error boundaries for graceful failure handling.
|
||||||
|
|
||||||
|
**Recommendation**: Add React Error Boundaries around routes.
|
||||||
|
|
||||||
|
### 13. Missing Health Check Depth
|
||||||
|
**Issue**: Health checks only verify service is running, not dependencies.
|
||||||
|
|
||||||
|
**Recommendation**: Add database, RabbitMQ, and S3 health checks:
|
||||||
|
```csharp
|
||||||
|
builder.Services.AddHealthChecks()
|
||||||
|
.AddNpgSql(connectionString)
|
||||||
|
.AddRabbitMQ()
|
||||||
|
.AddS3(options => { });
|
||||||
|
```
|
||||||
|
|
||||||
|
### 14. Synchronous File Operations in Event Handlers
|
||||||
|
**Issue**: File uploads may block event handling thread for large files.
|
||||||
|
|
||||||
|
**Recommendation**: Consider async streaming for large files.
|
||||||
|
|
||||||
|
## Architectural Suggestions
|
||||||
|
|
||||||
|
### 15. Consider Outbox Pattern
|
||||||
|
**Issue**: Publishing events and saving to DB aren't transactional, could lead to inconsistent state.
|
||||||
|
|
||||||
|
**Recommendation**: Implement transactional outbox pattern for guaranteed delivery:
|
||||||
|
```
|
||||||
|
1. Save entity + outbox message in same transaction
|
||||||
|
2. Background worker publishes from outbox
|
||||||
|
3. Delete outbox message after successful publish
|
||||||
|
```
|
||||||
|
|
||||||
|
### 16. Gateway Schema Build Process
|
||||||
|
**Issue**: Python script (`build_gateway.py`) for schema composition requires manual execution.
|
||||||
|
|
||||||
|
**Recommendation**: Integrate into CI/CD pipeline or consider runtime schema polling.
|
||||||
|
|
||||||
|
### 17. Secret Management
|
||||||
|
**Issue**: Credentials in appsettings files.
|
||||||
|
|
||||||
|
**Recommendation**: Use Azure Key Vault, AWS Secrets Manager, HashiCorp Vault, or similar secret management solution.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Key Files Reference
|
||||||
|
|
||||||
|
| File | Purpose |
|
||||||
|
|------|---------|
|
||||||
|
| `FictionArchive.API/Program.cs` | Gateway setup |
|
||||||
|
| `FictionArchive.API/build_gateway.py` | Schema composition script |
|
||||||
|
| `FictionArchive.Service.Shared/Services/EventBus/` | Event bus implementation |
|
||||||
|
| `FictionArchive.Service.Shared/Extensions/` | Service registration helpers |
|
||||||
|
| `FictionArchive.Service.Shared/Services/Database/` | DB infrastructure |
|
||||||
|
| `fictionarchive-web/src/auth/AuthContext.tsx` | Frontend auth state |
|
||||||
297
Documentation/CICD.md
Normal file
297
Documentation/CICD.md
Normal file
@@ -0,0 +1,297 @@
|
|||||||
|
# CI/CD Configuration
|
||||||
|
|
||||||
|
This document describes the CI/CD pipeline configuration for FictionArchive using Gitea Actions.
|
||||||
|
|
||||||
|
## Workflows Overview
|
||||||
|
|
||||||
|
| Workflow | File | Trigger | Purpose |
|
||||||
|
|----------|------|---------|---------|
|
||||||
|
| CI | `build.yml` | Push/PR to master | Build and test all projects |
|
||||||
|
| 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
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────────────────────────────────────────────┐
|
||||||
|
│ Push to master │
|
||||||
|
└─────────────────────────────┬───────────────────────────────────────┘
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
┌─────────────────────────┐
|
||||||
|
│ 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 │
|
||||||
|
└─────────────────────────────┬───────────────────────────────────────┘
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
┌─────────────────────────┐
|
||||||
|
│ claude_assistant.yml │
|
||||||
|
│ (AI code assistance) │
|
||||||
|
└─────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## Required Configuration
|
||||||
|
|
||||||
|
### Repository Secrets
|
||||||
|
|
||||||
|
Configure these in **Settings → Actions → Secrets**:
|
||||||
|
|
||||||
|
| Secret | Description | Required By |
|
||||||
|
|--------|-------------|-------------|
|
||||||
|
| `REGISTRY_TOKEN` | Gitea access token with `write:package` scope | `release.yml`, `build-gateway.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` - For Claude assistant to push commits
|
||||||
|
3. Copy the token and add it as a repository secret
|
||||||
|
|
||||||
|
### Repository Variables
|
||||||
|
|
||||||
|
Configure these in **Settings → Actions → Variables**:
|
||||||
|
|
||||||
|
| Variable | Description | Example | Required By |
|
||||||
|
|----------|-------------|---------|-------------|
|
||||||
|
| `VITE_GRAPHQL_URI` | GraphQL API endpoint URL | `https://api.fictionarchive.example.com/graphql/` | `release.yml` |
|
||||||
|
| `VITE_OIDC_AUTHORITY` | OIDC provider authority URL | `https://auth.example.com/application/o/fiction-archive/` | `release.yml` |
|
||||||
|
| `VITE_OIDC_CLIENT_ID` | OIDC client identifier | `your-client-id` | `release.yml` |
|
||||||
|
| `VITE_OIDC_REDIRECT_URI` | Post-login redirect URL | `https://fictionarchive.example.com/` | `release.yml` |
|
||||||
|
| `VITE_OIDC_POST_LOGOUT_REDIRECT_URI` | Post-logout redirect URL | `https://fictionarchive.example.com/` | `release.yml` |
|
||||||
|
|
||||||
|
## Workflow Details
|
||||||
|
|
||||||
|
### CI (`build.yml`)
|
||||||
|
|
||||||
|
**Trigger:** Push or pull request to `master`
|
||||||
|
|
||||||
|
**Jobs:**
|
||||||
|
1. `build-backend` - Builds .NET solution and runs tests
|
||||||
|
2. `build-frontend` - Builds React application with linting
|
||||||
|
|
||||||
|
**Requirements:**
|
||||||
|
- .NET 8.0 SDK
|
||||||
|
- Node.js 20
|
||||||
|
|
||||||
|
**Steps (Backend):**
|
||||||
|
1. Checkout repository
|
||||||
|
2. Setup .NET 8.0
|
||||||
|
3. Restore dependencies
|
||||||
|
4. Build solution (Release, with `SkipFusionBuild=true`)
|
||||||
|
5. Run tests
|
||||||
|
|
||||||
|
**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 tag matching `v*.*.*`
|
||||||
|
|
||||||
|
**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`
|
||||||
|
- `<registry>/<owner>/fictionarchive-api:<commit-sha>`
|
||||||
|
|
||||||
|
### Release (`release.yml`)
|
||||||
|
|
||||||
|
**Trigger:** Push tag matching `v*.*.*` (e.g., `v1.0.0`)
|
||||||
|
|
||||||
|
**Jobs:**
|
||||||
|
|
||||||
|
#### 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:
|
||||||
|
```
|
||||||
|
<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
|
||||||
|
# Login to registry
|
||||||
|
docker login <gitea-server-url> -u <username> -p <token>
|
||||||
|
|
||||||
|
# Pull an image
|
||||||
|
docker pull <gitea-server-url>/<owner>/fictionarchive-api:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Creating a Release
|
||||||
|
|
||||||
|
1. Ensure all changes are committed and pushed to `master`
|
||||||
|
2. Create and push a version tag:
|
||||||
|
```bash
|
||||||
|
git tag v1.0.0
|
||||||
|
git push origin v1.0.0
|
||||||
|
```
|
||||||
|
3. The release workflow will automatically build and push all images
|
||||||
|
4. Monitor progress in **Actions** tab
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Build Failures
|
||||||
|
|
||||||
|
**"REGISTRY_TOKEN secret not found"**
|
||||||
|
- Ensure the `REGISTRY_TOKEN` secret is configured in repository settings
|
||||||
|
- Verify the token has `write:package` scope
|
||||||
|
|
||||||
|
**"No subgraph artifacts found"**
|
||||||
|
- 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
|
||||||
|
|
||||||
|
**"VITE_* variables are empty"**
|
||||||
|
- Ensure all required variables are configured in repository settings
|
||||||
|
- Variables use `vars.*` context, not `secrets.*`
|
||||||
|
|
||||||
|
### Docker Push Failures
|
||||||
|
|
||||||
|
**"unauthorized: authentication required"**
|
||||||
|
- 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:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install act (GitHub Actions local runner)
|
||||||
|
# Note: act has partial Gitea Actions compatibility
|
||||||
|
|
||||||
|
# Run CI workflow
|
||||||
|
act push -W .gitea/workflows/build.yml
|
||||||
|
|
||||||
|
# Run with specific event
|
||||||
|
act push --eventpath .gitea/test-event.json
|
||||||
|
```
|
||||||
187
Documentation/README.md
Normal file
187
Documentation/README.md
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
# FictionArchive
|
||||||
|
|
||||||
|
A distributed microservices-based web application for managing fiction and novel content. Features include importing from external sources, multi-language translation, file storage, and user management.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
FictionArchive uses a GraphQL Fusion gateway pattern to orchestrate multiple domain services with event-driven communication via RabbitMQ.
|
||||||
|
More information available in [ARCHITECTURE.md](ARCHITECTURE.md)
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- .NET SDK 8.0+
|
||||||
|
- Node.js 20+
|
||||||
|
- Python 3 (for gateway build script)
|
||||||
|
- Docker & Docker Compose
|
||||||
|
- PostgreSQL 16+
|
||||||
|
- RabbitMQ 3+
|
||||||
|
|
||||||
|
**Required CLI Tools**
|
||||||
|
```bash
|
||||||
|
# Hot Chocolate Fusion CLI
|
||||||
|
dotnet tool install -g HotChocolate.Fusion.CommandLine
|
||||||
|
```
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
### Local Development
|
||||||
|
|
||||||
|
1. **Clone the repository**
|
||||||
|
```bash
|
||||||
|
git clone <repository-url>
|
||||||
|
cd FictionArchive
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Start infrastructure** (PostgreSQL, RabbitMQ)
|
||||||
|
```bash
|
||||||
|
docker compose up -d postgres rabbitmq
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Build and run backend**
|
||||||
|
```bash
|
||||||
|
dotnet restore
|
||||||
|
dotnet build FictionArchive.sln
|
||||||
|
|
||||||
|
# Start services (in separate terminals or use a process manager)
|
||||||
|
dotnet run --project FictionArchive.Service.NovelService
|
||||||
|
dotnet run --project FictionArchive.Service.UserService
|
||||||
|
dotnet run --project FictionArchive.Service.TranslationService
|
||||||
|
dotnet run --project FictionArchive.Service.FileService
|
||||||
|
dotnet run --project FictionArchive.Service.SchedulerService
|
||||||
|
dotnet run --project FictionArchive.Service.AuthenticationService
|
||||||
|
|
||||||
|
# Start the gateway (builds fusion schema automatically)
|
||||||
|
dotnet run --project FictionArchive.API
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Build and run frontend**
|
||||||
|
```bash
|
||||||
|
cd fictionarchive-web
|
||||||
|
npm install
|
||||||
|
npm run codegen # Generate GraphQL types
|
||||||
|
npm run dev # Start dev server at http://localhost:5173
|
||||||
|
```
|
||||||
|
|
||||||
|
### Docker Deployment
|
||||||
|
|
||||||
|
1. **Create environment file**
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
# Edit .env with your configuration
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Start all services**
|
||||||
|
```bash
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
### Environment Variables
|
||||||
|
|
||||||
|
Create a `.env` file in the project root:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# PostgreSQL
|
||||||
|
POSTGRES_USER=postgres
|
||||||
|
POSTGRES_PASSWORD=your-secure-password
|
||||||
|
|
||||||
|
# RabbitMQ
|
||||||
|
RABBITMQ_USER=guest
|
||||||
|
RABBITMQ_PASSWORD=your-secure-password
|
||||||
|
|
||||||
|
# External Services
|
||||||
|
NOVELPIA_USERNAME=your-username
|
||||||
|
NOVELPIA_PASSWORD=your-password
|
||||||
|
DEEPL_API_KEY=your-api-key
|
||||||
|
|
||||||
|
# S3 Storage
|
||||||
|
S3_ENDPOINT=https://s3.example.com
|
||||||
|
S3_BUCKET=fictionarchive
|
||||||
|
S3_ACCESS_KEY=your-access-key
|
||||||
|
S3_SECRET_KEY=your-secret-key
|
||||||
|
|
||||||
|
# OIDC Authentication
|
||||||
|
OIDC_AUTHORITY=https://auth.example.com/application/o/fiction-archive/
|
||||||
|
OIDC_CLIENT_ID=your-client-id
|
||||||
|
```
|
||||||
|
|
||||||
|
### Frontend Environment
|
||||||
|
|
||||||
|
Create `fictionarchive-web/.env.local`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
VITE_GRAPHQL_URI=http://localhost:5234/graphql/
|
||||||
|
VITE_OIDC_AUTHORITY=https://auth.example.com/application/o/fiction-archive/
|
||||||
|
VITE_OIDC_CLIENT_ID=your-client-id
|
||||||
|
VITE_OIDC_REDIRECT_URI=http://localhost:5173/
|
||||||
|
VITE_OIDC_POST_LOGOUT_REDIRECT_URI=http://localhost:5173/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Building the GraphQL Gateway
|
||||||
|
|
||||||
|
The API gateway uses Hot Chocolate Fusion to compose schemas from all subgraphs. The gateway schema is rebuilt automatically when building the API project.
|
||||||
|
|
||||||
|
**Manual rebuild:**
|
||||||
|
```bash
|
||||||
|
cd FictionArchive.API
|
||||||
|
python build_gateway.py
|
||||||
|
```
|
||||||
|
|
||||||
|
**Skip specific services** by adding them to `FictionArchive.API/gateway_skip.txt`:
|
||||||
|
```
|
||||||
|
FictionArchive.Service.NovelService.Tests
|
||||||
|
```
|
||||||
|
|
||||||
|
## CI/CD
|
||||||
|
|
||||||
|
The project uses Gitea Actions with the following workflows:
|
||||||
|
|
||||||
|
| Workflow | Trigger | Description |
|
||||||
|
|----------|---------|-------------|
|
||||||
|
| `build.yml` | Push/PR to master | CI checks - builds and tests |
|
||||||
|
| `build-subgraphs.yml` | Service changes on master | Builds subgraph `.fsp` packages |
|
||||||
|
| `build-gateway.yml` | Gateway changes or subgraph builds | Composes gateway and builds Docker image |
|
||||||
|
| `release.yml` | Tag `v*.*.*` | Builds and pushes all Docker images |
|
||||||
|
|
||||||
|
### Release Process
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git tag v1.0.0
|
||||||
|
git push origin v1.0.0
|
||||||
|
```
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
FictionArchive/
|
||||||
|
├── FictionArchive.sln
|
||||||
|
├── FictionArchive.Common/ # Shared enums and extensions
|
||||||
|
├── FictionArchive.Service.Shared/ # Shared infrastructure (EventBus, DB)
|
||||||
|
├── FictionArchive.API/ # GraphQL Fusion Gateway
|
||||||
|
├── FictionArchive.Service.NovelService/
|
||||||
|
├── FictionArchive.Service.UserService/
|
||||||
|
├── FictionArchive.Service.TranslationService/
|
||||||
|
├── FictionArchive.Service.FileService/
|
||||||
|
├── FictionArchive.Service.SchedulerService/
|
||||||
|
├── FictionArchive.Service.AuthenticationService/
|
||||||
|
├── FictionArchive.Service.NovelService.Tests/
|
||||||
|
├── fictionarchive-web/ # React frontend
|
||||||
|
├── docker-compose.yml
|
||||||
|
└── .gitea/workflows/ # CI/CD workflows
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run all tests
|
||||||
|
dotnet test FictionArchive.sln
|
||||||
|
|
||||||
|
# Run specific test project
|
||||||
|
dotnet test FictionArchive.Service.NovelService.Tests
|
||||||
|
```
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
- [ARCHITECTURE.md](ARCHITECTURE.md) - Detailed architecture documentation
|
||||||
|
- [AGENTS.md](AGENTS.md) - Development guidelines and coding standards
|
||||||
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
@@ -7,15 +7,25 @@ EXPOSE 8081
|
|||||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
ARG BUILD_CONFIGURATION=Release
|
ARG BUILD_CONFIGURATION=Release
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
COPY ["FictionArchive.API/FictionArchive.API.csproj", "FictionArchive.API/"]
|
COPY ["FictionArchive.API/FictionArchive.API.csproj", "FictionArchive.API/"]
|
||||||
|
COPY ["FictionArchive.Common/FictionArchive.Common.csproj", "FictionArchive.Common/"]
|
||||||
|
COPY ["FictionArchive.Service.Shared/FictionArchive.Service.Shared.csproj", "FictionArchive.Service.Shared/"]
|
||||||
RUN dotnet restore "FictionArchive.API/FictionArchive.API.csproj"
|
RUN dotnet restore "FictionArchive.API/FictionArchive.API.csproj"
|
||||||
COPY . .
|
|
||||||
|
COPY FictionArchive.API/ FictionArchive.API/
|
||||||
|
COPY FictionArchive.Common/ FictionArchive.Common/
|
||||||
|
COPY FictionArchive.Service.Shared/ FictionArchive.Service.Shared/
|
||||||
|
|
||||||
WORKDIR "/src/FictionArchive.API"
|
WORKDIR "/src/FictionArchive.API"
|
||||||
RUN dotnet build "./FictionArchive.API.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
# Skip fusion build - gateway.fgp should be pre-composed in CI
|
||||||
|
RUN dotnet build "./FictionArchive.API.csproj" -c $BUILD_CONFIGURATION -o /app/build -p:SkipFusionBuild=true
|
||||||
|
|
||||||
FROM build AS publish
|
FROM build AS publish
|
||||||
ARG BUILD_CONFIGURATION=Release
|
ARG BUILD_CONFIGURATION=Release
|
||||||
RUN dotnet publish "./FictionArchive.API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
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
|
FROM base AS final
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="15.1.11" />
|
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="15.1.11" />
|
||||||
<PackageReference Include="HotChocolate.Fusion" Version="15.1.11" />
|
<PackageReference Include="HotChocolate.Fusion" Version="15.1.11" />
|
||||||
<PackageReference Include="HotChocolate.Types.Scalars" 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">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.11">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
@@ -20,11 +21,12 @@
|
|||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.11" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.11" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.7" />
|
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.7" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.11" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Builds the Fusion graph file before building the application itself -->
|
<!-- Builds the Fusion graph file before building the application itself (skipped in CI) -->
|
||||||
<Target Name="RunFusionBuild" BeforeTargets="BeforeBuild">
|
<Target Name="RunFusionBuild" BeforeTargets="BeforeBuild" Condition="'$(SkipFusionBuild)' != 'true'">
|
||||||
<Exec Command="python build_gateway.py" WorkingDirectory="$(ProjectDir)" />
|
<Exec Command="python build_gateway.py $(FusionBuildArgs)" WorkingDirectory="$(ProjectDir)" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -12,7 +12,13 @@ public class Program
|
|||||||
|
|
||||||
#region Fusion Gateway
|
#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
|
builder.Services
|
||||||
.AddFusionGatewayServer()
|
.AddFusionGatewayServer()
|
||||||
@@ -21,14 +27,29 @@ public class Program
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
var allowedOrigin = builder.Configuration["Cors:AllowedOrigin"] ?? "http://localhost:4321";
|
||||||
|
builder.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy("AllowFictionArchiveOrigins",
|
||||||
|
policyBuilder =>
|
||||||
|
{
|
||||||
|
policyBuilder.WithOrigins(allowedOrigin)
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowAnyHeader()
|
||||||
|
.AllowCredentials();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseCors("AllowFictionArchiveOrigins");
|
||||||
|
|
||||||
app.MapHealthChecks("/healthz");
|
app.MapHealthChecks("/healthz");
|
||||||
|
|
||||||
|
app.UseHeaderPropagation();
|
||||||
|
|
||||||
app.MapGraphQL();
|
app.MapGraphQL();
|
||||||
|
|
||||||
app.Run();
|
app.RunWithGraphQLCommands(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,18 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"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,12 +1,22 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Local development script for building the Fusion gateway.
|
||||||
|
|
||||||
|
This script is used for local development only. In CI/CD, subgraphs are built
|
||||||
|
separately and the gateway is composed from pre-built .fsp artifacts.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
python build_gateway.py
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
- .NET 8.0 SDK
|
||||||
|
- HotChocolate Fusion CLI (dotnet tool install -g HotChocolate.Fusion.CommandLine)
|
||||||
|
"""
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# ----------------------------------------
|
|
||||||
# Helpers
|
|
||||||
# ----------------------------------------
|
|
||||||
|
|
||||||
def run(cmd, cwd=None):
|
def run(cmd, cwd=None):
|
||||||
"""Run a command and exit on failure."""
|
"""Run a command and exit on failure."""
|
||||||
@@ -19,7 +29,7 @@ def run(cmd, cwd=None):
|
|||||||
|
|
||||||
def load_skip_list(skip_file: Path):
|
def load_skip_list(skip_file: Path):
|
||||||
if not skip_file.exists():
|
if not skip_file.exists():
|
||||||
print(f"WARNING: skip-projects.txt not found at {skip_file}")
|
print(f"WARNING: gateway_skip.txt not found at {skip_file}")
|
||||||
return set()
|
return set()
|
||||||
|
|
||||||
lines = skip_file.read_text().splitlines()
|
lines = skip_file.read_text().splitlines()
|
||||||
@@ -53,7 +63,7 @@ print("----------------------------------------")
|
|||||||
|
|
||||||
service_dirs = [
|
service_dirs = [
|
||||||
d for d in services_dir.glob("FictionArchive.Service.*")
|
d for d in services_dir.glob("FictionArchive.Service.*")
|
||||||
if d.is_dir()
|
if d.is_dir() and (d / "subgraph-config.json").exists()
|
||||||
]
|
]
|
||||||
|
|
||||||
selected_services = []
|
selected_services = []
|
||||||
|
|||||||
@@ -2,3 +2,4 @@
|
|||||||
FictionArchive.Service.Shared
|
FictionArchive.Service.Shared
|
||||||
FictionArchive.Service.AuthenticationService
|
FictionArchive.Service.AuthenticationService
|
||||||
FictionArchive.Service.FileService
|
FictionArchive.Service.FileService
|
||||||
|
FictionArchive.Service.NovelService.Tests
|
||||||
|
|||||||
@@ -9,14 +9,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.11" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.11" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.11" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.11" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.0" />
|
||||||
<PackageReference Include="NodaTime" Version="3.2.2" />
|
<PackageReference Include="NodaTime" Version="3.2.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="Microsoft.Extensions.Configuration.Abstractions" />
|
|
||||||
<Reference Include="Microsoft.Extensions.Hosting.Abstractions">
|
|
||||||
<HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.AspNetCore.App\8.0.15\Microsoft.Extensions.Hosting.Abstractions.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Web;
|
|||||||
using Amazon.S3;
|
using Amazon.S3;
|
||||||
using Amazon.S3.Model;
|
using Amazon.S3.Model;
|
||||||
using FictionArchive.Service.FileService.Models;
|
using FictionArchive.Service.FileService.Models;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
@@ -10,6 +11,7 @@ namespace FictionArchive.Service.FileService.Controllers
|
|||||||
{
|
{
|
||||||
[Route("api/{*path}")]
|
[Route("api/{*path}")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
public class S3ProxyController : ControllerBase
|
public class S3ProxyController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly AmazonS3Client _amazonS3Client;
|
private readonly AmazonS3Client _amazonS3Client;
|
||||||
@@ -34,7 +36,15 @@ namespace FictionArchive.Service.FileService.Controllers
|
|||||||
Key = decodedPath
|
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)
|
catch (AmazonS3Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,17 +7,17 @@ EXPOSE 8081
|
|||||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
ARG BUILD_CONFIGURATION=Release
|
ARG BUILD_CONFIGURATION=Release
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY ["FictionArchive.Service.ImageService/FictionArchive.Service.ImageService.csproj", "FictionArchive.Service.ImageService/"]
|
COPY ["FictionArchive.Service.FileService/FictionArchive.Service.FileService.csproj", "FictionArchive.Service.FileService/"]
|
||||||
RUN dotnet restore "FictionArchive.Service.ImageService/FictionArchive.Service.ImageService.csproj"
|
RUN dotnet restore "FictionArchive.Service.FileService/FictionArchive.Service.FileService.csproj"
|
||||||
COPY . .
|
COPY . .
|
||||||
WORKDIR "/src/FictionArchive.Service.ImageService"
|
WORKDIR "/src/FictionArchive.Service.FileService"
|
||||||
RUN dotnet build "./FictionArchive.Service.ImageService.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
RUN dotnet build "./FictionArchive.Service.FileService.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
FROM build AS publish
|
FROM build AS publish
|
||||||
ARG BUILD_CONFIGURATION=Release
|
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
|
FROM base AS final
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=publish /app/publish .
|
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="AWSSDK.S3" Version="4.0.13.1" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
|
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.11" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ public class Program
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
// Add authentication with cookie support
|
||||||
|
builder.Services.AddOidcCookieAuthentication(builder.Configuration);
|
||||||
|
builder.Services.AddFictionArchiveAuthorization();
|
||||||
|
|
||||||
builder.Services.Configure<ProxyConfiguration>(builder.Configuration.GetSection("ProxyConfiguration"));
|
builder.Services.Configure<ProxyConfiguration>(builder.Configuration.GetSection("ProxyConfiguration"));
|
||||||
|
|
||||||
// Add S3 Client
|
// Add S3 Client
|
||||||
@@ -60,6 +64,9 @@ public class Program
|
|||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.UseAuthentication();
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapHealthChecks("/healthz");
|
app.MapHealthChecks("/healthz");
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|||||||
@@ -18,5 +18,15 @@
|
|||||||
"AccessKey": "REPLACE_ME",
|
"AccessKey": "REPLACE_ME",
|
||||||
"SecretKey": "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": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,13 @@ public class NovelUpdateServiceTests
|
|||||||
Images = new List<Image>()
|
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
|
var novel = new Novel
|
||||||
{
|
{
|
||||||
Url = "http://demo/novel",
|
Url = "http://demo/novel",
|
||||||
@@ -52,14 +59,14 @@ public class NovelUpdateServiceTests
|
|||||||
Source = source,
|
Source = source,
|
||||||
Name = LocalizationKey.CreateFromText("Demo Novel", Language.En),
|
Name = LocalizationKey.CreateFromText("Demo Novel", Language.En),
|
||||||
Description = LocalizationKey.CreateFromText("Description", Language.En),
|
Description = LocalizationKey.CreateFromText("Description", Language.En),
|
||||||
Chapters = new List<Chapter> { chapter },
|
Volumes = new List<Volume> { volume },
|
||||||
Tags = new List<NovelTag>()
|
Tags = new List<NovelTag>()
|
||||||
};
|
};
|
||||||
|
|
||||||
dbContext.Novels.Add(novel);
|
dbContext.Novels.Add(novel);
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
return new NovelCreateResult(novel, chapter);
|
return new NovelCreateResult(novel, volume, chapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NovelUpdateService CreateService(
|
private static NovelUpdateService CreateService(
|
||||||
@@ -81,7 +88,7 @@ public class NovelUpdateServiceTests
|
|||||||
{
|
{
|
||||||
using var dbContext = CreateDbContext();
|
using var dbContext = CreateDbContext();
|
||||||
var source = new Source { Name = "Demo", Key = "demo", Url = "http://demo" };
|
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 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 } };
|
var image1 = new ImageData { Url = "http://img/x1.jpg", Data = new byte[] { 1, 2, 3 } };
|
||||||
@@ -103,7 +110,7 @@ public class NovelUpdateServiceTests
|
|||||||
var pendingImageUrl = "https://pending/placeholder.jpg";
|
var pendingImageUrl = "https://pending/placeholder.jpg";
|
||||||
var service = CreateService(dbContext, adapter, eventBus, pendingImageUrl);
|
var service = CreateService(dbContext, adapter, eventBus, pendingImageUrl);
|
||||||
|
|
||||||
var updatedChapter = await service.PullChapterContents(novel.Id, chapter.Order);
|
var updatedChapter = await service.PullChapterContents(novel.Id, volume.Id, chapter.Order);
|
||||||
|
|
||||||
updatedChapter.Images.Should().HaveCount(2);
|
updatedChapter.Images.Should().HaveCount(2);
|
||||||
updatedChapter.Images.Select(i => i.OriginalPath).Should().BeEquivalentTo(new[] { image1.Url, image2.Url });
|
updatedChapter.Images.Select(i => i.OriginalPath).Should().BeEquivalentTo(new[] { image1.Url, image2.Url });
|
||||||
@@ -131,7 +138,7 @@ public class NovelUpdateServiceTests
|
|||||||
{
|
{
|
||||||
using var dbContext = CreateDbContext();
|
using var dbContext = CreateDbContext();
|
||||||
var source = new Source { Name = "Demo", Key = "demo", Url = "http://demo" };
|
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 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 } };
|
var image = new ImageData { Url = "http://img/x1.jpg", Data = new byte[] { 7, 8, 9 } };
|
||||||
@@ -150,7 +157,7 @@ public class NovelUpdateServiceTests
|
|||||||
|
|
||||||
var service = CreateService(dbContext, adapter, eventBus);
|
var service = CreateService(dbContext, adapter, eventBus);
|
||||||
|
|
||||||
var updatedChapter = await service.PullChapterContents(novel.Id, chapter.Order);
|
var updatedChapter = await service.PullChapterContents(novel.Id, volume.Id, chapter.Order);
|
||||||
|
|
||||||
var storedHtml = updatedChapter.Body.Texts.Single().Text;
|
var storedHtml = updatedChapter.Body.Texts.Single().Text;
|
||||||
var doc = new HtmlDocument();
|
var doc = new HtmlDocument();
|
||||||
@@ -161,5 +168,139 @@ public class NovelUpdateServiceTests
|
|||||||
imgNode.GetAttributeValue("src", string.Empty).Should().Be("https://pending/placeholder.jpg");
|
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 eventBus = Substitute.For<IEventBus>();
|
||||||
|
var service = CreateService(dbContext, adapter, eventBus);
|
||||||
|
|
||||||
|
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 eventBus = Substitute.For<IEventBus>();
|
||||||
|
var service = CreateService(dbContext, adapter, eventBus, 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 eventBus = Substitute.For<IEventBus>();
|
||||||
|
var service = CreateService(dbContext, adapter, eventBus, 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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,32 +6,35 @@ using FictionArchive.Service.NovelService.Models.SourceAdapters;
|
|||||||
using FictionArchive.Service.NovelService.Services;
|
using FictionArchive.Service.NovelService.Services;
|
||||||
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
||||||
using FictionArchive.Service.Shared.Services.EventBus;
|
using FictionArchive.Service.Shared.Services.EventBus;
|
||||||
|
using HotChocolate.Authorization;
|
||||||
|
using HotChocolate.Types;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace FictionArchive.Service.NovelService.GraphQL;
|
namespace FictionArchive.Service.NovelService.GraphQL;
|
||||||
|
|
||||||
public class Mutation
|
public class Mutation
|
||||||
{
|
{
|
||||||
public async Task<NovelUpdateRequestedEvent> ImportNovel(string novelUrl, IEventBus eventBus)
|
[Authorize]
|
||||||
|
public async Task<NovelUpdateRequestedEvent> ImportNovel(string novelUrl, NovelUpdateService service)
|
||||||
{
|
{
|
||||||
var importNovelRequestEvent = new NovelUpdateRequestedEvent()
|
return await service.QueueNovelImport(novelUrl);
|
||||||
{
|
|
||||||
NovelUrl = novelUrl
|
|
||||||
};
|
|
||||||
await eventBus.Publish(importNovelRequestEvent);
|
|
||||||
return importNovelRequestEvent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ChapterPullRequestedEvent> FetchChapterContents(uint novelId,
|
[Authorize]
|
||||||
uint chapterNumber,
|
public async Task<ChapterPullRequestedEvent> FetchChapterContents(
|
||||||
IEventBus eventBus)
|
uint novelId,
|
||||||
|
uint volumeId,
|
||||||
|
uint chapterOrder,
|
||||||
|
NovelUpdateService service)
|
||||||
{
|
{
|
||||||
var chapterPullEvent = new ChapterPullRequestedEvent()
|
return await service.QueueChapterPull(novelId, volumeId, chapterOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Error<KeyNotFoundException>]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<bool> DeleteNovel(uint novelId, NovelUpdateService service)
|
||||||
{
|
{
|
||||||
NovelId = novelId,
|
await service.DeleteNovel(novelId);
|
||||||
ChapterNumber = chapterNumber
|
return true;
|
||||||
};
|
|
||||||
await eventBus.Publish(chapterPullEvent);
|
|
||||||
return chapterPullEvent;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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 FictionArchive.Service.NovelService.Services;
|
||||||
|
using HotChocolate.Authorization;
|
||||||
using HotChocolate.Data;
|
using HotChocolate.Data;
|
||||||
using HotChocolate.Types;
|
using HotChocolate.Types;
|
||||||
|
|
||||||
@@ -7,12 +9,255 @@ namespace FictionArchive.Service.NovelService.GraphQL;
|
|||||||
|
|
||||||
public class Query
|
public class Query
|
||||||
{
|
{
|
||||||
|
[Authorize]
|
||||||
[UsePaging]
|
[UsePaging]
|
||||||
[UseProjection]
|
[UseProjection]
|
||||||
[UseFiltering]
|
[UseFiltering]
|
||||||
[UseSorting]
|
[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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -153,9 +153,6 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
b.Property<Guid>("NameId")
|
b.Property<Guid>("NameId")
|
||||||
.HasColumnType("uuid");
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
b.Property<long?>("NovelId")
|
|
||||||
.HasColumnType("bigint");
|
|
||||||
|
|
||||||
b.Property<long>("Order")
|
b.Property<long>("Order")
|
||||||
.HasColumnType("bigint");
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
@@ -165,13 +162,17 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
b.Property<string>("Url")
|
b.Property<string>("Url")
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<long>("VolumeId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("BodyId");
|
b.HasIndex("BodyId");
|
||||||
|
|
||||||
b.HasIndex("NameId");
|
b.HasIndex("NameId");
|
||||||
|
|
||||||
b.HasIndex("NovelId");
|
b.HasIndex("VolumeId", "Order")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
b.ToTable("Chapter");
|
b.ToTable("Chapter");
|
||||||
});
|
});
|
||||||
@@ -234,6 +235,9 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
|
|
||||||
b.HasIndex("SourceId");
|
b.HasIndex("SourceId");
|
||||||
|
|
||||||
|
b.HasIndex("ExternalId", "SourceId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
b.ToTable("Novels");
|
b.ToTable("Novels");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -354,6 +358,39 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
b.ToTable("TranslationEngines");
|
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 =>
|
modelBuilder.Entity("NovelNovelTag", b =>
|
||||||
{
|
{
|
||||||
b.Property<long>("NovelsId")
|
b.Property<long>("NovelsId")
|
||||||
@@ -424,13 +461,17 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", null)
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Volume", "Volume")
|
||||||
.WithMany("Chapters")
|
.WithMany("Chapters")
|
||||||
.HasForeignKey("NovelId");
|
.HasForeignKey("VolumeId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Body");
|
b.Navigation("Body");
|
||||||
|
|
||||||
b.Navigation("Name");
|
b.Navigation("Name");
|
||||||
|
|
||||||
|
b.Navigation("Volume");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||||
@@ -502,6 +543,25 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
b.Navigation("Name");
|
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 =>
|
modelBuilder.Entity("NovelNovelTag", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", null)
|
b.HasOne("FictionArchive.Service.NovelService.Models.Novels.Novel", null)
|
||||||
@@ -528,6 +588,11 @@ namespace FictionArchive.Service.NovelService.Migrations
|
|||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Novel", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Volumes");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.NovelService.Models.Novels.Volume", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Chapters");
|
b.Navigation("Chapters");
|
||||||
});
|
});
|
||||||
|
|||||||
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; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using FictionArchive.Service.Shared.Services.EventBus;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||||
|
|
||||||
|
public class ChapterCreatedEvent : IIntegrationEvent
|
||||||
|
{
|
||||||
|
public required uint ChapterId { get; init; }
|
||||||
|
public required uint NovelId { get; init; }
|
||||||
|
public required uint VolumeId { get; init; }
|
||||||
|
public required int VolumeOrder { get; init; }
|
||||||
|
public required uint ChapterOrder { get; init; }
|
||||||
|
public required string ChapterTitle { get; init; }
|
||||||
|
}
|
||||||
@@ -5,5 +5,6 @@ namespace FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
|||||||
public class ChapterPullRequestedEvent : IIntegrationEvent
|
public class ChapterPullRequestedEvent : IIntegrationEvent
|
||||||
{
|
{
|
||||||
public uint NovelId { get; set; }
|
public uint NovelId { get; set; }
|
||||||
public uint ChapterNumber { get; set; }
|
public uint VolumeId { get; set; }
|
||||||
|
public uint ChapterOrder { get; set; }
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using FictionArchive.Common.Enums;
|
||||||
|
using FictionArchive.Service.Shared.Services.EventBus;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||||
|
|
||||||
|
public class NovelCreatedEvent : IIntegrationEvent
|
||||||
|
{
|
||||||
|
public required uint NovelId { get; init; }
|
||||||
|
public required string Title { get; init; }
|
||||||
|
public required Language OriginalLanguage { get; init; }
|
||||||
|
public required string Source { get; init; }
|
||||||
|
public required string AuthorName { get; init; }
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using FictionArchive.Service.NovelService.Models.Images;
|
using FictionArchive.Service.NovelService.Models.Images;
|
||||||
using FictionArchive.Service.NovelService.Models.Localization;
|
using FictionArchive.Service.NovelService.Models.Localization;
|
||||||
using FictionArchive.Service.Shared.Models;
|
using FictionArchive.Service.Shared.Models;
|
||||||
|
|
||||||
namespace FictionArchive.Service.NovelService.Models.Novels;
|
namespace FictionArchive.Service.NovelService.Models.Novels;
|
||||||
|
|
||||||
|
[Table("Chapter")]
|
||||||
public class Chapter : BaseEntity<uint>
|
public class Chapter : BaseEntity<uint>
|
||||||
{
|
{
|
||||||
public uint Revision { get; set; }
|
public uint Revision { get; set; }
|
||||||
@@ -15,4 +17,10 @@ public class Chapter : BaseEntity<uint>
|
|||||||
|
|
||||||
// Images appearing in this chapter.
|
// Images appearing in this chapter.
|
||||||
public List<Image> Images { get; set; }
|
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 Name { get; set; }
|
||||||
public LocalizationKey Description { 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 List<NovelTag> Tags { get; set; }
|
||||||
public Image? CoverImage { 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 Language RawLanguage { get; set; }
|
||||||
public NovelStatus RawStatus { 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> SourceTags { get; set; }
|
||||||
public List<string> SystemTags { get; set; }
|
public List<string> SystemTags { get; set; }
|
||||||
public SourceDescriptor SourceDescriptor { 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; }
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ using FictionArchive.Service.NovelService.Services;
|
|||||||
using FictionArchive.Service.NovelService.Services.EventHandlers;
|
using FictionArchive.Service.NovelService.Services.EventHandlers;
|
||||||
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
||||||
using FictionArchive.Service.NovelService.Services.SourceAdapters.Novelpia;
|
using FictionArchive.Service.NovelService.Services.SourceAdapters.Novelpia;
|
||||||
|
using FictionArchive.Service.Shared;
|
||||||
using FictionArchive.Service.Shared.Extensions;
|
using FictionArchive.Service.Shared.Extensions;
|
||||||
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
||||||
using FictionArchive.Service.Shared.Services.GraphQL;
|
using FictionArchive.Service.Shared.Services.GraphQL;
|
||||||
@@ -17,6 +18,8 @@ public class Program
|
|||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
var isSchemaExport = SchemaExportDetector.IsSchemaExportMode(args);
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
builder.AddLocalAppsettings();
|
builder.AddLocalAppsettings();
|
||||||
|
|
||||||
@@ -24,6 +27,8 @@ public class Program
|
|||||||
|
|
||||||
#region Event Bus
|
#region Event Bus
|
||||||
|
|
||||||
|
if (!isSchemaExport)
|
||||||
|
{
|
||||||
builder.Services.AddRabbitMQ(opt =>
|
builder.Services.AddRabbitMQ(opt =>
|
||||||
{
|
{
|
||||||
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
||||||
@@ -32,18 +37,22 @@ public class Program
|
|||||||
.Subscribe<NovelUpdateRequestedEvent, NovelUpdateRequestedEventHandler>()
|
.Subscribe<NovelUpdateRequestedEvent, NovelUpdateRequestedEventHandler>()
|
||||||
.Subscribe<ChapterPullRequestedEvent, ChapterPullRequestedEventHandler>()
|
.Subscribe<ChapterPullRequestedEvent, ChapterPullRequestedEventHandler>()
|
||||||
.Subscribe<FileUploadRequestStatusUpdateEvent, FileUploadRequestStatusUpdateEventHandler>();
|
.Subscribe<FileUploadRequestStatusUpdateEvent, FileUploadRequestStatusUpdateEventHandler>();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GraphQL
|
#region GraphQL
|
||||||
|
|
||||||
builder.Services.AddDefaultGraphQl<Query, Mutation>();
|
builder.Services.AddDefaultGraphQl<Query, Mutation>()
|
||||||
|
.AddAuthorization();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Database
|
#region Database
|
||||||
|
|
||||||
builder.Services.RegisterDbContext<NovelServiceDbContext>(builder.Configuration.GetConnectionString("DefaultConnection"));
|
builder.Services.RegisterDbContext<NovelServiceDbContext>(
|
||||||
|
builder.Configuration.GetConnectionString("DefaultConnection"),
|
||||||
|
skipInfrastructure: isSchemaExport);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -53,12 +62,14 @@ public class Program
|
|||||||
builder.Services.AddHttpClient<NovelpiaAuthMessageHandler>(client =>
|
builder.Services.AddHttpClient<NovelpiaAuthMessageHandler>(client =>
|
||||||
{
|
{
|
||||||
client.BaseAddress = new Uri("https://novelpia.com");
|
client.BaseAddress = new Uri("https://novelpia.com");
|
||||||
});
|
})
|
||||||
|
.AddStandardResilienceHandler();
|
||||||
builder.Services.AddHttpClient<ISourceAdapter, NovelpiaAdapter>(client =>
|
builder.Services.AddHttpClient<ISourceAdapter, NovelpiaAdapter>(client =>
|
||||||
{
|
{
|
||||||
client.BaseAddress = new Uri("https://novelpia.com");
|
client.BaseAddress = new Uri("https://novelpia.com");
|
||||||
})
|
})
|
||||||
.AddHttpMessageHandler<NovelpiaAuthMessageHandler>();
|
.AddHttpMessageHandler<NovelpiaAuthMessageHandler>()
|
||||||
|
.AddStandardResilienceHandler();
|
||||||
|
|
||||||
builder.Services.Configure<NovelUpdateServiceConfiguration>(builder.Configuration.GetSection("UpdateService"));
|
builder.Services.Configure<NovelUpdateServiceConfiguration>(builder.Configuration.GetSection("UpdateService"));
|
||||||
builder.Services.AddTransient<NovelUpdateService>();
|
builder.Services.AddTransient<NovelUpdateService>();
|
||||||
@@ -67,11 +78,16 @@ public class Program
|
|||||||
|
|
||||||
builder.Services.AddHealthChecks();
|
builder.Services.AddHealthChecks();
|
||||||
|
|
||||||
|
// Authentication & Authorization
|
||||||
|
builder.Services.AddOidcAuthentication(builder.Configuration);
|
||||||
|
builder.Services.AddFictionArchiveAuthorization();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Update database
|
// Update database (skip in schema export mode)
|
||||||
using (var scope = app.Services.CreateScope())
|
if (!isSchemaExport)
|
||||||
{
|
{
|
||||||
|
using var scope = app.Services.CreateScope();
|
||||||
var dbContext = scope.ServiceProvider.GetRequiredService<NovelServiceDbContext>();
|
var dbContext = scope.ServiceProvider.GetRequiredService<NovelServiceDbContext>();
|
||||||
dbContext.UpdateDatabase();
|
dbContext.UpdateDatabase();
|
||||||
}
|
}
|
||||||
@@ -80,6 +96,9 @@ public class Program
|
|||||||
|
|
||||||
app.MapHealthChecks("/healthz");
|
app.MapHealthChecks("/healthz");
|
||||||
|
|
||||||
|
app.UseAuthentication();
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapGraphQL();
|
app.MapGraphQL();
|
||||||
|
|
||||||
app.RunWithGraphQLCommands(args);
|
app.RunWithGraphQLCommands(args);
|
||||||
|
|||||||
@@ -14,6 +14,6 @@ public class ChapterPullRequestedEventHandler : IIntegrationEventHandler<Chapter
|
|||||||
|
|
||||||
public async Task Handle(ChapterPullRequestedEvent @event)
|
public async Task Handle(ChapterPullRequestedEvent @event)
|
||||||
{
|
{
|
||||||
await _novelUpdateService.PullChapterContents(@event.NovelId, @event.ChapterNumber);
|
await _novelUpdateService.PullChapterContents(@event.NovelId, @event.VolumeId, @event.ChapterOrder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,10 +10,31 @@ public class NovelServiceDbContext(DbContextOptions options, ILogger<NovelServic
|
|||||||
: FictionArchiveDbContext(options, logger)
|
: FictionArchiveDbContext(options, logger)
|
||||||
{
|
{
|
||||||
public DbSet<Novel> Novels { get; set; }
|
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<Source> Sources { get; set; }
|
||||||
public DbSet<TranslationEngine> TranslationEngines { get; set; }
|
public DbSet<TranslationEngine> TranslationEngines { get; set; }
|
||||||
public DbSet<NovelTag> Tags { get; set; }
|
public DbSet<NovelTag> Tags { get; set; }
|
||||||
public DbSet<LocalizationKey> LocalizationKeys { get; set; }
|
public DbSet<LocalizationKey> LocalizationKeys { get; set; }
|
||||||
public DbSet<LocalizationRequest> LocalizationRequests { get; set; }
|
public DbSet<LocalizationRequest> LocalizationRequests { get; set; }
|
||||||
public DbSet<Image> Images { get; set; }
|
public DbSet<Image> Images { 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
|
using FictionArchive.Common.Enums;
|
||||||
using FictionArchive.Service.FileService.IntegrationEvents;
|
using FictionArchive.Service.FileService.IntegrationEvents;
|
||||||
using FictionArchive.Service.NovelService.Models.Configuration;
|
using FictionArchive.Service.NovelService.Models.Configuration;
|
||||||
using FictionArchive.Service.NovelService.Models.Enums;
|
using FictionArchive.Service.NovelService.Models.Enums;
|
||||||
using FictionArchive.Service.NovelService.Models.Images;
|
using FictionArchive.Service.NovelService.Models.Images;
|
||||||
|
using FictionArchive.Service.NovelService.Models.IntegrationEvents;
|
||||||
using FictionArchive.Service.NovelService.Models.Localization;
|
using FictionArchive.Service.NovelService.Models.Localization;
|
||||||
using FictionArchive.Service.NovelService.Models.Novels;
|
using FictionArchive.Service.NovelService.Models.Novels;
|
||||||
using FictionArchive.Service.NovelService.Models.SourceAdapters;
|
using FictionArchive.Service.NovelService.Models.SourceAdapters;
|
||||||
@@ -30,14 +32,283 @@ public class NovelUpdateService
|
|||||||
_novelUpdateServiceConfiguration = novelUpdateServiceConfiguration.Value;
|
_novelUpdateServiceConfiguration = novelUpdateServiceConfiguration.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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(string novelUrl)
|
public async Task<Novel> ImportNovel(string novelUrl)
|
||||||
{
|
{
|
||||||
|
// Step 1: Get metadata from source adapter
|
||||||
NovelMetadata? metadata = null;
|
NovelMetadata? metadata = null;
|
||||||
foreach (ISourceAdapter sourceAdapter in _sourceAdapters)
|
foreach (ISourceAdapter sourceAdapter in _sourceAdapters)
|
||||||
{
|
{
|
||||||
if (await sourceAdapter.CanProcessNovel(novelUrl))
|
if (await sourceAdapter.CanProcessNovel(novelUrl))
|
||||||
{
|
{
|
||||||
metadata = await sourceAdapter.GetMetadata(novelUrl);
|
metadata = await sourceAdapter.GetMetadata(novelUrl);
|
||||||
|
break; // Stop after finding adapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,91 +317,174 @@ public class NovelUpdateService
|
|||||||
throw new NotSupportedException("The provided novel url is currently unsupported.");
|
throw new NotSupportedException("The provided novel url is currently unsupported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var systemTags = metadata.SystemTags.Select(tag => new NovelTag()
|
// Step 2: Resolve or create Source
|
||||||
{
|
var source = await GetOrCreateSource(metadata.SourceDescriptor);
|
||||||
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
|
|
||||||
});
|
|
||||||
|
|
||||||
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)
|
||||||
|
.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()
|
// CREATE PATH: New novel
|
||||||
{
|
novel = await CreateNewNovel(metadata, source);
|
||||||
Name = LocalizationKey.CreateFromText(metadata.AuthorName, metadata.RawLanguage),
|
shouldPublishCoverEvent = novel.CoverImage != null;
|
||||||
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>()
|
|
||||||
}
|
}
|
||||||
};
|
else
|
||||||
}).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()
|
|
||||||
{
|
{
|
||||||
Name = metadata.SourceDescriptor.Name,
|
// UPDATE PATH: Existing novel
|
||||||
Url = metadata.SourceDescriptor.Url,
|
novel = existingNovel;
|
||||||
Key = metadata.SourceDescriptor.Key,
|
|
||||||
|
// 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();
|
await _dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
// Signal request for cover image if present
|
// Publish novel created event for new novels
|
||||||
if (addedNovel.Entity.CoverImage != null)
|
if (existingNovel == null)
|
||||||
{
|
{
|
||||||
await _eventBus.Publish(new FileUploadRequestCreatedEvent()
|
await _eventBus.Publish(new NovelCreatedEvent
|
||||||
{
|
{
|
||||||
RequestId = addedNovel.Entity.CoverImage.Id,
|
NovelId = novel.Id,
|
||||||
FileData = metadata.CoverImage.Data,
|
Title = novel.Name.Texts.First(t => t.Language == novel.RawLanguage).Text,
|
||||||
FilePath = $"Novels/{addedNovel.Entity.Id}/Images/cover.jpg"
|
OriginalLanguage = novel.RawLanguage,
|
||||||
|
Source = novel.Source.Key,
|
||||||
|
AuthorName = 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 _eventBus.Publish(new ChapterCreatedEvent
|
||||||
|
{
|
||||||
|
ChapterId = chapter.Id,
|
||||||
|
NovelId = novel.Id,
|
||||||
|
VolumeId = volume.Id,
|
||||||
|
VolumeOrder = volume.Order,
|
||||||
|
ChapterOrder = chapter.Order,
|
||||||
|
ChapterTitle = chapter.Name.Texts.First(t => t.Language == novel.RawLanguage).Text
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Chapter> PullChapterContents(uint novelId, uint chapterNumber)
|
// Publish cover image event if needed
|
||||||
|
if (shouldPublishCoverEvent && novel.CoverImage != null && metadata.CoverImage != null)
|
||||||
|
{
|
||||||
|
await _eventBus.Publish(new FileUploadRequestCreatedEvent
|
||||||
|
{
|
||||||
|
RequestId = novel.CoverImage.Id,
|
||||||
|
FileData = metadata.CoverImage.Data,
|
||||||
|
FilePath = $"Novels/{novel.Id}/Images/cover.jpg"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Publish chapter pull events for chapters without body content
|
||||||
|
foreach (var volume in novel.Volumes)
|
||||||
|
{
|
||||||
|
var chaptersNeedingPull = volume.Chapters
|
||||||
|
.Where(c => c.Body?.Texts == null || !c.Body.Texts.Any())
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
foreach (var chapter in chaptersNeedingPull)
|
||||||
|
{
|
||||||
|
await _eventBus.Publish(new ChapterPullRequestedEvent
|
||||||
|
{
|
||||||
|
NovelId = novel.Id,
|
||||||
|
VolumeId = volume.Id,
|
||||||
|
ChapterOrder = chapter.Order
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return novel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Chapter> PullChapterContents(uint novelId, uint volumeId, uint chapterOrder)
|
||||||
{
|
{
|
||||||
var novel = await _dbContext.Novels.Where(novel => novel.Id == novelId)
|
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(chapter => chapter.Body)
|
||||||
.ThenInclude(body => body.Texts)
|
.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();
|
.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 adapter = _sourceAdapters.FirstOrDefault(adapter => adapter.SourceDescriptor.Key == novel.Source.Key);
|
||||||
var rawChapter = await adapter.GetRawChapter(chapter.Url);
|
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,
|
Text = rawChapter.Text,
|
||||||
Language = novel.RawLanguage
|
Language = novel.RawLanguage
|
||||||
};
|
};
|
||||||
chapter.Body.Texts.Add(localizationText);
|
chapter.Body.Texts.Add(localizationText);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
localizationText.Text = rawChapter.Text;
|
||||||
|
}
|
||||||
|
|
||||||
chapter.Images = rawChapter.ImageData.Select(img => new Image()
|
chapter.Images = rawChapter.ImageData.Select(img => new Image()
|
||||||
{
|
{
|
||||||
OriginalPath = img.Url
|
OriginalPath = img.Url
|
||||||
@@ -195,10 +549,90 @@ public class NovelUpdateService
|
|||||||
if (match != null)
|
if (match != null)
|
||||||
{
|
{
|
||||||
match.Attributes["src"].Value = newUrl;
|
match.Attributes["src"].Value = newUrl;
|
||||||
|
bodyText.Text = chapterDoc.DocumentNode.OuterHtml;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<NovelUpdateRequestedEvent> QueueNovelImport(string novelUrl)
|
||||||
|
{
|
||||||
|
var importNovelRequestEvent = new NovelUpdateRequestedEvent()
|
||||||
|
{
|
||||||
|
NovelUrl = novelUrl
|
||||||
|
};
|
||||||
|
await _eventBus.Publish(importNovelRequestEvent);
|
||||||
|
return importNovelRequestEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ChapterPullRequestedEvent> QueueChapterPull(uint novelId, uint volumeId, uint chapterOrder)
|
||||||
|
{
|
||||||
|
var chapterPullEvent = new ChapterPullRequestedEvent()
|
||||||
|
{
|
||||||
|
NovelId = novelId,
|
||||||
|
VolumeId = volumeId,
|
||||||
|
ChapterOrder = chapterOrder
|
||||||
|
};
|
||||||
|
await _eventBus.Publish(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(),
|
ExternalId = novelId.ToString(),
|
||||||
SystemTags = new List<string>(),
|
SystemTags = new List<string>(),
|
||||||
SourceTags = new List<string>(),
|
SourceTags = new List<string>(),
|
||||||
Chapters = new List<ChapterMetadata>(),
|
Volumes = new List<VolumeMetadata>(),
|
||||||
SourceDescriptor = SourceDescriptor
|
SourceDescriptor = SourceDescriptor
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -133,15 +133,16 @@ public class NovelpiaAdapter : ISourceAdapter
|
|||||||
novel.SourceTags.Add(tag);
|
novel.SourceTags.Add(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Author's posts (from notice_table in the page HTML)
|
||||||
|
var authorsPosts = ParseAuthorsPosts(novelData);
|
||||||
|
|
||||||
// Chapters
|
// Chapters
|
||||||
uint page = 0;
|
uint page = 0;
|
||||||
List<ChapterMetadata> chapters = new List<ChapterMetadata>();
|
List<ChapterMetadata> chapters = new List<ChapterMetadata>();
|
||||||
List<uint> seenChapterIds = new List<uint>();
|
List<uint> seenChapterIds = new List<uint>();
|
||||||
uint chapterOrder = 0;
|
uint chapterOrder = 1;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
await Task.Delay(500);
|
|
||||||
_logger.LogInformation("Next chapter batch");
|
|
||||||
var response = await _httpClient.PostAsync(EpisodeListEndpoint, new FormUrlEncodedContent(new Dictionary<string, string>
|
var response = await _httpClient.PostAsync(EpisodeListEndpoint, new FormUrlEncodedContent(new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{"novel_no", novelId.ToString()},
|
{"novel_no", novelId.ToString()},
|
||||||
@@ -170,7 +171,25 @@ public class NovelpiaAdapter : ISourceAdapter
|
|||||||
}
|
}
|
||||||
page++;
|
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;
|
return novel;
|
||||||
}
|
}
|
||||||
@@ -243,4 +262,40 @@ public class NovelpiaAdapter : ISourceAdapter
|
|||||||
}
|
}
|
||||||
return await image.Content.ReadAsByteArrayAsync();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -19,5 +19,15 @@
|
|||||||
"ConnectionString": "amqp://localhost",
|
"ConnectionString": "amqp://localhost",
|
||||||
"ClientIdentifier": "NovelService"
|
"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",
|
"subgraph": "Novels",
|
||||||
"http": {
|
"http": {
|
||||||
"baseAddress": "http://localhost:5101/graphql"
|
"baseAddress": "https://localhost:7208/graphql"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using FictionArchive.Service.SchedulerService.Models;
|
using FictionArchive.Service.SchedulerService.Models;
|
||||||
using FictionArchive.Service.SchedulerService.Services;
|
using FictionArchive.Service.SchedulerService.Services;
|
||||||
|
using FictionArchive.Service.Shared.Constants;
|
||||||
|
using HotChocolate.Authorization;
|
||||||
using HotChocolate.Types;
|
using HotChocolate.Types;
|
||||||
using Quartz;
|
using Quartz;
|
||||||
|
|
||||||
@@ -10,18 +12,21 @@ public class Mutation
|
|||||||
{
|
{
|
||||||
[Error<DuplicateNameException>]
|
[Error<DuplicateNameException>]
|
||||||
[Error<FormatException>]
|
[Error<FormatException>]
|
||||||
|
[Authorize(Roles = [AuthorizationConstants.Roles.Admin])]
|
||||||
public async Task<SchedulerJob> ScheduleEventJob(string key, string description, string eventType, string eventData, string cronSchedule, JobManagerService jobManager)
|
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);
|
return await jobManager.ScheduleEventJob(key, description, eventType, eventData, cronSchedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Error<JobPersistenceException>]
|
[Error<JobPersistenceException>]
|
||||||
|
[Authorize(Roles = [AuthorizationConstants.Roles.Admin])]
|
||||||
public async Task<bool> RunJob(string jobKey, JobManagerService jobManager)
|
public async Task<bool> RunJob(string jobKey, JobManagerService jobManager)
|
||||||
{
|
{
|
||||||
return await jobManager.TriggerJob(jobKey);
|
return await jobManager.TriggerJob(jobKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Error<KeyNotFoundException>]
|
[Error<KeyNotFoundException>]
|
||||||
|
[Authorize(Roles = [AuthorizationConstants.Roles.Admin])]
|
||||||
public async Task<bool> DeleteJob(string jobKey, JobManagerService jobManager)
|
public async Task<bool> DeleteJob(string jobKey, JobManagerService jobManager)
|
||||||
{
|
{
|
||||||
bool deleted = await jobManager.DeleteJob(jobKey);
|
bool deleted = await jobManager.DeleteJob(jobKey);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using FictionArchive.Service.SchedulerService.GraphQL;
|
using FictionArchive.Service.SchedulerService.GraphQL;
|
||||||
using FictionArchive.Service.SchedulerService.Services;
|
using FictionArchive.Service.SchedulerService.Services;
|
||||||
|
using FictionArchive.Service.Shared;
|
||||||
using FictionArchive.Service.Shared.Extensions;
|
using FictionArchive.Service.Shared.Extensions;
|
||||||
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
||||||
using Quartz;
|
using Quartz;
|
||||||
@@ -11,30 +12,52 @@ public class Program
|
|||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
var isSchemaExport = SchemaExportDetector.IsSchemaExportMode(args);
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
builder.Services.AddDefaultGraphQl<Query, Mutation>();
|
builder.Services.AddDefaultGraphQl<Query, Mutation>()
|
||||||
|
.AddAuthorization();
|
||||||
builder.Services.AddHealthChecks();
|
builder.Services.AddHealthChecks();
|
||||||
builder.Services.AddTransient<JobManagerService>();
|
builder.Services.AddTransient<JobManagerService>();
|
||||||
|
|
||||||
|
// Authentication & Authorization
|
||||||
|
builder.Services.AddOidcAuthentication(builder.Configuration);
|
||||||
|
builder.Services.AddFictionArchiveAuthorization();
|
||||||
|
|
||||||
#region Database
|
#region Database
|
||||||
|
|
||||||
builder.Services.RegisterDbContext<SchedulerServiceDbContext>(builder.Configuration.GetConnectionString("DefaultConnection"));
|
builder.Services.RegisterDbContext<SchedulerServiceDbContext>(
|
||||||
|
builder.Configuration.GetConnectionString("DefaultConnection"),
|
||||||
|
skipInfrastructure: isSchemaExport);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Event Bus
|
#region Event Bus
|
||||||
|
|
||||||
|
if (!isSchemaExport)
|
||||||
|
{
|
||||||
builder.Services.AddRabbitMQ(opt =>
|
builder.Services.AddRabbitMQ(opt =>
|
||||||
{
|
{
|
||||||
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Quartz
|
#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 =>
|
builder.Services.AddQuartz(opt =>
|
||||||
{
|
{
|
||||||
opt.UsePersistentStore(pso =>
|
opt.UsePersistentStore(pso =>
|
||||||
@@ -52,13 +75,16 @@ public class Program
|
|||||||
{
|
{
|
||||||
opt.WaitForJobsToComplete = true;
|
opt.WaitForJobsToComplete = true;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
var app = builder.Build();
|
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>();
|
var dbContext = scope.ServiceProvider.GetRequiredService<SchedulerServiceDbContext>();
|
||||||
dbContext.UpdateDatabase();
|
dbContext.UpdateDatabase();
|
||||||
}
|
}
|
||||||
@@ -67,6 +93,9 @@ public class Program
|
|||||||
|
|
||||||
app.MapHealthChecks("/healthz");
|
app.MapHealthChecks("/healthz");
|
||||||
|
|
||||||
|
app.UseAuthentication();
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapGraphQL();
|
app.MapGraphQL();
|
||||||
|
|
||||||
app.RunWithGraphQLCommands(args);
|
app.RunWithGraphQLCommands(args);
|
||||||
|
|||||||
@@ -12,5 +12,15 @@
|
|||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Host=localhost;Database=FictionArchive_SchedulerService;Username=postgres;password=postgres"
|
"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,169 @@
|
|||||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using FictionArchive.Service.Shared.Constants;
|
||||||
|
using FictionArchive.Service.Shared.Models.Authentication;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.Shared.Extensions;
|
||||||
|
|
||||||
|
public static class AuthenticationExtensions
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddOidcAuthentication(this IServiceCollection services, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
var oidcConfig = configuration.GetSection("OIDC").Get<OidcConfiguration>();
|
||||||
|
|
||||||
|
if (oidcConfig == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("OIDC configuration is required but not found in app settings");
|
||||||
|
}
|
||||||
|
|
||||||
|
ValidateOidcConfiguration(oidcConfig);
|
||||||
|
|
||||||
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.AddJwtBearer(options =>
|
||||||
|
{
|
||||||
|
options.Authority = oidcConfig.Authority;
|
||||||
|
options.Audience = oidcConfig.Audience;
|
||||||
|
options.RequireHttpsMetadata = !string.IsNullOrEmpty(oidcConfig.Authority) && oidcConfig.Authority.StartsWith("https://");
|
||||||
|
|
||||||
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ValidateIssuer = oidcConfig.ValidateIssuer,
|
||||||
|
ValidIssuer = oidcConfig.ValidIssuer,
|
||||||
|
ValidateAudience = oidcConfig.ValidateAudience,
|
||||||
|
ValidateLifetime = oidcConfig.ValidateLifetime,
|
||||||
|
ValidateIssuerSigningKey = oidcConfig.ValidateIssuerSigningKey,
|
||||||
|
ClockSkew = TimeSpan.FromMinutes(5)
|
||||||
|
};
|
||||||
|
|
||||||
|
options.Events = CreateLoggingJwtBearerEvents();
|
||||||
|
});
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JwtBearerEvents CreateLoggingJwtBearerEvents(JwtBearerEvents? existingEvents = null)
|
||||||
|
{
|
||||||
|
return new JwtBearerEvents
|
||||||
|
{
|
||||||
|
OnMessageReceived = existingEvents?.OnMessageReceived ?? (_ => Task.CompletedTask),
|
||||||
|
OnAuthenticationFailed = context =>
|
||||||
|
{
|
||||||
|
var logger = context.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>()
|
||||||
|
.CreateLogger("JwtBearerAuthentication");
|
||||||
|
|
||||||
|
logger.LogWarning(context.Exception, "JWT authentication failed: {Message}", context.Exception.Message);
|
||||||
|
|
||||||
|
return existingEvents?.OnAuthenticationFailed?.Invoke(context) ?? Task.CompletedTask;
|
||||||
|
},
|
||||||
|
OnChallenge = context =>
|
||||||
|
{
|
||||||
|
var logger = context.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>()
|
||||||
|
.CreateLogger("JwtBearerAuthentication");
|
||||||
|
|
||||||
|
logger.LogDebug(
|
||||||
|
"JWT challenge issued. Error: {Error}, ErrorDescription: {ErrorDescription}",
|
||||||
|
context.Error,
|
||||||
|
context.ErrorDescription);
|
||||||
|
|
||||||
|
return existingEvents?.OnChallenge?.Invoke(context) ?? Task.CompletedTask;
|
||||||
|
},
|
||||||
|
OnTokenValidated = context =>
|
||||||
|
{
|
||||||
|
var logger = context.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>()
|
||||||
|
.CreateLogger("JwtBearerAuthentication");
|
||||||
|
|
||||||
|
logger.LogDebug(
|
||||||
|
"JWT token validated for subject: {Subject}",
|
||||||
|
context.Principal?.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? "unknown");
|
||||||
|
|
||||||
|
return existingEvents?.OnTokenValidated?.Invoke(context) ?? Task.CompletedTask;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddOidcCookieAuthentication(this IServiceCollection services, IConfiguration configuration, string cookieName = "fa_session")
|
||||||
|
{
|
||||||
|
var oidcConfig = configuration.GetSection("OIDC").Get<OidcConfiguration>();
|
||||||
|
|
||||||
|
if (oidcConfig == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("OIDC configuration is required but not found in app settings");
|
||||||
|
}
|
||||||
|
|
||||||
|
ValidateOidcConfiguration(oidcConfig);
|
||||||
|
|
||||||
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.AddJwtBearer(options =>
|
||||||
|
{
|
||||||
|
options.Authority = oidcConfig.Authority;
|
||||||
|
options.Audience = oidcConfig.Audience;
|
||||||
|
options.RequireHttpsMetadata = !string.IsNullOrEmpty(oidcConfig.Authority) && oidcConfig.Authority.StartsWith("https://");
|
||||||
|
|
||||||
|
var cookieEvents = new JwtBearerEvents
|
||||||
|
{
|
||||||
|
OnMessageReceived = context =>
|
||||||
|
{
|
||||||
|
// Try to get token from cookie first, then from Authorization header
|
||||||
|
if (context.Request.Cookies.ContainsKey(cookieName))
|
||||||
|
{
|
||||||
|
context.Token = context.Request.Cookies[cookieName];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
options.Events = CreateLoggingJwtBearerEvents(cookieEvents);
|
||||||
|
|
||||||
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ValidateIssuer = oidcConfig.ValidateIssuer,
|
||||||
|
ValidIssuer = oidcConfig.ValidIssuer,
|
||||||
|
ValidateAudience = oidcConfig.ValidateAudience,
|
||||||
|
ValidateLifetime = oidcConfig.ValidateLifetime,
|
||||||
|
ValidateIssuerSigningKey = oidcConfig.ValidateIssuerSigningKey,
|
||||||
|
ClockSkew = TimeSpan.FromMinutes(5)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddFictionArchiveAuthorization(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddAuthorizationBuilder()
|
||||||
|
.AddPolicy(AuthorizationConstants.Policies.Admin, policy => policy.RequireRole(AuthorizationConstants.Roles.Admin))
|
||||||
|
.AddPolicy(AuthorizationConstants.Policies.User, policy => policy.RequireAuthenticatedUser());
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ValidateOidcConfiguration(OidcConfiguration config)
|
||||||
|
{
|
||||||
|
var errors = new List<string>();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(config.Authority))
|
||||||
|
errors.Add("OIDC Authority is required");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(config.ClientId))
|
||||||
|
errors.Add("OIDC ClientId is required");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(config.Audience))
|
||||||
|
errors.Add("OIDC Audience is required");
|
||||||
|
|
||||||
|
if (!Uri.TryCreate(config.Authority, UriKind.Absolute, out var authorityUri))
|
||||||
|
errors.Add($"OIDC Authority '{config.Authority}' is not a valid URI");
|
||||||
|
else if (!authorityUri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
!authorityUri.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase))
|
||||||
|
errors.Add("OIDC Authority must use HTTPS unless running on localhost");
|
||||||
|
|
||||||
|
if (errors.Any())
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"OIDC configuration validation failed:{Environment.NewLine}{string.Join(Environment.NewLine, errors)}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,8 +6,20 @@ namespace FictionArchive.Service.Shared.Extensions;
|
|||||||
|
|
||||||
public static class DatabaseExtensions
|
public static class DatabaseExtensions
|
||||||
{
|
{
|
||||||
public static IServiceCollection RegisterDbContext<TContext>(this IServiceCollection services,
|
public static IServiceCollection RegisterDbContext<TContext>(
|
||||||
string connectionString) where TContext : FictionArchiveDbContext
|
this IServiceCollection services,
|
||||||
|
string connectionString,
|
||||||
|
bool skipInfrastructure = false) where TContext : FictionArchiveDbContext
|
||||||
|
{
|
||||||
|
if (skipInfrastructure)
|
||||||
|
{
|
||||||
|
// For schema export: use in-memory provider to allow EF Core entity discovery
|
||||||
|
services.AddDbContext<TContext>(options =>
|
||||||
|
{
|
||||||
|
options.UseInMemoryDatabase($"SchemaExport_{typeof(TContext).Name}");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
services.AddDbContext<TContext>(options =>
|
services.AddDbContext<TContext>(options =>
|
||||||
{
|
{
|
||||||
@@ -16,6 +28,7 @@ public static class DatabaseExtensions
|
|||||||
o.UseNodaTime();
|
o.UseNodaTime();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,7 @@ public static class GraphQLExtensions
|
|||||||
.AddErrorFilter<LoggingErrorFilter>()
|
.AddErrorFilter<LoggingErrorFilter>()
|
||||||
.AddType<UnsignedIntType>()
|
.AddType<UnsignedIntType>()
|
||||||
.AddType<InstantType>()
|
.AddType<InstantType>()
|
||||||
|
.ModifyCostOptions(opt => opt.MaxFieldCost = 10000)
|
||||||
.AddMutationConventions(applyToAllMutations: true)
|
.AddMutationConventions(applyToAllMutations: true)
|
||||||
.AddFiltering(opt => opt.AddDefaults().BindRuntimeType<uint, UnsignedIntOperationFilterInputType>())
|
.AddFiltering(opt => opt.AddDefaults().BindRuntimeType<uint, UnsignedIntOperationFilterInputType>())
|
||||||
.AddSorting()
|
.AddSorting()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="GraphQL.Server.Ui.GraphiQL" Version="8.3.3" />
|
<PackageReference Include="GraphQL.Server.Ui.GraphiQL" Version="8.3.3" />
|
||||||
<PackageReference Include="HotChocolate.AspNetCore" Version="15.1.11" />
|
<PackageReference Include="HotChocolate.AspNetCore" Version="15.1.11" />
|
||||||
|
<PackageReference Include="HotChocolate.AspNetCore.Authorization" Version="15.1.11" />
|
||||||
<PackageReference Include="HotChocolate.AspNetCore.CommandLine" Version="15.1.11" />
|
<PackageReference Include="HotChocolate.AspNetCore.CommandLine" Version="15.1.11" />
|
||||||
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="15.1.11" />
|
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="15.1.11" />
|
||||||
<PackageReference Include="HotChocolate.Types.Scalars" Version="15.1.11" />
|
<PackageReference Include="HotChocolate.Types.Scalars" Version="15.1.11" />
|
||||||
@@ -18,16 +19,20 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.11" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.11" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.11" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.11">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.11">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="10.1.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="NodaTime.Serialization.JsonNet" Version="3.2.0" />
|
<PackageReference Include="NodaTime.Serialization.JsonNet" Version="3.2.0" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="9.0.4" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="9.0.4" />
|
||||||
|
<PackageReference Include="Polly" Version="8.6.5" />
|
||||||
<PackageReference Include="RabbitMQ.Client" Version="7.2.0" />
|
<PackageReference Include="RabbitMQ.Client" Version="7.2.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.11" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
namespace FictionArchive.Service.Shared.Models.Authentication;
|
||||||
|
|
||||||
|
public class OidcConfiguration
|
||||||
|
{
|
||||||
|
public string Authority { get; set; } = string.Empty;
|
||||||
|
public string ClientId { get; set; } = string.Empty;
|
||||||
|
public string Audience { get; set; } = string.Empty;
|
||||||
|
public string? ValidIssuer { get; set; }
|
||||||
|
public bool ValidateIssuer { get; set; } = true;
|
||||||
|
public bool ValidateAudience { get; set; } = true;
|
||||||
|
public bool ValidateLifetime { get; set; } = true;
|
||||||
|
public bool ValidateIssuerSigningKey { get; set; } = true;
|
||||||
|
}
|
||||||
22
FictionArchive.Service.Shared/SchemaExportDetector.cs
Normal file
22
FictionArchive.Service.Shared/SchemaExportDetector.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
namespace FictionArchive.Service.Shared;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Detects if the application is running in schema export mode (for HotChocolate CLI commands).
|
||||||
|
/// In this mode, infrastructure like RabbitMQ and databases should not be initialized.
|
||||||
|
/// </summary>
|
||||||
|
public static class SchemaExportDetector
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the current run is a schema export command.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="args">Command line arguments passed to Main()</param>
|
||||||
|
/// <returns>True if running schema export, false otherwise</returns>
|
||||||
|
public static bool IsSchemaExportMode(string[] args)
|
||||||
|
{
|
||||||
|
// HotChocolate CLI pattern: "schema export" after "--" delimiter
|
||||||
|
// Handles: dotnet run -- schema export --output schema.graphql
|
||||||
|
var normalizedArgs = args.SkipWhile(a => a == "--").ToArray();
|
||||||
|
return normalizedArgs.Length > 0 &&
|
||||||
|
normalizedArgs[0].Equals("schema", StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,6 +69,7 @@ public class RabbitMQEventBus : IEventBus, IHostedService
|
|||||||
await channel.ExchangeDeclareAsync(ExchangeName, ExchangeType.Direct,
|
await channel.ExchangeDeclareAsync(ExchangeName, ExchangeType.Direct,
|
||||||
cancellationToken: cancellationToken);
|
cancellationToken: cancellationToken);
|
||||||
|
|
||||||
|
await channel.BasicQosAsync(prefetchSize: 0, prefetchCount: 1, global: false, cancellationToken: cancellationToken);
|
||||||
await channel.QueueDeclareAsync(_options.ClientIdentifier, true, false, false,
|
await channel.QueueDeclareAsync(_options.ClientIdentifier, true, false, false,
|
||||||
cancellationToken: cancellationToken);
|
cancellationToken: cancellationToken);
|
||||||
var consumer = new AsyncEventingBasicConsumer(channel);
|
var consumer = new AsyncEventingBasicConsumer(channel);
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ using FictionArchive.Service.TranslationService.Models.Enums;
|
|||||||
using FictionArchive.Service.TranslationService.Services;
|
using FictionArchive.Service.TranslationService.Services;
|
||||||
using FictionArchive.Service.TranslationService.Services.Database;
|
using FictionArchive.Service.TranslationService.Services.Database;
|
||||||
using FictionArchive.Service.TranslationService.Services.TranslationEngines;
|
using FictionArchive.Service.TranslationService.Services.TranslationEngines;
|
||||||
|
using HotChocolate.Authorization;
|
||||||
|
|
||||||
namespace FictionArchive.Service.TranslationService.GraphQL;
|
namespace FictionArchive.Service.TranslationService.GraphQL;
|
||||||
|
|
||||||
public class Mutation
|
public class Mutation
|
||||||
{
|
{
|
||||||
|
[Authorize]
|
||||||
public async Task<TranslationResult> TranslateText(string text, Language from, Language to, string translationEngineKey, TranslationEngineService translationEngineService)
|
public async Task<TranslationResult> TranslateText(string text, Language from, Language to, string translationEngineKey, TranslationEngineService translationEngineService)
|
||||||
{
|
{
|
||||||
var result = await translationEngineService.Translate(from, to, text, translationEngineKey);
|
var result = await translationEngineService.Translate(from, to, text, translationEngineKey);
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
using FictionArchive.Service.TranslationService.Models;
|
using FictionArchive.Service.TranslationService.Models;
|
||||||
using FictionArchive.Service.TranslationService.Models.Database;
|
using FictionArchive.Service.TranslationService.Models.DTOs;
|
||||||
using FictionArchive.Service.TranslationService.Services.Database;
|
using FictionArchive.Service.TranslationService.Services.Database;
|
||||||
using FictionArchive.Service.TranslationService.Services.TranslationEngines;
|
using FictionArchive.Service.TranslationService.Services.TranslationEngines;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using HotChocolate.Authorization;
|
||||||
|
using HotChocolate.Data;
|
||||||
|
|
||||||
namespace FictionArchive.Service.TranslationService.GraphQL;
|
namespace FictionArchive.Service.TranslationService.GraphQL;
|
||||||
|
|
||||||
public class Query
|
public class Query
|
||||||
{
|
{
|
||||||
|
[Authorize]
|
||||||
[UseFiltering]
|
[UseFiltering]
|
||||||
[UseSorting]
|
[UseSorting]
|
||||||
public IEnumerable<TranslationEngineDescriptor> GetTranslationEngines(IEnumerable<ITranslationEngine> engines)
|
public IEnumerable<TranslationEngineDescriptor> GetTranslationEngines(IEnumerable<ITranslationEngine> engines)
|
||||||
@@ -15,12 +17,25 @@ public class Query
|
|||||||
return engines.Select(engine => engine.Descriptor);
|
return engines.Select(engine => engine.Descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
[UsePaging]
|
[UsePaging]
|
||||||
[UseProjection]
|
[UseProjection]
|
||||||
[UseFiltering]
|
[UseFiltering]
|
||||||
[UseSorting]
|
[UseSorting]
|
||||||
public IQueryable<TranslationRequest> GetTranslationRequests(TranslationServiceDbContext dbContext)
|
public IQueryable<TranslationRequestDto> GetTranslationRequests(TranslationServiceDbContext dbContext)
|
||||||
{
|
{
|
||||||
return dbContext.TranslationRequests.AsQueryable();
|
return dbContext.TranslationRequests.Select(request => new TranslationRequestDto
|
||||||
|
{
|
||||||
|
Id = request.Id,
|
||||||
|
CreatedTime = request.CreatedTime,
|
||||||
|
LastUpdatedTime = request.LastUpdatedTime,
|
||||||
|
OriginalText = request.OriginalText,
|
||||||
|
TranslatedText = request.TranslatedText,
|
||||||
|
From = request.From,
|
||||||
|
To = request.To,
|
||||||
|
TranslationEngineKey = request.TranslationEngineKey,
|
||||||
|
Status = request.Status,
|
||||||
|
BilledCharacterCount = request.BilledCharacterCount
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using FictionArchive.Common.Enums;
|
||||||
|
using FictionArchive.Service.TranslationService.Models.Enums;
|
||||||
|
using NodaTime;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.TranslationService.Models.DTOs;
|
||||||
|
|
||||||
|
public class TranslationRequestDto
|
||||||
|
{
|
||||||
|
public Guid Id { get; init; }
|
||||||
|
public Instant CreatedTime { get; init; }
|
||||||
|
public Instant LastUpdatedTime { get; init; }
|
||||||
|
public required string OriginalText { get; init; }
|
||||||
|
public string? TranslatedText { get; init; }
|
||||||
|
public Language From { get; init; }
|
||||||
|
public Language To { get; init; }
|
||||||
|
public required string TranslationEngineKey { get; init; }
|
||||||
|
public TranslationRequestStatus Status { get; init; }
|
||||||
|
public uint BilledCharacterCount { get; init; }
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using DeepL;
|
using DeepL;
|
||||||
using FictionArchive.Common.Extensions;
|
using FictionArchive.Common.Extensions;
|
||||||
|
using FictionArchive.Service.Shared;
|
||||||
using FictionArchive.Service.Shared.Extensions;
|
using FictionArchive.Service.Shared.Extensions;
|
||||||
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
using FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
||||||
using FictionArchive.Service.Shared.Services.GraphQL;
|
using FictionArchive.Service.Shared.Services.GraphQL;
|
||||||
@@ -18,6 +19,8 @@ public class Program
|
|||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
var isSchemaExport = SchemaExportDetector.IsSchemaExportMode(args);
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
builder.AddLocalAppsettings();
|
builder.AddLocalAppsettings();
|
||||||
|
|
||||||
@@ -25,24 +28,30 @@ public class Program
|
|||||||
|
|
||||||
#region Event Bus
|
#region Event Bus
|
||||||
|
|
||||||
|
if (!isSchemaExport)
|
||||||
|
{
|
||||||
builder.Services.AddRabbitMQ(opt =>
|
builder.Services.AddRabbitMQ(opt =>
|
||||||
{
|
{
|
||||||
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
builder.Configuration.GetSection("RabbitMQ").Bind(opt);
|
||||||
})
|
})
|
||||||
.Subscribe<TranslationRequestCreatedEvent, TranslationRequestCreatedEventHandler>();
|
.Subscribe<TranslationRequestCreatedEvent, TranslationRequestCreatedEventHandler>();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region Database
|
#region Database
|
||||||
|
|
||||||
builder.Services.RegisterDbContext<TranslationServiceDbContext>(builder.Configuration.GetConnectionString("DefaultConnection"));
|
builder.Services.RegisterDbContext<TranslationServiceDbContext>(
|
||||||
|
builder.Configuration.GetConnectionString("DefaultConnection"),
|
||||||
|
skipInfrastructure: isSchemaExport);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GraphQL
|
#region GraphQL
|
||||||
|
|
||||||
builder.Services.AddDefaultGraphQl<Query, Mutation>();
|
builder.Services.AddDefaultGraphQl<Query, Mutation>()
|
||||||
|
.AddAuthorization();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -58,11 +67,16 @@ public class Program
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
// Authentication & Authorization
|
||||||
|
builder.Services.AddOidcAuthentication(builder.Configuration);
|
||||||
|
builder.Services.AddFictionArchiveAuthorization();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Update database
|
// Update database (skip in schema export mode)
|
||||||
using (var scope = app.Services.CreateScope())
|
if (!isSchemaExport)
|
||||||
{
|
{
|
||||||
|
using var scope = app.Services.CreateScope();
|
||||||
var dbContext = scope.ServiceProvider.GetRequiredService<TranslationServiceDbContext>();
|
var dbContext = scope.ServiceProvider.GetRequiredService<TranslationServiceDbContext>();
|
||||||
dbContext.UpdateDatabase();
|
dbContext.UpdateDatabase();
|
||||||
}
|
}
|
||||||
@@ -71,6 +85,9 @@ public class Program
|
|||||||
|
|
||||||
app.MapHealthChecks("/healthz");
|
app.MapHealthChecks("/healthz");
|
||||||
|
|
||||||
|
app.UseAuthentication();
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapGraphQL();
|
app.MapGraphQL();
|
||||||
|
|
||||||
app.RunWithGraphQLCommands(args);
|
app.RunWithGraphQLCommands(args);
|
||||||
|
|||||||
@@ -15,5 +15,15 @@
|
|||||||
"ConnectionString": "amqp://localhost",
|
"ConnectionString": "amqp://localhost",
|
||||||
"ClientIdentifier": "TranslationService"
|
"ClientIdentifier": "TranslationService"
|
||||||
},
|
},
|
||||||
"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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
FictionArchive.Service.UserNovelDataService/Dockerfile
Normal file
23
FictionArchive.Service.UserNovelDataService/Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
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.UserNovelDataService/FictionArchive.Service.UserNovelDataService.csproj", "FictionArchive.Service.UserNovelDataService/"]
|
||||||
|
RUN dotnet restore "FictionArchive.Service.UserNovelDataService/FictionArchive.Service.UserNovelDataService.csproj"
|
||||||
|
COPY . .
|
||||||
|
WORKDIR "/src/FictionArchive.Service.UserNovelDataService"
|
||||||
|
RUN dotnet build "./FictionArchive.Service.UserNovelDataService.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
RUN dotnet publish "./FictionArchive.Service.UserNovelDataService.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.UserNovelDataService.dll"]
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.11">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="..\.dockerignore">
|
||||||
|
<Link>.dockerignore</Link>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\FictionArchive.Service.Shared\FictionArchive.Service.Shared.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
498
FictionArchive.Service.UserNovelDataService/GraphQL/Mutation.cs
Normal file
498
FictionArchive.Service.UserNovelDataService/GraphQL/Mutation.cs
Normal file
@@ -0,0 +1,498 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using FictionArchive.Service.UserNovelDataService.Models.Database;
|
||||||
|
using FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
using FictionArchive.Service.UserNovelDataService.Services;
|
||||||
|
using HotChocolate.Authorization;
|
||||||
|
using HotChocolate.Types;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.GraphQL;
|
||||||
|
|
||||||
|
public class Mutation
|
||||||
|
{
|
||||||
|
[Authorize]
|
||||||
|
[Error<InvalidOperationException>]
|
||||||
|
public async Task<BookmarkPayload> UpsertBookmark(
|
||||||
|
UserNovelDataServiceDbContext dbContext,
|
||||||
|
ClaimsPrincipal claimsPrincipal,
|
||||||
|
UpsertBookmarkInput input)
|
||||||
|
{
|
||||||
|
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
if (string.IsNullOrEmpty(oAuthProviderId))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unable to determine current user identity");
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await dbContext.Users
|
||||||
|
.FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
// Auto-create user if not exists
|
||||||
|
user = new User { OAuthProviderId = oAuthProviderId };
|
||||||
|
dbContext.Users.Add(user);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
var existingBookmark = await dbContext.Bookmarks
|
||||||
|
.FirstOrDefaultAsync(b => b.UserId == user.Id && b.ChapterId == input.ChapterId);
|
||||||
|
|
||||||
|
if (existingBookmark != null)
|
||||||
|
{
|
||||||
|
// Update existing
|
||||||
|
existingBookmark.Description = input.Description;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Create new
|
||||||
|
existingBookmark = new Bookmark
|
||||||
|
{
|
||||||
|
UserId = user.Id,
|
||||||
|
NovelId = input.NovelId,
|
||||||
|
ChapterId = input.ChapterId,
|
||||||
|
Description = input.Description
|
||||||
|
};
|
||||||
|
dbContext.Bookmarks.Add(existingBookmark);
|
||||||
|
}
|
||||||
|
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
return new BookmarkPayload
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
Bookmark = new BookmarkDto
|
||||||
|
{
|
||||||
|
Id = existingBookmark.Id,
|
||||||
|
ChapterId = existingBookmark.ChapterId,
|
||||||
|
NovelId = existingBookmark.NovelId,
|
||||||
|
Description = existingBookmark.Description,
|
||||||
|
CreatedTime = existingBookmark.CreatedTime
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Error<InvalidOperationException>]
|
||||||
|
public async Task<BookmarkPayload> RemoveBookmark(
|
||||||
|
UserNovelDataServiceDbContext dbContext,
|
||||||
|
ClaimsPrincipal claimsPrincipal,
|
||||||
|
uint chapterId)
|
||||||
|
{
|
||||||
|
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
if (string.IsNullOrEmpty(oAuthProviderId))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unable to determine current user identity");
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await dbContext.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return new BookmarkPayload { Success = false };
|
||||||
|
}
|
||||||
|
|
||||||
|
var bookmark = await dbContext.Bookmarks
|
||||||
|
.FirstOrDefaultAsync(b => b.UserId == user.Id && b.ChapterId == chapterId);
|
||||||
|
|
||||||
|
if (bookmark == null)
|
||||||
|
{
|
||||||
|
return new BookmarkPayload { Success = false };
|
||||||
|
}
|
||||||
|
|
||||||
|
dbContext.Bookmarks.Remove(bookmark);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
return new BookmarkPayload { Success = true };
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Error<InvalidOperationException>]
|
||||||
|
public async Task<ReadingListPayload> CreateReadingList(
|
||||||
|
UserNovelDataServiceDbContext dbContext,
|
||||||
|
ClaimsPrincipal claimsPrincipal,
|
||||||
|
CreateReadingListInput input)
|
||||||
|
{
|
||||||
|
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
if (string.IsNullOrEmpty(oAuthProviderId))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unable to determine current user identity");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(input.Name))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Reading list name is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await dbContext.Users
|
||||||
|
.FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
user = new User { OAuthProviderId = oAuthProviderId };
|
||||||
|
dbContext.Users.Add(user);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
var readingList = new ReadingList
|
||||||
|
{
|
||||||
|
UserId = user.Id,
|
||||||
|
Name = input.Name.Trim(),
|
||||||
|
Description = input.Description?.Trim()
|
||||||
|
};
|
||||||
|
|
||||||
|
dbContext.ReadingLists.Add(readingList);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
return new ReadingListPayload
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
ReadingList = new ReadingListDto
|
||||||
|
{
|
||||||
|
Id = readingList.Id,
|
||||||
|
Name = readingList.Name,
|
||||||
|
Description = readingList.Description,
|
||||||
|
Items = [],
|
||||||
|
ItemCount = 0,
|
||||||
|
CreatedTime = readingList.CreatedTime
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Error<InvalidOperationException>]
|
||||||
|
public async Task<ReadingListPayload> UpdateReadingList(
|
||||||
|
UserNovelDataServiceDbContext dbContext,
|
||||||
|
ClaimsPrincipal claimsPrincipal,
|
||||||
|
UpdateReadingListInput input)
|
||||||
|
{
|
||||||
|
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
if (string.IsNullOrEmpty(oAuthProviderId))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unable to determine current user identity");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(input.Name))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Reading list name is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await dbContext.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return new ReadingListPayload { Success = false };
|
||||||
|
}
|
||||||
|
|
||||||
|
var readingList = await dbContext.ReadingLists
|
||||||
|
.Include(r => r.Items)
|
||||||
|
.FirstOrDefaultAsync(r => r.Id == input.Id && r.UserId == user.Id);
|
||||||
|
|
||||||
|
if (readingList == null)
|
||||||
|
{
|
||||||
|
return new ReadingListPayload { Success = false };
|
||||||
|
}
|
||||||
|
|
||||||
|
readingList.Name = input.Name.Trim();
|
||||||
|
readingList.Description = input.Description?.Trim();
|
||||||
|
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
return new ReadingListPayload
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
ReadingList = new ReadingListDto
|
||||||
|
{
|
||||||
|
Id = readingList.Id,
|
||||||
|
Name = readingList.Name,
|
||||||
|
Description = readingList.Description,
|
||||||
|
Items = readingList.Items.OrderBy(i => i.Order).Select(i => new ReadingListItemDto
|
||||||
|
{
|
||||||
|
NovelId = i.NovelId,
|
||||||
|
Order = i.Order,
|
||||||
|
AddedTime = i.CreatedTime
|
||||||
|
}),
|
||||||
|
ItemCount = readingList.Items.Count,
|
||||||
|
CreatedTime = readingList.CreatedTime
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Error<InvalidOperationException>]
|
||||||
|
public async Task<DeleteReadingListPayload> DeleteReadingList(
|
||||||
|
UserNovelDataServiceDbContext dbContext,
|
||||||
|
ClaimsPrincipal claimsPrincipal,
|
||||||
|
int id)
|
||||||
|
{
|
||||||
|
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
if (string.IsNullOrEmpty(oAuthProviderId))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unable to determine current user identity");
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await dbContext.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return new DeleteReadingListPayload { Success = false };
|
||||||
|
}
|
||||||
|
|
||||||
|
var readingList = await dbContext.ReadingLists
|
||||||
|
.FirstOrDefaultAsync(r => r.Id == id && r.UserId == user.Id);
|
||||||
|
|
||||||
|
if (readingList == null)
|
||||||
|
{
|
||||||
|
return new DeleteReadingListPayload { Success = false };
|
||||||
|
}
|
||||||
|
|
||||||
|
dbContext.ReadingLists.Remove(readingList);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
return new DeleteReadingListPayload { Success = true };
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Error<InvalidOperationException>]
|
||||||
|
public async Task<ReadingListPayload> AddToReadingList(
|
||||||
|
UserNovelDataServiceDbContext dbContext,
|
||||||
|
ClaimsPrincipal claimsPrincipal,
|
||||||
|
AddToReadingListInput input)
|
||||||
|
{
|
||||||
|
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
if (string.IsNullOrEmpty(oAuthProviderId))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unable to determine current user identity");
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await dbContext.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return new ReadingListPayload { Success = false };
|
||||||
|
}
|
||||||
|
|
||||||
|
var readingList = await dbContext.ReadingLists
|
||||||
|
.Include(r => r.Items)
|
||||||
|
.FirstOrDefaultAsync(r => r.Id == input.ReadingListId && r.UserId == user.Id);
|
||||||
|
|
||||||
|
if (readingList == null)
|
||||||
|
{
|
||||||
|
return new ReadingListPayload { Success = false };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Idempotent: if already in list, return success
|
||||||
|
var existingItem = readingList.Items.FirstOrDefault(i => i.NovelId == input.NovelId);
|
||||||
|
if (existingItem != null)
|
||||||
|
{
|
||||||
|
return new ReadingListPayload
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
ReadingList = new ReadingListDto
|
||||||
|
{
|
||||||
|
Id = readingList.Id,
|
||||||
|
Name = readingList.Name,
|
||||||
|
Description = readingList.Description,
|
||||||
|
Items = readingList.Items.OrderBy(i => i.Order).Select(i => new ReadingListItemDto
|
||||||
|
{
|
||||||
|
NovelId = i.NovelId,
|
||||||
|
Order = i.Order,
|
||||||
|
AddedTime = i.CreatedTime
|
||||||
|
}),
|
||||||
|
ItemCount = readingList.Items.Count,
|
||||||
|
CreatedTime = readingList.CreatedTime
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add at the end (highest order + 1)
|
||||||
|
var maxOrder = readingList.Items.Any() ? readingList.Items.Max(i => i.Order) : -1;
|
||||||
|
var newItem = new ReadingListItem
|
||||||
|
{
|
||||||
|
ReadingListId = readingList.Id,
|
||||||
|
NovelId = input.NovelId,
|
||||||
|
Order = maxOrder + 1
|
||||||
|
};
|
||||||
|
|
||||||
|
dbContext.ReadingListItems.Add(newItem);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Reload to get updated items
|
||||||
|
readingList = await dbContext.ReadingLists
|
||||||
|
.AsNoTracking()
|
||||||
|
.Include(r => r.Items.OrderBy(i => i.Order))
|
||||||
|
.FirstAsync(r => r.Id == input.ReadingListId);
|
||||||
|
|
||||||
|
return new ReadingListPayload
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
ReadingList = new ReadingListDto
|
||||||
|
{
|
||||||
|
Id = readingList.Id,
|
||||||
|
Name = readingList.Name,
|
||||||
|
Description = readingList.Description,
|
||||||
|
Items = readingList.Items.Select(i => new ReadingListItemDto
|
||||||
|
{
|
||||||
|
NovelId = i.NovelId,
|
||||||
|
Order = i.Order,
|
||||||
|
AddedTime = i.CreatedTime
|
||||||
|
}),
|
||||||
|
ItemCount = readingList.Items.Count,
|
||||||
|
CreatedTime = readingList.CreatedTime
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Error<InvalidOperationException>]
|
||||||
|
public async Task<ReadingListPayload> RemoveFromReadingList(
|
||||||
|
UserNovelDataServiceDbContext dbContext,
|
||||||
|
ClaimsPrincipal claimsPrincipal,
|
||||||
|
int listId,
|
||||||
|
uint novelId)
|
||||||
|
{
|
||||||
|
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
if (string.IsNullOrEmpty(oAuthProviderId))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unable to determine current user identity");
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await dbContext.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return new ReadingListPayload { Success = false };
|
||||||
|
}
|
||||||
|
|
||||||
|
var readingList = await dbContext.ReadingLists
|
||||||
|
.Include(r => r.Items)
|
||||||
|
.FirstOrDefaultAsync(r => r.Id == listId && r.UserId == user.Id);
|
||||||
|
|
||||||
|
if (readingList == null)
|
||||||
|
{
|
||||||
|
return new ReadingListPayload { Success = false };
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = readingList.Items.FirstOrDefault(i => i.NovelId == novelId);
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
dbContext.ReadingListItems.Remove(item);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reload to get updated items
|
||||||
|
readingList = await dbContext.ReadingLists
|
||||||
|
.AsNoTracking()
|
||||||
|
.Include(r => r.Items.OrderBy(i => i.Order))
|
||||||
|
.FirstAsync(r => r.Id == listId);
|
||||||
|
|
||||||
|
return new ReadingListPayload
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
ReadingList = new ReadingListDto
|
||||||
|
{
|
||||||
|
Id = readingList.Id,
|
||||||
|
Name = readingList.Name,
|
||||||
|
Description = readingList.Description,
|
||||||
|
Items = readingList.Items.Select(i => new ReadingListItemDto
|
||||||
|
{
|
||||||
|
NovelId = i.NovelId,
|
||||||
|
Order = i.Order,
|
||||||
|
AddedTime = i.CreatedTime
|
||||||
|
}),
|
||||||
|
ItemCount = readingList.Items.Count,
|
||||||
|
CreatedTime = readingList.CreatedTime
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[Error<InvalidOperationException>]
|
||||||
|
public async Task<ReadingListPayload> ReorderReadingListItem(
|
||||||
|
UserNovelDataServiceDbContext dbContext,
|
||||||
|
ClaimsPrincipal claimsPrincipal,
|
||||||
|
ReorderReadingListItemInput input)
|
||||||
|
{
|
||||||
|
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
if (string.IsNullOrEmpty(oAuthProviderId))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unable to determine current user identity");
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await dbContext.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return new ReadingListPayload { Success = false };
|
||||||
|
}
|
||||||
|
|
||||||
|
var readingList = await dbContext.ReadingLists
|
||||||
|
.Include(r => r.Items)
|
||||||
|
.FirstOrDefaultAsync(r => r.Id == input.ReadingListId && r.UserId == user.Id);
|
||||||
|
|
||||||
|
if (readingList == null)
|
||||||
|
{
|
||||||
|
return new ReadingListPayload { Success = false };
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = readingList.Items.FirstOrDefault(i => i.NovelId == input.NovelId);
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Novel not found in reading list");
|
||||||
|
}
|
||||||
|
|
||||||
|
var oldOrder = item.Order;
|
||||||
|
var newOrder = input.NewOrder;
|
||||||
|
|
||||||
|
// Shift other items
|
||||||
|
if (newOrder < oldOrder)
|
||||||
|
{
|
||||||
|
// Moving up: shift items between newOrder and oldOrder down
|
||||||
|
foreach (var i in readingList.Items.Where(x => x.Order >= newOrder && x.Order < oldOrder))
|
||||||
|
{
|
||||||
|
i.Order++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (newOrder > oldOrder)
|
||||||
|
{
|
||||||
|
// Moving down: shift items between oldOrder and newOrder up
|
||||||
|
foreach (var i in readingList.Items.Where(x => x.Order > oldOrder && x.Order <= newOrder))
|
||||||
|
{
|
||||||
|
i.Order--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
item.Order = newOrder;
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
return new ReadingListPayload
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
ReadingList = new ReadingListDto
|
||||||
|
{
|
||||||
|
Id = readingList.Id,
|
||||||
|
Name = readingList.Name,
|
||||||
|
Description = readingList.Description,
|
||||||
|
Items = readingList.Items.OrderBy(i => i.Order).Select(i => new ReadingListItemDto
|
||||||
|
{
|
||||||
|
NovelId = i.NovelId,
|
||||||
|
Order = i.Order,
|
||||||
|
AddedTime = i.CreatedTime
|
||||||
|
}),
|
||||||
|
ItemCount = readingList.Items.Count,
|
||||||
|
CreatedTime = readingList.CreatedTime
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
136
FictionArchive.Service.UserNovelDataService/GraphQL/Query.cs
Normal file
136
FictionArchive.Service.UserNovelDataService/GraphQL/Query.cs
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using FictionArchive.Service.UserNovelDataService.Models.Database;
|
||||||
|
using FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
using FictionArchive.Service.UserNovelDataService.Services;
|
||||||
|
using HotChocolate.Authorization;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.GraphQL;
|
||||||
|
|
||||||
|
public class Query
|
||||||
|
{
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IQueryable<BookmarkDto>> GetBookmarks(
|
||||||
|
UserNovelDataServiceDbContext dbContext,
|
||||||
|
ClaimsPrincipal claimsPrincipal,
|
||||||
|
uint novelId)
|
||||||
|
{
|
||||||
|
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
if (string.IsNullOrEmpty(oAuthProviderId))
|
||||||
|
{
|
||||||
|
return new List<BookmarkDto>().AsQueryable();
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await dbContext.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return new List<BookmarkDto>().AsQueryable();
|
||||||
|
}
|
||||||
|
|
||||||
|
return dbContext.Bookmarks
|
||||||
|
.AsNoTracking()
|
||||||
|
.Where(b => b.UserId == user.Id && b.NovelId == novelId)
|
||||||
|
.OrderByDescending(b => b.CreatedTime)
|
||||||
|
.Select(b => new BookmarkDto
|
||||||
|
{
|
||||||
|
Id = b.Id,
|
||||||
|
ChapterId = b.ChapterId,
|
||||||
|
NovelId = b.NovelId,
|
||||||
|
Description = b.Description,
|
||||||
|
CreatedTime = b.CreatedTime
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IEnumerable<ReadingListDto>> GetReadingLists(
|
||||||
|
UserNovelDataServiceDbContext dbContext,
|
||||||
|
ClaimsPrincipal claimsPrincipal)
|
||||||
|
{
|
||||||
|
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
if (string.IsNullOrEmpty(oAuthProviderId))
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await dbContext.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var lists = await dbContext.ReadingLists
|
||||||
|
.AsNoTracking()
|
||||||
|
.Include(r => r.Items)
|
||||||
|
.Where(r => r.UserId == user.Id)
|
||||||
|
.OrderByDescending(r => r.LastUpdatedTime)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return lists.Select(r => new ReadingListDto
|
||||||
|
{
|
||||||
|
Id = r.Id,
|
||||||
|
Name = r.Name,
|
||||||
|
Description = r.Description,
|
||||||
|
ItemCount = r.Items.Count,
|
||||||
|
Items = r.Items.Select(i => new ReadingListItemDto
|
||||||
|
{
|
||||||
|
NovelId = i.NovelId,
|
||||||
|
Order = i.Order,
|
||||||
|
AddedTime = i.CreatedTime
|
||||||
|
}),
|
||||||
|
CreatedTime = r.CreatedTime
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ReadingListDto?> GetReadingList(
|
||||||
|
UserNovelDataServiceDbContext dbContext,
|
||||||
|
ClaimsPrincipal claimsPrincipal,
|
||||||
|
int id)
|
||||||
|
{
|
||||||
|
var oAuthProviderId = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
|
if (string.IsNullOrEmpty(oAuthProviderId))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await dbContext.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync(u => u.OAuthProviderId == oAuthProviderId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var readingList = await dbContext.ReadingLists
|
||||||
|
.AsNoTracking()
|
||||||
|
.Include(r => r.Items.OrderBy(i => i.Order))
|
||||||
|
.FirstOrDefaultAsync(r => r.Id == id && r.UserId == user.Id);
|
||||||
|
|
||||||
|
if (readingList == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ReadingListDto
|
||||||
|
{
|
||||||
|
Id = readingList.Id,
|
||||||
|
Name = readingList.Name,
|
||||||
|
Description = readingList.Description,
|
||||||
|
ItemCount = readingList.Items.Count,
|
||||||
|
Items = readingList.Items.Select(i => new ReadingListItemDto
|
||||||
|
{
|
||||||
|
NovelId = i.NovelId,
|
||||||
|
Order = i.Order,
|
||||||
|
AddedTime = i.CreatedTime
|
||||||
|
}),
|
||||||
|
CreatedTime = readingList.CreatedTime
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
99
FictionArchive.Service.UserNovelDataService/Migrations/20251230181559_AddBookmarks.Designer.cs
generated
Normal file
99
FictionArchive.Service.UserNovelDataService/Migrations/20251230181559_AddBookmarks.Designer.cs
generated
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using FictionArchive.Service.UserNovelDataService.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.UserNovelDataService.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(UserNovelDataServiceDbContext))]
|
||||||
|
[Migration("20251230181559_AddBookmarks")]
|
||||||
|
partial class AddBookmarks
|
||||||
|
{
|
||||||
|
/// <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.UserNovelDataService.Models.Database.Bookmark", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<long>("ChapterId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<long>("NovelId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId", "ChapterId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("UserId", "NovelId");
|
||||||
|
|
||||||
|
b.ToTable("Bookmarks");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.User", 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.Property<string>("OAuthProviderId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Bookmark", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using NodaTime;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddBookmarks : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Users",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
OAuthProviderId = table.Column<string>(type: "text", 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_Users", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Bookmarks",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
ChapterId = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
NovelId = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
Description = table.Column<string>(type: "text", nullable: true),
|
||||||
|
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_Bookmarks", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Bookmarks_Users_UserId",
|
||||||
|
column: x => x.UserId,
|
||||||
|
principalTable: "Users",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Bookmarks_UserId_ChapterId",
|
||||||
|
table: "Bookmarks",
|
||||||
|
columns: new[] { "UserId", "ChapterId" },
|
||||||
|
unique: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Bookmarks_UserId_NovelId",
|
||||||
|
table: "Bookmarks",
|
||||||
|
columns: new[] { "UserId", "NovelId" });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Bookmarks");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
198
FictionArchive.Service.UserNovelDataService/Migrations/20260119184741_AddNovelVolumeChapter.Designer.cs
generated
Normal file
198
FictionArchive.Service.UserNovelDataService/Migrations/20260119184741_AddNovelVolumeChapter.Designer.cs
generated
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using FictionArchive.Service.UserNovelDataService.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.UserNovelDataService.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(UserNovelDataServiceDbContext))]
|
||||||
|
[Migration("20260119184741_AddNovelVolumeChapter")]
|
||||||
|
partial class AddNovelVolumeChapter
|
||||||
|
{
|
||||||
|
/// <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.UserNovelDataService.Models.Database.Bookmark", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<long>("ChapterId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<long>("NovelId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId", "ChapterId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("UserId", "NovelId");
|
||||||
|
|
||||||
|
b.ToTable("Bookmarks");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Chapter", 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<long>("VolumeId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("VolumeId");
|
||||||
|
|
||||||
|
b.ToTable("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Novel", 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.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Novels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.User", 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.Property<string>("OAuthProviderId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.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<long>("NovelId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NovelId");
|
||||||
|
|
||||||
|
b.ToTable("Volumes");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Bookmark", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.Volume", "Volume")
|
||||||
|
.WithMany("Chapters")
|
||||||
|
.HasForeignKey("VolumeId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Volume");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Volume", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.Novel", "Novel")
|
||||||
|
.WithMany("Volumes")
|
||||||
|
.HasForeignKey("NovelId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Novel");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Novel", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Volumes");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Volume", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Chapters");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using NodaTime;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddNovelVolumeChapter : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Novels",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
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_Novels", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Volumes",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
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_Volumes", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Volumes_Novels_NovelId",
|
||||||
|
column: x => x.NovelId,
|
||||||
|
principalTable: "Novels",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Chapters",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
VolumeId = 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_Chapters", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Chapters_Volumes_VolumeId",
|
||||||
|
column: x => x.VolumeId,
|
||||||
|
principalTable: "Volumes",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Chapters_VolumeId",
|
||||||
|
table: "Chapters",
|
||||||
|
column: "VolumeId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Volumes_NovelId",
|
||||||
|
table: "Volumes",
|
||||||
|
column: "NovelId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Chapters");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Volumes");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Novels");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
289
FictionArchive.Service.UserNovelDataService/Migrations/20260120014840_AddReadingLists.Designer.cs
generated
Normal file
289
FictionArchive.Service.UserNovelDataService/Migrations/20260120014840_AddReadingLists.Designer.cs
generated
Normal file
@@ -0,0 +1,289 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using FictionArchive.Service.UserNovelDataService.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.UserNovelDataService.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(UserNovelDataServiceDbContext))]
|
||||||
|
[Migration("20260120014840_AddReadingLists")]
|
||||||
|
partial class AddReadingLists
|
||||||
|
{
|
||||||
|
/// <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.UserNovelDataService.Models.Database.Bookmark", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<long>("ChapterId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<long>("NovelId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId", "ChapterId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("UserId", "NovelId");
|
||||||
|
|
||||||
|
b.ToTable("Bookmarks");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Chapter", 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<long>("VolumeId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("VolumeId");
|
||||||
|
|
||||||
|
b.ToTable("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Novel", 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.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Novels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.ReadingList", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("ReadingLists");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.ReadingListItem", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<long>("NovelId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<int>("Order")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("ReadingListId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ReadingListId", "NovelId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("ReadingListId", "Order");
|
||||||
|
|
||||||
|
b.ToTable("ReadingListItems");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.User", 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.Property<string>("OAuthProviderId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.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<long>("NovelId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NovelId");
|
||||||
|
|
||||||
|
b.ToTable("Volumes");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Bookmark", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.Volume", "Volume")
|
||||||
|
.WithMany("Chapters")
|
||||||
|
.HasForeignKey("VolumeId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Volume");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.ReadingList", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.ReadingListItem", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.ReadingList", "ReadingList")
|
||||||
|
.WithMany("Items")
|
||||||
|
.HasForeignKey("ReadingListId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("ReadingList");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Volume", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.Novel", "Novel")
|
||||||
|
.WithMany("Volumes")
|
||||||
|
.HasForeignKey("NovelId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Novel");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Novel", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Volumes");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.ReadingList", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Items");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Volume", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Chapters");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using NodaTime;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddReadingLists : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ReadingLists",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
Name = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Description = table.Column<string>(type: "text", nullable: true),
|
||||||
|
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_ReadingLists", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ReadingLists_Users_UserId",
|
||||||
|
column: x => x.UserId,
|
||||||
|
principalTable: "Users",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ReadingListItems",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
ReadingListId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
NovelId = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
Order = table.Column<int>(type: "integer", 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_ReadingListItems", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ReadingListItems_ReadingLists_ReadingListId",
|
||||||
|
column: x => x.ReadingListId,
|
||||||
|
principalTable: "ReadingLists",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ReadingListItems_ReadingListId_NovelId",
|
||||||
|
table: "ReadingListItems",
|
||||||
|
columns: new[] { "ReadingListId", "NovelId" },
|
||||||
|
unique: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ReadingListItems_ReadingListId_Order",
|
||||||
|
table: "ReadingListItems",
|
||||||
|
columns: new[] { "ReadingListId", "Order" });
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ReadingLists_UserId",
|
||||||
|
table: "ReadingLists",
|
||||||
|
column: "UserId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ReadingListItems");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ReadingLists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,286 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using FictionArchive.Service.UserNovelDataService.Services;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using NodaTime;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(UserNovelDataServiceDbContext))]
|
||||||
|
partial class UserNovelDataServiceDbContextModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.11")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Bookmark", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<long>("ChapterId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<long>("NovelId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId", "ChapterId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("UserId", "NovelId");
|
||||||
|
|
||||||
|
b.ToTable("Bookmarks");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Chapter", 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<long>("VolumeId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("VolumeId");
|
||||||
|
|
||||||
|
b.ToTable("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Novel", 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.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Novels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.ReadingList", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("ReadingLists");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.ReadingListItem", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Instant>("LastUpdatedTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<long>("NovelId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<int>("Order")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("ReadingListId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ReadingListId", "NovelId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("ReadingListId", "Order");
|
||||||
|
|
||||||
|
b.ToTable("ReadingListItems");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.User", 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.Property<string>("OAuthProviderId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.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<long>("NovelId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NovelId");
|
||||||
|
|
||||||
|
b.ToTable("Volumes");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Bookmark", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.Volume", "Volume")
|
||||||
|
.WithMany("Chapters")
|
||||||
|
.HasForeignKey("VolumeId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Volume");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.ReadingList", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.ReadingListItem", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.ReadingList", "ReadingList")
|
||||||
|
.WithMany("Items")
|
||||||
|
.HasForeignKey("ReadingListId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("ReadingList");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Volume", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("FictionArchive.Service.UserNovelDataService.Models.Database.Novel", "Novel")
|
||||||
|
.WithMany("Volumes")
|
||||||
|
.HasForeignKey("NovelId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Novel");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Novel", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Volumes");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.ReadingList", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Items");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("FictionArchive.Service.UserNovelDataService.Models.Database.Volume", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Chapters");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
|
||||||
|
public record AddToReadingListInput(int ReadingListId, uint NovelId);
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using NodaTime;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
|
||||||
|
public class BookmarkDto
|
||||||
|
{
|
||||||
|
public int Id { get; init; }
|
||||||
|
public uint ChapterId { get; init; }
|
||||||
|
public uint NovelId { get; init; }
|
||||||
|
public string? Description { get; init; }
|
||||||
|
public Instant CreatedTime { get; init; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
|
||||||
|
public class BookmarkPayload
|
||||||
|
{
|
||||||
|
public BookmarkDto? Bookmark { get; init; }
|
||||||
|
public bool Success { get; init; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
|
||||||
|
public record CreateReadingListInput(string Name, string? Description);
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
|
||||||
|
public class DeleteReadingListPayload
|
||||||
|
{
|
||||||
|
public bool Success { get; init; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using NodaTime;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
|
||||||
|
public class ReadingListDto
|
||||||
|
{
|
||||||
|
public int Id { get; init; }
|
||||||
|
public required string Name { get; init; }
|
||||||
|
public string? Description { get; init; }
|
||||||
|
public IEnumerable<ReadingListItemDto> Items { get; init; } = [];
|
||||||
|
public int ItemCount { get; init; }
|
||||||
|
public Instant CreatedTime { get; init; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using NodaTime;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
|
||||||
|
public class ReadingListItemDto
|
||||||
|
{
|
||||||
|
public uint NovelId { get; init; }
|
||||||
|
public int Order { get; init; }
|
||||||
|
public Instant AddedTime { get; init; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
|
||||||
|
public class ReadingListPayload
|
||||||
|
{
|
||||||
|
public ReadingListDto? ReadingList { get; init; }
|
||||||
|
public bool Success { get; init; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
|
||||||
|
public record ReorderReadingListItemInput(int ReadingListId, uint NovelId, int NewOrder);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
|
||||||
|
public record UpdateReadingListInput(int Id, string Name, string? Description);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.DTOs;
|
||||||
|
|
||||||
|
public record UpsertBookmarkInput(uint NovelId, uint ChapterId, string? Description);
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using FictionArchive.Service.Shared.Models;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.Database;
|
||||||
|
|
||||||
|
public class Bookmark : BaseEntity<int>
|
||||||
|
{
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
public virtual User User { get; set; } = null!;
|
||||||
|
|
||||||
|
public uint ChapterId { get; set; }
|
||||||
|
public uint NovelId { get; set; }
|
||||||
|
|
||||||
|
public string? Description { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using FictionArchive.Service.Shared.Models;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.Database;
|
||||||
|
|
||||||
|
public class Chapter : BaseEntity<uint>
|
||||||
|
{
|
||||||
|
public uint VolumeId { get; set; }
|
||||||
|
public virtual Volume Volume { get; set; } = null!;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using FictionArchive.Service.Shared.Models;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.Database;
|
||||||
|
|
||||||
|
public class Novel : BaseEntity<uint>
|
||||||
|
{
|
||||||
|
public virtual ICollection<Volume> Volumes { get; set; } = new List<Volume>();
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using FictionArchive.Service.Shared.Models;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.Database;
|
||||||
|
|
||||||
|
public class ReadingList : BaseEntity<int>
|
||||||
|
{
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
public virtual User User { get; set; } = null!;
|
||||||
|
|
||||||
|
public required string Name { get; set; }
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<ReadingListItem> Items { get; set; } = new List<ReadingListItem>();
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using FictionArchive.Service.Shared.Models;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.Database;
|
||||||
|
|
||||||
|
public class ReadingListItem : BaseEntity<int>
|
||||||
|
{
|
||||||
|
public int ReadingListId { get; set; }
|
||||||
|
public virtual ReadingList ReadingList { get; set; } = null!;
|
||||||
|
|
||||||
|
public uint NovelId { get; set; }
|
||||||
|
public int Order { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using FictionArchive.Service.Shared.Models;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.Database;
|
||||||
|
|
||||||
|
public class User : BaseEntity<Guid>
|
||||||
|
{
|
||||||
|
public required string OAuthProviderId { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using FictionArchive.Service.Shared.Models;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.Database;
|
||||||
|
|
||||||
|
public class Volume : BaseEntity<uint>
|
||||||
|
{
|
||||||
|
public uint NovelId { get; set; }
|
||||||
|
public virtual Novel Novel { get; set; } = null!;
|
||||||
|
public virtual ICollection<Chapter> Chapters { get; set; } = new List<Chapter>();
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using FictionArchive.Service.Shared.Services.EventBus;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.IntegrationEvents;
|
||||||
|
|
||||||
|
public class ChapterCreatedEvent : IIntegrationEvent
|
||||||
|
{
|
||||||
|
public required uint ChapterId { get; init; }
|
||||||
|
public required uint NovelId { get; init; }
|
||||||
|
public required uint VolumeId { get; init; }
|
||||||
|
public required int VolumeOrder { get; init; }
|
||||||
|
public required uint ChapterOrder { get; init; }
|
||||||
|
public required string ChapterTitle { get; init; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using FictionArchive.Common.Enums;
|
||||||
|
using FictionArchive.Service.Shared.Services.EventBus;
|
||||||
|
|
||||||
|
namespace FictionArchive.Service.UserNovelDataService.Models.IntegrationEvents;
|
||||||
|
|
||||||
|
public class NovelCreatedEvent : IIntegrationEvent
|
||||||
|
{
|
||||||
|
public required uint NovelId { get; init; }
|
||||||
|
public required string Title { get; init; }
|
||||||
|
public required Language OriginalLanguage { get; init; }
|
||||||
|
public required string Source { get; init; }
|
||||||
|
public required string AuthorName { get; init; }
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user