using HopFrame.Core.Services; using HopFrame.Web; using Microsoft.EntityFrameworkCore; using SpotiParty.Web; using SpotiParty.Web.Components; using SpotiParty.Web.Models; using SpotiParty.Web.Services; var builder = WebApplication.CreateBuilder(args); builder.Configuration.AddEnvironmentVariables(); // Add services to the container. builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); builder.AddServiceDefaults(); AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); builder.Services.AddHttpContextAccessor(); builder.Services.AddScoped(); builder.AddNpgsqlDbContext("SpotiParty"); builder.Services.AddDbContextFactory(options => { options.UseNpgsql(builder.Configuration.GetConnectionString("SpotiParty")); }); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddHopFrame(config => { config.SetLoginPage("/login"); config.AddDbContext(context => { context.Table(table => { table .SetViewPolicy(DashboardAuthHandler.AdminPolicy) .SetCreatePolicy(DashboardAuthHandler.AdminPolicy) .SetUpdatePolicy(DashboardAuthHandler.AdminPolicy) .SetDeletePolicy(DashboardAuthHandler.AdminPolicy); table.Property(u => u.RefreshToken) .List(false) .DisplayValue(false) .SetEditable(false); }); context.Table() .SetDisplayName(Guid.NewGuid().ToString()) .Ignore(true); }); config.AddCustomRepository(e => e.Id, table => { table.SetDisplayName("Events"); table.Property(e => e.Id) .List(false) .SetEditable(false) .SetCreatable(false); table.Property(e => e.Host) .List(false) .SetEditable(false) .SetCreatable(false) .SetDisplayedProperty(u => u.DisplayName); table.ShowSearchSuggestions(false); }); config.AddPlugin(); }); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error", createScopeForErrors: true); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } await using (var scope = app.Services.CreateAsyncScope()) { var context = scope.ServiceProvider.GetRequiredService(); await context.Database.MigrateAsync(); } app.MapDefaultEndpoints(); app.UseStatusCodePagesWithReExecute("/not-found"); //app.UseHttpsRedirection(); app.UseAntiforgery(); app.MapStaticAssets(); app.MapRazorComponents() .AddInteractiveServerRenderMode() .AddHopFramePages(); app.Run();