Change data to conform with SG

This commit is contained in:
CodeLiturgy 2022-08-17 21:21:00 +01:00
parent ca1c937e97
commit 7ba619240c
16 changed files with 189 additions and 96 deletions

4
.gitmodules vendored
View File

@ -1,5 +1,5 @@
[submodule "include/MapTo"] [submodule "include/BlueWest.MapTo"]
path = include/MapTo path = include/BlueWest.MapTo
url = git@git.codeliturgy.com:CodeLiturgy/MapTo.git url = git@git.codeliturgy.com:CodeLiturgy/MapTo.git
[submodule "include/Math-Expression-Evaluator"] [submodule "include/Math-Expression-Evaluator"]
path = include/Math-Expression-Evaluator path = include/Math-Expression-Evaluator

View File

@ -4,10 +4,11 @@ using BlueWest.WebApi.MySQL;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace BlueWest.WebApi.Controllers; namespace BlueWest.WebApi.Controllers
{
[ApiController] [ApiController]
[Route("[controller]")] [Route("[controller]")]
public class ContriesController : ControllerBase public class CountriesController : ControllerBase
{ {
private readonly CountriesDbContext _dbContext; private readonly CountriesDbContext _dbContext;
@ -15,7 +16,7 @@ public class ContriesController : ControllerBase
/// Controller responsible for handling country data in the Country table /// Controller responsible for handling country data in the Country table
/// </summary> /// </summary>
/// <param name="dbContext"></param> /// <param name="dbContext"></param>
public ContriesController(CountriesDbContext dbContext) public CountriesController(CountriesDbContext dbContext)
{ {
_dbContext = dbContext; _dbContext = dbContext;
} }
@ -81,7 +82,7 @@ public class ContriesController : ControllerBase
/// <returns></returns> /// <returns></returns>
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpGet("")] [HttpGet]
public ActionResult GetCountries() public ActionResult GetCountries()
{ {
var array = _dbContext.Countries; var array = _dbContext.Countries;
@ -115,4 +116,5 @@ public class ContriesController : ControllerBase
} }
} }
}

View File

@ -5,59 +5,62 @@ using BlueWest.WebApi.MySQL;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace BlueWest.WebApi.Controllers; namespace BlueWest.WebApi.Controllers
public class CurrencyController : ControllerBase
{ {
private readonly CountriesDbContext _dbContext; [ApiController]
[Route("[controller]")]
public CurrencyController(CountriesDbContext dbContext) public class CurrenciesController : ControllerBase
{ {
_dbContext = dbContext; private readonly CountriesDbContext _dbContext;
}
public CurrenciesController(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)
{ {
var updatedCurrency = new Currency(currencyToUpdate, currencyNumber, new List<Country>()); _dbContext = dbContext;
_dbContext.Update(updatedCurrency); }
[ProducesResponseType(StatusCodes.Status201Created)]
[HttpPost]
public ActionResult AddCurrency(CurrencyCreate currency)
{
var newCurrency = new Currency();
_dbContext.Currencies.Add(newCurrency);
_dbContext.SaveChanges(); _dbContext.SaveChanges();
return Ok(updatedCurrency); return CreatedAtRoute(nameof(GetCurrencyById), new {CurrencyId = currency.Code}, currency);
} }
return new NotFoundResult();
}
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [HttpPut("{currencyNumber}")]
[HttpGet("countries/{CurrencyId}", Name = nameof(GetCurrencyById))] public ActionResult UpdateCurrency(int currencyNumber, CurrencyUpdate currencyToUpdate)
public ActionResult GetCurrencyById(int CurrencyId)
{
var array = _dbContext.Countries.FirstOrDefault(x => x.Code == CurrencyId);
if (array != null)
{ {
return Ok(array); var currency = _dbContext.Currencies.FirstOrDefault(x => x.Num == currencyNumber);
if (currency != null)
{
var updatedCurrency = new Currency(currencyToUpdate, currencyNumber, new List<Country>());
_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();
} }
} }

View File

@ -52,8 +52,15 @@ public class CountriesDbContext : DbContext
{ {
builder.HasKey(x => x.Num); builder.HasKey(x => x.Num);
}); });
modelBuilder.Entity<Currency>()
.HasMany(ub => ub.Countries)
.WithMany(au => au.Currencies);
modelBuilder.Entity<Country>()
.HasMany(ub => ub.Currencies)
.WithMany(au => au.Countries);
} }
} }

View File

@ -39,10 +39,11 @@ namespace BlueWest.WebApi
Host1 = CreateHostBuilder(args) Host1 = CreateHostBuilder(args)
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.Build(); .Build();
Host1.RunAsync(); Host1.Run();
System.Threading.Thread.Sleep(2500); // Use RunASync
/*System.Threading.Thread.Sleep(2500);
_threadServer = new ThreadServer(EventManager); _threadServer = new ThreadServer(EventManager);
_threadServer.Init(); _threadServer.Init();*/
} }
public static IHostBuilder CreateHostBuilder(string[] args) => public static IHostBuilder CreateHostBuilder(string[] args) =>

View File

@ -8,9 +8,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\include\MapTo\src\BlueWest.MapTo\BlueWest.MapTo.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> <ProjectReference Include="..\include\BlueWest.MapTo\src\BlueWest.MapTo\BlueWest.MapTo.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\include\Math-Expression-Evaluator\SimpleExpressionEvaluator\SimpleExpressionEvaluator.csproj" /> <ProjectReference Include="..\include\Math-Expression-Evaluator\SimpleExpressionEvaluator\SimpleExpressionEvaluator.csproj" />
</ItemGroup> </ItemGroup>
<Import Project="..\include\MapTo\src\BlueWest.MapTo\MapTo.props" /> <Import Project="..\include\BlueWest.MapTo\src\BlueWest.MapTo\MapTo.props" />
</Project> </Project>

