|
|
@ -6,6 +6,8 @@ using Server.Services;
|
|
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
using Infrastructure.Repositories;
|
|
|
|
using Infrastructure.Repositories;
|
|
|
|
using AutoMapper;
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Server.Mappers;
|
|
|
|
using Server.Mappers;
|
|
|
|
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
@ -34,6 +36,8 @@ builder.Services.AddAutoMapper(typeof(PaginatedResultProfile));
|
|
|
|
builder.Services.AddAutoMapper(typeof(TrainingProgramProfile));
|
|
|
|
builder.Services.AddAutoMapper(typeof(TrainingProgramProfile));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
|
|
|
|
|
|
|
@ -50,9 +54,41 @@ builder.Services.AddApiVersioning(options =>
|
|
|
|
options.SubstituteApiVersionInUrl = true;
|
|
|
|
options.SubstituteApiVersionInUrl = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
builder.Services.AddSwaggerGen(c =>
|
|
|
|
builder.Services.AddSwaggerGen(option =>
|
|
|
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Optifit API", Version = "v1" })
|
|
|
|
{
|
|
|
|
);
|
|
|
|
option.SwaggerDoc("v1", new OpenApiInfo { Title = "Optifit API", Version = "v1" });
|
|
|
|
|
|
|
|
option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
In = ParameterLocation.Header,
|
|
|
|
|
|
|
|
Description = "Please enter a valid token",
|
|
|
|
|
|
|
|
Name = "Authorization",
|
|
|
|
|
|
|
|
Type = SecuritySchemeType.Http,
|
|
|
|
|
|
|
|
BearerFormat = "JWT",
|
|
|
|
|
|
|
|
Scheme = "Bearer"
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
option.AddSecurityRequirement(new OpenApiSecurityRequirement
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
new OpenApiSecurityScheme
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Reference = new OpenApiReference
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Type=ReferenceType.SecurityScheme,
|
|
|
|
|
|
|
|
Id="Bearer"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
new string[]{}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
builder.Services.AddDbContext<ApplicationDbContext>(
|
|
|
|
|
|
|
|
options => options.UseInMemoryDatabase("AppDb"));
|
|
|
|
|
|
|
|
builder.Services.AddAuthorization();
|
|
|
|
|
|
|
|
builder.Services.AddIdentityApiEndpoints<IdentityUser>()
|
|
|
|
|
|
|
|
.AddEntityFrameworkStores<ApplicationDbContext>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
builder.Services.AddRouting(options => options.LowercaseUrls = true);
|
|
|
|
builder.Services.AddRouting(options => options.LowercaseUrls = true);
|
|
|
|
|
|
|
|
|
|
|
@ -70,6 +106,23 @@ if (app.Environment.IsDevelopment())
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.MapIdentityApi<IdentityUser>();
|
|
|
|
|
|
|
|
app.MapSwagger().RequireAuthorization();
|
|
|
|
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.MapControllers();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.MapPost("/logout", async (SignInManager<IdentityUser> signInManager,
|
|
|
|
|
|
|
|
[FromBody]object empty) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (empty != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await signInManager.SignOutAsync();
|
|
|
|
|
|
|
|
return Results.Ok();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Results.Unauthorized();
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.WithOpenApi()
|
|
|
|
|
|
|
|
.RequireAuthorization();
|
|
|
|
|
|
|
|
|
|
|
|
app.Run();
|
|
|
|
app.Run();
|