DATA-2: new schema entities + Minimal API endpoints + Scalar + DAL teardown
- Entities: Breeder->Contact, +Enclosure/ColorVariety/GerbilPhoto/HealthRecord/WeightRecord;
Gerbil expanded (single Genotype text col, Status/Gender enums-as-string, FK ids,
ImportSource/ExternalRef provenance); Litter Strength->TotalBorn +ExpectedGoHomeDate/Notes.
ColorVariety HasData seed = 18 from GEN-1 catalog. Gerbil<->Litter cycle handled
(SetNull/Restrict). Enums stored as strings.
- Minimal API (no controllers): Endpoints/*.cs MapGroup+TypedResults for gerbils, litters,
contacts, enclosures, color-varieties, health/weight-records, inbreeding (converted from
controller, same routes/shapes), photos (Oscar contract: GET array/POST multipart/DELETE,
url /photos/files/{fileName}). Gridify paged {items,totalCount,page,pageSize}, camelCase,
409 conflict-deletes, flat FK ids, litter parent-gender validation (400 {code,...}).
- Scalar replaces Swashbuckle (AddOpenApi/MapOpenApi + MapScalarApiReference at /scalar);
launchUrl swagger->scalar. GenericRepository/UnitOfWork/Converters deleted; DbContext direct.
- InbreedingService reads real FK props now; pure calculator + 8 tests untouched.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
using GerbilManagerWebAPI.DAL;
|
||||
using System.Text.Json.Serialization;
|
||||
using GerbilManagerWebAPI.Endpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Scalar.AspNetCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.AddServiceDefaults();
|
||||
|
||||
// LAN reachability: bind on all interfaces so devices on the home network (the
|
||||
// SPA on a phone/laptop) can reach the API. We keep whatever port Aspire /
|
||||
// launchSettings assigned and only widen the host from localhost to 0.0.0.0.
|
||||
// LAN reachability: bind on all interfaces (keep the Aspire/launch-assigned port),
|
||||
// so phones/laptops on the home network can reach the API (trusted LAN, no auth).
|
||||
var aspnetUrls = Environment.GetEnvironmentVariable("ASPNETCORE_URLS");
|
||||
if (!string.IsNullOrWhiteSpace(aspnetUrls))
|
||||
{
|
||||
@@ -17,43 +18,49 @@ if (!string.IsNullOrWhiteSpace(aspnetUrls))
|
||||
builder.WebHost.UseUrls(lanUrls);
|
||||
}
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.AddNpgsqlDbContext<ApplicationContext>("gerbilmanager");
|
||||
builder.Services.AddScoped<UnitOfWork>();
|
||||
|
||||
// Permissive CORS for the trusted home LAN (no auth — see hive scope rule).
|
||||
// The SPA calls the API cross-origin from other devices on the network.
|
||||
// JSON: camelCase property names + enums serialised as their string names (frontend contract).
|
||||
builder.Services.ConfigureHttpJsonOptions(o =>
|
||||
{
|
||||
o.SerializerOptions.PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase;
|
||||
o.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
||||
});
|
||||
|
||||
// Permissive CORS for the trusted home LAN (no auth — see board constraint).
|
||||
const string LanCorsPolicy = "lan";
|
||||
builder.Services.AddCors(options => options.AddPolicy(LanCorsPolicy, policy =>
|
||||
policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()));
|
||||
|
||||
// OpenAPI document for the Scalar API reference (Swashbuckle removed).
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapDefaultEndpoints();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
// API reference at /scalar (built on the OpenAPI doc at /openapi/v1.json).
|
||||
app.MapOpenApi();
|
||||
app.MapScalarApiReference();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
|
||||
// Aspire provisions an empty database in dev — bring the schema up to date.
|
||||
using var scope = app.Services.CreateScope();
|
||||
scope.ServiceProvider.GetRequiredService<ApplicationContext>().Database.Migrate();
|
||||
}
|
||||
|
||||
// No HTTPS redirection: the LAN clients (phone) talk plain HTTP to avoid
|
||||
// dev-certificate trust issues on the device.
|
||||
|
||||
app.UseCors(LanCorsPolicy);
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
// Endpoint groups (Minimal API, no controllers).
|
||||
app.MapGerbilEndpoints();
|
||||
app.MapLitterEndpoints();
|
||||
app.MapContactEndpoints();
|
||||
app.MapEnclosureEndpoints();
|
||||
app.MapColorVarietyEndpoints();
|
||||
app.MapHealthRecordEndpoints();
|
||||
app.MapWeightRecordEndpoints();
|
||||
app.MapInbreedingEndpoints();
|
||||
app.MapPhotoEndpoints();
|
||||
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user