1 | using backend.Data;
|
---|
2 | using backend.Email;
|
---|
3 | using backend.Helpers;
|
---|
4 | using backend.Services;
|
---|
5 | using Microsoft.EntityFrameworkCore;
|
---|
6 | using Microsoft.OpenApi.Models;
|
---|
7 | using WebApi.Helpers;
|
---|
8 |
|
---|
9 | var builder = WebApplication.CreateBuilder(args);
|
---|
10 |
|
---|
11 | // Add services to the container.
|
---|
12 | builder.Services.Configure<AppSettings>(builder.Configuration.GetSection("AppSettings"));
|
---|
13 | builder.Services.AddControllers().AddNewtonsoftJson();
|
---|
14 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
---|
15 | builder.Services.AddEndpointsApiExplorer();
|
---|
16 | builder.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 | });
|
---|
46 | builder.Services.AddScoped<IUserService, UserService>();
|
---|
47 | builder.Services.AddScoped<IRestaurantService, RestaurantService>();
|
---|
48 | builder.Services.AddScoped<IReservationService, ReservationService>();
|
---|
49 | builder.Services.AddScoped<IMenuService, MenuService>();
|
---|
50 | builder.Services.AddScoped<IReviewService, ReviewService>();
|
---|
51 | builder.Services.AddScoped<ISmsService, SmsService>();
|
---|
52 | builder.Services.AddScoped<IToDoService, ToDoService>();
|
---|
53 |
|
---|
54 | builder.Services.AddTransient<IEmailSender, EmailSender>();
|
---|
55 |
|
---|
56 | builder.Services.AddDbContext<DataContext>(p => p.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
|
---|
57 |
|
---|
58 | var app = builder.Build();
|
---|
59 |
|
---|
60 | app.UseCors(x => x
|
---|
61 | .AllowAnyOrigin()
|
---|
62 | .AllowAnyMethod()
|
---|
63 | .AllowAnyHeader());
|
---|
64 |
|
---|
65 | // custom jwt auth middleware
|
---|
66 | app.UseMiddleware<JwtMiddleware>();
|
---|
67 |
|
---|
68 | // Configure the HTTP request pipeline.
|
---|
69 | if (app.Environment.IsDevelopment())
|
---|
70 | {
|
---|
71 | app.UseSwagger();
|
---|
72 | app.UseSwaggerUI();
|
---|
73 | }
|
---|
74 |
|
---|
75 | app.UseHttpsRedirection();
|
---|
76 |
|
---|
77 | app.UseAuthorization();
|
---|
78 |
|
---|
79 | app.MapControllers();
|
---|
80 |
|
---|
81 | app.Run();
|
---|