104 lines
2.8 KiB
C#
104 lines
2.8 KiB
C#
using JSMR.Application.Circles.Queries.Search;
|
|
using JSMR.Application.Creators.Queries.Search;
|
|
using JSMR.Application.DI;
|
|
using JSMR.Application.Tags.Queries.Search;
|
|
using JSMR.Application.VoiceWorks.Queries.Search;
|
|
using JSMR.Infrastructure.Data;
|
|
using JSMR.Infrastructure.DI;
|
|
using Microsoft.AspNetCore.Http.Json;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
builder.Services
|
|
.AddMemoryCache() // TODO
|
|
.AddApplication()
|
|
.AddInfrastructure();
|
|
|
|
// DbContext (MySQL here; swap to Npgsql when you migrate)
|
|
var cs = builder.Configuration.GetConnectionString("AppDb")
|
|
?? throw new InvalidOperationException("Missing ConnectionStrings:AppDb");
|
|
|
|
builder.Services.AddDbContext<AppDbContext>(opt =>
|
|
opt.UseMySql(cs, ServerVersion.AutoDetect(cs))
|
|
.EnableSensitiveDataLogging(false));
|
|
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
|
builder.Services.AddOpenApi();
|
|
|
|
builder.Services.Configure<JsonOptions>(options =>
|
|
{
|
|
options.SerializerOptions.PropertyNameCaseInsensitive = true;
|
|
options.SerializerOptions.Converters.Add(
|
|
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)); // or null for exact names
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapOpenApi();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
// Health check
|
|
app.MapGet("/health", () => Results.Ok(new { status = "ok" }));
|
|
|
|
// ---- Endpoints ----
|
|
|
|
// Circles Search
|
|
app.MapPost("/api/circles/search", async (
|
|
SearchCirclesRequest request,
|
|
SearchCirclesHandler handler,
|
|
CancellationToken cancallationToken) =>
|
|
{
|
|
var result = await handler.HandleAsync(request, cancallationToken);
|
|
|
|
return Results.Ok(result);
|
|
});
|
|
|
|
// Voice Works Search
|
|
app.MapPost("/api/voiceworks/search", async (
|
|
SearchVoiceWorksRequest request,
|
|
SearchVoiceWorksHandler handler,
|
|
CancellationToken cancallationToken) =>
|
|
{
|
|
var result = await handler.HandleAsync(request, cancallationToken);
|
|
|
|
return Results.Ok(result);
|
|
});
|
|
|
|
// Tags Search
|
|
app.MapPost("/api/tags/search", async (
|
|
SearchTagsRequest request,
|
|
SearchTagsHandler handler,
|
|
CancellationToken cancallationToken) =>
|
|
{
|
|
var result = await handler.HandleAsync(request, cancallationToken);
|
|
|
|
return Results.Ok(result);
|
|
});
|
|
|
|
// Creators Search
|
|
app.MapPost("/api/creators/search", async (
|
|
SearchCreatorsRequest request,
|
|
SearchCreatorsHandler handler,
|
|
CancellationToken cancallationToken) =>
|
|
{
|
|
var result = await handler.HandleAsync(request, cancallationToken);
|
|
|
|
return Results.Ok(result);
|
|
});
|
|
|
|
app.Run();
|