4 Commits

22 changed files with 279 additions and 133 deletions

View File

@@ -1,75 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace FictionArchive.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class TestController : ControllerBase
{
/*private readonly FictionArchiveDbContext _dbContext;
private readonly ISourceAdapter _novelpiaAdapter;
private readonly ITranslationEngineAdapter _translationEngine;
public TestController(ISourceAdapter novelpiaAdapter, FictionArchiveDbContext dbContext, ITranslationEngineAdapter translationEngine)
{
_novelpiaAdapter = novelpiaAdapter;
_dbContext = dbContext;
_translationEngine = translationEngine;
}
[HttpGet("GetNovel")]
public async Task<Novel> GetNovel(string novelUrl)
{
var novel = await _novelpiaAdapter.GetMetadata(novelUrl);
novel.Source = new Source()
{
Name = "Novelpia",
Id = 1,
Url = "https://novelpia.com"
};
_dbContext.Novels.Add(novel);
await _dbContext.SaveChangesAsync();
return novel;
}
[HttpGet("GetChapter")]
public async Task<string> GetChapter(uint novelId, uint chapterNumber)
{
var novel = await _dbContext.Novels.Include(n => n.Chapters).ThenInclude(c => c.Translations).FirstOrDefaultAsync(n => n.Id == novelId);
var chapter = novel.Chapters.FirstOrDefault(c => c.Order == chapterNumber);
var rawChapter = await _novelpiaAdapter.GetRawChapter(chapter.Url);
chapter.Translations.Add(new ChapterTranslation()
{
Language = novel.RawLanguage,
Body = rawChapter
});
await _dbContext.SaveChangesAsync();
return rawChapter;
}
[HttpPost("TranslateChapter")]
public async Task<ChapterTranslation> TranslateChapter(uint novelId, uint chapterNumber, Language to)
{
var novel = await _dbContext.Novels.Include(n => n.Chapters)
.ThenInclude(c => c.Translations).FirstOrDefaultAsync(novel => novel.Id == novelId);
var chapter = novel.Chapters.FirstOrDefault(c => c.Order == chapterNumber);
var chapterRaw = chapter.Translations.FirstOrDefault(ct => ct.Language == novel.RawLanguage);
var newTranslation = new ChapterTranslation()
{
Language = to,
TranslationEngine = new TranslationEngine()
{
Name = "DeepL"
}
};
var translation = await _translationEngine.GetTranslation(chapterRaw.Body, novel.RawLanguage, to);
newTranslation.Body = translation;
chapter.Translations.Add(newTranslation);
await _dbContext.SaveChangesAsync();
return newTranslation;
}*/
}
}

View File

@@ -11,6 +11,7 @@
<PackageReference Include="HotChocolate.AspNetCore" Version="15.1.11" /> <PackageReference Include="HotChocolate.AspNetCore" Version="15.1.11" />
<PackageReference Include="HotChocolate.Data" Version="15.1.11" /> <PackageReference Include="HotChocolate.Data" 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.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.EntityFrameworkCore.Design" Version="9.0.11"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.11">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
@@ -28,8 +29,11 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Controllers\" />
<Folder Include="GraphQL\" /> <Folder Include="GraphQL\" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FictionArchive.Service.Shared\FictionArchive.Service.Shared.csproj" />
</ItemGroup>
</Project> </Project>

View File

@@ -1,3 +1,5 @@
using FictionArchive.Service.Shared.Extensions;
namespace FictionArchive.API; namespace FictionArchive.API;
public class Program public class Program
@@ -6,38 +8,26 @@ public class Program
{ {
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// OpenAPI & REST
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddMemoryCache();
builder.Services.AddHealthChecks(); builder.Services.AddHealthChecks();
#region Fusion Gateway
builder.Services.AddHttpClient("Fusion");
builder.Services
.AddFusionGatewayServer()
.ConfigureFromFile("gateway.fgp")
.CoreBuilder.ApplySaneDefaults();
#endregion
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapGraphQL();
app.MapHealthChecks("/healthz"); app.MapHealthChecks("/healthz");
app.MapControllers(); app.MapGraphQL();
app.Run(); app.Run();
} }

