Added API project.
This commit is contained in:
103
JSMR.Api/Program.cs
Normal file
103
JSMR.Api/Program.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user