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