commit
d23847f4c5
@ -0,0 +1,25 @@
|
||||
using Entities;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DbContextLib.Identity;
|
||||
|
||||
public class AuthDbContext: IdentityDbContext<IdentityUser>
|
||||
{
|
||||
|
||||
public AuthDbContext(DbContextOptions<AuthDbContext> options) : base(options) { }
|
||||
public AuthDbContext() { }
|
||||
/*
|
||||
/// <summary>
|
||||
/// Configures the database options if they are not already configured.
|
||||
/// </summary>
|
||||
/// <param name="optionsBuilder">The options builder instance.</param>
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
optionsBuilder.UseSqlite($"Data Source=uca.HeartTrack.db");
|
||||
}
|
||||
}*/
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace Dto;
|
||||
|
||||
public class ActivityFitFileDto
|
||||
{
|
||||
public string ActivityName { get; set; }
|
||||
public string ActivityType { get; set; }
|
||||
public int EffortFeel { get; set; }
|
||||
//public IFormFile
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
using DbContextLib.Identity;
|
||||
using Entities;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
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 Model.Service;
|
||||
|
||||
using StubAPI;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
|
||||
namespace HeartTrackAPI;
|
||||
|
||||
public class AppBootstrap(IConfiguration configuration)
|
||||
{
|
||||
private IConfiguration Configuration { get; } = configuration;
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllers();
|
||||
services.AddEndpointsApiExplorer();
|
||||
//services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOption>();
|
||||
// include Xml comment
|
||||
// addsecurityRequiment
|
||||
// securityDef
|
||||
services.AddSwaggerGen();
|
||||
AddHeartTrackContextServices(services);
|
||||
AddModelService(services);
|
||||
AddIdentityServices(services);
|
||||
AddApiVersioning(services);
|
||||
AddSwagger(services);
|
||||
|
||||
services.AddHealthChecks();
|
||||
|
||||
}
|
||||
|
||||
private void AddHeartTrackContextServices(IServiceCollection services)
|
||||
{
|
||||
var connectionString = Configuration.GetConnectionString("HeartTrackAuthConnection");
|
||||
if (string.IsNullOrWhiteSpace(connectionString))
|
||||
{
|
||||
throw new InvalidOperationException("The connection string for the database is not set.");
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddDbContext<AuthDbContext>(options => options.UseInMemoryDatabase("AuthDb"));
|
||||
// builder.Services.AddDbContext<HeartTrackContext>(options => options.UseSqlite(connectionString));
|
||||
services.AddSingleton<IDataManager, StubData>();
|
||||
}
|
||||
|
||||
}
|
||||
private void AddModelService(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IDataManager, StubData>();
|
||||
services.AddTransient<IActivityManager, ActivityManager>();
|
||||
}
|
||||
|
||||
private void AddIdentityServices(IServiceCollection services)
|
||||
{
|
||||
// services.AddTransient<IEmailSender<AthleteEntity>, EmailSender>();
|
||||
services.AddAuthorization();
|
||||
|
||||
services.AddIdentityApiEndpoints<IdentityUser>()
|
||||
.AddEntityFrameworkStores<AuthDbContext>();
|
||||
//services.AddIdentity<AthleteEntity, IdentityRole>()
|
||||
// .AddEntityFrameworkStores<AuthDbContext>().AddDefaultTokenProviders();
|
||||
}
|
||||
|
||||
private void AddApiVersioning(IServiceCollection services)
|
||||
{
|
||||
|
||||
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"));
|
||||
});
|
||||
|
||||
}
|
||||
private void AddSwagger(IServiceCollection services)
|
||||
{
|
||||
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";
|
||||
setup.SubstituteApiVersionInUrl = true;
|
||||
});
|
||||
}
|
||||
|
||||
public void Configure(WebApplication app, IWebHostEnvironment env)
|
||||
{
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.MapControllers();
|
||||
app.UseAuthorization();
|
||||
app.MapIdentityApi<IdentityUser>();
|
||||
|
||||
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());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,25 +1,23 @@
|
||||
using Model;
|
||||
using DbContextLib;
|
||||
using DbContextLib.Identity;
|
||||
using Entities;
|
||||
using HeartTrackAPI;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc.Versioning;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Model.Manager;
|
||||
using Model.Repository;
|
||||
using StubAPI;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddSingleton<IDataManager, StubData>();
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
builder.Logging.AddConsole();
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
var init = new AppBootstrap(builder.Configuration);
|
||||
|
||||
init.ConfigureServices(builder.Services);
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapControllers();
|
||||
init.Configure(app, app.Environment);
|
||||
// app?.Services?.GetService<HeartTrackContext>()?.Database.EnsureCreated();
|
||||
app.Run();
|
@ -0,0 +1,64 @@
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
namespace HeartTrackAPI.Utils;
|
||||
|
||||
public class SwaggerOptions: IConfigureNamedOptions<SwaggerGenOptions>
|
||||
|
||||
{
|
||||
private readonly IApiVersionDescriptionProvider _provider;
|
||||
|
||||
public SwaggerOptions(
|
||||
IApiVersionDescriptionProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure each API discovered for Swagger Documentation
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
public void Configure(SwaggerGenOptions options)
|
||||
{
|
||||
// add swagger document for every API version discovered
|
||||
foreach (var description in _provider.ApiVersionDescriptions)
|
||||
{
|
||||
options.SwaggerDoc(
|
||||
description.GroupName,
|
||||
CreateVersionInfo(description));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configure Swagger Options. Inherited from the Interface
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="options"></param>
|
||||
public void Configure(string name, SwaggerGenOptions options)
|
||||
{
|
||||
Configure(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create information about the version of the API
|
||||
/// </summary>
|
||||
/// <param name="description"></param>
|
||||
/// <returns>Information about the API</returns>
|
||||
private OpenApiInfo CreateVersionInfo(
|
||||
ApiVersionDescription desc)
|
||||
{
|
||||
var info = new OpenApiInfo()
|
||||
{
|
||||
Title = ".NET Core (.NET 6) Web API For Lol",
|
||||
Version = desc.ApiVersion.ToString()
|
||||
};
|
||||
|
||||
if (desc.IsDeprecated)
|
||||
{
|
||||
info.Description += " This API version has been deprecated. Please use one of the new APIs available from the explorer.";
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace Model.Manager;
|
||||
|
||||
public class ActivityManager : IActivityManager
|
||||
{
|
||||
public void AddActivityFromFitFile(byte filePath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
namespace Model.Manager;
|
||||
|
||||
public interface IActivityManager
|
||||
{
|
||||
public void AddActivityFromFitFile(byte filePath);
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace Model.Manager;
|
||||
|
||||
public class UserManager
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
|
||||
using Entities;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
|
||||
namespace Model.Service;
|
||||
|
||||
public class EmailSender : IEmailSender<AthleteEntity>
|
||||
{
|
||||
private IEmailSender<AthleteEntity> _emailSenderImplementation;
|
||||
|
||||
public async Task SendEmailAsync(string email, string subject, string htmlMessage)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task SendConfirmationLinkAsync(AthleteEntity user, string email, string confirmationLink)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task SendPasswordResetLinkAsync(AthleteEntity user, string email, string resetLink)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task SendPasswordResetCodeAsync(AthleteEntity user, string email, string resetCode)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue