Cleanup warnings, add docs
This commit is contained in:
parent
62ad4f150d
commit
8dfd6e80cc
|
@ -15,7 +15,6 @@
|
|||
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.8" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authorization.Policy" Version="2.2.0" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -6,12 +6,24 @@ using Microsoft.EntityFrameworkCore;
|
|||
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
/// Db set of Industries.
|
||||
/// </summary>
|
||||
public DbSet<Industry> Industries { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Db set of Products.
|
||||
/// </summary>
|
||||
public DbSet<Product> Products { get; set; }
|
||||
|
||||
|
||||
|
@ -25,6 +37,10 @@ namespace BlueWest.WebApi.EF
|
|||
Database.EnsureCreated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On database model creating
|
||||
/// </summary>
|
||||
/// <param name="modelBuilder">Builder model of the database</param>
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
|
|
@ -9,13 +9,22 @@ namespace BlueWest.WebApi.EF
|
|||
/// <summary>
|
||||
/// Countries and Currencies
|
||||
/// </summary>
|
||||
internal sealed class CountryDbContext : DbContext
|
||||
public sealed class CountryDbContext : DbContext
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Countries Database Table
|
||||
/// </summary>
|
||||
public DbSet<Country> Countries { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Currencies Database Table
|
||||
/// </summary>
|
||||
public DbSet<Currency> Currencies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// App Configuration
|
||||
/// </summary>
|
||||
public IConfiguration Configuration;
|
||||
|
||||
|
||||
|
|
|
@ -5,12 +5,16 @@ using BlueWest.WebApi.EF;
|
|||
|
||||
namespace BlueWest.WebApi.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Empty constructor
|
||||
/// </summary>
|
||||
|
||||
public struct ExchangeEvent { }
|
||||
/// <summary>
|
||||
/// Interface for getting and storing exchange rates data
|
||||
/// </summary>
|
||||
///
|
||||
internal sealed class ExchangeInterface : EventListener<ExchangeEvent>, IDisposable, IAsyncDisposable
|
||||
public sealed class ExchangeInterface : EventListener<ExchangeEvent>, IDisposable, IAsyncDisposable
|
||||
{
|
||||
private readonly EventManager _eventManager;
|
||||
private readonly CountryDbContext _countryDbContext;
|
||||
|
@ -18,6 +22,16 @@ namespace BlueWest.WebApi.Interfaces
|
|||
private readonly UserDbContext _userDbContext;
|
||||
|
||||
#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(
|
||||
CountryDbContext countryDbContext,
|
||||
FinanceDbContext financeDbContext,
|
||||
|
@ -31,6 +45,9 @@ namespace BlueWest.WebApi.Interfaces
|
|||
Init();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Empty constructor
|
||||
/// </summary>
|
||||
public ExchangeInterface() { }
|
||||
|
||||
private void Init()
|
||||
|
@ -51,13 +68,17 @@ namespace BlueWest.WebApi.Interfaces
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop Listening for events
|
||||
/// Stop Listening for events on dispose
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_eventManager.EventStopListening<ExchangeEvent>(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop Listening for events on dispose async
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
_eventManager.EventStopListening<ExchangeEvent>(this);
|
||||
|
|
|
@ -7,14 +7,44 @@ using Microsoft.EntityFrameworkCore;
|
|||
|
||||
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);
|
||||
internal static (bool, string, Country) ErrorMessage(string message) => (false, message, null);
|
||||
internal static (bool, string, Country) Success(bool success, Country country) => (success, "1", null);
|
||||
/// <summary>
|
||||
/// Returns Not found projection
|
||||
/// </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,
|
||||
CountryUpdate countryUpdate,
|
||||
int countryId)
|
||||
|
@ -28,13 +58,16 @@ namespace BlueWest.WebApi.EF
|
|||
|
||||
}
|
||||
|
||||
internal static async Task<Country> GetCountryByIdAsync(this DbSet<Country> countries, int countryId) =>
|
||||
await countries.FirstOrDefaultAsync(x => x.Id == countryId);
|
||||
|
||||
|
||||
internal static (bool, string, Country) AddCurrency( this CountryDbContext dbContext, int countryId, CurrencyCreate currencyCreate)
|
||||
/// <summary>
|
||||
/// Adds a new Currency to the specified country
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
/// <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
|
||||
if (country == null) return (false, "Country Not found.", null);
|
||||
|
@ -46,12 +79,20 @@ namespace BlueWest.WebApi.EF
|
|||
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,
|
||||
int countryId, CurrencyCreate currencyCreate,
|
||||
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
|
||||
if (country == null) return (false, $"{nameof(country)} Not found.", null);
|
||||
|
|
|
@ -5,12 +5,25 @@ using Microsoft.EntityFrameworkCore;
|
|||
|
||||
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);
|
||||
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);
|
||||
if (currency == null) return NotFound();
|
||||
|
|
|
@ -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) { }
|
||||
}
|
||||
}
|
||||
|
|
@ -7,23 +7,31 @@ namespace BlueWest.WebApi.EF
|
|||
/// <summary>
|
||||
/// Finance operations table
|
||||
/// </summary>
|
||||
internal sealed class FinanceDbContext : DbContext
|
||||
public sealed class FinanceDbContext : DbContext
|
||||
{
|
||||
[DatabaseFundamentals(typeof(FinanceDbContext), typeof(FinanceOp))]
|
||||
internal DbSet<FinanceOp> Transactions { get; set; }
|
||||
/// <summary>
|
||||
/// Table storing transactions
|
||||
/// </summary>
|
||||
public DbSet<FinanceOp> Transactions { get; set; }
|
||||
|
||||
[DatabaseFundamentals(typeof(FinanceDbContext), typeof(FinanceOpType))]
|
||||
internal DbSet<FinanceOpType> TransactionTypes { get; set; }
|
||||
/// <summary>
|
||||
/// Table storing transaction types.
|
||||
/// </summary>
|
||||
public DbSet<FinanceOpType> TransactionTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Finance transactions context
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
internal FinanceDbContext(DbContextOptions<FinanceDbContext> options) : base(options)
|
||||
public FinanceDbContext(DbContextOptions<FinanceDbContext> options) : base(options)
|
||||
{
|
||||
Database.EnsureCreated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On database model creating
|
||||
/// </summary>
|
||||
/// <param name="modelBuilder">Builder model of the database</param>
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
|
|
@ -6,28 +6,34 @@ using Microsoft.Extensions.Configuration;
|
|||
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; }
|
||||
internal IConfiguration Configuration;
|
||||
/// <summary>
|
||||
/// Users entity.
|
||||
/// </summary>
|
||||
public DbSet<User> Users { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// App configuration.
|
||||
/// </summary>
|
||||
public IConfiguration Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Database for the context of database users
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
internal UserDbContext(DbContextOptions<UserDbContext> options) : base(options)
|
||||
public UserDbContext(DbContextOptions<UserDbContext> options) : base(options)
|
||||
{
|
||||
Database.EnsureCreated();
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
/*optionsBuilder.UseMySql(
|
||||
Configuration.GetConnectionString("LocalMySQL"),
|
||||
new MySqlServerVersion(new Version(8, 0, 11))
|
||||
);*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On database model creating
|
||||
/// </summary>
|
||||
/// <param name="modelBuilder">Builder model of the database</param>
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
|
|
@ -10,16 +10,16 @@ using Microsoft.AspNetCore.Mvc;
|
|||
namespace BlueWest.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Controller responsible to get country data
|
||||
/// Controller responsible to get countryId data
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
internal class CountryController : ControllerBase
|
||||
public class CountryController : ControllerBase
|
||||
{
|
||||
private readonly CountryDbContext _dbContext;
|
||||
|
||||
/// <summary>
|
||||
/// Controller responsible for handling country data in the Country table
|
||||
/// Controller responsible for handling countryId data in the Country table
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
public CountryController(CountryDbContext dbContext)
|
||||
|
@ -31,8 +31,8 @@ namespace BlueWest.WebApi.Controllers
|
|||
/// <summary>
|
||||
/// Add Country
|
||||
/// </summary>
|
||||
/// <param name="countryToCreate">The country data to create</param>
|
||||
/// <returns>The newly created country</returns>
|
||||
/// <param name="countryToCreate">The countryId data to create</param>
|
||||
/// <returns>The newly created countryId</returns>
|
||||
/// /// <summary>
|
||||
/// Creates a Country.
|
||||
/// </summary>
|
||||
|
@ -47,7 +47,7 @@ namespace BlueWest.WebApi.Controllers
|
|||
/// }
|
||||
///
|
||||
/// </remarks>
|
||||
/// <response code="201">Returns the newly created country</response>
|
||||
/// <response code="201">Returns the newly created countryId</response>
|
||||
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status406NotAcceptable)]
|
||||
|
||||
|
@ -65,7 +65,7 @@ namespace BlueWest.WebApi.Controllers
|
|||
/// <summary>
|
||||
/// Updates a Country
|
||||
/// </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>
|
||||
/// <returns></returns>
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
|
@ -73,11 +73,11 @@ namespace BlueWest.WebApi.Controllers
|
|||
[HttpPut("{countryCode}")]
|
||||
public ActionResult UpdateCountry(int countryCode, CountryUpdate countryToUpdate)
|
||||
{
|
||||
var (success, country) = _dbContext.UpdateCountry(countryToUpdate, countryCode);
|
||||
var (success, countryId) = _dbContext.UpdateCountry(countryToUpdate, countryCode);
|
||||
|
||||
if (success)
|
||||
{
|
||||
return Ok(country);
|
||||
return Ok(countryId);
|
||||
}
|
||||
|
||||
return new NotFoundResult();
|
||||
|
@ -106,7 +106,7 @@ namespace BlueWest.WebApi.Controllers
|
|||
/// <summary>
|
||||
/// Get Country by Id
|
||||
/// </summary>
|
||||
/// <param name="countryId">ISO 3166-1 country numeric code</param>
|
||||
/// <param name="countryId">ISO 3166-1 countryId numeric code</param>
|
||||
/// <returns></returns>
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
|
@ -124,7 +124,7 @@ namespace BlueWest.WebApi.Controllers
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get currencies of a country
|
||||
/// Get currencies of a countryId
|
||||
/// </summary>
|
||||
/// <param name="countryId"></param>
|
||||
/// <returns></returns>
|
||||
|
@ -133,9 +133,9 @@ namespace BlueWest.WebApi.Controllers
|
|||
[HttpGet("{countryId}/currencies")]
|
||||
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
|
||||
.Countries
|
||||
|
|
|
@ -13,10 +13,14 @@ namespace BlueWest.WebApi.Controllers
|
|||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
internal class CurrencyController : ControllerBase
|
||||
public class CurrencyController : ControllerBase
|
||||
{
|
||||
private readonly CountryDbContext _dbContext;
|
||||
|
||||
/// <summary>
|
||||
/// Api Controller for Currency data
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
public CurrencyController(CountryDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
|
@ -39,7 +43,6 @@ namespace BlueWest.WebApi.Controllers
|
|||
/// Add Currency to the table of currencies
|
||||
/// </summary>
|
||||
/// <param name="currencyToCreate">Currency data to create</param>
|
||||
/// <param name="currencyAssociatedCountries">Countries</param>
|
||||
/// <returns></returns>
|
||||
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||
[HttpPost]
|
||||
|
|
|
@ -11,10 +11,14 @@ namespace BlueWest.WebApi.Controllers;
|
|||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
internal class FinanceController : ControllerBase
|
||||
public class FinanceController : ControllerBase
|
||||
{
|
||||
private readonly FinanceDbContext _dbContext;
|
||||
|
||||
/// <summary>
|
||||
/// Finance Controller Api Controller
|
||||
/// </summary>
|
||||
/// <param name="dbContext">The finance database context</param>
|
||||
public FinanceController(FinanceDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
|
|
|
@ -6,8 +6,14 @@ using Swashbuckle.AspNetCore.SwaggerGen;
|
|||
|
||||
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)
|
||||
{
|
||||
if (context.Type.IsEnum)
|
||||
|
|
|
@ -9,9 +9,12 @@ using Microsoft.AspNetCore.Mvc;
|
|||
|
||||
namespace BlueWest.WebApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Api Controller for handling users data
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
internal class UserController : ControllerBase
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly UserDbContext _dbContext;
|
||||
|
|
|
@ -10,6 +10,10 @@ namespace BlueWest.WebApi.EF.Model
|
|||
{
|
||||
#region Initialization
|
||||
|
||||
static ModelBuilderExtensions()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setup the database model
|
||||
/// </summary>
|
||||
|
@ -105,20 +109,6 @@ namespace BlueWest.WebApi.EF.Model
|
|||
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
|
||||
modelBuilder
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
namespace BlueWest.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Auth Manager
|
||||
/// </summary>
|
||||
public class AuthManager
|
||||
{
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
using BlueWest.WebApi.EF;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace BlueWest.WebApi;
|
||||
|
||||
public class EntityDbContext : IdentityUser
|
||||
{
|
||||
|
||||
}
|
|
@ -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; }
|
||||
}
|
|
@ -43,6 +43,10 @@ namespace BlueWest.WebApi
|
|||
/// </summary>
|
||||
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)
|
||||
{
|
||||
MainHost = CreateHostBuilder(args)
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Text.Json.Serialization;
|
||||
using BlueWest.Tools;
|
||||
using BlueWest.WebApi.Extensions;
|
||||
using BlueWest.WebApi.Interfaces;
|
||||
using BlueWest.WebApi.Tools;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace BlueWest.WebApi
|
||||
{
|
||||
|
@ -50,7 +54,33 @@ namespace BlueWest.WebApi
|
|||
.AddJsonOptions(options => options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve);
|
||||
|
||||
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
|
||||
.AddSingleton<EventManager>()
|
||||
.PrepareDatabasePool(_configuration, _environment)
|
||||
|
|
|
@ -23,10 +23,6 @@ namespace BlueWest.Data
|
|||
|
||||
public List<Industry> Industry { get; set; }
|
||||
|
||||
public Company()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,10 +16,6 @@ namespace BlueWest.Data
|
|||
|
||||
public DateTime FoundingDate { get; set; }
|
||||
|
||||
public CompanyCreate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,6 @@ namespace BlueWest.Data
|
|||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public CompanyType()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,10 +7,6 @@ namespace BlueWest.Data
|
|||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public CompanyTypeCreate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,6 @@ namespace BlueWest.Data
|
|||
public string Name { get; set; }
|
||||
public Industry Industry { get; set; }
|
||||
public List<Company> Seller { get; set; }
|
||||
|
||||
public Product()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,17 +33,6 @@ namespace BlueWest.Data
|
|||
public List<Currency> Currencies { 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() { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,14 +13,12 @@ namespace BlueWest.Data
|
|||
public string Name { 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 CountryCreate() { }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@ namespace BlueWest.Data
|
|||
|
||||
public string TLD { get; set; }
|
||||
|
||||
public CountryUnique() { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ namespace BlueWest.Data
|
|||
/// ISO 3166-1 numeric code
|
||||
/// </summary>
|
||||
public int Code { get; set; }
|
||||
public CountryUpdate() { }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,6 @@ namespace BlueWest.Data
|
|||
public int Num { get; set; }
|
||||
[MaxLength(3)] public string Code { get; set; }
|
||||
public List<Country> Countries { get; set; }
|
||||
|
||||
public Currency() { }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,9 @@ namespace BlueWest.Data
|
|||
[MapFrom(typeof(Currency))]
|
||||
public partial class CurrencyCreate
|
||||
{
|
||||
public int Num { get; set; } // Primary key
|
||||
public int Num { get; set; }
|
||||
[MaxLength(3)] public string Code { get; set; }
|
||||
public List<CountryUnique> CountriesToCreate { get; set; }
|
||||
public CurrencyCreate() { }
|
||||
|
||||
//public List<CountryUnique> CountriesToCreate { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@ namespace BlueWest.Data
|
|||
public int Num { get; set; } // Primary key
|
||||
[MaxLength(3)] public string Code { get; set; }
|
||||
|
||||
public CurrencyUnique() { }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,5 @@ namespace BlueWest.Data
|
|||
// ISO 4217 Code
|
||||
[MaxLength(3)] public string Code { get; set; }
|
||||
|
||||
public CurrencyUpdate() { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ namespace BlueWest.Data
|
|||
private string Description {get;}
|
||||
|
||||
|
||||
public FinanceOp() { }
|
||||
|
||||
public FinanceOp(TimeSpan creationDate, int userId,
|
||||
Currency currency, FinanceOpType financeOpType)
|
||||
|
|
|
@ -10,10 +10,6 @@ namespace BlueWest.Data
|
|||
|
||||
private string Description;
|
||||
|
||||
public FinanceOpType()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,19 +15,12 @@ namespace BlueWest.Data
|
|||
|
||||
public List<FinanceOp> FinanceTransactions { get; set; }
|
||||
|
||||
public Country Country { get; set; }
|
||||
|
||||
[ForeignKey("Countries")]
|
||||
public int CountryId { get; set; }
|
||||
[ForeignKey("CountryId")] public Country Country { get; set; }
|
||||
|
||||
public User(int id, string name)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public User()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,10 +8,5 @@ namespace BlueWest.Data
|
|||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public UserCreate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue