Reescrita dos geradores: biblioteca IGenerator, minimal API e novo frontend
- GeradoresService: cada tipo passa a ser um IGenerator (NIF, NIPC, NISS, CC, passaporte, IBAN, NIB, cartões, referência MB, pessoa, telefone, código postal, email, matrícula, EAN, UUID) registado em GeneratorRegistry; remove DAL/EF - GeradoresWS: minimal APIs em /api/v1 com OpenAPI + Scalar e health check - UnitTest: testes de ida e volta, valores conhecidos, detecção e API - geradoresfe: UI construída a partir dos metadados da API, validador livre, exportação CSV/JSON/TXT, nginx com API_UPSTREAM configurável - Docker, docker-compose e Jenkinsfile actualizados Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,56 +1,40 @@
|
||||
using GeradoresService.DAL;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Primus.ProfitabilityModel.WebAPI.Filters;
|
||||
using System.Text.Json.Serialization;
|
||||
using GeradoresService;
|
||||
using GeradoresWS;
|
||||
using Scalar.AspNetCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllers().AddJsonOptions(options =>
|
||||
builder.Services.AddSingleton<GeneratorRegistry>();
|
||||
builder.Services.AddProblemDetails();
|
||||
builder.Services.AddHealthChecks();
|
||||
builder.Services.AddOpenApi(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
||||
});
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
|
||||
options.SwaggerDoc("v1", new OpenApiInfo
|
||||
options.AddDocumentTransformer((document, _, _) =>
|
||||
{
|
||||
|
||||
Version = "v1",
|
||||
Title = "FactoryId",
|
||||
Contact = new OpenApiContact
|
||||
{
|
||||
Name = "Marco Santos"
|
||||
},
|
||||
document.Info.Title = "FactoryId API";
|
||||
document.Info.Description = "Geradores e validadores de identificadores portugueses (NIF, NISS, CC, IBAN, …) para testes.";
|
||||
document.Info.Contact = new() { Name = "Marco Santos" };
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
// Registra o filtro de esquema que aplica descrições para todos os enums
|
||||
options.SchemaFilter<EnumDescriptionFilter>();
|
||||
});
|
||||
|
||||
|
||||
var connectionString = builder.Configuration.GetConnectionString("GeradoresConnection");
|
||||
builder.Services.AddDbContext<GeradoresContext>(options => options.UseSqlServer(connectionString));
|
||||
// API pública, só de leitura e sem credenciais: qualquer origem pode fazer GET.
|
||||
builder.Services.AddCors(options =>
|
||||
options.AddDefaultPolicy(policy => policy.AllowAnyOrigin().WithMethods("GET").AllowAnyHeader()));
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseExceptionHandler();
|
||||
app.UseStatusCodePages();
|
||||
app.UseCors();
|
||||
|
||||
app.UseAuthorization();
|
||||
app.MapOpenApi();
|
||||
app.MapScalarApiReference("/docs", options => options.WithTitle("FactoryId API"));
|
||||
app.MapGet("/", () => Results.Redirect("/docs")).ExcludeFromDescription();
|
||||
app.MapHealthChecks("/health");
|
||||
|
||||
app.UseCors(options =>
|
||||
{
|
||||
options.AllowAnyOrigin();
|
||||
options.AllowAnyMethod();
|
||||
options.AllowAnyHeader();
|
||||
});
|
||||
|
||||
app.MapControllers();
|
||||
app.MapGeneratorEndpoints();
|
||||
|
||||
app.Run();
|
||||
|
||||
public partial class Program;
|
||||
|
||||
Reference in New Issue
Block a user