Change data to conform with SG
This commit is contained in:
parent
ca1c937e97
commit
7ba619240c
|
@ -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
|
||||
|
|
|
@ -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
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
public ContriesController(CountriesDbContext dbContext)
|
||||
public CountriesController(CountriesDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
@ -81,7 +82,7 @@ public class ContriesController : ControllerBase
|
|||
/// <returns></returns>
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[HttpGet("")]
|
||||
[HttpGet]
|
||||
public ActionResult GetCountries()
|
||||
{
|
||||
var array = _dbContext.Countries;
|
||||
|
@ -115,4 +116,5 @@ public class ContriesController : ControllerBase
|
|||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Country>());
|
||||
_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<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();
|
||||
}
|
||||
}
|
|
@ -52,8 +52,15 @@ public class CountriesDbContext : DbContext
|
|||
{
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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) =>
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\include\MapTo\src\BlueWest.MapTo\MapTo.props" />
|
||||
<Import Project="..\include\BlueWest.MapTo\src\BlueWest.MapTo\MapTo.props" />
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -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<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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
[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<Country> Countries { get; set; }
|
||||
|
||||
public Currency()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
|
@ -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; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ using MapTo;
|
|||
|
||||
namespace BlueWest.Data
|
||||
{
|
||||
[MapFrom(typeof(FinanceTransaction))]
|
||||
[MapFrom( typeof(FinanceTransaction))]
|
||||
|
||||
public partial class FinanceTransactionInsertDto
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
namespace BlueWest.Data
|
||||
{
|
||||
[UseUpdate]
|
||||
[MapFrom(typeof(User))]
|
||||
|
||||
public partial struct UserUpdateDto
|
||||
public partial class UserUpdateDto
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue