diff --git a/.gitmodules b/.gitmodules
index 868039c..7dd25db 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,5 +1,5 @@
-[submodule "include/MapTo"]
- path = include/MapTo
+[submodule "include/BlueWest.MapTo"]
+ path = include/BlueWest.MapTo
url = git@git.codeliturgy.com:CodeLiturgy/MapTo.git
[submodule "include/Math-Expression-Evaluator"]
path = include/Math-Expression-Evaluator
diff --git a/BlueWest.Api/Controllers/CountriesController.cs b/BlueWest.Api/Controllers/CountriesController.cs
index cb5f64b..57a9a81 100644
--- a/BlueWest.Api/Controllers/CountriesController.cs
+++ b/BlueWest.Api/Controllers/CountriesController.cs
@@ -4,10 +4,11 @@ using BlueWest.WebApi.MySQL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
-namespace BlueWest.WebApi.Controllers;
+namespace BlueWest.WebApi.Controllers
+{
[ApiController]
[Route("[controller]")]
-public class ContriesController : ControllerBase
+public class CountriesController : ControllerBase
{
private readonly CountriesDbContext _dbContext;
@@ -15,7 +16,7 @@ public class ContriesController : ControllerBase
/// Controller responsible for handling country data in the Country table
///
///
- public ContriesController(CountriesDbContext dbContext)
+ public CountriesController(CountriesDbContext dbContext)
{
_dbContext = dbContext;
}
@@ -81,7 +82,7 @@ public class ContriesController : ControllerBase
///
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
- [HttpGet("")]
+ [HttpGet]
public ActionResult GetCountries()
{
var array = _dbContext.Countries;
@@ -115,4 +116,5 @@ public class ContriesController : ControllerBase
}
-}
\ No newline at end of file
+}
+}
diff --git a/BlueWest.Api/Controllers/CurrenciesController.cs b/BlueWest.Api/Controllers/CurrenciesController.cs
index 979ef0d..661a09a 100644
--- a/BlueWest.Api/Controllers/CurrenciesController.cs
+++ b/BlueWest.Api/Controllers/CurrenciesController.cs
@@ -5,59 +5,62 @@ using BlueWest.WebApi.MySQL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
-namespace BlueWest.WebApi.Controllers;
-
-public class CurrencyController : ControllerBase
+namespace BlueWest.WebApi.Controllers
{
- private readonly CountriesDbContext _dbContext;
-
- public CurrencyController(CountriesDbContext dbContext)
+ [ApiController]
+ [Route("[controller]")]
+ public class CurrenciesController : ControllerBase
{
- _dbContext = dbContext;
- }
+ private readonly CountriesDbContext _dbContext;
-
- [ProducesResponseType(StatusCodes.Status201Created)]
- [HttpPost]
- public ActionResult AddCurrency(Currency currency)
- {
- _dbContext.Currencies.Add(currency);
- _dbContext.SaveChanges();
- return CreatedAtRoute(nameof(GetCurrencyById), new {CurrencyId = currency.Code}, currency);
- }
-
- [ProducesResponseType(StatusCodes.Status200OK)]
- [ProducesResponseType(StatusCodes.Status400BadRequest)]
- [HttpPut("countries/{currencyNumber}")]
- public ActionResult UpdateCurrency(int currencyNumber, CurrencyUpdate currencyToUpdate)
- {
-
- var currency = _dbContext.Currencies.FirstOrDefault(x => x.Num ==currencyNumber);
-
- if (currency != null)
+ public CurrenciesController(CountriesDbContext dbContext)
{
- var updatedCurrency = new Currency(currencyToUpdate, currencyNumber, new List());
- _dbContext.Update(updatedCurrency);
+ _dbContext = dbContext;
+ }
+
+
+ [ProducesResponseType(StatusCodes.Status201Created)]
+ [HttpPost]
+ public ActionResult AddCurrency(CurrencyCreate currency)
+ {
+ var newCurrency = new Currency();
+ _dbContext.Currencies.Add(newCurrency);
_dbContext.SaveChanges();
- return Ok(updatedCurrency);
+ return CreatedAtRoute(nameof(GetCurrencyById), new {CurrencyId = currency.Code}, currency);
}
-
- return new NotFoundResult();
- }
-
- [ProducesResponseType(StatusCodes.Status200OK)]
- [ProducesResponseType(StatusCodes.Status404NotFound)]
- [HttpGet("countries/{CurrencyId}", Name = nameof(GetCurrencyById))]
- public ActionResult GetCurrencyById(int CurrencyId)
- {
- var array = _dbContext.Countries.FirstOrDefault(x => x.Code == CurrencyId);
-
- if (array != null)
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status400BadRequest)]
+ [HttpPut("{currencyNumber}")]
+ public ActionResult UpdateCurrency(int currencyNumber, CurrencyUpdate currencyToUpdate)
{
- return Ok(array);
+ var currency = _dbContext.Currencies.FirstOrDefault(x => x.Num == currencyNumber);
+
+ if (currency != null)
+ {
+ var updatedCurrency = new Currency(currencyToUpdate, currencyNumber, new List());
+ _dbContext.Update(updatedCurrency);
+ _dbContext.SaveChanges();
+ return Ok(updatedCurrency);
+ }
+
+ return new NotFoundResult();
+ }
+
+
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(StatusCodes.Status404NotFound)]
+ [HttpGet("{currencyId}", Name = nameof(GetCurrencyById))]
+ public ActionResult GetCurrencyById(int currencyId)
+ {
+ var array = _dbContext.Countries.FirstOrDefault(x => x.Code == currencyId);
+
+ if (array != null)
+ {
+ return Ok(array);
+ }
+
+ return new NotFoundResult();
}
-
- return new NotFoundResult();
}
}
\ No newline at end of file
diff --git a/BlueWest.Api/MySQL/CountriesDbContext.cs b/BlueWest.Api/MySQL/CountriesDbContext.cs
index 1507999..8a50dcb 100644
--- a/BlueWest.Api/MySQL/CountriesDbContext.cs
+++ b/BlueWest.Api/MySQL/CountriesDbContext.cs
@@ -52,8 +52,15 @@ public class CountriesDbContext : DbContext
{
builder.HasKey(x => x.Num);
});
-
+ modelBuilder.Entity()
+ .HasMany(ub => ub.Countries)
+ .WithMany(au => au.Currencies);
+
+ modelBuilder.Entity()
+ .HasMany(ub => ub.Currencies)
+ .WithMany(au => au.Countries);
+
}
}
\ No newline at end of file
diff --git a/BlueWest.Api/Program.cs b/BlueWest.Api/Program.cs
index 854a391..c4f1863 100644
--- a/BlueWest.Api/Program.cs
+++ b/BlueWest.Api/Program.cs
@@ -39,10 +39,11 @@ namespace BlueWest.WebApi
Host1 = CreateHostBuilder(args)
.UseContentRoot(Directory.GetCurrentDirectory())
.Build();
- Host1.RunAsync();
- System.Threading.Thread.Sleep(2500);
+ Host1.Run();
+ // Use RunASync
+ /*System.Threading.Thread.Sleep(2500);
_threadServer = new ThreadServer(EventManager);
- _threadServer.Init();
+ _threadServer.Init();*/
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
diff --git a/BlueWest.Data/BlueWest.Data.csproj b/BlueWest.Data/BlueWest.Data.csproj
index 6dab272..423d42d 100644
--- a/BlueWest.Data/BlueWest.Data.csproj
+++ b/BlueWest.Data/BlueWest.Data.csproj
@@ -8,9 +8,9 @@
-
+
-
+
diff --git a/BlueWest.Data/Finance/Currency/Country.cs b/BlueWest.Data/Finance/Currency/Country.cs
index fa5ab73..bbc44a3 100644
--- a/BlueWest.Data/Finance/Currency/Country.cs
+++ b/BlueWest.Data/Finance/Currency/Country.cs
@@ -1,20 +1,34 @@
-namespace BlueWest.Data;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using MapTo;
-public class Country
+namespace BlueWest.Data
{
- public int Code { get; set; } // Primary key
- public string StateName { get; set; }
- public string TLD { get; set; }
-
- public Country(int code, string stateName, string tld)
+
+ [MapFrom(typeof(CountryUpdate))]
+ public partial class Country
{
- Code = code;
- StateName = stateName;
- TLD = tld;
- }
+ // ISO 3166-1 numeric code
+ public int Code { get; set; } // Primary key
+ public string StateName { get; set; }
- public Country()
- {
+ [MaxLength(2)] public string Alpha2Code { get; set; }
+ public string TLD { get; set; }
+
+ public List Currencies { get; set; }
+
+ public Country(int code, string stateName, string tld, List currencies)
+ {
+ Code = code;
+ StateName = stateName;
+ TLD = tld;
+ Currencies = currencies;
+ }
+
+ public Country()
+ {
- }
-}
\ No newline at end of file
+ }
+ }
+}
+
diff --git a/BlueWest.Data/Finance/Currency/CountryCreate.cs b/BlueWest.Data/Finance/Currency/CountryCreate.cs
index 0e90e67..9bcb72b 100644
--- a/BlueWest.Data/Finance/Currency/CountryCreate.cs
+++ b/BlueWest.Data/Finance/Currency/CountryCreate.cs
@@ -1,6 +1,19 @@
-namespace BlueWest.Data;
+using System.ComponentModel.DataAnnotations;
+using MapTo;
-public class CountryCreate
+namespace BlueWest.Data
{
-
-}
\ No newline at end of file
+ [MapFrom( typeof(Country))]
+
+ public partial class CountryCreate
+ {
+ // ISO 3166-1 numeric code
+ public int Code { get; set; } // Primary key
+ public string StateName { get; set; }
+
+ [MaxLength(2)] public string Alpha2Code { get; set; }
+ public string TLD { get; set; }
+
+ }
+}
+
diff --git a/BlueWest.Data/Finance/Currency/CountryUpdate.cs b/BlueWest.Data/Finance/Currency/CountryUpdate.cs
index 5f79207..5b676d3 100644
--- a/BlueWest.Data/Finance/Currency/CountryUpdate.cs
+++ b/BlueWest.Data/Finance/Currency/CountryUpdate.cs
@@ -1,6 +1,16 @@
-namespace BlueWest.Data;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using MapTo;
-public class CountryUpdate
+namespace BlueWest.Data
{
-
-}
\ No newline at end of file
+ [MapFrom( typeof(Country))]
+
+ public partial class CountryUpdate
+ {
+ public string StateName { get; set; }
+ public string Alpha2Code { get; set; }
+ public string TLD { get; set; }
+ }
+}
+
diff --git a/BlueWest.Data/Finance/Currency/Currency.cs b/BlueWest.Data/Finance/Currency/Currency.cs
index 1d76115..55cbabf 100644
--- a/BlueWest.Data/Finance/Currency/Currency.cs
+++ b/BlueWest.Data/Finance/Currency/Currency.cs
@@ -1,8 +1,21 @@
-namespace BlueWest.Data;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using MapTo;
-public class Currency
+namespace BlueWest.Data
{
- public int Num { get; set; } // Primary key
- public string Code { get; set; }
- public Country Country { get; set; }
-}
\ No newline at end of file
+ [MapFrom(typeof(CurrencyUpdate))]
+
+ public partial class Currency
+ {
+ [MaxLength(3)]public int Num { get; set; } // Primary key
+ [MaxLength(3)]public string Code { get; set; }
+ public List Countries { get; set; }
+
+ public Currency()
+ {
+
+ }
+ }
+}
+
diff --git a/BlueWest.Data/Finance/Currency/CurrencyCreate.cs b/BlueWest.Data/Finance/Currency/CurrencyCreate.cs
new file mode 100644
index 0000000..4474d9d
--- /dev/null
+++ b/BlueWest.Data/Finance/Currency/CurrencyCreate.cs
@@ -0,0 +1,13 @@
+using System.ComponentModel.DataAnnotations;
+using MapTo;
+
+namespace BlueWest.Data
+{
+ [MapFrom(typeof(Currency))]
+ public partial class CurrencyCreate
+ {
+ [MaxLength(3)] public int Num { get; set; } // Primary key
+ [MaxLength(3)] public string Code { get; set; }
+ }
+}
+
diff --git a/BlueWest.Data/Finance/Currency/CurrencyUpdate.cs b/BlueWest.Data/Finance/Currency/CurrencyUpdate.cs
index 58bc1f7..39cd1f6 100644
--- a/BlueWest.Data/Finance/Currency/CurrencyUpdate.cs
+++ b/BlueWest.Data/Finance/Currency/CurrencyUpdate.cs
@@ -1,6 +1,15 @@
-namespace BlueWest.Data;
+using System.Collections.Generic;
+using MapTo;
-public class CurrencyUpdate
+namespace BlueWest.Data
{
-
-}
\ No newline at end of file
+ [MapFrom(typeof(Currency))]
+
+ public partial class CurrencyUpdate
+ {
+ // ISO 4217 Code
+ public string Code { get; set; }
+
+
+ }
+}
diff --git a/BlueWest.Data/Finance/Transaction/FinanceTransactionInsertDto.cs b/BlueWest.Data/Finance/Transaction/FinanceTransactionInsertDto.cs
index df11584..8675f4b 100644
--- a/BlueWest.Data/Finance/Transaction/FinanceTransactionInsertDto.cs
+++ b/BlueWest.Data/Finance/Transaction/FinanceTransactionInsertDto.cs
@@ -5,7 +5,7 @@ using MapTo;
namespace BlueWest.Data
{
- [MapFrom(typeof(FinanceTransaction))]
+ [MapFrom( typeof(FinanceTransaction))]
public partial class FinanceTransactionInsertDto
{
diff --git a/BlueWest.Data/User/User.cs b/BlueWest.Data/User/User.cs
index 9a014b0..48b3297 100644
--- a/BlueWest.Data/User/User.cs
+++ b/BlueWest.Data/User/User.cs
@@ -4,8 +4,8 @@ using MapTo;
namespace BlueWest.Data
{
- [UseUpdate]
- [MapFrom(typeof(UserUpdateDto))]
+ [MapFrom( typeof(UserUpdateDto))]
+ [UseUpdate]
public partial class User
{
public TimeSpan Id { get; } = TimeSpan.Zero;
diff --git a/BlueWest.Data/User/UserUpdateDto.cs b/BlueWest.Data/User/UserUpdateDto.cs
index 8ee0f1f..3b78a00 100644
--- a/BlueWest.Data/User/UserUpdateDto.cs
+++ b/BlueWest.Data/User/UserUpdateDto.cs
@@ -2,9 +2,10 @@
namespace BlueWest.Data
{
+ [UseUpdate]
[MapFrom(typeof(User))]
- public partial struct UserUpdateDto
+ public partial class UserUpdateDto
{
public string Name { get; set; }
}
diff --git a/BlueWest.sln b/BlueWest.sln
index e8e0e2d..5b2eede 100644
--- a/BlueWest.sln
+++ b/BlueWest.sln
@@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest.Data", "BlueWest.D
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest.Api", "BlueWest.Api\BlueWest.Api.csproj", "{6D3321B5-CF1A-4251-B28D-329EDA6DC278}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlueWest.MapTo", "include\MapTo\src\BlueWest.MapTo\BlueWest.MapTo.csproj", "{72B37540-A12F-466E-A58F-7BA2B247CB74}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlueWest.MapTo", "include\BlueWest.MapTo\src\BlueWest.MapTo\BlueWest.MapTo.csproj", "{72B37540-A12F-466E-A58F-7BA2B247CB74}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleExpressionEvaluator", "include\Math-Expression-Evaluator\SimpleExpressionEvaluator\SimpleExpressionEvaluator.csproj", "{30637214-EDE9-4C2E-BFD6-E4B163FA308B}"
EndProject
@@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "data", "data", "{19577B27-7
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleExpressionEvaluator.Tests", "include\Math-Expression-Evaluator\SimpleExpressionEvaluator.Tests\SimpleExpressionEvaluator.Tests.csproj", "{08F4484E-5FD8-4590-A8D7-12FBE47120C8}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlueWest.MapTo.Tests", "include\BlueWest.MapTo\test\BlueWest.MapTo.Tests\BlueWest.MapTo.Tests.csproj", "{5BE0A68C-B3ED-4FA1-B74B-3E857504899B}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -49,6 +51,10 @@ Global
{08F4484E-5FD8-4590-A8D7-12FBE47120C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08F4484E-5FD8-4590-A8D7-12FBE47120C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08F4484E-5FD8-4590-A8D7-12FBE47120C8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5BE0A68C-B3ED-4FA1-B74B-3E857504899B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5BE0A68C-B3ED-4FA1-B74B-3E857504899B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5BE0A68C-B3ED-4FA1-B74B-3E857504899B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5BE0A68C-B3ED-4FA1-B74B-3E857504899B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -61,5 +67,6 @@ Global
{72B37540-A12F-466E-A58F-7BA2B247CB74} = {A1606EEC-6AC5-4779-B140-F57089F5A05F}
{E518C62D-768C-4885-9C9D-FD5761605B54} = {19577B27-7EDF-4DBA-83D5-E047467BDFEF}
{08F4484E-5FD8-4590-A8D7-12FBE47120C8} = {A1606EEC-6AC5-4779-B140-F57089F5A05F}
+ {5BE0A68C-B3ED-4FA1-B74B-3E857504899B} = {A1606EEC-6AC5-4779-B140-F57089F5A05F}
EndGlobalSection
EndGlobal