42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using LexWells.Infrastructure.Common;
|
|
using LexWells.Infrastructure.EntityFramework;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using NewsArchival.Api.Data;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// 1. Infrastructure First (Redis + HttpClient + Robots)
|
|
builder.Services.AddLexWellsInfrastructure(
|
|
builder.Configuration.GetConnectionString("Redis") ?? "localhost:6379");
|
|
|
|
// 2. Database Support
|
|
builder.Services.AddLexWellsDatabase<AppDbContext>(
|
|
builder.Configuration.GetConnectionString("DefaultConnection") ?? "Data Source=news.db");
|
|
|
|
builder.Services.AddControllers();
|
|
builder.Services.AddOpenApi();
|
|
|
|
var app = builder.Build();
|
|
|
|
using (var scope = app.Services.CreateScope())
|
|
{
|
|
var context = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
|
|
|
context.Database.Migrate();
|
|
}
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapOpenApi();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.MapControllers();
|
|
|
|
app.MapGet("/api/check", async (string id, AppDbContext db) =>
|
|
await db.Articles.AnyAsync(a => a.Id == id)
|
|
? Results.Ok(new { exists = true })
|
|
: Results.NotFound(new { exists = false }));
|
|
|
|
app.Run(); |