[b66b3ac] | 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"));
|
---|
[057037b] | 12 | builder.Services.AddControllers().AddNewtonsoftJson();
|
---|
[b66b3ac] | 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>();
|
---|
[057037b] | 46 | builder.Services.AddScoped<IRestaurantService, RestaurantService>();
|
---|
| 47 | builder.Services.AddScoped<IReservationService, ReservationService>();
|
---|
[cc4db18] | 48 | builder.Services.AddScoped<IMenuService, MenuService>();
|
---|
[057037b] | 49 | builder.Services.AddScoped<ISmsService, SmsService>();
|
---|
[b66b3ac] | 50 |
|
---|
| 51 | builder.Services.AddDbContext<DataContext>(p => p.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
|
---|
| 52 |
|
---|
| 53 | var app = builder.Build();
|
---|
| 54 |
|
---|
| 55 | app.UseCors(x => x
|
---|
| 56 | .AllowAnyOrigin()
|
---|
| 57 | .AllowAnyMethod()
|
---|
| 58 | .AllowAnyHeader());
|
---|
| 59 |
|
---|
| 60 | // custom jwt auth middleware
|
---|
| 61 | app.UseMiddleware<JwtMiddleware>();
|
---|
| 62 |
|
---|
| 63 | // Configure the HTTP request pipeline.
|
---|
| 64 | if (app.Environment.IsDevelopment())
|
---|
| 65 | {
|
---|
| 66 | app.UseSwagger();
|
---|
| 67 | app.UseSwaggerUI();
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | app.UseHttpsRedirection();
|
---|
| 71 |
|
---|
| 72 | app.UseAuthorization();
|
---|
| 73 |
|
---|
| 74 | app.MapControllers();
|
---|
| 75 |
|
---|
| 76 | app.Run();
|
---|