View File

@@ -23,7 +23,7 @@
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "swagger", "launchUrl": "graphql",
"applicationUrl": "https://localhost:7063;http://localhost:5234", "applicationUrl": "https://localhost:7063;http://localhost:5234",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"

View File

@@ -0,0 +1,99 @@
@echo off
setlocal enabledelayedexpansion
set ROOT=%~dp0
for %%A in ("%ROOT%..") do set SERVICES_DIR=%%~fA\
REM ----------------------------------------
REM List of project names to skip
REM (space-separated, match folder names exactly)
REM ----------------------------------------
set SKIP_PROJECTS=FictionArchive.Service.Shared FictionArchive.Service.AuthenticationService
echo ----------------------------------------
echo Finding GraphQL services...
echo ----------------------------------------
set SERVICE_LIST=
for /d %%F in ("%SERVICES_DIR%FictionArchive.Service.*") do (
set "PROJECT_NAME=%%~nxF"
set "SKIP=0"
REM Check if this project name is in the skip list
for %%X in (%SKIP_PROJECTS%) do (
if /I "!PROJECT_NAME!"=="%%X" (
set "SKIP=1"
)
)
if !SKIP!==0 (
echo Found service: !PROJECT_NAME!
set SERVICE_LIST=!SERVICE_LIST! %%F
) else (
echo Skipping service: !PROJECT_NAME!
)
)
echo:
echo ----------------------------------------
echo Exporting schemas and packing subgraphs...
echo ----------------------------------------
for %%S in (%SERVICE_LIST%) do (
echo Processing service folder: %%S
pushd "%%S"
echo Running schema export...
dotnet run -- schema export --output schema.graphql
if errorlevel 1 (
echo ERROR during schema export in %%S
popd
exit /b 1
)
echo Running fusion subgraph pack...
fusion subgraph pack
if errorlevel 1 (
echo ERROR during subgraph pack in %%S
popd
exit /b 1
)
popd
echo Completed: %%S
echo.
)
echo ----------------------------------------
echo Running fusion compose...
echo ----------------------------------------
pushd "%ROOT%"
if exist gateway.fgp del gateway.fgp
for %%S in (%SERVICE_LIST%) do (
REM Extract the full folder name WITH dots preserved
set "SERVICE_NAME=%%~nxS"
echo Composing subgraph: !SERVICE_NAME!
fusion compose -p gateway.fgp -s "..\!SERVICE_NAME!"
if errorlevel 1 (
echo ERROR during fusion compose
popd
exit /b 1
)
)
popd
echo ----------------------------------------
echo Fusion build complete!
echo ----------------------------------------
endlocal
exit /b 0

View File

