2023-12-07 00:20:59 +00:00
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-12-07 00:29:11 +00:00
|
|
|
using YPS.Beer.Configuration;
|
2023-12-07 00:20:59 +00:00
|
|
|
using YPS.Beer.Data;
|
|
|
|
using YPS.Beer.Models;
|
|
|
|
using YPS.Beer.Services;
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
2023-12-07 00:29:11 +00:00
|
|
|
var punkServiceConfiguration = new PunkServiceConfiguration();
|
|
|
|
builder.Configuration.GetSection(PunkServiceConfiguration.ConfigurationSection).Bind(punkServiceConfiguration);
|
|
|
|
|
|
|
|
|
2023-12-07 00:20:59 +00:00
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
builder.Services.AddControllers();
|
2023-12-07 00:29:11 +00:00
|
|
|
builder.Services.AddHttpClient<IPunkService, PunkService>()
|
|
|
|
.ConfigureHttpClient(client => client.BaseAddress = new Uri(punkServiceConfiguration.BaseUrl));
|
2023-12-07 00:20:59 +00:00
|
|
|
builder.Services.AddScoped<IBeerService, BeerService>();
|
|
|
|
|
|
|
|
builder.Services.AddDbContext<BeerContext>(options => options.UseInMemoryDatabase("yps-beer"));
|
|
|
|
|
|
|
|
builder.Services.AddIdentityCore<User>()
|
|
|
|
.AddEntityFrameworkStores<BeerContext>()
|
|
|
|
.AddApiEndpoints();
|
|
|
|
|
|
|
|
builder.Services.AddAuthentication(IdentityConstants.ApplicationScheme)
|
|
|
|
.AddBearerToken(IdentityConstants.BearerScheme)
|
|
|
|
.AddApplicationCookie();
|
|
|
|
builder.Services.AddAuthorizationBuilder();
|
|
|
|
|
|
|
|
builder.Services.AddCors();
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
|
|
|
|
app.UseCors(cors => cors.AllowAnyHeader().AllowAnyMethod().SetIsOriginAllowed(_ => true).AllowCredentials());
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
|
|
|
app.MapIdentityApi<User>();
|
|
|
|
|
2023-12-07 00:29:11 +00:00
|
|
|
app.Run();
|