2025-08-25 00:06:43 -03:00
|
|
|
// Note: repository implementation removed for workshop exercise (TODOs in project files)
|
|
|
|
using Microsoft.AspNetCore.Diagnostics;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
2025-08-24 12:08:35 -03:00
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
2025-08-25 00:06:43 -03:00
|
|
|
// Add services
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
builder.Services.AddSwaggerGen(o =>
|
|
|
|
{
|
|
|
|
o.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
|
|
|
|
{
|
|
|
|
Title = "CampusWorkshops API",
|
|
|
|
Version = "v1",
|
|
|
|
Description = "API para gestão de workshops do campus (MVP in-memory)."
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// DI
|
2025-08-24 12:08:35 -03:00
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
2025-08-25 00:06:43 -03:00
|
|
|
// Exception handler that returns RFC7807 ProblemDetails for unhandled errors
|
|
|
|
app.UseExceptionHandler(errApp =>
|
2025-08-24 12:08:35 -03:00
|
|
|
{
|
2025-08-25 00:06:43 -03:00
|
|
|
errApp.Run(async context =>
|
|
|
|
{
|
|
|
|
var feature = context.Features.Get<IExceptionHandlerFeature>();
|
|
|
|
var ex = feature?.Error;
|
|
|
|
|
|
|
|
var pd = new ProblemDetails
|
|
|
|
{
|
|
|
|
Title = "An unexpected error occurred.",
|
|
|
|
Status = StatusCodes.Status500InternalServerError,
|
|
|
|
Detail = app.Environment.IsDevelopment() ? ex?.Message : null
|
|
|
|
};
|
|
|
|
|
|
|
|
context.Response.StatusCode = pd.Status.Value;
|
|
|
|
context.Response.ContentType = "application/problem+json";
|
|
|
|
await context.Response.WriteAsJsonAsync(pd);
|
|
|
|
});
|
|
|
|
});
|
2025-08-24 12:08:35 -03:00
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
2025-08-25 00:06:43 -03:00
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI(c =>
|
2025-08-24 12:08:35 -03:00
|
|
|
{
|
2025-08-25 00:06:43 -03:00
|
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "CampusWorkshops API v1");
|
|
|
|
c.RoutePrefix = "swagger"; // serve at /swagger
|
|
|
|
});
|
2025-08-24 12:08:35 -03:00
|
|
|
|
2025-08-25 00:06:43 -03:00
|
|
|
app.MapControllers();
|
2025-08-24 12:08:35 -03:00
|
|
|
|
|
|
|
app.Run();
|