use bundled http logging feature instead of hand-made middleware

tests
maxime 1 year ago
parent 19ec55009b
commit 9af2167c14

@ -16,6 +16,9 @@ var config = builder.Configuration;
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHttpLogging(o => {});
builder.Services.AddControllers()
.ConfigureApiBehaviorOptions(options => options.InvalidModelStateResponseFactory = context =>
new BadRequestObjectResult(context.ModelState)
@ -53,16 +56,17 @@ builder.Services.AddScoped<IUserService, DbUserService>();
builder.Services.AddScoped<ITeamService, DbTeamService>();
builder.Services.AddScoped<ITacticService, DbTacticService>();
var app = builder.Build();
System.AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
app.Use((context, next) =>
{
var req = context.Request;
Console.WriteLine($"{req.Method}: {req.Path}{req.QueryString}");
return next.Invoke();
});
// app.Use((context, next) =>
// {
// var req = context.Request;
// Console.WriteLine($"{req.Method}: {req.Path}{req.QueryString}");
// return next.Invoke();
// });
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
@ -71,6 +75,7 @@ if (app.Environment.IsDevelopment())
app.UseSwaggerUI();
}
app.UseHttpLogging();
app.UseHttpsRedirection();
app.UseCors("cors");

@ -136,28 +136,23 @@ public class DbTacticService(AppContext.AppContext context) : ITacticService
public async Task<bool> RemoveTacticStep(int tacticId, int stepId)
{
var toRemove = new Stack<int>();
toRemove.Push(stepId);
var toRemove = new Stack<TacticStepEntity>();
while (toRemove.TryPop(out var id))
{
var step = await context.TacticSteps
.FirstOrDefaultAsync(t => t.TacticId == tacticId && t.StepId == id);
var beginStep = await context
.TacticSteps
.FirstOrDefaultAsync(t => t.TacticId == tacticId && t.StepId == stepId);
if (step == null)
{
if (id == stepId)
if (beginStep == null)
return false;
throw new Exception(
$"step contains a children that does not exists in the database ({tacticId} / {id})"
);
}
var stepChildren = context.TacticSteps.Where(s => s.ParentId == id);
foreach (var stepChild in stepChildren)
toRemove.Push(beginStep);
while (toRemove.TryPop(out var step))
{
toRemove.Push(stepChild.StepId);
}
await context.TacticSteps
.Where(s => s.TacticId == tacticId && s.ParentId == step.StepId)
.ForEachAsync(toRemove.Push);
context.Remove(step);
}

Loading…
Cancel
Save