source: resTools_backend/backend/Program.cs@ 49b0bbd

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

todo items full functionality

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