clean AppBootstrap.cs
continuous-integration/drone/push Build is passing Details

Test_CI
David D'ALMEIDA 1 year ago
parent 306aee3cd3
commit 597c551875

@ -1,13 +1,10 @@
using System.Reflection;
using DbContextLib;
using DbContextLib.Identity;
using Entities;
using HeartTrackAPI.Utils;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
@ -39,30 +36,29 @@ public class AppBootstrap(IConfiguration configuration)
private void AddHeartTrackContextServices(IServiceCollection services)
{
string connectionString;
string? connectionString;
switch (Environment.GetEnvironmentVariable("TYPE"))
{
case "BDD":
var HOST = System.Environment.GetEnvironmentVariable("HOST");
var PORT = System.Environment.GetEnvironmentVariable("PORTDB");
var DATABASE = System.Environment.GetEnvironmentVariable("DATABASE");
var USERNAME = System.Environment.GetEnvironmentVariable("USERNAME");
var PASSWORD = System.Environment.GetEnvironmentVariable("PASSWORD");
var host = Environment.GetEnvironmentVariable("HOST");
var port = Environment.GetEnvironmentVariable("PORTDB");
var database = Environment.GetEnvironmentVariable("DATABASE");
var username = Environment.GetEnvironmentVariable("USERNAME");
var password = Environment.GetEnvironmentVariable("PASSWORD");
connectionString = $"Server={HOST};port={PORT};database={DATABASE};user={USERNAME};password={PASSWORD}";
connectionString = $"Server={host};port={port};database={database};user={username};password={password}";
Console.WriteLine("========RUNNING USING THE MYSQL SERVER==============");
Console.WriteLine(connectionString);
Console.WriteLine(connectionString);
Console.WriteLine("======================");
// with auth when it was working was'nt here
services.AddDbContext<AuthDbContext>(options => options.UseInMemoryDatabase("AuthDb"));
services.AddDbContext<HeartTrackContext>(options =>
options.UseMySql($"{connectionString}", new MySqlServerVersion(new Version(10, 11, 1)))
, ServiceLifetime.Singleton);
break;
default:
Console.WriteLine("====== RUNNING USING THE IN SQLLITE DATABASE ======");
Console.WriteLine("====== RUNNING USING THE IN SQLITE DATABASE ======");
connectionString = Configuration.GetConnectionString("HeartTrackAuthConnection");
if (!string.IsNullOrWhiteSpace(connectionString))
{
@ -109,7 +105,6 @@ public class AppBootstrap(IConfiguration configuration)
services.AddIdentityApiEndpoints<IdentityUser>()
.AddEntityFrameworkStores<AuthDbContext>();
//services.AddIdentity<AthleteEntity, IdentityRole>()
// .AddEntityFrameworkStores<AuthDbContext>().AddDefaultTokenProviders();
}
@ -121,8 +116,6 @@ public class AppBootstrap(IConfiguration configuration)
opt.ReportApiVersions = true;
opt.AssumeDefaultVersionWhenUnspecified = true;
opt.DefaultApiVersion = new Microsoft.AspNetCore.Mvc.ApiVersion(1, 0);
// options.ApiVersionReader = new HeaderApiVersionReader("api-version");
opt.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(),
new HeaderApiVersionReader("x-api-version"),
new MediaTypeApiVersionReader("x-api-version"));
@ -171,12 +164,7 @@ public class AppBootstrap(IConfiguration configuration)
{
options.OperationFilter<SwaggerDefaultValues>();
});
/* services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "HeartTrackAPI", Version = "v1" });
options.SwaggerDoc("v2", new OpenApiInfo { Title = "HeartTrackAPI", Version = "v2" });
});*/
services.AddVersionedApiExplorer(setup =>
{
setup.GroupNameFormat = "'v'VVV";
@ -205,8 +193,6 @@ public class AppBootstrap(IConfiguration configuration)
app.UseSwaggerUI(options =>
{
foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions)
//foreach (var description in apiVersionDescriptionProvider)
{
options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json",
description.GroupName.ToUpperInvariant());

Loading…
Cancel
Save