Cleanup warnings, add docs

This commit is contained in:
CodeLiturgy 2022-08-22 00:51:45 +01:00
parent 62ad4f150d
commit 8dfd6e80cc
38 changed files with 250 additions and 227 deletions

View File

@ -15,7 +15,6 @@
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.8" /> <PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authorization.Policy" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Authorization.Policy" Version="2.2.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup> </ItemGroup>

View File

@ -6,12 +6,24 @@ using Microsoft.EntityFrameworkCore;
namespace BlueWest.WebApi.EF namespace BlueWest.WebApi.EF
{ {
internal sealed class CompanyDbContext : DbContext /// <summary>
/// Context for accessing company data
/// </summary>
public sealed class CompanyDbContext : DbContext
{ {
/// <summary>
/// Db set of Companies
/// </summary>
public DbSet<Company> Companies { get; set; } public DbSet<Company> Companies { get; set; }
/// <summary>
/// Db set of Industries.
/// </summary>
public DbSet<Industry> Industries { get; set; } public DbSet<Industry> Industries { get; set; }
/// <summary>
/// Db set of Products.
/// </summary>
public DbSet<Product> Products { get; set; } public DbSet<Product> Products { get; set; }
@ -25,6 +37,10 @@ namespace BlueWest.WebApi.EF
Database.EnsureCreated(); Database.EnsureCreated();
} }
/// <summary>
/// On database model creating
/// </summary>
/// <param name="modelBuilder">Builder model of the database</param>
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);

View File

@ -9,13 +9,22 @@ namespace BlueWest.WebApi.EF
/// <summary> /// <summary>
/// Countries and Currencies /// Countries and Currencies
/// </summary> /// </summary>
internal sealed class CountryDbContext : DbContext public sealed class CountryDbContext : DbContext
{ {
/// <summary>
/// Countries Database Table
/// </summary>
public DbSet<Country> Countries { get; set; } public DbSet<Country> Countries { get; set; }
/// <summary>
/// Currencies Database Table
/// </summary>
public DbSet<Currency> Currencies { get; set; } public DbSet<Currency> Currencies { get; set; }
/// <summary>
/// App Configuration
/// </summary>
public IConfiguration Configuration; public IConfiguration Configuration;

View File

@ -5,12 +5,16 @@ using BlueWest.WebApi.EF;
namespace BlueWest.WebApi.Interfaces namespace BlueWest.WebApi.Interfaces
{ {
/// <summary>
/// Empty constructor
/// </summary>
public struct ExchangeEvent { } public struct ExchangeEvent { }
/// <summary> /// <summary>
/// Interface for getting and storing exchange rates data /// Interface for getting and storing exchange rates data
/// </summary> /// </summary>
/// ///
internal sealed class ExchangeInterface : EventListener<ExchangeEvent>, IDisposable, IAsyncDisposable public sealed class ExchangeInterface : EventListener<ExchangeEvent>, IDisposable, IAsyncDisposable
{ {
private readonly EventManager _eventManager; private readonly EventManager _eventManager;
private readonly CountryDbContext _countryDbContext; private readonly CountryDbContext _countryDbContext;
@ -18,6 +22,16 @@ namespace BlueWest.WebApi.Interfaces
private readonly UserDbContext _userDbContext; private readonly UserDbContext _userDbContext;
#region Initialization #region Initialization
/// <summary>
/// Exchange Interface Object
/// </summary>
/// <param name="countryDbContext">Country context</param>
/// <param name="financeDbContext">Finance context</param>
/// <param name="userDbContext">User context</param>
/// <param name="eventManager">Event manager injection</param>
public ExchangeInterface( public ExchangeInterface(
CountryDbContext countryDbContext, CountryDbContext countryDbContext,
FinanceDbContext financeDbContext, FinanceDbContext financeDbContext,
@ -31,6 +45,9 @@ namespace BlueWest.WebApi.Interfaces
Init(); Init();
} }
/// <summary>
/// Empty constructor
/// </summary>
public ExchangeInterface() { } public ExchangeInterface() { }
private void Init() private void Init()
@ -51,13 +68,17 @@ namespace BlueWest.WebApi.Interfaces
} }
/// <summary> /// <summary>
/// Stop Listening for events /// Stop Listening for events on dispose
/// </summary> /// </summary>
public void Dispose() public void Dispose()
{ {
_eventManager.EventStopListening<ExchangeEvent>(this); _eventManager.EventStopListening<ExchangeEvent>(this);
} }
/// <summary>
/// Stop Listening for events on dispose async
/// </summary>
/// <returns></returns>
public ValueTask DisposeAsync() public ValueTask DisposeAsync()
{ {
_eventManager.EventStopListening<ExchangeEvent>(this); _eventManager.EventStopListening<ExchangeEvent>(this);

View File

@ -7,14 +7,44 @@ using Microsoft.EntityFrameworkCore;
namespace BlueWest.WebApi.EF namespace BlueWest.WebApi.EF
{ {
internal static class CountryDbExtensions /// <summary>
/// Country table database extensions
/// </summary>
public static class CountryDbExtensions
{ {
static CountryDbExtensions()
{
}
internal static (bool, Country) NotFound() => (false, null); /// <summary>
internal static (bool, string, Country) ErrorMessage(string message) => (false, message, null); /// Returns Not found projection
internal static (bool, string, Country) Success(bool success, Country country) => (success, "1", null); /// </summary>
/// <returns></returns>
public static (bool, Country) NotFound() => (false, null);
internal static (bool, Country) UpdateCountry( /// <summary>
/// Returns Error Message projection
/// </summary>
/// <param name="message"></param>
/// <returns>(false, message, null)</returns>
public static (bool, string, Country) ErrorMessage(string message) => (false, message, null);
/// <summary>
/// Returns Success intent projection
/// </summary>
/// <param name="success">Success message</param>
/// <param name="country">Entity object</param>
/// <returns>(bool success, Country country)</returns>
public static (bool, string, Country) Success(bool success, Country country) => (success, "1", null);
/// <summary>
/// Updates a country data.
/// </summary>
/// <param name="dbContext">DbContext.</param>
/// <param name="countryUpdate">Country data to update.</param>
/// <param name="countryId">Country Id.</param>
/// <returns></returns>
public static (bool, Country) UpdateCountry(
this CountryDbContext dbContext, this CountryDbContext dbContext,
CountryUpdate countryUpdate, CountryUpdate countryUpdate,
int countryId) int countryId)
@ -28,13 +58,16 @@ namespace BlueWest.WebApi.EF
} }
internal static async Task<Country> GetCountryByIdAsync(this DbSet<Country> countries, int countryId) => /// <summary>
await countries.FirstOrDefaultAsync(x => x.Id == countryId); /// Adds a new Currency to the specified country
/// </summary>
/// <param name="dbContext"></param>
internal static (bool, string, Country) AddCurrency( this CountryDbContext dbContext, int countryId, CurrencyCreate currencyCreate) /// <param name="countryId"></param>
/// <param name="currencyCreate"></param>
/// <returns></returns>
public static (bool, string, Country) AddCurrency( this CountryDbContext dbContext, int countryId, CurrencyCreate currencyCreate)
{ {
var country = dbContext.Countries.FirstOrDefault(d => d.Code == countryId); var country = dbContext.Countries.FirstOrDefault(d => d.Id == countryId);
// Check if currency exists // Check if currency exists
if (country == null) return (false, "Country Not found.", null); if (country == null) return (false, "Country Not found.", null);
@ -46,12 +79,20 @@ namespace BlueWest.WebApi.EF
return Success(success, country); return Success(success, country);
} }
internal static (bool, string, Country) AddCurrency( /// <summary>
/// Add Currency with optional duplication checks
/// </summary>
/// <param name="dbContext"></param>
/// <param name="countryId">Country Id</param>
/// <param name="currencyCreate">Data to create currency</param>
/// <param name="duplicationValidations">List of expressions</param>
/// <returns></returns>
public static (bool, string, Country) AddCurrency(
this CountryDbContext dbContext, this CountryDbContext dbContext,
int countryId, CurrencyCreate currencyCreate, int countryId, CurrencyCreate currencyCreate,
Expression<Func<Currency,bool>>[] duplicationValidations) Expression<Func<Currency,bool>>[] duplicationValidations)
{ {
var country = dbContext.Countries.FirstOrDefault(d => d.Code == countryId); var country = dbContext.Countries.FirstOrDefault(d => d.Id == countryId);
// Check if currency exists // Check if currency exists
if (country == null) return (false, $"{nameof(country)} Not found.", null); if (country == null) return (false, $"{nameof(country)} Not found.", null);

View File

@ -5,12 +5,25 @@ using Microsoft.EntityFrameworkCore;
namespace BlueWest.WebApi.EF namespace BlueWest.WebApi.EF
{ {
internal static class CurrencyExtensions /// <summary>
/// Currency table data extensions
/// </summary>
public static class CurrencyExtensions
{ {
internal static (bool, Currency) NotFound() => (false, null); /// <summary>
/// Not found projection
/// </summary>
/// <returns></returns>
public static (bool, Currency) NotFound() => (false, null);
internal static (bool, Currency) AddCurrency(this CountryDbContext dbContext, CurrencyCreate currencyToCreate) /// <summary>
/// Add new Currency
/// </summary>
/// <param name="dbContext"></param>
/// <param name="currencyToCreate"></param>
/// <returns></returns>
public static (bool, Currency) AddCurrency(this CountryDbContext dbContext, CurrencyCreate currencyToCreate)
{ {
var newCurrency = new Currency(currencyToCreate); var newCurrency = new Currency(currencyToCreate);
dbContext.Add(newCurrency); dbContext.Add(newCurrency);
@ -19,7 +32,14 @@ namespace BlueWest.WebApi.EF
} }
internal static (bool, Currency) UpdateCurrency(this CountryDbContext dbContext, int currencyId, CurrencyUpdate currencyToUpdate) /// <summary>
/// Updates currency
/// </summary>
/// <param name="dbContext"></param>
/// <param name="currencyId"></param>
/// <param name="currencyToUpdate"></param>
/// <returns></returns>
public static (bool, Currency) UpdateCurrency(this CountryDbContext dbContext, int currencyId, CurrencyUpdate currencyToUpdate)
{ {
var currency = dbContext.Currencies.FirstOrDefault(x => x.Id == currencyId); var currency = dbContext.Currencies.FirstOrDefault(x => x.Id == currencyId);
if (currency == null) return NotFound(); if (currency == null) return NotFound();

View File

@ -1,14 +0,0 @@
using System;
namespace BlueWest.WebApi.EF
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class DatabaseFundamentalsAttribute : Attribute
{
public Type DatabaseContextType;
public Type EntityType;
public DatabaseFundamentalsAttribute(Type databaseContextType, Type entityType) { }
}
}

View File

@ -7,23 +7,31 @@ namespace BlueWest.WebApi.EF
/// <summary> /// <summary>
/// Finance operations table /// Finance operations table
/// </summary> /// </summary>
internal sealed class FinanceDbContext : DbContext public sealed class FinanceDbContext : DbContext
{ {
[DatabaseFundamentals(typeof(FinanceDbContext), typeof(FinanceOp))] /// <summary>
internal DbSet<FinanceOp> Transactions { get; set; } /// Table storing transactions
/// </summary>
public DbSet<FinanceOp> Transactions { get; set; }
[DatabaseFundamentals(typeof(FinanceDbContext), typeof(FinanceOpType))] /// <summary>
internal DbSet<FinanceOpType> TransactionTypes { get; set; } /// Table storing transaction types.
/// </summary>
public DbSet<FinanceOpType> TransactionTypes { get; set; }
/// <summary> /// <summary>
/// Finance transactions context /// Finance transactions context
/// </summary> /// </summary>
/// <param name="options"></param> /// <param name="options"></param>
internal FinanceDbContext(DbContextOptions<FinanceDbContext> options) : base(options) public FinanceDbContext(DbContextOptions<FinanceDbContext> options) : base(options)
{ {
Database.EnsureCreated(); Database.EnsureCreated();
} }
/// <summary>
/// On database model creating
/// </summary>
/// <param name="modelBuilder">Builder model of the database</param>
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);

View File

@ -6,28 +6,34 @@ using Microsoft.Extensions.Configuration;
namespace BlueWest.WebApi.EF namespace BlueWest.WebApi.EF
{ {
internal sealed class UserDbContext : DbContext /// <summary>
/// Database context for app users
/// </summary>
public sealed class UserDbContext : DbContext
{ {
internal DbSet<User> Users { get; set; } /// <summary>
internal IConfiguration Configuration; /// Users entity.
/// </summary>
public DbSet<User> Users { get; set; }
/// <summary>
/// App configuration.
/// </summary>
public IConfiguration Configuration;
/// <summary> /// <summary>
/// Database for the context of database users /// Database for the context of database users
/// </summary> /// </summary>
/// <param name="options"></param> /// <param name="options"></param>
internal UserDbContext(DbContextOptions<UserDbContext> options) : base(options) public UserDbContext(DbContextOptions<UserDbContext> options) : base(options)
{ {
Database.EnsureCreated(); Database.EnsureCreated();
} }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) /// <summary>
{ /// On database model creating
/*optionsBuilder.UseMySql( /// </summary>
Configuration.GetConnectionString("LocalMySQL"), /// <param name="modelBuilder">Builder model of the database</param>
new MySqlServerVersion(new Version(8, 0, 11))
);*/
}
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);

View File

@ -10,16 +10,16 @@ using Microsoft.AspNetCore.Mvc;
namespace BlueWest.WebApi.Controllers namespace BlueWest.WebApi.Controllers
{ {
/// <summary> /// <summary>
/// Controller responsible to get country data /// Controller responsible to get countryId data
/// </summary> /// </summary>
[ApiController] [ApiController]
[Route("[controller]")] [Route("[controller]")]
internal class CountryController : ControllerBase public class CountryController : ControllerBase
{ {
private readonly CountryDbContext _dbContext; private readonly CountryDbContext _dbContext;
/// <summary> /// <summary>
/// Controller responsible for handling country data in the Country table /// Controller responsible for handling countryId data in the Country table
/// </summary> /// </summary>
/// <param name="dbContext"></param> /// <param name="dbContext"></param>
public CountryController(CountryDbContext dbContext) public CountryController(CountryDbContext dbContext)
@ -31,8 +31,8 @@ namespace BlueWest.WebApi.Controllers
/// <summary> /// <summary>
/// Add Country /// Add Country
/// </summary> /// </summary>
/// <param name="countryToCreate">The country data to create</param> /// <param name="countryToCreate">The countryId data to create</param>
/// <returns>The newly created country</returns> /// <returns>The newly created countryId</returns>
/// /// <summary> /// /// <summary>
/// Creates a Country. /// Creates a Country.
/// </summary> /// </summary>
@ -47,7 +47,7 @@ namespace BlueWest.WebApi.Controllers
/// } /// }
/// ///
/// </remarks> /// </remarks>
/// <response code="201">Returns the newly created country</response> /// <response code="201">Returns the newly created countryId</response>
[ProducesResponseType(StatusCodes.Status201Created)] [ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status406NotAcceptable)] [ProducesResponseType(StatusCodes.Status406NotAcceptable)]
@ -65,7 +65,7 @@ namespace BlueWest.WebApi.Controllers
/// <summary> /// <summary>
/// Updates a Country /// Updates a Country
/// </summary> /// </summary>
/// <param name="countryCode">The country ISO 3166 code</param> /// <param name="countryCode">The countryId ISO 3166 code</param>
/// <param name="countryToUpdate">Country payload data</param> /// <param name="countryToUpdate">Country payload data</param>
/// <returns></returns> /// <returns></returns>
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
@ -73,11 +73,11 @@ namespace BlueWest.WebApi.Controllers
[HttpPut("{countryCode}")] [HttpPut("{countryCode}")]
public ActionResult UpdateCountry(int countryCode, CountryUpdate countryToUpdate) public ActionResult UpdateCountry(int countryCode, CountryUpdate countryToUpdate)
{ {
var (success, country) = _dbContext.UpdateCountry(countryToUpdate, countryCode); var (success, countryId) = _dbContext.UpdateCountry(countryToUpdate, countryCode);
if (success) if (success)
{ {
return Ok(country); return Ok(countryId);
} }
return new NotFoundResult(); return new NotFoundResult();
@ -106,7 +106,7 @@ namespace BlueWest.WebApi.Controllers
/// <summary> /// <summary>
/// Get Country by Id /// Get Country by Id
/// </summary> /// </summary>
/// <param name="countryId">ISO 3166-1 country numeric code</param> /// <param name="countryId">ISO 3166-1 countryId numeric code</param>
/// <returns></returns> /// <returns></returns>
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
@ -124,7 +124,7 @@ namespace BlueWest.WebApi.Controllers
} }
/// <summary> /// <summary>
/// Get currencies of a country /// Get currencies of a countryId
/// </summary> /// </summary>
/// <param name="countryId"></param> /// <param name="countryId"></param>
/// <returns></returns> /// <returns></returns>
@ -133,9 +133,9 @@ namespace BlueWest.WebApi.Controllers
[HttpGet("{countryId}/currencies")] [HttpGet("{countryId}/currencies")]
public ActionResult GetCountryCurrencies(int countryId) public ActionResult GetCountryCurrencies(int countryId)
{ {
var country = _dbContext.Countries.FirstOrDefault(d => d.Id == countryId); var countryObj = _dbContext.Countries.FirstOrDefault(d => d.Id == countryId);
if (country == null) return new NotFoundResult(); if (countryObj == null) return new NotFoundResult();
var array = _dbContext var array = _dbContext
.Countries .Countries

View File

@ -13,10 +13,14 @@ namespace BlueWest.WebApi.Controllers
/// </summary> /// </summary>
[ApiController] [ApiController]
[Route("[controller]")] [Route("[controller]")]
internal class CurrencyController : ControllerBase public class CurrencyController : ControllerBase
{ {
private readonly CountryDbContext _dbContext; private readonly CountryDbContext _dbContext;
/// <summary>
/// Api Controller for Currency data
/// </summary>
/// <param name="dbContext"></param>
public CurrencyController(CountryDbContext dbContext) public CurrencyController(CountryDbContext dbContext)
{ {
_dbContext = dbContext; _dbContext = dbContext;
@ -39,7 +43,6 @@ namespace BlueWest.WebApi.Controllers
/// Add Currency to the table of currencies /// Add Currency to the table of currencies
/// </summary> /// </summary>
/// <param name="currencyToCreate">Currency data to create</param> /// <param name="currencyToCreate">Currency data to create</param>
/// <param name="currencyAssociatedCountries">Countries</param>
/// <returns></returns> /// <returns></returns>
[ProducesResponseType(StatusCodes.Status201Created)] [ProducesResponseType(StatusCodes.Status201Created)]
[HttpPost] [HttpPost]

View File

@ -11,10 +11,14 @@ namespace BlueWest.WebApi.Controllers;
/// </summary> /// </summary>
[ApiController] [ApiController]
[Route("[controller]")] [Route("[controller]")]
internal class FinanceController : ControllerBase public class FinanceController : ControllerBase
{ {
private readonly FinanceDbContext _dbContext; private readonly FinanceDbContext _dbContext;
/// <summary>
/// Finance Controller Api Controller
/// </summary>
/// <param name="dbContext">The finance database context</param>
public FinanceController(FinanceDbContext dbContext) public FinanceController(FinanceDbContext dbContext)
{ {
_dbContext = dbContext; _dbContext = dbContext;

View File

@ -6,8 +6,14 @@ using Swashbuckle.AspNetCore.SwaggerGen;
namespace BlueWest.WebApi.Tools namespace BlueWest.WebApi.Tools
{ {
internal class SwaggerEnumSchemaFilter : ISchemaFilter /// <inheritdoc />
public class SwaggerEnumSchemaFilter : ISchemaFilter
{ {
/// <summary>
/// Apply Swagger OpenApi schema
/// </summary>
/// <param name="model">OpenApiSchema model</param>
/// <param name="context">Schema filter context</param>
public void Apply(OpenApiSchema model, SchemaFilterContext context) public void Apply(OpenApiSchema model, SchemaFilterContext context)
{ {
if (context.Type.IsEnum) if (context.Type.IsEnum)

View File

@ -9,9 +9,12 @@ using Microsoft.AspNetCore.Mvc;
namespace BlueWest.WebApi.Controllers namespace BlueWest.WebApi.Controllers
{ {
/// <summary>
/// Api Controller for handling users data
/// </summary>
[ApiController] [ApiController]
[Route("[controller]")] [Route("[controller]")]
internal class UserController : ControllerBase public class UserController : ControllerBase
{ {
private readonly UserDbContext _dbContext; private readonly UserDbContext _dbContext;

View File

@ -10,6 +10,10 @@ namespace BlueWest.WebApi.EF.Model
{ {
#region Initialization #region Initialization
static ModelBuilderExtensions()
{
}
/// <summary> /// <summary>
/// Setup the database model /// Setup the database model
/// </summary> /// </summary>
@ -105,20 +109,6 @@ namespace BlueWest.WebApi.EF.Model
private static ModelBuilder ConfigureUserModel(this ModelBuilder modelBuilder) private static ModelBuilder ConfigureUserModel(this ModelBuilder modelBuilder)
{ {
// User => Country
modelBuilder
.Entity<User>(builder => builder
.HasOne<Country>()
.WithMany(co => co.Users));
// Country => User
modelBuilder
.Entity<Country>(builder => builder
.HasMany<User>()
.WithOne(u => u.Country)
.HasForeignKey(x => x.CountryId));
// FinanceOp => User // FinanceOp => User
modelBuilder modelBuilder

View File

@ -1,46 +0,0 @@
using System;
using System.IO;
using System.Reflection;
using BlueWest.WebApi.Tools;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace BlueWest.WebApi.Extensions
{
public static class SwaggerExtensions
{
/// <summary>
/// Swagger documentation provider options
/// </summary>
/// <param name="swaggerGenOptions"></param>
public static void ConfigureSwaggerOptions(this SwaggerGenOptions swaggerGenOptions)
{
swaggerGenOptions.SchemaFilter<SwaggerEnumSchemaFilter>();
swaggerGenOptions.SwaggerDoc("v1", new OpenApiInfo
{
Title = "BlueWest.Api.App",
Version = "v1",
Description = "BlueWest.Api.App",
TermsOfService = new Uri("https://git.codeliturgy.com/terms-of-service"),
Contact = new OpenApiContact
{
Name = "Benny",
Email = string.Empty,
Url = new Uri("https://git.codeliturgy.com"),
},
License = new OpenApiLicense
{
Name = "Use under LICX",
Url = new Uri("https://git.codeliturgy.com/license"),
}
});
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
swaggerGenOptions.IncludeXmlComments(xmlPath);
}
}
}

View File

@ -1,5 +1,8 @@
namespace BlueWest.Data; namespace BlueWest.Data;
/// <summary>
/// Auth Manager
/// </summary>
public class AuthManager public class AuthManager
{ {

View File

@ -1,9 +0,0 @@
using BlueWest.WebApi.EF;
using Microsoft.AspNetCore.Identity;
namespace BlueWest.WebApi;
public class EntityDbContext : IdentityUser
{
}

View File

@ -1,10 +0,0 @@
using System.Security.Principal;
namespace BlueWest.Data;
public class IdentityContext : IIdentity
{
public string AuthenticationType { get; }
public bool IsAuthenticated { get; }
public string Name { get; }
}

View File

@ -43,6 +43,10 @@ namespace BlueWest.WebApi
/// </summary> /// </summary>
public static IHost MainHost { get; private set; } public static IHost MainHost { get; private set; }
/// <summary>
/// Entry point of the application
/// </summary>
/// <param name="args">Command line arguments.</param>
public static void Main(string[] args) public static void Main(string[] args)
{ {
MainHost = CreateHostBuilder(args) MainHost = CreateHostBuilder(args)

View File

@ -1,11 +1,15 @@
using System;
using System.IO;
using System.Reflection;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using BlueWest.Tools; using BlueWest.Tools;
using BlueWest.WebApi.Extensions;
using BlueWest.WebApi.Interfaces; using BlueWest.WebApi.Interfaces;
using BlueWest.WebApi.Tools;
using Microsoft.OpenApi.Models;
namespace BlueWest.WebApi namespace BlueWest.WebApi
{ {
@ -50,7 +54,33 @@ namespace BlueWest.WebApi
.AddJsonOptions(options => options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve); .AddJsonOptions(options => options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve);
services services
.AddSwaggerGen(options => options.ConfigureSwaggerOptions()); .AddSwaggerGen(options =>
{
options.SchemaFilter<SwaggerEnumSchemaFilter>();
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "BlueWest.Api.App",
Version = "v1",
Description = "BlueWest.Api.App",
TermsOfService = new Uri("https://git.codeliturgy.com/terms-of-service"),
Contact = new OpenApiContact
{
Name = "Benny",
Email = string.Empty,
Url = new Uri("https://git.codeliturgy.com"),
},
License = new OpenApiLicense
{
Name = "Use under LICX",
Url = new Uri("https://git.codeliturgy.com/license"),
}
});
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
options.IncludeXmlComments(xmlPath);
});
services services
.AddSingleton<EventManager>() .AddSingleton<EventManager>()
.PrepareDatabasePool(_configuration, _environment) .PrepareDatabasePool(_configuration, _environment)

View File

@ -23,10 +23,6 @@ namespace BlueWest.Data
public List<Industry> Industry { get; set; } public List<Industry> Industry { get; set; }
public Company()
{
}
} }
} }

View File

@ -16,10 +16,6 @@ namespace BlueWest.Data
public DateTime FoundingDate { get; set; } public DateTime FoundingDate { get; set; }
public CompanyCreate()
{
}
} }
} }

View File

@ -8,10 +8,6 @@ namespace BlueWest.Data
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public CompanyType()
{
}
} }
} }

View File

@ -7,10 +7,6 @@ namespace BlueWest.Data
{ {
public string Name { get; set; } public string Name { get; set; }
public CompanyTypeCreate()
{
}
} }
} }

View File

@ -7,11 +7,6 @@ namespace BlueWest.Data
public string Name { get; set; } public string Name { get; set; }
public Industry Industry { get; set; } public Industry Industry { get; set; }
public List<Company> Seller { get; set; } public List<Company> Seller { get; set; }
public Product()
{
}
} }
} }

View File

@ -33,17 +33,6 @@ namespace BlueWest.Data
public List<Currency> Currencies { get; set; } public List<Currency> Currencies { get; set; }
public List<User> Users { get; set; } public List<User> Users { get; set; }
[JsonConstructor]
public Country(string stateName, string tld, List<Currency> currencies)
{
StateName = stateName;
TLD = tld;
Currencies = currencies;
}
public Country() { }
} }
} }

View File

@ -13,14 +13,12 @@ namespace BlueWest.Data
public string Name { get; set; } public string Name { get; set; }
public string StateName { get; set; } public string StateName { get; set; }
public List<CurrencyUnique> CurrenciesToCreate { get; set; } //public List<CurrencyUnique> CurrenciesToCreate { get; set; }
[MaxLength(2)] public string Alpha2Code { get; set; } public string Alpha2Code { get; set; }
public string TLD { get; set; } public string TLD { get; set; }
public CountryCreate() { }
} }
} }

View File

@ -21,8 +21,6 @@ namespace BlueWest.Data
public string TLD { get; set; } public string TLD { get; set; }
public CountryUnique() { }
} }
} }

View File

@ -16,7 +16,6 @@ namespace BlueWest.Data
/// ISO 3166-1 numeric code /// ISO 3166-1 numeric code
/// </summary> /// </summary>
public int Code { get; set; } public int Code { get; set; }
public CountryUpdate() { }
} }
} }

View File

@ -16,8 +16,6 @@ namespace BlueWest.Data
public int Num { get; set; } public int Num { get; set; }
[MaxLength(3)] public string Code { get; set; } [MaxLength(3)] public string Code { get; set; }
public List<Country> Countries { get; set; } public List<Country> Countries { get; set; }
public Currency() { }
} }
} }

View File

@ -7,11 +7,9 @@ namespace BlueWest.Data
[MapFrom(typeof(Currency))] [MapFrom(typeof(Currency))]
public partial class CurrencyCreate public partial class CurrencyCreate
{ {
public int Num { get; set; } // Primary key public int Num { get; set; }
[MaxLength(3)] public string Code { get; set; } [MaxLength(3)] public string Code { get; set; }
public List<CountryUnique> CountriesToCreate { get; set; } //public List<CountryUnique> CountriesToCreate { get; set; }
public CurrencyCreate() { }
} }
} }

View File

@ -10,8 +10,6 @@ namespace BlueWest.Data
public int Num { get; set; } // Primary key public int Num { get; set; } // Primary key
[MaxLength(3)] public string Code { get; set; } [MaxLength(3)] public string Code { get; set; }
public CurrencyUnique() { }
} }
} }

View File

@ -13,6 +13,5 @@ namespace BlueWest.Data
// ISO 4217 Code // ISO 4217 Code
[MaxLength(3)] public string Code { get; set; } [MaxLength(3)] public string Code { get; set; }
public CurrencyUpdate() { }
} }
} }

View File

@ -20,7 +20,6 @@ namespace BlueWest.Data
private string Description {get;} private string Description {get;}
public FinanceOp() { }
public FinanceOp(TimeSpan creationDate, int userId, public FinanceOp(TimeSpan creationDate, int userId,
Currency currency, FinanceOpType financeOpType) Currency currency, FinanceOpType financeOpType)

View File

@ -10,10 +10,6 @@ namespace BlueWest.Data
private string Description; private string Description;
public FinanceOpType()
{
}
} }
} }

View File

@ -15,19 +15,12 @@ namespace BlueWest.Data
public List<FinanceOp> FinanceTransactions { get; set; } public List<FinanceOp> FinanceTransactions { get; set; }
public Country Country { get; set; } [ForeignKey("CountryId")] public Country Country { get; set; }
[ForeignKey("Countries")]
public int CountryId { get; set; }
public User(int id, string name) public User(int id, string name)
{ {
Id = id; Id = id;
Name = name; Name = name;
} }
public User()
{
}
} }
} }

View File

@ -8,10 +8,5 @@ namespace BlueWest.Data
{ {
public string Name { get; set; } public string Name { get; set; }
public UserCreate()
{
}
} }
} }