using backend.Data; using backend.Email; using backend.Helpers; using backend.Jobs; using backend.Services; using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi.Models; using Quartz; using WebApi.Helpers; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.Configure(builder.Configuration.GetSection("AppSettings")); builder.Services.AddControllers().AddNewtonsoftJson(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo() { Title = "resTools backend", Version = "v1" }); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { In = Microsoft.OpenApi.Models.ParameterLocation.Header, Description = "Please enter into field the word 'Bearer' following by space and JWT", Name = "Authorization", Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey, Scheme="Bearer" }); c.AddSecurityRequirement(new OpenApiSecurityRequirement() { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }, Name = "Bearer", In = ParameterLocation.Header, }, new List() } }); }); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddTransient(); builder.Services.AddDbContext(p => p.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); builder.Services.AddQuartz(q => { q.UseMicrosoftDependencyInjectionScopedJobFactory(); var jobKey = new JobKey("QueueJob"); q.AddJob(opts => opts.WithIdentity(jobKey)); q.AddTrigger(opts => opts .ForJob(jobKey) .WithIdentity("QueueJob-trigger") .WithCronSchedule("0 0/1 * * * ?")); }); IServiceCollection serviceCollection = builder.Services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true); var app = builder.Build(); app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); // custom jwt auth middleware app.UseMiddleware(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.Run();