View File

@ -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; } [MapFrom(typeof(CountryUpdate))]
public string TLD { get; set; } public partial class Country
public Country(int code, string stateName, string tld)
{ {
Code = code; // ISO 3166-1 numeric code
StateName = stateName; public int Code { get; set; } // Primary key
TLD = tld; public string StateName { get; set; }
}
public Country() [MaxLength(2)] public string Alpha2Code { get; set; }
{ public string TLD { get; set; }
public List<Currency> Currencies { get; set; }
public Country(int code, string stateName, string tld, List<Currency> currencies)
{
Code = code;
StateName = stateName;
TLD = tld;
Currencies = currencies;
}
public Country()
{
} }
} }
}

View File

@ -1,6 +1,19 @@
namespace BlueWest.Data; using System.ComponentModel.DataAnnotations;
using MapTo;
public class CountryCreate namespace BlueWest.Data
{ {
[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; }
}
}

View File

@ -1,6 +1,16 @@
namespace BlueWest.Data; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using MapTo;
public class CountryUpdate namespace BlueWest.Data
{ {
[MapFrom( typeof(Country))]
}
public partial class CountryUpdate
{
public string StateName { get; set; }
public string Alpha2Code { get; set; }
public string TLD { get; set; }
}
}

View File

@ -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 [MapFrom(typeof(CurrencyUpdate))]
public string Code { get; set; }
public Country Country { get; set; } public partial class Currency
} {
[MaxLength(3)]public int Num { get; set; } // Primary key
[MaxLength(3)]public string Code { get; set; }
public List<Country> Countries { get; set; }
public Currency()
{
}
}
}

View File

@ -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; }
}
}

View File

@ -1,6 +1,15 @@
namespace BlueWest.Data; using System.Collections.Generic;
using MapTo;
public class CurrencyUpdate namespace BlueWest.Data
{ {
[MapFrom(typeof(Currency))]
}
public partial class CurrencyUpdate
{
// ISO 4217 Code
public string Code { get; set; }
}
}

View File

@ -5,7 +5,7 @@ using MapTo;
namespace BlueWest.Data namespace BlueWest.Data
{ {
[MapFrom(typeof(FinanceTransaction))] [MapFrom( typeof(FinanceTransaction))]
public partial class FinanceTransactionInsertDto public partial class FinanceTransactionInsertDto
{ {

View File

@ -4,8 +4,8 @@ using MapTo;
namespace BlueWest.Data namespace BlueWest.Data
{ {
[UseUpdate] [MapFrom( typeof(UserUpdateDto))]
[MapFrom(typeof(UserUpdateDto))] [UseUpdate]
public partial class User public partial class User
{ {
public TimeSpan Id { get; } = TimeSpan.Zero; public TimeSpan Id { get; } = TimeSpan.Zero;

View File

@ -2,9 +2,10 @@
namespace BlueWest.Data namespace BlueWest.Data
{ {
[UseUpdate]
[MapFrom(typeof(User))] [MapFrom(typeof(User))]
public partial struct UserUpdateDto public partial class UserUpdateDto
{ {
public string Name { get; set; } public string Name { get; set; }
} }

View File

@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest.Data", "BlueWest.D
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest.Api", "BlueWest.Api\BlueWest.Api.csproj", "{6D3321B5-CF1A-4251-B28D-329EDA6DC278}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlueWest.Api", "BlueWest.Api\BlueWest.Api.csproj", "{6D3321B5-CF1A-4251-B28D-329EDA6DC278}"
EndProject 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 EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleExpressionEvaluator", "include\Math-Expression-Evaluator\SimpleExpressionEvaluator\SimpleExpressionEvaluator.csproj", "{30637214-EDE9-4C2E-BFD6-E4B163FA308B}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleExpressionEvaluator", "include\Math-Expression-Evaluator\SimpleExpressionEvaluator\SimpleExpressionEvaluator.csproj", "{30637214-EDE9-4C2E-BFD6-E4B163FA308B}"
EndProject EndProject
@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "data", "data", "{19577B27-7
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleExpressionEvaluator.Tests", "include\Math-Expression-Evaluator\SimpleExpressionEvaluator.Tests\SimpleExpressionEvaluator.Tests.csproj", "{08F4484E-5FD8-4590-A8D7-12FBE47120C8}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleExpressionEvaluator.Tests", "include\Math-Expression-Evaluator\SimpleExpressionEvaluator.Tests\SimpleExpressionEvaluator.Tests.csproj", "{08F4484E-5FD8-4590-A8D7-12FBE47120C8}"
EndProject 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 Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{08F4484E-5FD8-4590-A8D7-12FBE47120C8}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -61,5 +67,6 @@ Global
{72B37540-A12F-466E-A58F-7BA2B247CB74} = {A1606EEC-6AC5-4779-B140-F57089F5A05F} {72B37540-A12F-466E-A58F-7BA2B247CB74} = {A1606EEC-6AC5-4779-B140-F57089F5A05F}
{E518C62D-768C-4885-9C9D-FD5761605B54} = {19577B27-7EDF-4DBA-83D5-E047467BDFEF} {E518C62D-768C-4885-9C9D-FD5761605B54} = {19577B27-7EDF-4DBA-83D5-E047467BDFEF}
{08F4484E-5FD8-4590-A8D7-12FBE47120C8} = {A1606EEC-6AC5-4779-B140-F57089F5A05F} {08F4484E-5FD8-4590-A8D7-12FBE47120C8} = {A1606EEC-6AC5-4779-B140-F57089F5A05F}
{5BE0A68C-B3ED-4FA1-B74B-3E857504899B} = {A1606EEC-6AC5-4779-B140-F57089F5A05F}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal