Compare commits
3 Commits
feature/FA
...
ceb4271182
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ceb4271182 | ||
|
|
ffa51cfce4 | ||
| 592fa7fb36 |
@@ -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;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
<PackageReference Include="HotChocolate.AspNetCore" Version="15.1.11" />
|
||||
<PackageReference Include="HotChocolate.Data" 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="Microsoft.EntityFrameworkCore.Design" Version="9.0.11">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@@ -28,8 +29,11 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="GraphQL\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FictionArchive.Service.Shared\FictionArchive.Service.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using FictionArchive.Service.Shared.Extensions;
|
||||
|
||||
namespace FictionArchive.API;
|
||||
|
||||
public class Program
|
||||
@@ -6,38 +8,26 @@ public class Program
|
||||
{
|
||||
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();
|
||||
|
||||
#region Fusion Gateway
|
||||
|
||||
builder.Services.AddHttpClient("Fusion");
|
||||
|
||||
builder.Services
|
||||
.AddFusionGatewayServer()
|
||||
.ConfigureFromFile("gateway.fgp")
|
||||
.CoreBuilder.ApplySaneDefaults();
|
||||
|
||||
#endregion
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapGraphQL();
|
||||
|
||||
app.MapHealthChecks("/healthz");
|
||||
|
||||
app.MapControllers();
|
||||
app.MapGraphQL();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"launchUrl": "graphql",
|
||||
"applicationUrl": "https://localhost:7063;http://localhost:5234",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
|
||||
BIN
FictionArchive.API/gateway.fgp
Normal file
BIN
FictionArchive.API/gateway.fgp
Normal file
Binary file not shown.
@@ -8,6 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HotChocolate.AspNetCore.CommandLine" Version="15.1.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.11">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -77,6 +77,8 @@ public class Program
|
||||
|
||||
app.MapGraphQL();
|
||||
|
||||
app.RunWithGraphQLCommands(args);
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
6
FictionArchive.Service.NovelService/subgraph-config.json
Normal file
6
FictionArchive.Service.NovelService/subgraph-config.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"subgraph": "Novels",
|
||||
"http": {
|
||||
"baseAddress": "http://localhost:5101/graphql"
|
||||
}
|
||||
}
|
||||
@@ -10,15 +10,21 @@ public static class GraphQLExtensions
|
||||
public static IRequestExecutorBuilder AddDefaultGraphQl<TQuery, TMutation>(this IServiceCollection services) where TQuery : class where TMutation : class
|
||||
{
|
||||
return services.AddGraphQLServer()
|
||||
.AddQueryType<TQuery>()
|
||||
.AddMutationType<TMutation>()
|
||||
.AddDiagnosticEventListener<ErrorEventListener>()
|
||||
.AddErrorFilter<LoggingErrorFilter>()
|
||||
.AddType<UnsignedIntType>()
|
||||
.AddType<InstantType>()
|
||||
.AddMutationConventions(applyToAllMutations: true)
|
||||
.AddFiltering(opt => opt.AddDefaults().BindRuntimeType<uint, UnsignedIntOperationFilterInputType>())
|
||||
.AddSorting()
|
||||
.AddProjections();
|
||||
.AddQueryType<TQuery>()
|
||||
.AddMutationType<TMutation>()
|
||||
.ApplySaneDefaults();
|
||||
|
||||
}
|
||||
|
||||
public static IRequestExecutorBuilder ApplySaneDefaults(this IRequestExecutorBuilder builder)
|
||||
{
|
||||
return builder.AddDiagnosticEventListener<ErrorEventListener>()
|
||||
.AddErrorFilter<LoggingErrorFilter>()
|
||||
.AddType<UnsignedIntType>()
|
||||
.AddType<InstantType>()
|
||||
.AddMutationConventions(applyToAllMutations: true)
|
||||
.AddFiltering(opt => opt.AddDefaults().BindRuntimeType<uint, UnsignedIntOperationFilterInputType>())
|
||||
.AddSorting()
|
||||
.AddProjections();
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.User
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FictionArchive.Service.AuthenticationService", "FictionArchive.Service.AuthenticationService\FictionArchive.Service.AuthenticationService.csproj", "{70C4AE82-B01E-421D-B590-C0F47E63CD0C}"
|
||||
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
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
||||
Reference in New Issue
Block a user