Ok everything good now 🔥🔥
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
60eefb61cd
commit
306aee3cd3
@ -0,0 +1,13 @@
|
|||||||
|
public class HeartRateDto
|
||||||
|
{
|
||||||
|
public DateTime Timestamp { get; set; }
|
||||||
|
public double? Latitude { get; set; }
|
||||||
|
public double? Longitude { get; set; }
|
||||||
|
public double? Altitude { get; set; }
|
||||||
|
public int HeartRate { get; set; }
|
||||||
|
public int? Cadence { get; set; }
|
||||||
|
public double? Distance { get; set; }
|
||||||
|
public double? Speed { get; set; }
|
||||||
|
public int? Power { get; set; }
|
||||||
|
public double? Temperature { get; set; }
|
||||||
|
}
|
@ -1,174 +1,23 @@
|
|||||||
using System.Reflection;
|
|
||||||
using DbContextLib;
|
using DbContextLib;
|
||||||
using DbContextLib.Identity;
|
|
||||||
using HeartTrackAPI;
|
using HeartTrackAPI;
|
||||||
using HeartTrackAPI.Utils;
|
using StubbedContextLib;
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Versioning;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using Microsoft.OpenApi.Models;
|
|
||||||
using Model.Manager;
|
|
||||||
using Model2Entities;
|
|
||||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
builder.Logging.AddConsole();
|
builder.Logging.AddConsole();
|
||||||
builder.WebHost.ConfigureKestrel(serverOptions => { serverOptions.Limits.MaxRequestBodySize = long.MaxValue; });
|
builder.WebHost.ConfigureKestrel(serverOptions =>
|
||||||
|
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
|
||||||
builder.Services.AddSwaggerGen(options =>
|
|
||||||
{
|
|
||||||
options.OperationFilter<SwaggerDefaultValues>();
|
|
||||||
|
|
||||||
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
|
||||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
|
||||||
options.IncludeXmlComments(xmlPath);
|
|
||||||
|
|
||||||
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
|
||||||
{
|
|
||||||
Description =
|
|
||||||
"JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
|
|
||||||
Name = "Authorization",
|
|
||||||
In = ParameterLocation.Header,
|
|
||||||
Type = SecuritySchemeType.ApiKey
|
|
||||||
});
|
|
||||||
var scheme = new OpenApiSecurityRequirement
|
|
||||||
{
|
|
||||||
{
|
|
||||||
new OpenApiSecurityScheme
|
|
||||||
{
|
|
||||||
Reference = new OpenApiReference
|
|
||||||
{
|
|
||||||
Type = ReferenceType.SecurityScheme,
|
|
||||||
Id = "Bearer"
|
|
||||||
},
|
|
||||||
Scheme = "oauth2",
|
|
||||||
Name = "Bearer",
|
|
||||||
In = ParameterLocation.Header,
|
|
||||||
},
|
|
||||||
new List<string>()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
options.AddSecurityRequirement(scheme);
|
|
||||||
});
|
|
||||||
builder.Services.AddTransient<IConfigureOptions<SwaggerGenOptions>, SwaggerOptions>();
|
|
||||||
builder.Services.AddSwaggerGen(options => { options.OperationFilter<SwaggerDefaultValues>(); });
|
|
||||||
/* services.AddSwaggerGen(options =>
|
|
||||||
{
|
|
||||||
options.SwaggerDoc("v1", new OpenApiInfo { Title = "HeartTrackAPI", Version = "v1" });
|
|
||||||
options.SwaggerDoc("v2", new OpenApiInfo { Title = "HeartTrackAPI", Version = "v2" });
|
|
||||||
});*/
|
|
||||||
|
|
||||||
builder.Services.AddVersionedApiExplorer(setup =>
|
|
||||||
{
|
{
|
||||||
setup.GroupNameFormat = "'v'VVV";
|
serverOptions.Limits.MaxRequestBodySize = long.MaxValue;
|
||||||
setup.SubstituteApiVersionInUrl = true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
string connectionString;
|
var init = new AppBootstrap(builder.Configuration);
|
||||||
|
|
||||||
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");
|
|
||||||
|
|
||||||
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
|
|
||||||
builder.Services.AddDbContext<AuthDbContext>(options => options.UseInMemoryDatabase("AuthDb"));
|
|
||||||
builder.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 ======");
|
|
||||||
connectionString = builder.Configuration.GetConnectionString("HeartTrackAuthConnection");
|
|
||||||
if (!string.IsNullOrWhiteSpace(connectionString))
|
|
||||||
{
|
|
||||||
builder.Services.AddDbContext<AuthDbContext>(options => options.UseInMemoryDatabase("AuthDb"));
|
|
||||||
Console.WriteLine(connectionString);
|
|
||||||
Console.WriteLine("======================");
|
|
||||||
//options => options.UseSqlite(connectionString)
|
|
||||||
//services.AddDbContext<HeartTrackContext>();
|
|
||||||
builder.Services.AddDbContext<HeartTrackContext>(options =>
|
|
||||||
options.UseSqlite(connectionString), ServiceLifetime.Singleton);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
builder.Services.AddDbContext<AuthDbContext>(options => options.UseInMemoryDatabase("AuthDb"));
|
|
||||||
builder.Services.AddDbContext<HeartTrackContext>(options => options.UseInMemoryDatabase("HeartTrackDb"));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// app.Services.GetService<HeartTrackContext>()!.Database.EnsureCreated();
|
|
||||||
|
|
||||||
builder.Services.AddSingleton<IDataManager>(provider =>
|
|
||||||
{
|
|
||||||
provider.GetRequiredService<HeartTrackContext>().Database.EnsureCreated();
|
|
||||||
return new DbDataManager(provider.GetRequiredService<HeartTrackContext>());
|
|
||||||
});
|
|
||||||
builder.Services.AddAuthorization();
|
|
||||||
|
|
||||||
builder.Services.AddIdentityApiEndpoints<IdentityUser>()
|
|
||||||
.AddEntityFrameworkStores<AuthDbContext>();
|
|
||||||
|
|
||||||
builder.Services.AddApiVersioning(opt =>
|
|
||||||
{
|
|
||||||
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"));
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.Services.AddHealthChecks();
|
|
||||||
|
|
||||||
|
init.ConfigureServices(builder.Services);
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
init.Configure(app, app.Environment);
|
||||||
app.MapIdentityApi<IdentityUser>();
|
|
||||||
|
|
||||||
app.MapControllers();
|
|
||||||
app.UseAuthorization();
|
|
||||||
|
|
||||||
app.MapHealthChecks("/health");
|
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
|
||||||
if (true)
|
|
||||||
{
|
|
||||||
var apiVersionDescriptionProvider = app.Services.GetRequiredService<IApiVersionDescriptionProvider>();
|
|
||||||
app.UseSwagger();
|
|
||||||
app.UseSwaggerUI();
|
|
||||||
app.MapSwagger();
|
|
||||||
app.UseSwaggerUI(options =>
|
|
||||||
{
|
|
||||||
foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions)
|
|
||||||
|
|
||||||
//foreach (var description in apiVersionDescriptionProvider)
|
|
||||||
{
|
|
||||||
options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json",
|
|
||||||
description.GroupName.ToUpperInvariant());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
var context = app.Services.GetService<HeartTrackContext>() ?? app.Services.GetService<TrainingStubbedContext>();
|
||||||
|
context!.Database.EnsureCreated();
|
||||||
app.Run();
|
app.Run();
|
Loading…
Reference in new issue