@@ -0,0 +1,104 @@
#!/usr/bin/env bash
set -euo pipefail
###############################################
# Resolve important directories
###############################################
# Directory where this script lives
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Services live one directory above the script's directory
SERVICES_DIR="$(cd "$ROOT/.." && pwd)"
###############################################
# Skip list (folder names, match exactly)
###############################################
SKIP_PROJECTS=(
"FictionArchive.Service.Shared"
"FictionArchive.Service.Legacy"
)
echo "----------------------------------------"
echo " Finding GraphQL services..."
echo "----------------------------------------"
SERVICE_LIST=()
# Convert skip projects into a single searchable string
SKIP_STRING=" ${SKIP_PROJECTS[*]} "
# Find service directories
shopt -s nullglob
for FOLDER in "$SERVICES_DIR"/FictionArchive.Service.*; do
[ -d "$FOLDER" ] || continue
PROJECT_NAME="$(basename "$FOLDER")"
# Skip entries that match the skip list
if [[ "$SKIP_STRING" == *" $PROJECT_NAME "* ]]; then
echo "Skipping service: $PROJECT_NAME"
continue
fi
echo "Found service: $PROJECT_NAME"
SERVICE_LIST+=("$FOLDER")
done
shopt -u nullglob
echo
echo "----------------------------------------"
echo " Exporting schemas and packing subgraphs..."
echo "----------------------------------------"
for SERVICE in "${SERVICE_LIST[@]}"; do
PROJECT_NAME="$(basename "$SERVICE")"
echo "Processing service: $PROJECT_NAME"
pushd "$SERVICE" >/dev/null
echo "Building service..."
dotnet build -c Release >/dev/null
# Automatically detect built DLL in bin/Release/<TFM>/
DLL_PATH="$(find "bin/Release" -maxdepth 3 -name '*.dll' | head -n 1)"
if [[ -z "$DLL_PATH" ]]; then
echo "ERROR: Could not locate DLL for $PROJECT_NAME"
popd >/dev/null
exit 1
fi
echo "Running schema export..."
dotnet exec "$DLL_PATH" schema export --output schema.graphql
echo "Running subgraph pack..."
fusion subgraph pack
popd >/dev/null
echo "Completed: $PROJECT_NAME"
echo
done
echo "----------------------------------------"
echo " Running fusion compose..."
echo "----------------------------------------"
pushd "$ROOT" >/dev/null
# Remove old composition file
rm -f gateway.fgp
for SERVICE in "${SERVICE_LIST[@]}"; do
SERVICE_NAME="$(basename "$SERVICE")"
echo "Composing subgraph: $SERVICE_NAME"
# Note: Fusion compose must reference parent dir (services live above ROOT)
fusion compose -p gateway.fgp -s "../$SERVICE_NAME"
done
popd >/dev/null
echo "----------------------------------------"
echo " Fusion build complete!"
echo "----------------------------------------"

Binary file not shown.

View File

@@ -8,6 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="HotChocolate.AspNetCore.CommandLine" Version="15.1.11" />
<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>

View File

@@ -77,6 +77,6 @@ public class Program
app.MapGraphQL(); app.MapGraphQL();
app.Run(); app.RunWithGraphQLCommands(args);
} }
} }

View File

@@ -0,0 +1,6 @@
{
"subgraph": "Novels",
"http": {
"baseAddress": "http://localhost:5101/graphql"
}
}

View File

@@ -69,6 +69,6 @@ public class Program
app.MapGraphQL(); app.MapGraphQL();
app.Run(); app.RunWithGraphQLCommands(args);
} }
} }

View File

@@ -0,0 +1,6 @@
{
"subgraph": "Scheduler",
"http": {
"baseAddress": "http://localhost:5213/graphql"
}
}

View File

