diff --git a/BlueWest.Api/BlueWest.Api.csproj b/BlueWest.Api/BlueWest.Api.csproj index 3c6f711..ac23ef4 100644 --- a/BlueWest.Api/BlueWest.Api.csproj +++ b/BlueWest.Api/BlueWest.Api.csproj @@ -20,9 +20,13 @@ - + + + + + diff --git a/BlueWest.Api/Context/CompanyDbContext.cs b/BlueWest.Api/Context/CompanyDbContext.cs new file mode 100644 index 0000000..237b18e --- /dev/null +++ b/BlueWest.Api/Context/CompanyDbContext.cs @@ -0,0 +1,36 @@ + +using BlueWest.Data; +using BlueWest.WebApi.EF.Model; +using MapTo; +using Microsoft.EntityFrameworkCore; + +namespace BlueWest.WebApi.EF +{ + internal sealed class CompanyDbContext : DbContext + { + public DbSet Companies { get; set; } + + public DbSet Industries { get; set; } + + public DbSet Products { get; set; } + + + + /// + /// Options to be injected in the app + /// + /// + public CompanyDbContext(DbContextOptions options) : base(options) + { + Database.EnsureCreated(); + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + modelBuilder.ConfigureCurrentDbModel(); + } + + } +} + diff --git a/BlueWest.Api/Context/CountryDbContext.cs b/BlueWest.Api/Context/CountryDbContext.cs index f3a4310..f18b427 100644 --- a/BlueWest.Api/Context/CountryDbContext.cs +++ b/BlueWest.Api/Context/CountryDbContext.cs @@ -1,15 +1,15 @@ using BlueWest.Data; -using BlueWest.WebApi.MySQL.Model; +using BlueWest.WebApi.EF.Model; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; -namespace BlueWest.WebApi.MySQL +namespace BlueWest.WebApi.EF { /// /// Countries and Currencies /// - public sealed class CountryDbContext : DbContext + internal sealed class CountryDbContext : DbContext { public DbSet Countries { get; set; } @@ -26,7 +26,6 @@ namespace BlueWest.WebApi.MySQL public CountryDbContext(DbContextOptions options) : base(options) { Database.EnsureCreated(); - } /// @@ -39,5 +38,6 @@ namespace BlueWest.WebApi.MySQL base.OnModelCreating(modelBuilder); modelBuilder.ConfigureCurrentDbModel(); } + } } diff --git a/BlueWest.Api/Context/Interfaces/ExchangeInterface.cs b/BlueWest.Api/Context/ExchangeInterface.cs similarity index 93% rename from BlueWest.Api/Context/Interfaces/ExchangeInterface.cs rename to BlueWest.Api/Context/ExchangeInterface.cs index 11bb333..6894ddc 100644 --- a/BlueWest.Api/Context/Interfaces/ExchangeInterface.cs +++ b/BlueWest.Api/Context/ExchangeInterface.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; using BlueWest.Tools; -using BlueWest.WebApi.MySQL; +using BlueWest.WebApi.EF; namespace BlueWest.WebApi.Interfaces { @@ -10,7 +10,7 @@ namespace BlueWest.WebApi.Interfaces /// Interface for getting and storing exchange rates data /// /// - public sealed class ExchangeInterface : EventListener, IDisposable, IAsyncDisposable + internal sealed class ExchangeInterface : EventListener, IDisposable, IAsyncDisposable { private readonly EventManager _eventManager; private readonly CountryDbContext _countryDbContext; diff --git a/BlueWest.Api/Context/Extensions/CountryDbExtensions.cs b/BlueWest.Api/Context/Extensions/CountryDbExtensions.cs new file mode 100644 index 0000000..725a79b --- /dev/null +++ b/BlueWest.Api/Context/Extensions/CountryDbExtensions.cs @@ -0,0 +1,61 @@ +using System.Linq; +using System.Threading.Tasks; +using BlueWest.Data; +using Microsoft.EntityFrameworkCore; + +namespace BlueWest.WebApi.EF +{ + internal static class CountryDbExtensions + { + + internal static Country GetCountryById(this DbSet countries, int countryId) => countries.GetOne(x => x.Id == countryId); + internal static (bool, T) NotFound() where T : class => (false, null); + + internal static (bool, Country) AddCountry (this CountryDbContext dbContext, CountryCreate countryCreate) + { + Country newCountry = new Country(countryCreate); + return dbContext.Countries.Add(dbContext, newCountry); + } + + internal static async Task<(bool, Country)> AddCountryAsync (this CountryDbContext dbContext, CountryCreate countryCreate) + { + var newCountry = new Country(countryCreate); + return await dbContext.Countries.AddAsync(dbContext, newCountry); + } + + internal static (bool, Country) UpdateCountry(this CountryDbContext dbContext, CountryUpdate countryUpdate, + int countryId) + { + var country = dbContext.Countries.FirstOrDefault(x => x.Id == countryId); + + if (country != null) + { + var updatedCountry = new Country(countryUpdate); + return dbContext.Countries.Update(dbContext, updatedCountry); + } + + return NotFound(); + } + + internal static async Task GetCountryByIdAsync(this DbSet countries, int countryId) => + await countries.FirstOrDefaultAsync(x => x.Id == countryId); + + + internal static async Task<(bool, Country)> UpdateCountryAsync(this CountryDbContext dbContext, CountryUpdate countryUpdate, + int countryCode) + { + var country = await dbContext.Countries.FirstOrDefaultAsync(x => x.Code == countryCode); + + if (country != null) + { + var updatedCountry = new Country(countryUpdate); + return await dbContext.Countries.UpdateAsync(dbContext, updatedCountry); + } + + return NotFound(); + } + + + } +} + diff --git a/BlueWest.Api/Context/Extensions/CurrencyExtensions.cs b/BlueWest.Api/Context/Extensions/CurrencyExtensions.cs new file mode 100644 index 0000000..d2c7b8e --- /dev/null +++ b/BlueWest.Api/Context/Extensions/CurrencyExtensions.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Linq; +using BlueWest.Data; +using Microsoft.EntityFrameworkCore; + +namespace BlueWest.WebApi.EF +{ + internal static class CurrencyExtensions + { + + internal static Currency GetCurrencyById(this DbSet currencies, int currencyId) => currencies.GetOne(x => x.Id == currencyId); + internal static (bool, T) NotFound() where T : class => (false, null); + + + internal static (bool, Currency) AddCurrency(this CountryDbContext dbContext, CurrencyCreate currencyToCreate) + { + + var newCurrency = new Currency(currencyToCreate); + return dbContext.Currencies.Add(dbContext, newCurrency); + } + + + internal 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(); + + var newCurrency = new Currency(currencyToUpdate); + var operationResult = dbContext.Currencies.Update(dbContext, newCurrency); + return operationResult; + + } + } +} + diff --git a/BlueWest.Api/Context/Extensions/DatabaseFundamentalsAttribute.cs b/BlueWest.Api/Context/Extensions/DatabaseFundamentalsAttribute.cs new file mode 100644 index 0000000..2ded8f2 --- /dev/null +++ b/BlueWest.Api/Context/Extensions/DatabaseFundamentalsAttribute.cs @@ -0,0 +1,14 @@ +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) { } + } +} + diff --git a/BlueWest.Api/Context/Extensions/GenericExtensions.cs b/BlueWest.Api/Context/Extensions/GenericExtensions.cs new file mode 100644 index 0000000..184400f --- /dev/null +++ b/BlueWest.Api/Context/Extensions/GenericExtensions.cs @@ -0,0 +1,51 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; +using BlueWest.Data; +using Microsoft.EntityFrameworkCore; + +namespace BlueWest.WebApi.EF; + +public static class GenericExtensions +{ + + + internal static T GetOne(this DbSet dbSet, Expression> predicate) where T: class => dbSet.FirstOrDefault(predicate); + + internal static async Task GetOneAsync(this DbSet dbSet, Expression> predicate) where T: class => await dbSet.FirstOrDefaultAsync(predicate); + + + internal static (bool, T) NotFound() where T : class => (false, null); + + internal static (bool, T) Add(this DbSet dbSet, DbContext dbContext, T objectToAdd) where T: class + { + var newEntity = dbSet.Add(objectToAdd).Entity; + return (dbContext.SaveChanges() >= 0, newEntity); + } + + internal static async Task<(bool, T)> AddAsync(this DbSet dbSet, DbContext dbContext, T objectToAdd) where T: class + { + var newEntity = dbSet.Add(objectToAdd); + bool resultOperation = await dbContext.SaveChangesAsync() >= 0; + return (resultOperation, objectToAdd); + } + + + internal static (bool, T) Update(this DbSet dbSet, DbContext dbContext, T objectToUpdate) where T: class + { + + dbContext.Update(objectToUpdate); + var resultOperation = dbContext.SaveChanges() >= 0; + return resultOperation ? (true, objectToUpdate) : (false, null); + } + + internal static async Task<(bool, T)> UpdateAsync(this DbSet dbSet, DbContext dbContext, T objectToUpdate) where T: class + { + dbSet.Update(objectToUpdate); + var result = await dbContext.SaveChangesAsync() >= 0; + return (result, objectToUpdate); + } + +} \ No newline at end of file diff --git a/BlueWest.Api/Context/FinanceDbContext.cs b/BlueWest.Api/Context/FinanceDbContext.cs index f080167..6a7b4f0 100644 --- a/BlueWest.Api/Context/FinanceDbContext.cs +++ b/BlueWest.Api/Context/FinanceDbContext.cs @@ -1,23 +1,25 @@ using BlueWest.Data; -using BlueWest.WebApi.MySQL.Model; +using BlueWest.WebApi.EF.Model; using Microsoft.EntityFrameworkCore; -namespace BlueWest.WebApi.MySQL +namespace BlueWest.WebApi.EF { /// /// Finance operations table /// - public sealed class FinanceDbContext : DbContext + internal sealed class FinanceDbContext : DbContext { - public DbSet Transactions { get; set; } + [DatabaseFundamentals(typeof(FinanceDbContext), typeof(FinanceOp))] + internal DbSet Transactions { get; set; } - public DbSet TransactionTypes { get; set; } + [DatabaseFundamentals(typeof(FinanceDbContext), typeof(FinanceOpType))] + internal DbSet TransactionTypes { get; set; } /// /// Finance transactions context /// /// - public FinanceDbContext(DbContextOptions options) : base(options) + internal FinanceDbContext(DbContextOptions options) : base(options) { Database.EnsureCreated(); } diff --git a/BlueWest.Api/Context/UserDbContext.cs b/BlueWest.Api/Context/UserDbContext.cs index 655b9a4..3eaa396 100644 --- a/BlueWest.Api/Context/UserDbContext.cs +++ b/BlueWest.Api/Context/UserDbContext.cs @@ -1,24 +1,21 @@ using BlueWest.Data; -using BlueWest.WebApi.MySQL.Model; +using BlueWest.WebApi.EF.Model; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; -namespace BlueWest.WebApi.MySQL +namespace BlueWest.WebApi.EF { - public sealed class UserDbContext : DbContext + internal sealed class UserDbContext : DbContext { - public DbSet Users { get; set; } + internal DbSet Users { get; set; } + internal IConfiguration Configuration; - - public IConfiguration Configuration; - - /// /// Database for the context of database users /// /// - public UserDbContext(DbContextOptions options) : base(options) + internal UserDbContext(DbContextOptions options) : base(options) { Database.EnsureCreated(); } diff --git a/BlueWest.Api/Controllers/CountryController.cs b/BlueWest.Api/Controllers/CountryController.cs index c371720..667d040 100644 --- a/BlueWest.Api/Controllers/CountryController.cs +++ b/BlueWest.Api/Controllers/CountryController.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; using BlueWest.Data; -using BlueWest.WebApi.MySQL; +using BlueWest.WebApi.EF; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -12,7 +12,7 @@ namespace BlueWest.WebApi.Controllers /// [ApiController] [Route("[controller]")] - public class CountryController : ControllerBase + internal class CountryController : ControllerBase { private readonly CountryDbContext _dbContext; @@ -50,10 +50,8 @@ namespace BlueWest.WebApi.Controllers [HttpPost] public ActionResult AddCountry(CountryCreate countryToCreate) { - var newCountry = countryToCreate.ToCountry(); - _dbContext.Countries.Add(newCountry); - _dbContext.SaveChanges(); - return CreatedAtRoute(nameof(GetCountryById), new {countryId = newCountry.Code}, newCountry); + _dbContext.AddCountry(countryToCreate); + return CreatedAtRoute(nameof(GetCountryById), new {countryId = countryToCreate.Code}); } /// @@ -67,13 +65,11 @@ namespace BlueWest.WebApi.Controllers [HttpPut("{countryCode}")] public ActionResult UpdateCountry(int countryCode, CountryUpdate countryToUpdate) { - var country = _dbContext.Countries.FirstOrDefault(x => x.Code == countryCode); + var (success, country) = _dbContext.UpdateCountry(countryToUpdate, countryCode); - if (country != null) + if (success) { - var updatedCountry = new Country(countryToUpdate, countryCode, country.Currencies, country.Users); - _dbContext.Countries.Update(updatedCountry); - return Ok(updatedCountry); + return Ok(country); } return new NotFoundResult(); diff --git a/BlueWest.Api/Controllers/CurrencyController.cs b/BlueWest.Api/Controllers/CurrencyController.cs index 8842190..598fe86 100644 --- a/BlueWest.Api/Controllers/CurrencyController.cs +++ b/BlueWest.Api/Controllers/CurrencyController.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using BlueWest.Data; -using BlueWest.WebApi.MySQL; +using BlueWest.WebApi.EF; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -13,11 +13,10 @@ namespace BlueWest.WebApi.Controllers /// [ApiController] [Route("[controller]")] - public class CurrencyController : ControllerBase + internal class CurrencyController : ControllerBase { private readonly CountryDbContext _dbContext; - public CurrencyController(CountryDbContext dbContext) { _dbContext = dbContext; @@ -32,14 +31,8 @@ namespace BlueWest.WebApi.Controllers [HttpGet] public ActionResult GetCurrencies() { - var dbContext = _dbContext.Currencies; - - if (dbContext != null) - { - return Ok(dbContext.ToArray()); - } - - return new NotFoundResult(); + var currencies = _dbContext.Currencies.ToArray(); + return Ok(currencies); } /// @@ -53,9 +46,13 @@ namespace BlueWest.WebApi.Controllers public ActionResult AddCurrency(CurrencyCreate currencyToCreate) { - var newCurrency = currencyToCreate.ToCurrency(); - _dbContext.Currencies.Add(newCurrency); - _dbContext.SaveChanges(); + var (success, newCurrency) = _dbContext.AddCurrency(currencyToCreate); + + if (!success) + { + return new NotFoundResult(); + } + return CreatedAtRoute(nameof(GetCurrencyById), new {CurrencyId = newCurrency.Code}, newCurrency); } @@ -70,14 +67,11 @@ namespace BlueWest.WebApi.Controllers [HttpPut("{currencyNumber}")] public ActionResult UpdateCurrency(int currencyNumber, CurrencyUpdate currencyToUpdate) { - var currency = _dbContext.Currencies.FirstOrDefault(x => x.Num == currencyNumber); + var (success, currency) = _dbContext.UpdateCurrency(currencyNumber, currencyToUpdate); - if (currency != null) + if (success) { - var updatedCurrency = new Currency(currencyToUpdate, currencyNumber, new List()); - _dbContext.Update(updatedCurrency); - _dbContext.SaveChanges(); - return Ok(updatedCurrency); + return Ok(currency); } return new NotFoundResult(); @@ -94,11 +88,11 @@ namespace BlueWest.WebApi.Controllers [HttpGet("{currencyId}", Name = nameof(GetCurrencyById))] public ActionResult GetCurrencyById(int currencyId) { - var array = _dbContext.Countries.FirstOrDefault(x => x.Code == currencyId); + var currency = _dbContext.Currencies.GetCurrencyById(currencyId); - if (array != null) + if (currency != null) { - return Ok(array); + return Ok(currency); } return new NotFoundResult(); diff --git a/BlueWest.Api/Controllers/FinanceController.cs b/BlueWest.Api/Controllers/FinanceController.cs index 0471a35..b54223b 100644 --- a/BlueWest.Api/Controllers/FinanceController.cs +++ b/BlueWest.Api/Controllers/FinanceController.cs @@ -1,6 +1,6 @@ using System; using BlueWest.Data; -using BlueWest.WebApi.MySQL; +using BlueWest.WebApi.EF; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -11,7 +11,7 @@ namespace BlueWest.WebApi.Controllers; /// [ApiController] [Route("[controller]")] -public class FinanceController : ControllerBase +internal class FinanceController : ControllerBase { private readonly FinanceDbContext _dbContext; diff --git a/BlueWest.Api/Controllers/SwaggerEnumSchemaFilter.cs b/BlueWest.Api/Controllers/SwaggerEnumSchemaFilter.cs index a2a9aeb..4948230 100644 --- a/BlueWest.Api/Controllers/SwaggerEnumSchemaFilter.cs +++ b/BlueWest.Api/Controllers/SwaggerEnumSchemaFilter.cs @@ -6,7 +6,7 @@ using Swashbuckle.AspNetCore.SwaggerGen; namespace BlueWest.WebApi.Tools { - public class SwaggerEnumSchemaFilter : ISchemaFilter + internal class SwaggerEnumSchemaFilter : ISchemaFilter { public void Apply(OpenApiSchema model, SchemaFilterContext context) { diff --git a/BlueWest.Api/Controllers/UserController.cs b/BlueWest.Api/Controllers/UserController.cs index 7efc74a..9ac1923 100644 --- a/BlueWest.Api/Controllers/UserController.cs +++ b/BlueWest.Api/Controllers/UserController.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using BlueWest.Data; -using BlueWest.WebApi.MySQL; +using BlueWest.WebApi.EF; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -11,7 +11,7 @@ namespace BlueWest.WebApi.Controllers { [ApiController] [Route("[controller]")] - public class UserController : ControllerBase + internal class UserController : ControllerBase { private readonly UserDbContext _dbContext; @@ -70,7 +70,7 @@ namespace BlueWest.WebApi.Controllers [HttpPost] public ActionResult AddUser(UserCreate userCreate) { - var user = new User(userCreate, 0, new List(), null, -1); + var user = new User(userCreate); _dbContext.Users.Add(user); _dbContext.SaveChanges(); return CreatedAtRoute(nameof(GetUserById), new {userId = user.Id}, user); diff --git a/BlueWest.Api/Extensions/ModelBuilderExtensions.cs b/BlueWest.Api/Extensions/ModelBuilderExtensions.cs index 1662892..784e116 100644 --- a/BlueWest.Api/Extensions/ModelBuilderExtensions.cs +++ b/BlueWest.Api/Extensions/ModelBuilderExtensions.cs @@ -1,13 +1,15 @@ using BlueWest.Data; using Microsoft.EntityFrameworkCore; -namespace BlueWest.WebApi.MySQL.Model +namespace BlueWest.WebApi.EF.Model { /// /// Database model configuration extensions /// public static class ModelBuilderExtensions { + #region Initialization + /// /// Setup the database model /// @@ -16,36 +18,77 @@ namespace BlueWest.WebApi.MySQL.Model { modelBuilder .ConfigureDatabaseKeys() - .CountryCurrencyModel() + .CurrencyModel() .ConfigureUserModel(); } + + #endregion + #region DatabasePK + private static ModelBuilder ConfigureDatabaseKeys(this ModelBuilder modelBuilder) { - // User PK - modelBuilder.Entity(builder => builder - .HasKey(user => user.Id)); + // User + modelBuilder + .Entity(builder => builder + .HasKey(user => user.Id)) + .Entity().Property(user => user.Id) + .ValueGeneratedOnAdd(); - // Country PK - modelBuilder.Entity(builder => builder - .HasKey(country => country.Code)); + // Country + modelBuilder + .Entity(builder => builder + .HasKey(country => country.Id)) + .Entity().Property(country => country.Id) + .ValueGeneratedOnAdd(); - // Currency PK - modelBuilder.Entity(builder => builder - .HasKey(currency => currency.Num)); + // Currency + modelBuilder + .Entity(builder => builder + .HasKey(currency => currency.Id)) + .Entity() + .Property(currency => currency.Id) + .ValueGeneratedOnAdd(); - // FinanceOp PK + // Company PK + modelBuilder + .Entity(builder => builder + .HasKey(company => company.Id)) + .Entity().Property(company => company.Id) + .ValueGeneratedOnAdd(); + + // Industry PK + modelBuilder + .Entity(builder => builder + .HasKey(industry => industry.Id)) + .Entity().Property(industry => industry.Id) + .ValueGeneratedOnAdd(); + + + // Product + modelBuilder + .Entity(builder => builder + .HasKey(industry => industry.Id)); + + modelBuilder + .Entity() + .Property(industry => industry.Id) + .ValueGeneratedOnAdd(); + + // FinanceOp return modelBuilder.Entity(builder => builder .HasKey(financeOp => financeOp.Id)); } + #endregion - private static ModelBuilder CountryCurrencyModel(this ModelBuilder modelBuilder) + #region Database Models + + private static ModelBuilder CurrencyModel(this ModelBuilder modelBuilder) { - // Relationships modelBuilder .Entity() .HasMany(ub => ub.Countries) @@ -87,6 +130,8 @@ namespace BlueWest.WebApi.MySQL.Model return modelBuilder; } + + #endregion } } diff --git a/BlueWest.Api/Extensions/StartupExtensions.cs b/BlueWest.Api/Extensions/StartupExtensions.cs index 350a418..32821a7 100644 --- a/BlueWest.Api/Extensions/StartupExtensions.cs +++ b/BlueWest.Api/Extensions/StartupExtensions.cs @@ -1,5 +1,5 @@ using System; -using BlueWest.WebApi.MySQL; +using BlueWest.WebApi.EF; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -51,11 +51,14 @@ namespace BlueWest.WebApi public static IServiceCollection PrepareDatabasePool(this IServiceCollection serviceCollection, IConfiguration configuration, IWebHostEnvironment environment) { - + return serviceCollection .AddDbContextPool(options => options.GetMySqlSettings(configuration, environment)) .AddDbContextPool(options => options.GetMySqlSettings(configuration, environment)) - .AddDbContextPool(options => options.GetMySqlSettings(configuration, environment)); + .AddDbContextPool(options => options.GetMySqlSettings(configuration, environment)) + .AddDbContextPool(options => options.GetMySqlSettings(configuration, environment)); + + } } } \ No newline at end of file diff --git a/BlueWest.Api/Identity/EntityDbContext.cs b/BlueWest.Api/Identity/EntityDbContext.cs index 41cb472..e16a17b 100644 --- a/BlueWest.Api/Identity/EntityDbContext.cs +++ b/BlueWest.Api/Identity/EntityDbContext.cs @@ -1,4 +1,4 @@ -using BlueWest.WebApi.MySQL; +using BlueWest.WebApi.EF; using Microsoft.AspNetCore.Identity; namespace BlueWest.WebApi; diff --git a/BlueWest.Api/Program.cs b/BlueWest.Api/Program.cs index c7ef863..3b329b3 100644 --- a/BlueWest.Api/Program.cs +++ b/BlueWest.Api/Program.cs @@ -13,6 +13,9 @@ using BlueWest.WebApi.Interfaces; namespace BlueWest.WebApi { + /// + /// Entry point of the application. + /// public class Program { /// @@ -35,18 +38,21 @@ namespace BlueWest.WebApi optimizationLevel: OptimizationLevel.Release)); }*/ - public static IHost Host1 { get; private set; } + /// + /// Host Interface of the application. + /// + public static IHost MainHost { get; private set; } public static void Main(string[] args) { - Host1 = CreateHostBuilder(args) + MainHost = CreateHostBuilder(args) .UseContentRoot(Directory.GetCurrentDirectory()) .Build(); - Host1.RunAsync(); - - var tryGetEventManager = Host1.Services.GetService(typeof(EventManager)); - _ = Host1.Services.GetService(typeof(ExchangeInterface)); + MainHost.RunAsync(); + + var tryGetEventManager = MainHost.Services.GetService(typeof(EventManager)); + _ = MainHost.Services.GetService(typeof(ExchangeInterface)); if(tryGetEventManager == null) Console.WriteLine($"Failed to get {nameof(EventManager)} Service."); @@ -62,7 +68,7 @@ namespace BlueWest.WebApi } - public static IHostBuilder CreateHostBuilder(string[] args) => + private static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => diff --git a/BlueWest.Data/BlueWest.Data.csproj b/BlueWest.Data.Capital/BlueWest.Data.Capital.csproj similarity index 100% rename from BlueWest.Data/BlueWest.Data.csproj rename to BlueWest.Data.Capital/BlueWest.Data.Capital.csproj diff --git a/BlueWest.Data.Capital/Company/Company.cs b/BlueWest.Data.Capital/Company/Company.cs new file mode 100644 index 0000000..cdba176 --- /dev/null +++ b/BlueWest.Data.Capital/Company/Company.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using MapTo; + +namespace BlueWest.Data +{ + [MapFrom(typeof(CompanyCreate))] + public partial class Company + { + public int Id { get; set; } + + public string Name { get; set; } + + public string Address { get; set; } + + public CompanyType CompanyType { get; set; } + + public Country CurrentCountry { get; set; } + + public Country OriginCountry { get; set; } + + public DateTime FoundingDate { get; set; } + + public List Industry { get; set; } + + public Company() + { + + } + } +} + diff --git a/BlueWest.Data.Capital/Company/CompanyCreate.cs b/BlueWest.Data.Capital/Company/CompanyCreate.cs new file mode 100644 index 0000000..b7c15ff --- /dev/null +++ b/BlueWest.Data.Capital/Company/CompanyCreate.cs @@ -0,0 +1,25 @@ +using System; +using MapTo; + +namespace BlueWest.Data +{ + [MapFrom(typeof(Company))] + public partial class CompanyCreate + { + public string Name { get; set; } + + public string Address { get; set; } + + public Country CurrentCountry { get; set; } + + public Country OriginCountry { get; set; } + + public DateTime FoundingDate { get; set; } + + public CompanyCreate() + { + + } + } +} + diff --git a/BlueWest.Data.Capital/Company/CompanySeller.cs b/BlueWest.Data.Capital/Company/CompanySeller.cs new file mode 100644 index 0000000..06d6842 --- /dev/null +++ b/BlueWest.Data.Capital/Company/CompanySeller.cs @@ -0,0 +1,8 @@ +namespace BlueWest.Data +{ + public partial class CompanySeller + { + + } +} + diff --git a/BlueWest.Data.Capital/Company/CompanyType.cs b/BlueWest.Data.Capital/Company/CompanyType.cs new file mode 100644 index 0000000..9338975 --- /dev/null +++ b/BlueWest.Data.Capital/Company/CompanyType.cs @@ -0,0 +1,17 @@ +using MapTo; + +namespace BlueWest.Data +{ + [MapFrom(typeof(Company))] + public partial class CompanyType + { + public int Id { get; set; } + public string Name { get; set; } + + public CompanyType() + { + + } + } +} + diff --git a/BlueWest.Data.Capital/Company/CompanyTypeCreate.cs b/BlueWest.Data.Capital/Company/CompanyTypeCreate.cs new file mode 100644 index 0000000..4b7817c --- /dev/null +++ b/BlueWest.Data.Capital/Company/CompanyTypeCreate.cs @@ -0,0 +1,16 @@ +using MapTo; + +namespace BlueWest.Data +{ + [MapFrom(typeof(Company))] + public partial class CompanyTypeCreate + { + public string Name { get; set; } + + public CompanyTypeCreate() + { + + } + } +} + diff --git a/BlueWest.Data.Capital/Company/Product.cs b/BlueWest.Data.Capital/Company/Product.cs new file mode 100644 index 0000000..4cb024a --- /dev/null +++ b/BlueWest.Data.Capital/Company/Product.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace BlueWest.Data +{ + public partial class Product + { + public string Name { get; set; } + public Industry Industry { get; set; } + public List Seller { get; set; } + + public Product() + { + + } + } +} + diff --git a/BlueWest.Data/Country/Country.cs b/BlueWest.Data.Capital/Country/Country.cs similarity index 85% rename from BlueWest.Data/Country/Country.cs rename to BlueWest.Data.Capital/Country/Country.cs index c3d36a7..059f416 100644 --- a/BlueWest.Data/Country/Country.cs +++ b/BlueWest.Data.Capital/Country/Country.cs @@ -14,12 +14,14 @@ namespace BlueWest.Data public partial class Country { + public int Id { get; set; } /// /// ISO 3166-1 numeric code - /// Primary key. /// public int Code { get; set; } + public string Name { get; set; } + /// /// ISO 3166-1 State Name /// @@ -33,15 +35,15 @@ namespace BlueWest.Data [JsonConstructor] - public Country(int code, string stateName, string tld, List currencies) + public Country(string stateName, string tld, List currencies) { - Code = code; StateName = stateName; TLD = tld; Currencies = currencies; } public Country() { } + } } diff --git a/BlueWest.Data/Country/CountryCreate.cs b/BlueWest.Data.Capital/Country/CountryCreate.cs similarity index 56% rename from BlueWest.Data/Country/CountryCreate.cs rename to BlueWest.Data.Capital/Country/CountryCreate.cs index ab1370e..6848c5c 100644 --- a/BlueWest.Data/Country/CountryCreate.cs +++ b/BlueWest.Data.Capital/Country/CountryCreate.cs @@ -8,7 +8,9 @@ namespace BlueWest.Data public partial class CountryCreate { // ISO 3166-1 numeric code - public int Code { get; set; } // Primary key + public int Code { get; set; } + + public string Name { get; set; } public string StateName { get; set; } public List CurrenciesToCreate { get; set; } @@ -18,19 +20,8 @@ namespace BlueWest.Data public string TLD { get; set; } public CountryCreate() { } - - public Country ToCountry() - { - var currencies = new List(); - - foreach (var currencyCreate in CurrenciesToCreate) - { - currencies.Add(new Currency(currencyCreate, null)); - } - - return new Country(this, currencies, null); - } - + + } } diff --git a/BlueWest.Data/Country/CountryUnique.cs b/BlueWest.Data.Capital/Country/CountryUnique.cs similarity index 77% rename from BlueWest.Data/Country/CountryUnique.cs rename to BlueWest.Data.Capital/Country/CountryUnique.cs index 159e9b3..d63d061 100644 --- a/BlueWest.Data/Country/CountryUnique.cs +++ b/BlueWest.Data.Capital/Country/CountryUnique.cs @@ -9,7 +9,12 @@ namespace BlueWest.Data public partial class CountryUnique { // ISO 3166-1 numeric code - public int Code { get; set; } // Primary key + public int Id { get; set; } + + public int Code { get; set; } + + public string Name { get; set; } + public string StateName { get; set; } [MaxLength(2)] public string Alpha2Code { get; set; } diff --git a/BlueWest.Data/Country/CountryUpdate.cs b/BlueWest.Data.Capital/Country/CountryUpdate.cs similarity index 69% rename from BlueWest.Data/Country/CountryUpdate.cs rename to BlueWest.Data.Capital/Country/CountryUpdate.cs index 40323dd..1698bd9 100644 --- a/BlueWest.Data/Country/CountryUpdate.cs +++ b/BlueWest.Data.Capital/Country/CountryUpdate.cs @@ -8,10 +8,14 @@ namespace BlueWest.Data public partial class CountryUpdate { + public string Name { get; set; } public string StateName { get; set; } public string Alpha2Code { get; set; } public string TLD { get; set; } - + /// + /// ISO 3166-1 numeric code + /// + public int Code { get; set; } public CountryUpdate() { } } } diff --git a/BlueWest.Data.Capital/Country/generated/GeneratedCountries.cs b/BlueWest.Data.Capital/Country/generated/GeneratedCountries.cs new file mode 100644 index 0000000..a7165c9 --- /dev/null +++ b/BlueWest.Data.Capital/Country/generated/GeneratedCountries.cs @@ -0,0 +1,8 @@ +namespace BlueWest.Data.generated +{ + public class GeneratedCountries + { + + } +} + diff --git a/BlueWest.Data/Currency/Currency.cs b/BlueWest.Data.Capital/Currency/Currency.cs similarity index 78% rename from BlueWest.Data/Currency/Currency.cs rename to BlueWest.Data.Capital/Currency/Currency.cs index d3155ba..3f2fe8a 100644 --- a/BlueWest.Data/Currency/Currency.cs +++ b/BlueWest.Data.Capital/Currency/Currency.cs @@ -12,14 +12,12 @@ namespace BlueWest.Data public partial class Currency { - public int Num { get; set; } // Primary key + public int Id { get; set; } + public int Num { get; set; } [MaxLength(3)] public string Code { get; set; } public List Countries { get; set; } - public Currency() - { - - } + public Currency() { } } } diff --git a/BlueWest.Data/Currency/CurrencyCreate.cs b/BlueWest.Data.Capital/Currency/CurrencyCreate.cs similarity index 51% rename from BlueWest.Data/Currency/CurrencyCreate.cs rename to BlueWest.Data.Capital/Currency/CurrencyCreate.cs index 9e47eaf..79c4daf 100644 --- a/BlueWest.Data/Currency/CurrencyCreate.cs +++ b/BlueWest.Data.Capital/Currency/CurrencyCreate.cs @@ -11,20 +11,7 @@ namespace BlueWest.Data [MaxLength(3)] public string Code { get; set; } public List CountriesToCreate { get; set; } public CurrencyCreate() { } - - public Currency ToCurrency() - { - List countries = new List(); - - foreach (var countryCreate in CountriesToCreate) - { - var newCountry = new Country(countryCreate, null, null); - countries.Add(newCountry); - } - - return new Currency(this, countries); - - } + } } diff --git a/BlueWest.Data/Currency/CurrencyUnique.cs b/BlueWest.Data.Capital/Currency/CurrencyUnique.cs similarity index 100% rename from BlueWest.Data/Currency/CurrencyUnique.cs rename to BlueWest.Data.Capital/Currency/CurrencyUnique.cs diff --git a/BlueWest.Data/Currency/CurrencyUpdate.cs b/BlueWest.Data.Capital/Currency/CurrencyUpdate.cs similarity index 89% rename from BlueWest.Data/Currency/CurrencyUpdate.cs rename to BlueWest.Data.Capital/Currency/CurrencyUpdate.cs index c9427b7..6cfaf2f 100644 --- a/BlueWest.Data/Currency/CurrencyUpdate.cs +++ b/BlueWest.Data.Capital/Currency/CurrencyUpdate.cs @@ -8,6 +8,8 @@ namespace BlueWest.Data public partial class CurrencyUpdate { + public int Num { get; set; } + // ISO 4217 Code [MaxLength(3)] public string Code { get; set; } diff --git a/BlueWest.Data.Capital/Industry/Industry.cs b/BlueWest.Data.Capital/Industry/Industry.cs new file mode 100644 index 0000000..90a441a --- /dev/null +++ b/BlueWest.Data.Capital/Industry/Industry.cs @@ -0,0 +1,9 @@ +namespace BlueWest.Data +{ + public partial class Industry + { + public int Id { get; set; } + public string IndustryType { get; set; } + } +} + diff --git a/BlueWest.Data.Capital/Media/MediaSource.cs b/BlueWest.Data.Capital/Media/MediaSource.cs new file mode 100644 index 0000000..ba4480a --- /dev/null +++ b/BlueWest.Data.Capital/Media/MediaSource.cs @@ -0,0 +1,8 @@ +namespace BlueWest.Data.Media +{ + public class MediaSource + { + public MediaSourceType SourceType { get; set; } + } +} + diff --git a/BlueWest.Data.Capital/Media/MediaSourceType.cs b/BlueWest.Data.Capital/Media/MediaSourceType.cs new file mode 100644 index 0000000..47bf541 --- /dev/null +++ b/BlueWest.Data.Capital/Media/MediaSourceType.cs @@ -0,0 +1,8 @@ +namespace BlueWest.Data.Media +{ + public class MediaSourceType + { + public string SourceTypeName { get; set; } + } +} + diff --git a/BlueWest.Data.Capital/Media/Website.cs b/BlueWest.Data.Capital/Media/Website.cs new file mode 100644 index 0000000..5454c77 --- /dev/null +++ b/BlueWest.Data.Capital/Media/Website.cs @@ -0,0 +1,11 @@ +namespace BlueWest.Data.Media +{ + public class Website + { + public int Id { get; set; } + public string WebsiteDomain { get; set; } + public string IsHttps { get; set; } + public bool HasCloudflareLikeService { get; set; } + } +} + diff --git a/BlueWest.Data/Transaction/FinanceOp.cs b/BlueWest.Data.Capital/Transaction/FinanceOp.cs similarity index 100% rename from BlueWest.Data/Transaction/FinanceOp.cs rename to BlueWest.Data.Capital/Transaction/FinanceOp.cs diff --git a/BlueWest.Data/Transaction/FinanceOpCreate.cs b/BlueWest.Data.Capital/Transaction/FinanceOpCreate.cs similarity index 100% rename from BlueWest.Data/Transaction/FinanceOpCreate.cs rename to BlueWest.Data.Capital/Transaction/FinanceOpCreate.cs diff --git a/BlueWest.Data/Transaction/FinanceOpRead.cs b/BlueWest.Data.Capital/Transaction/FinanceOpRead.cs similarity index 100% rename from BlueWest.Data/Transaction/FinanceOpRead.cs rename to BlueWest.Data.Capital/Transaction/FinanceOpRead.cs diff --git a/BlueWest.Data/Transaction/FinanceOpType.cs b/BlueWest.Data.Capital/Transaction/FinanceOpType.cs similarity index 100% rename from BlueWest.Data/Transaction/FinanceOpType.cs rename to BlueWest.Data.Capital/Transaction/FinanceOpType.cs diff --git a/BlueWest.Data/Transaction/MathOperation.cs b/BlueWest.Data.Capital/Transaction/MathOperation.cs similarity index 100% rename from BlueWest.Data/Transaction/MathOperation.cs rename to BlueWest.Data.Capital/Transaction/MathOperation.cs diff --git a/BlueWest.Data/Transaction/TransactionAmount.cs b/BlueWest.Data.Capital/Transaction/TransactionAmount.cs similarity index 100% rename from BlueWest.Data/Transaction/TransactionAmount.cs rename to BlueWest.Data.Capital/Transaction/TransactionAmount.cs diff --git a/BlueWest.Data/User/User.cs b/BlueWest.Data.Capital/User/User.cs similarity index 100% rename from BlueWest.Data/User/User.cs rename to BlueWest.Data.Capital/User/User.cs diff --git a/BlueWest.Data/User/UserCreate.cs b/BlueWest.Data.Capital/User/UserCreate.cs similarity index 100% rename from BlueWest.Data/User/UserCreate.cs rename to BlueWest.Data.Capital/User/UserCreate.cs diff --git a/BlueWest.Data/User/UserUnique.cs b/BlueWest.Data.Capital/User/UserUnique.cs similarity index 100% rename from BlueWest.Data/User/UserUnique.cs rename to BlueWest.Data.Capital/User/UserUnique.cs diff --git a/BlueWest.Data.Geography/BlueWest.Data.Geography.csproj b/BlueWest.Data.Geography/BlueWest.Data.Geography.csproj new file mode 100644 index 0000000..f3f4eda --- /dev/null +++ b/BlueWest.Data.Geography/BlueWest.Data.Geography.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/BlueWest.Data.Geography/Coordinate.cs b/BlueWest.Data.Geography/Coordinate.cs new file mode 100644 index 0000000..c18978e --- /dev/null +++ b/BlueWest.Data.Geography/Coordinate.cs @@ -0,0 +1,12 @@ +namespace BlueWest.Data.Geography +{ + public partial class Coordinate + { + public Guid Key { get; set; } + public double Latitude { get; set; } + public double Longitude { get; set; } + public Country Country { get; set; } + public TimeSpan CreatedTime { get; set; } + } +} + diff --git a/BlueWest.Frontend b/BlueWest.Frontend index 8f656cb..75205ac 160000 --- a/BlueWest.Frontend +++ b/BlueWest.Frontend @@ -1 +1 @@ -Subproject commit 8f656cbcc1c5782b1c5983600568704b6244b1ef +Subproject commit 75205acb359d624f2bdd9cb32474aca993fb77f1 diff --git a/BlueWest.sln b/BlueWest.sln index 08b662a..043fa48 100644 --- a/BlueWest.sln +++ b/BlueWest.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.31911.196 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest", "BlueWest\BlueWest.csproj", "{293E7852-8AFD-4EFB-8C2D-F1BBE68AEE78}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest.Data", "BlueWest.Data\BlueWest.Data.csproj", "{E518C62D-768C-4885-9C9D-FD5761605B54}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest.Data.Capital", "BlueWest.Data.Capital\BlueWest.Data.Capital.csproj", "{E518C62D-768C-4885-9C9D-FD5761605B54}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest.Api", "BlueWest.Api\BlueWest.Api.csproj", "{6D3321B5-CF1A-4251-B28D-329EDA6DC278}" EndProject @@ -34,6 +34,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{552B9217-4 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlueWest.Api.Gateway", "BlueWest.Api.Gateway\BlueWest.Api.Gateway.csproj", "{A78343AF-77C6-48FD-A9C4-F8B7CBA56212}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlueWest.Data.Geography", "BlueWest.Data.Geography\BlueWest.Data.Geography.csproj", "{D5924A3F-0AA1-4AF4-AEDB-3B9F91E6531E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -72,6 +74,10 @@ Global {A78343AF-77C6-48FD-A9C4-F8B7CBA56212}.Debug|Any CPU.Build.0 = Debug|Any CPU {A78343AF-77C6-48FD-A9C4-F8B7CBA56212}.Release|Any CPU.ActiveCfg = Release|Any CPU {A78343AF-77C6-48FD-A9C4-F8B7CBA56212}.Release|Any CPU.Build.0 = Release|Any CPU + {D5924A3F-0AA1-4AF4-AEDB-3B9F91E6531E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D5924A3F-0AA1-4AF4-AEDB-3B9F91E6531E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D5924A3F-0AA1-4AF4-AEDB-3B9F91E6531E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D5924A3F-0AA1-4AF4-AEDB-3B9F91E6531E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlueWest/Core/System/BlueProgram.cs b/BlueWest/Core/System/BlueProgram.cs index 5787df1..4300171 100644 --- a/BlueWest/Core/System/BlueProgram.cs +++ b/BlueWest/Core/System/BlueProgram.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using BlueWest.Tools; -using BlueWest.Core.Threading; namespace BlueWest.Core @@ -18,7 +17,7 @@ namespace BlueWest.Core public void Run() { - new ThreadServer(EventManager); + _ = new ThreadServer(EventManager); BlueWestConsoleBanner(); } diff --git a/BlueWest/Core/System/ThreadServer.cs b/BlueWest/Core/System/ThreadServer.cs index 6af1048..d25b1a8 100644 --- a/BlueWest/Core/System/ThreadServer.cs +++ b/BlueWest/Core/System/ThreadServer.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Reflection; using System.Threading; using BlueWest.Core.ComponentSystem; -using BlueWest.Core.Threading; using BlueWest.Tools; namespace BlueWest.Core diff --git a/BlueWest/Core/Threading/Threads.cs b/BlueWest/Core/Threading/Threads.cs deleted file mode 100644 index 1b916ed..0000000 --- a/BlueWest/Core/Threading/Threads.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Threading; - -namespace BlueWest.Core.Threading -{ - public static class Threads - { - - - } -} \ No newline at end of file diff --git a/include/BlueWest.MapTo b/include/BlueWest.MapTo index f7963d2..aa5b01c 160000 --- a/include/BlueWest.MapTo +++ b/include/BlueWest.MapTo @@ -1 +1 @@ -Subproject commit f7963d2d7e32a45bc7da61e31b07c55ca4829fb4 +Subproject commit aa5b01cdc42a00e873f126049a9c111b1d5220fa