source: resTools_backend/backend/Program.cs@ 13f1472

Last change on this file since 13f1472 was 13f1472, checked in by Danilo <danilo.najkov@…>, 22 months ago

vip functionallity + menu fields + alergens filtering + google/fb login + email queueing

  • Property mode set to 100644
File size: 3.0 KB
Line 
1using backend.Data;
2using backend.Email;
3using backend.Helpers;
4using backend.Jobs;
5using backend.Services;
6using Microsoft.EntityFrameworkCore;
7using Microsoft.OpenApi.Models;
8using Quartz;
9using WebApi.Helpers;
10
11var builder = WebApplication.CreateBuilder(args);
12
13// Add services to the container.
14builder.Services.Configure<AppSettings>(builder.Configuration.GetSection("AppSettings"));
15builder.Services.AddControllers().AddNewtonsoftJson();
16// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
17builder.Services.AddEndpointsApiExplorer();
18builder.Services.AddSwaggerGen(c =>
19{
20 c.SwaggerDoc("v1", new OpenApiInfo() { Title = "resTools backend", Version = "v1" });
21 c.AddSecurityDefinition("Bearer",
22 new OpenApiSecurityScheme
23 {
24 In = Microsoft.OpenApi.Models.ParameterLocation.Header,
25 Description = "Please enter into field the word 'Bearer' following by space and JWT",
26 Name = "Authorization",
27 Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey,
28 Scheme="Bearer"
29 });
30 c.AddSecurityRequirement(new OpenApiSecurityRequirement()
31 {
32 {
33 new OpenApiSecurityScheme
34 {
35 Reference = new OpenApiReference
36 {
37 Type = ReferenceType.SecurityScheme,
38 Id = "Bearer"
39 },
40 Name = "Bearer",
41 In = ParameterLocation.Header,
42
43 },
44 new List<string>()
45 }
46 });
47});
48builder.Services.AddScoped<IUserService, UserService>();
49builder.Services.AddScoped<IRestaurantService, RestaurantService>();
50builder.Services.AddScoped<IReservationService, ReservationService>();
51builder.Services.AddScoped<IMenuService, MenuService>();
52builder.Services.AddScoped<IReviewService, ReviewService>();
53builder.Services.AddScoped<ISmsService, SmsService>();
54builder.Services.AddScoped<IToDoService, ToDoService>();
55
56builder.Services.AddTransient<IEmailSender, EmailSender>();
57
58builder.Services.AddDbContext<DataContext>(p => p.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
59
60builder.Services.AddQuartz(q =>
61{
62 q.UseMicrosoftDependencyInjectionScopedJobFactory();
63 var jobKey = new JobKey("QueueJob");
64 q.AddJob<QueueJob>(opts => opts.WithIdentity(jobKey));
65
66 q.AddTrigger(opts => opts
67 .ForJob(jobKey)
68 .WithIdentity("QueueJob-trigger")
69 .WithCronSchedule("0 0/1 * * * ?"));
70
71});
72
73IServiceCollection serviceCollection = builder.Services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
74
75var app = builder.Build();
76
77app.UseCors(x => x
78 .AllowAnyOrigin()
79 .AllowAnyMethod()
80 .AllowAnyHeader());
81
82// custom jwt auth middleware
83app.UseMiddleware<JwtMiddleware>();
84
85// Configure the HTTP request pipeline.
86if (app.Environment.IsDevelopment())
87{
88 app.UseSwagger();
89 app.UseSwaggerUI();
90}
91
92app.UseHttpsRedirection();
93
94app.UseAuthorization();
95
96app.MapControllers();
97
98app.Run();
Note: See TracBrowser for help on using the repository browser.