@@ -12,7 +12,13 @@ public static class GraphQLExtensions
return services.AddGraphQLServer() return services.AddGraphQLServer()
.AddQueryType<TQuery>() .AddQueryType<TQuery>()
.AddMutationType<TMutation>() .AddMutationType<TMutation>()
.AddDiagnosticEventListener<ErrorEventListener>() .ApplySaneDefaults();
}
public static IRequestExecutorBuilder ApplySaneDefaults(this IRequestExecutorBuilder builder)
{
return builder.AddDiagnosticEventListener<ErrorEventListener>()
.AddErrorFilter<LoggingErrorFilter>() .AddErrorFilter<LoggingErrorFilter>()
.AddType<UnsignedIntType>() .AddType<UnsignedIntType>()
.AddType<InstantType>() .AddType<InstantType>()

View File

@@ -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.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" />
<PackageReference Include="HotChocolate.Types.NodaTime" Version="15.1.11" /> <PackageReference Include="HotChocolate.Types.NodaTime" Version="15.1.11" />

View File

@@ -1,4 +1,5 @@
// <auto-generated /> // <auto-generated />
using System;
using FictionArchive.Service.TranslationService.Services.Database; using FictionArchive.Service.TranslationService.Services.Database;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
@@ -12,7 +13,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace FictionArchive.Service.TranslationService.Migrations namespace FictionArchive.Service.TranslationService.Migrations
{ {
[DbContext(typeof(TranslationServiceDbContext))] [DbContext(typeof(TranslationServiceDbContext))]
[Migration("20251118052322_Initial")] [Migration("20251122225458_Initial")]
partial class Initial partial class Initial
{ {
/// <inheritdoc /> /// <inheritdoc />
@@ -27,11 +28,9 @@ namespace FictionArchive.Service.TranslationService.Migrations
modelBuilder.Entity("FictionArchive.Service.TranslationService.Models.Database.TranslationRequest", b => modelBuilder.Entity("FictionArchive.Service.TranslationService.Models.Database.TranslationRequest", b =>
{ {
b.Property<long>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("bigint"); .HasColumnType("uuid");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<long>("BilledCharacterCount") b.Property<long>("BilledCharacterCount")
.HasColumnType("bigint"); .HasColumnType("bigint");

View File

@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore.Migrations; using System;
using Microsoft.EntityFrameworkCore.Migrations;
using NodaTime; using NodaTime;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable #nullable disable
@@ -16,8 +16,7 @@ namespace FictionArchive.Service.TranslationService.Migrations
name: "TranslationRequests", name: "TranslationRequests",
columns: table => new columns: table => new
{ {
Id = table.Column<long>(type: "bigint", nullable: false) Id = table.Column<Guid>(type: "uuid", nullable: false),
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OriginalText = table.Column<string>(type: "text", nullable: false), OriginalText = table.Column<string>(type: "text", nullable: false),
TranslatedText = table.Column<string>(type: "text", nullable: true), TranslatedText = table.Column<string>(type: "text", nullable: true),
From = table.Column<int>(type: "integer", nullable: false), From = table.Column<int>(type: "integer", nullable: false),

View File

@@ -1,4 +1,5 @@
// <auto-generated /> // <auto-generated />
using System;
using FictionArchive.Service.TranslationService.Services.Database; using FictionArchive.Service.TranslationService.Services.Database;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
@@ -24,11 +25,9 @@ namespace FictionArchive.Service.TranslationService.Migrations
modelBuilder.Entity("FictionArchive.Service.TranslationService.Models.Database.TranslationRequest", b => modelBuilder.Entity("FictionArchive.Service.TranslationService.Models.Database.TranslationRequest", b =>
{ {
b.Property<long>("Id") b.Property<Guid>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("bigint"); .HasColumnType("uuid");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<long>("BilledCharacterCount") b.Property<long>("BilledCharacterCount")
.HasColumnType("bigint"); .HasColumnType("bigint");

View File

@@ -73,6 +73,6 @@ public class Program
app.MapGraphQL(); app.MapGraphQL();
app.Run(); app.RunWithGraphQLCommands(args);
} }
} }

View File

@@ -0,0 +1,6 @@
{
"subgraph": "Translation",
"http": {
"baseAddress": "http://localhost:5234/graphql"
}
}

View File

@@ -47,6 +47,6 @@ public class Program
app.MapHealthChecks("/healthz"); app.MapHealthChecks("/healthz");
app.Run(); app.RunWithGraphQLCommands(args);
} }
} }

View File

@@ -0,0 +1,6 @@
{
"subgraph": "User",
"http": {
"baseAddress": "http://localhost:5145/graphql"
}
}

View File

@@ -16,11 +16,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.User
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.AuthenticationService", "FictionArchive.Service.AuthenticationService\FictionArchive.Service.AuthenticationService.csproj", "{70C4AE82-B01E-421D-B590-C0F47E63CD0C}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.AuthenticationService", "FictionArchive.Service.AuthenticationService\FictionArchive.Service.AuthenticationService.csproj", "{70C4AE82-B01E-421D-B590-C0F47E63CD0C}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{35C67E32-A17F-4EAB-B141-88AFCE11FF9C}"
ProjectSection(SolutionItems) = preProject
compose.yaml = compose.yaml
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU