Skip to content

Commit

Permalink
Fix some bugs and swap prod logger to json
Browse files Browse the repository at this point in the history
  • Loading branch information
NixFey committed Dec 25, 2024
1 parent 0a72e0f commit 04ffb28
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
6 changes: 5 additions & 1 deletion FiMAdminApi.Data/DataContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FiMAdminApi.Data.Enums;
using FiMAdminApi.Data.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;

namespace FiMAdminApi.Data;

Expand Down Expand Up @@ -28,6 +29,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.Entity<EventStaff>()
.Property(e => e.Permissions)
.HasConversion(v => v.Select(p => p.ToString()).ToList(),
v => v.Select(Enum.Parse<EventPermission>).ToList());
v => v.Select(Enum.Parse<EventPermission>).ToList(),
new ValueComparer<List<EventPermission>>((c1, c2) => c2 != null && c1 != null && c1.SequenceEqual(c2),
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
c => c.ToList()));
}
}
2 changes: 2 additions & 0 deletions FiMAdminApi/EventSync/Steps/LoadQualSchedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ await dbContext.Matches
}));

evt.Status = EventStatus.QualsInProgress;

await dbContext.SaveChangesAsync();
}
}
}
20 changes: 15 additions & 5 deletions FiMAdminApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,33 @@
using FiMAdminApi.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.EntityFrameworkCore;
using Npgsql.NameTranslation;

var builder = WebApplication.CreateSlimBuilder(args);

builder.Logging.AddConsole(opt =>
{
builder.Configuration.GetSection("Logging:Console").Bind(opt);
});

builder.Services.ConfigureHttpJsonOptions(options =>
{
// options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
options.SerializerOptions.TypeInfoResolver = SerializerContext.Default;
});
// builder.Services.AddControllers().AddJsonOptions(opt =>
// {
// opt.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
// });

builder.Services.AddApiConfiguration();

// If a data protection directory is not provided, just use the default configuration
var dpDir = builder.Configuration["DataProtectionDirectory"];
if (!string.IsNullOrEmpty(dpDir))
{
var dirInfo = new DirectoryInfo(dpDir);
if (!dirInfo.Exists) throw new ApplicationException($"Data protection directory {dpDir} does not exist");
builder.Services.AddDataProtection().PersistKeysToFileSystem(dirInfo);
}

builder.Services.AddHealthChecks().AddNpgSql(builder.Configuration.GetConnectionString("fimDbConnection") ??
throw new Exception("DB Connection string was null"), name: "Database");

Expand Down
5 changes: 4 additions & 1 deletion FiMAdminApi/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Debug"
"Microsoft.AspNetCore": "Information"
},
"Console": {
"FormatterName": "simple"
}
}
}
3 changes: 3 additions & 0 deletions FiMAdminApi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"Default": "Warning",
"FimAdminApi": "Information",
"Microsoft.AspNetCore": "Warning"
},
"Console": {
"FormatterName": "json"
}
},
"AllowedHosts": "*",
Expand Down

0 comments on commit 04ffb28

Please sign in to comment.