Added style guidance and performed enforcement
This commit is contained in:
@ -21,7 +21,7 @@ namespace IO.Swagger.Attributes
|
||||
// Per https://blog.markvincze.com/how-to-validate-action-parameters-with-dataannotation-attributes/
|
||||
if (context.ActionDescriptor is ControllerActionDescriptor descriptor)
|
||||
{
|
||||
foreach (var parameter in descriptor.MethodInfo.GetParameters())
|
||||
foreach (ParameterInfo parameter in descriptor.MethodInfo.GetParameters())
|
||||
{
|
||||
object args = null;
|
||||
if (context.ActionArguments.ContainsKey(parameter.Name))
|
||||
@ -41,13 +41,13 @@ namespace IO.Swagger.Attributes
|
||||
|
||||
private static void ValidateAttributes(ParameterInfo parameter, object args, ModelStateDictionary modelState)
|
||||
{
|
||||
foreach (var attributeData in parameter.CustomAttributes)
|
||||
foreach (CustomAttributeData attributeData in parameter.CustomAttributes)
|
||||
{
|
||||
var attributeInstance = parameter.GetCustomAttribute(attributeData.AttributeType);
|
||||
System.Attribute attributeInstance = parameter.GetCustomAttribute(attributeData.AttributeType);
|
||||
|
||||
if (attributeInstance is ValidationAttribute validationAttribute)
|
||||
{
|
||||
var isValid = validationAttribute.IsValid(args);
|
||||
bool isValid = validationAttribute.IsValid(args);
|
||||
if (!isValid)
|
||||
{
|
||||
modelState.AddModelError(parameter.Name, validationAttribute.FormatErrorMessage(parameter.Name));
|
||||
|
||||
@ -62,10 +62,10 @@ namespace IO.Swagger.Controllers
|
||||
[ProducesResponseType(typeof(UserDto), 200)]
|
||||
public virtual async Task<IActionResult> GetUserDetails()
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
string userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
if (!int.TryParse(userIdString, out int userId))
|
||||
return Unauthorized();
|
||||
var user = await repository.RetrieveUser(userId);
|
||||
Models.db.User user = await repository.RetrieveUser(userId);
|
||||
return Ok(mapper.Map<UserDto>(user));
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ namespace IO.Swagger.Controllers
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage)));
|
||||
var user = await repository.LoginUser(body);
|
||||
Models.db.User user = await repository.LoginUser(body);
|
||||
return user == null ? Unauthorized() : Ok(new TokenDto { Token = jwt.GenerateJwt(user.Id) });
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ namespace IO.Swagger.Controllers
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage)));
|
||||
|
||||
var user = await repository.RegisterUser(body);
|
||||
Models.db.User user = await repository.RegisterUser(body);
|
||||
return user == null ? StatusCode(409) : Ok(new TokenDto { Token = jwt.GenerateJwt(user.Id) });
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,14 +118,14 @@ namespace IO.Swagger.Controllers
|
||||
[ProducesResponseType(typeof(IEnumerable<string>), 400)]
|
||||
public virtual async Task<IActionResult> CreateCurrency([FromBody] CurrencyCreateBody body)
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
string userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
if (!int.TryParse(userIdString, out int userId))
|
||||
return Unauthorized();
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage)));
|
||||
|
||||
var createdCurr = await repo.CreateCurrency(body, userId);
|
||||
bool createdCurr = await repo.CreateCurrency(body, userId);
|
||||
return createdCurr ? StatusCode(201) : StatusCode(422);
|
||||
}
|
||||
|
||||
@ -145,13 +145,13 @@ namespace IO.Swagger.Controllers
|
||||
[ProducesResponseType(typeof(IEnumerable<string>), 400)]
|
||||
public virtual async Task<IActionResult> MintCurrency([FromBody] CurrencyMintBody body)
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
string userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
if (!int.TryParse(userIdString, out int userId))
|
||||
return Unauthorized();
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage)));
|
||||
|
||||
var minted = await repo.MintCurrency(body, userId);
|
||||
bool minted = await repo.MintCurrency(body, userId);
|
||||
return minted ? Ok() : StatusCode(409);
|
||||
}
|
||||
|
||||
@ -168,18 +168,19 @@ namespace IO.Swagger.Controllers
|
||||
[ProducesResponseType(typeof(IEnumerable<CurrencyInfoDto>), 200)]
|
||||
public virtual async Task<IActionResult> GetAllCurrencies()
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
string userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
if (!int.TryParse(userIdString, out int userId))
|
||||
return Unauthorized();
|
||||
|
||||
var rawCurrencies = await repo.GetAllCurrencies();
|
||||
var res = new List<CurrencyInfoDto>();
|
||||
foreach (var raw in rawCurrencies)
|
||||
List<Models.db.Currency> rawCurrencies = await repo.GetAllCurrencies();
|
||||
List<CurrencyInfoDto> res = new();
|
||||
foreach (Models.db.Currency raw in rawCurrencies)
|
||||
{
|
||||
var c = mapper.Map<CurrencyInfoDto>(raw);
|
||||
CurrencyInfoDto c = mapper.Map<CurrencyInfoDto>(raw);
|
||||
c.IsOwner = raw.UserId == userId;
|
||||
res.Add(c);
|
||||
}
|
||||
|
||||
return Ok(res);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,8 +49,6 @@ namespace IO.Swagger.Controllers
|
||||
this.mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get user's wallet balances
|
||||
/// </summary>
|
||||
@ -64,12 +62,12 @@ namespace IO.Swagger.Controllers
|
||||
[ProducesResponseType(typeof(IEnumerable<WalletBalanceDto>), 200)]
|
||||
public virtual async Task<IActionResult> GetUserBalances()
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
string userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
if (!int.TryParse(userIdString, out int userId))
|
||||
return Unauthorized();
|
||||
|
||||
var balances = await transactionRepository.GetBalancesForUser(userId);
|
||||
var res = balances.Select(t => new WalletBalanceDto
|
||||
List<Tuple<Models.db.Currency, float>> balances = await transactionRepository.GetBalancesForUser(userId);
|
||||
IEnumerable<WalletBalanceDto> res = balances.Select(t => new WalletBalanceDto
|
||||
{
|
||||
Currency = mapper.Map<CurrencyDto>(t.Item1),
|
||||
Balance = t.Item2
|
||||
@ -90,11 +88,11 @@ namespace IO.Swagger.Controllers
|
||||
[ProducesResponseType(typeof(IEnumerable<TransactionDto>), 200)]
|
||||
public virtual async Task<IActionResult> GetUserTransactions()
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
string userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
if (!int.TryParse(userIdString, out int userId))
|
||||
return Unauthorized();
|
||||
|
||||
var transactions = await transactionRepository.GetTransactionsForUser(userId);
|
||||
List<Models.db.Transaction> transactions = await transactionRepository.GetTransactionsForUser(userId);
|
||||
return Ok(transactions.Select(mapper.Map<TransactionDto>));
|
||||
}
|
||||
|
||||
@ -140,14 +138,14 @@ namespace IO.Swagger.Controllers
|
||||
[ProducesResponseType(typeof(TransactionReturnCode), 409)]
|
||||
public virtual async Task<IActionResult> TransferPhysicalCurrency([FromBody] WalletTransferPhysicalBody body)
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
string userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
if (!int.TryParse(userIdString, out int userId))
|
||||
return Unauthorized();
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage)));
|
||||
|
||||
var transactionResult = await transactionRepository.TransferPhysical(body, userId);
|
||||
return transactionResult == TransactionReturnCode.Success ? Ok() : StatusCode(409, (int)transactionResult);
|
||||
TransactionReturnCode transactionResult = await transactionRepository.TransferPhysical(body, userId);
|
||||
return transactionResult == TransactionReturnCode.Success ? Ok() : StatusCode(409, (int) transactionResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,16 +32,16 @@ namespace IO.Swagger.Filters
|
||||
/// <param name="context">FilterContext</param>
|
||||
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
|
||||
{
|
||||
swaggerDoc.Servers.Add(new OpenApiServer() { Url = this.BasePath });
|
||||
swaggerDoc.Servers.Add(new OpenApiServer() { Url = BasePath });
|
||||
|
||||
var pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(this.BasePath)).ToList();
|
||||
System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<string, OpenApiPathItem>> pathsToModify = swaggerDoc.Paths.Where(p => p.Key.StartsWith(BasePath)).ToList();
|
||||
|
||||
foreach (var path in pathsToModify)
|
||||
foreach (System.Collections.Generic.KeyValuePair<string, OpenApiPathItem> path in pathsToModify)
|
||||
{
|
||||
if (path.Key.StartsWith(this.BasePath))
|
||||
if (path.Key.StartsWith(BasePath))
|
||||
{
|
||||
string newKey = Regex.Replace(path.Key, $"^{this.BasePath}", string.Empty);
|
||||
swaggerDoc.Paths.Remove(path.Key);
|
||||
string newKey = Regex.Replace(path.Key, $"^{BasePath}", string.Empty);
|
||||
bool unused = swaggerDoc.Paths.Remove(path.Key);
|
||||
swaggerDoc.Paths.Add(newKey, path.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,29 +18,29 @@ namespace IO.Swagger.Filters
|
||||
/// <param name="context">OperationFilterContext</param>
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
var pars = context.ApiDescription.ParameterDescriptions;
|
||||
System.Collections.Generic.IList<Microsoft.AspNetCore.Mvc.ApiExplorer.ApiParameterDescription> pars = context.ApiDescription.ParameterDescriptions;
|
||||
|
||||
foreach (var par in pars)
|
||||
foreach (Microsoft.AspNetCore.Mvc.ApiExplorer.ApiParameterDescription par in pars)
|
||||
{
|
||||
var swaggerParam = operation.Parameters.SingleOrDefault(p => p.Name == par.Name);
|
||||
OpenApiParameter swaggerParam = operation.Parameters.SingleOrDefault(p => p.Name == par.Name);
|
||||
|
||||
var attributes = ((ControllerParameterDescriptor)par.ParameterDescriptor).ParameterInfo.CustomAttributes;
|
||||
System.Collections.Generic.IEnumerable<System.Reflection.CustomAttributeData> attributes = ((ControllerParameterDescriptor) par.ParameterDescriptor).ParameterInfo.CustomAttributes;
|
||||
|
||||
if (attributes != null && attributes.Count() > 0 && swaggerParam != null)
|
||||
if (attributes != null && attributes.Any() && swaggerParam != null)
|
||||
{
|
||||
// Required - [Required]
|
||||
var requiredAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RequiredAttribute));
|
||||
System.Reflection.CustomAttributeData requiredAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RequiredAttribute));
|
||||
if (requiredAttr != null)
|
||||
{
|
||||
swaggerParam.Required = true;
|
||||
}
|
||||
|
||||
// Regex Pattern [RegularExpression]
|
||||
var regexAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RegularExpressionAttribute));
|
||||
System.Reflection.CustomAttributeData regexAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RegularExpressionAttribute));
|
||||
if (regexAttr != null)
|
||||
{
|
||||
string regex = (string)regexAttr.ConstructorArguments[0].Value;
|
||||
if (swaggerParam is OpenApiParameter)
|
||||
string regex = (string) regexAttr.ConstructorArguments[0].Value;
|
||||
if (swaggerParam is not null)
|
||||
{
|
||||
swaggerParam.Schema.Pattern = regex;
|
||||
}
|
||||
@ -48,42 +48,43 @@ namespace IO.Swagger.Filters
|
||||
|
||||
// String Length [StringLength]
|
||||
int? minLenght = null, maxLength = null;
|
||||
var stringLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(StringLengthAttribute));
|
||||
System.Reflection.CustomAttributeData stringLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(StringLengthAttribute));
|
||||
if (stringLengthAttr != null)
|
||||
{
|
||||
if (stringLengthAttr.NamedArguments.Count == 1)
|
||||
{
|
||||
minLenght = (int)stringLengthAttr.NamedArguments.Single(p => p.MemberName == "MinimumLength").TypedValue.Value;
|
||||
minLenght = (int) stringLengthAttr.NamedArguments.Single(p => p.MemberName == "MinimumLength").TypedValue.Value;
|
||||
}
|
||||
maxLength = (int)stringLengthAttr.ConstructorArguments[0].Value;
|
||||
|
||||
maxLength = (int) stringLengthAttr.ConstructorArguments[0].Value;
|
||||
}
|
||||
|
||||
var minLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MinLengthAttribute));
|
||||
System.Reflection.CustomAttributeData minLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MinLengthAttribute));
|
||||
if (minLengthAttr != null)
|
||||
{
|
||||
minLenght = (int)minLengthAttr.ConstructorArguments[0].Value;
|
||||
minLenght = (int) minLengthAttr.ConstructorArguments[0].Value;
|
||||
}
|
||||
|
||||
var maxLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MaxLengthAttribute));
|
||||
System.Reflection.CustomAttributeData maxLengthAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(MaxLengthAttribute));
|
||||
if (maxLengthAttr != null)
|
||||
{
|
||||
maxLength = (int)maxLengthAttr.ConstructorArguments[0].Value;
|
||||
maxLength = (int) maxLengthAttr.ConstructorArguments[0].Value;
|
||||
}
|
||||
|
||||
if (swaggerParam is OpenApiParameter)
|
||||
if (swaggerParam is not null)
|
||||
{
|
||||
swaggerParam.Schema.MinLength = minLenght;
|
||||
swaggerParam.Schema.MaxLength = maxLength;
|
||||
}
|
||||
|
||||
// Range [Range]
|
||||
var rangeAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RangeAttribute));
|
||||
System.Reflection.CustomAttributeData rangeAttr = attributes.FirstOrDefault(p => p.AttributeType == typeof(RangeAttribute));
|
||||
if (rangeAttr != null)
|
||||
{
|
||||
int rangeMin = (int)rangeAttr.ConstructorArguments[0].Value;
|
||||
int rangeMax = (int)rangeAttr.ConstructorArguments[1].Value;
|
||||
int rangeMin = (int) rangeAttr.ConstructorArguments[0].Value;
|
||||
int rangeMax = (int) rangeAttr.ConstructorArguments[1].Value;
|
||||
|
||||
if (swaggerParam is OpenApiParameter)
|
||||
if (swaggerParam is not null)
|
||||
{
|
||||
swaggerParam.Schema.Minimum = rangeMin;
|
||||
swaggerParam.Schema.Maximum = rangeMax;
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace IO.Swagger.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -10,7 +8,7 @@ namespace IO.Swagger.Migrations
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
var unused = migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
@ -23,16 +21,13 @@ namespace IO.Swagger.Migrations
|
||||
PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Salt = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Users", x => x.Id);
|
||||
});
|
||||
constraints: table => table.PrimaryKey("PK_Users", x => x.Id));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.DropTableOperation> unused = migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace IO.Swagger.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -10,11 +8,11 @@ namespace IO.Swagger.Migrations
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.DropColumnOperation> unused2 = migrationBuilder.DropColumn(
|
||||
name: "Username",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.AlterOperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AlterColumnOperation> unused1 = migrationBuilder.AlterColumn<string>(
|
||||
name: "LastName",
|
||||
table: "Users",
|
||||
type: "nvarchar(32)",
|
||||
@ -24,7 +22,7 @@ namespace IO.Swagger.Migrations
|
||||
oldType: "nvarchar(max)",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.AlterOperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AlterColumnOperation> unused = migrationBuilder.AlterColumn<string>(
|
||||
name: "FirstName",
|
||||
table: "Users",
|
||||
type: "nvarchar(32)",
|
||||
@ -38,7 +36,7 @@ namespace IO.Swagger.Migrations
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.AlterOperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AlterColumnOperation> unused2 = migrationBuilder.AlterColumn<string>(
|
||||
name: "LastName",
|
||||
table: "Users",
|
||||
type: "nvarchar(max)",
|
||||
@ -48,7 +46,7 @@ namespace IO.Swagger.Migrations
|
||||
oldMaxLength: 32,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.AlterOperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AlterColumnOperation> unused1 = migrationBuilder.AlterColumn<string>(
|
||||
name: "FirstName",
|
||||
table: "Users",
|
||||
type: "nvarchar(max)",
|
||||
@ -58,7 +56,7 @@ namespace IO.Swagger.Migrations
|
||||
oldMaxLength: 32,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddColumnOperation> unused = migrationBuilder.AddColumn<string>(
|
||||
name: "Username",
|
||||
table: "Users",
|
||||
type: "nvarchar(max)",
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using System;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace IO.Swagger.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -11,7 +9,7 @@ namespace IO.Swagger.Migrations
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
var unused11 = migrationBuilder.CreateTable(
|
||||
name: "Currencies",
|
||||
columns: table => new
|
||||
{
|
||||
@ -23,15 +21,15 @@ namespace IO.Swagger.Migrations
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Currencies", x => x.CurrencyId);
|
||||
table.ForeignKey(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddPrimaryKeyOperation> unused10 = table.PrimaryKey("PK_Currencies", x => x.CurrencyId);
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation> unused9 = table.ForeignKey(
|
||||
name: "FK_Currencies_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
var unused8 = migrationBuilder.CreateTable(
|
||||
name: "Transactions",
|
||||
columns: table => new
|
||||
{
|
||||
@ -46,40 +44,40 @@ namespace IO.Swagger.Migrations
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Transactions", x => x.TransactionId);
|
||||
table.ForeignKey(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddPrimaryKeyOperation> unused7 = table.PrimaryKey("PK_Transactions", x => x.TransactionId);
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation> unused6 = table.ForeignKey(
|
||||
name: "FK_Transactions_Currencies_CurrencyId",
|
||||
column: x => x.CurrencyId,
|
||||
principalTable: "Currencies",
|
||||
principalColumn: "CurrencyId");
|
||||
table.ForeignKey(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation> unused5 = table.ForeignKey(
|
||||
name: "FK_Transactions_Users_FromUserId",
|
||||
column: x => x.FromUserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id");
|
||||
table.ForeignKey(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.AddForeignKeyOperation> unused4 = table.ForeignKey(
|
||||
name: "FK_Transactions_Users_ToUserId",
|
||||
column: x => x.ToUserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.CreateIndexOperation> unused3 = migrationBuilder.CreateIndex(
|
||||
name: "IX_Currencies_UserId",
|
||||
table: "Currencies",
|
||||
column: "UserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.CreateIndexOperation> unused2 = migrationBuilder.CreateIndex(
|
||||
name: "IX_Transactions_CurrencyId",
|
||||
table: "Transactions",
|
||||
column: "CurrencyId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.CreateIndexOperation> unused1 = migrationBuilder.CreateIndex(
|
||||
name: "IX_Transactions_FromUserId",
|
||||
table: "Transactions",
|
||||
column: "FromUserId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.CreateIndexOperation> unused = migrationBuilder.CreateIndex(
|
||||
name: "IX_Transactions_ToUserId",
|
||||
table: "Transactions",
|
||||
column: "ToUserId");
|
||||
@ -88,10 +86,10 @@ namespace IO.Swagger.Migrations
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.DropTableOperation> unused1 = migrationBuilder.DropTable(
|
||||
name: "Transactions");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
Microsoft.EntityFrameworkCore.Migrations.Operations.Builders.OperationBuilder<Microsoft.EntityFrameworkCore.Migrations.Operations.DropTableOperation> unused = migrationBuilder.DropTable(
|
||||
name: "Currencies");
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,11 +40,11 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class AuthLoginBody {\n");
|
||||
sb.Append(" Email: ").Append(Email).Append('\n');
|
||||
sb.Append(" Password: ").Append(Password).Append('\n');
|
||||
sb.Append("}\n");
|
||||
StringBuilder sb = new();
|
||||
StringBuilder unused3 = sb.Append("class AuthLoginBody {\n");
|
||||
StringBuilder unused2 = sb.Append(" Email: ").Append(Email).Append('\n');
|
||||
StringBuilder unused1 = sb.Append(" Password: ").Append(Password).Append('\n');
|
||||
StringBuilder unused = sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@ -64,9 +64,7 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is null) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
return obj.GetType() == GetType() && Equals((AuthLoginBody)obj);
|
||||
return obj is not null && (ReferenceEquals(this, obj) || (obj.GetType() == GetType() && Equals((AuthLoginBody) obj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -76,20 +74,18 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(AuthLoginBody other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
return
|
||||
(
|
||||
return other is not null
|
||||
&& (ReferenceEquals(this, other)
|
||||
|| ((
|
||||
Email == other.Email ||
|
||||
Email != null &&
|
||||
Email.Equals(other.Email)
|
||||
(Email != null &&
|
||||
Email.Equals(other.Email))
|
||||
) &&
|
||||
(
|
||||
Password == other.Password ||
|
||||
Password != null &&
|
||||
Password.Equals(other.Password)
|
||||
);
|
||||
(Password != null &&
|
||||
Password.Equals(other.Password))
|
||||
)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -100,12 +96,12 @@ namespace IO.Swagger.Models.RequestDto
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
var hashCode = 41;
|
||||
int hashCode = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
if (Email != null)
|
||||
hashCode = hashCode * 59 + Email.GetHashCode();
|
||||
hashCode = (hashCode * 59) + Email.GetHashCode();
|
||||
if (Password != null)
|
||||
hashCode = hashCode * 59 + Password.GetHashCode();
|
||||
hashCode = (hashCode * 59) + Password.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
@ -113,15 +109,9 @@ namespace IO.Swagger.Models.RequestDto
|
||||
#region Operators
|
||||
#pragma warning disable 1591
|
||||
|
||||
public static bool operator ==(AuthLoginBody left, AuthLoginBody right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
public static bool operator ==(AuthLoginBody left, AuthLoginBody right) => Equals(left, right);
|
||||
|
||||
public static bool operator !=(AuthLoginBody left, AuthLoginBody right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
public static bool operator !=(AuthLoginBody left, AuthLoginBody right) => !Equals(left, right);
|
||||
|
||||
#pragma warning restore 1591
|
||||
#endregion Operators
|
||||
|
||||
@ -63,13 +63,13 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class AuthRegisterBody {\n");
|
||||
sb.Append(" FirstName: ").Append(FirstName).Append("\n");
|
||||
sb.Append(" LastName: ").Append(LastName).Append("\n");
|
||||
sb.Append(" Email: ").Append(Email).Append("\n");
|
||||
sb.Append(" Password: ").Append(Password).Append("\n");
|
||||
sb.Append("}\n");
|
||||
StringBuilder sb = new();
|
||||
StringBuilder unused5 = sb.Append("class AuthRegisterBody {\n");
|
||||
StringBuilder unused4 = sb.Append(" FirstName: ").Append(FirstName).Append('\n');
|
||||
StringBuilder unused3 = sb.Append(" LastName: ").Append(LastName).Append('\n');
|
||||
StringBuilder unused2 = sb.Append(" Email: ").Append(Email).Append('\n');
|
||||
StringBuilder unused1 = sb.Append(" Password: ").Append(Password).Append('\n');
|
||||
StringBuilder unused = sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@ -89,9 +89,7 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
return obj.GetType() == GetType() && Equals((AuthRegisterBody)obj);
|
||||
return obj is not null && (ReferenceEquals(this, obj) || (obj.GetType() == GetType() && Equals((AuthRegisterBody) obj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -101,30 +99,27 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(AuthRegisterBody other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
return
|
||||
(
|
||||
FirstName == other.FirstName ||
|
||||
FirstName != null &&
|
||||
FirstName.Equals(other.FirstName)
|
||||
return other is not null
|
||||
&& (ReferenceEquals(this, other)
|
||||
|| ((FirstName == other.FirstName ||
|
||||
(FirstName != null &&
|
||||
FirstName.Equals(other.FirstName))
|
||||
) &&
|
||||
(
|
||||
LastName == other.LastName ||
|
||||
LastName != null &&
|
||||
LastName.Equals(other.LastName)
|
||||
(LastName != null &&
|
||||
LastName.Equals(other.LastName))
|
||||
) &&
|
||||
(
|
||||
Email == other.Email ||
|
||||
Email != null &&
|
||||
Email.Equals(other.Email)
|
||||
(Email != null &&
|
||||
Email.Equals(other.Email))
|
||||
) &&
|
||||
(
|
||||
Password == other.Password ||
|
||||
Password != null &&
|
||||
Password.Equals(other.Password)
|
||||
);
|
||||
(Password != null &&
|
||||
Password.Equals(other.Password))
|
||||
)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -135,16 +130,16 @@ namespace IO.Swagger.Models.RequestDto
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
var hashCode = 41;
|
||||
int hashCode = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
if (FirstName != null)
|
||||
hashCode = hashCode * 59 + FirstName.GetHashCode();
|
||||
hashCode = (hashCode * 59) + FirstName.GetHashCode();
|
||||
if (LastName != null)
|
||||
hashCode = hashCode * 59 + LastName.GetHashCode();
|
||||
hashCode = (hashCode * 59) + LastName.GetHashCode();
|
||||
if (Email != null)
|
||||
hashCode = hashCode * 59 + Email.GetHashCode();
|
||||
hashCode = (hashCode * 59) + Email.GetHashCode();
|
||||
if (Password != null)
|
||||
hashCode = hashCode * 59 + Password.GetHashCode();
|
||||
hashCode = (hashCode * 59) + Password.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
@ -152,15 +147,9 @@ namespace IO.Swagger.Models.RequestDto
|
||||
#region Operators
|
||||
#pragma warning disable 1591
|
||||
|
||||
public static bool operator ==(AuthRegisterBody left, AuthRegisterBody right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
public static bool operator ==(AuthRegisterBody left, AuthRegisterBody right) => Equals(left, right);
|
||||
|
||||
public static bool operator !=(AuthRegisterBody left, AuthRegisterBody right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
public static bool operator !=(AuthRegisterBody left, AuthRegisterBody right) => !Equals(left, right);
|
||||
|
||||
#pragma warning restore 1591
|
||||
#endregion Operators
|
||||
|
||||
@ -49,12 +49,12 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class CurrencyAddAssetBody {\n");
|
||||
sb.Append(" CollectionId: ").Append(CollectionId).Append("\n");
|
||||
sb.Append(" AssetName: ").Append(AssetName).Append("\n");
|
||||
sb.Append(" AssetLink: ").Append(AssetLink).Append("\n");
|
||||
sb.Append("}\n");
|
||||
StringBuilder sb = new();
|
||||
StringBuilder unused4 = sb.Append("class CurrencyAddAssetBody {\n");
|
||||
StringBuilder unused3 = sb.Append(" CollectionId: ").Append(CollectionId).Append('\n');
|
||||
StringBuilder unused2 = sb.Append(" AssetName: ").Append(AssetName).Append('\n');
|
||||
StringBuilder unused1 = sb.Append(" AssetLink: ").Append(AssetLink).Append('\n');
|
||||
StringBuilder unused = sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@ -74,9 +74,7 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
return obj.GetType() == GetType() && Equals((CurrencyAddAssetBody)obj);
|
||||
return obj is not null && (ReferenceEquals(this, obj) || (obj.GetType() == GetType() && Equals((CurrencyAddAssetBody) obj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -86,25 +84,23 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(CurrencyAddAssetBody other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
return
|
||||
(
|
||||
return other is not null
|
||||
&& (ReferenceEquals(this, other)
|
||||
|| ((
|
||||
CollectionId == other.CollectionId ||
|
||||
CollectionId != null &&
|
||||
CollectionId.Equals(other.CollectionId)
|
||||
(CollectionId != null &&
|
||||
CollectionId.Equals(other.CollectionId))
|
||||
) &&
|
||||
(
|
||||
AssetName == other.AssetName ||
|
||||
AssetName != null &&
|
||||
AssetName.Equals(other.AssetName)
|
||||
(AssetName != null &&
|
||||
AssetName.Equals(other.AssetName))
|
||||
) &&
|
||||
(
|
||||
AssetLink == other.AssetLink ||
|
||||
AssetLink != null &&
|
||||
AssetLink.Equals(other.AssetLink)
|
||||
);
|
||||
(AssetLink != null &&
|
||||
AssetLink.Equals(other.AssetLink))
|
||||
)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -115,14 +111,14 @@ namespace IO.Swagger.Models.RequestDto
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
var hashCode = 41;
|
||||
int hashCode = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
if (CollectionId != null)
|
||||
hashCode = hashCode * 59 + CollectionId.GetHashCode();
|
||||
hashCode = (hashCode * 59) + CollectionId.GetHashCode();
|
||||
if (AssetName != null)
|
||||
hashCode = hashCode * 59 + AssetName.GetHashCode();
|
||||
hashCode = (hashCode * 59) + AssetName.GetHashCode();
|
||||
if (AssetLink != null)
|
||||
hashCode = hashCode * 59 + AssetLink.GetHashCode();
|
||||
hashCode = (hashCode * 59) + AssetLink.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
@ -130,15 +126,9 @@ namespace IO.Swagger.Models.RequestDto
|
||||
#region Operators
|
||||
#pragma warning disable 1591
|
||||
|
||||
public static bool operator ==(CurrencyAddAssetBody left, CurrencyAddAssetBody right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
public static bool operator ==(CurrencyAddAssetBody left, CurrencyAddAssetBody right) => Equals(left, right);
|
||||
|
||||
public static bool operator !=(CurrencyAddAssetBody left, CurrencyAddAssetBody right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
public static bool operator !=(CurrencyAddAssetBody left, CurrencyAddAssetBody right) => !Equals(left, right);
|
||||
|
||||
#pragma warning restore 1591
|
||||
#endregion Operators
|
||||
|
||||
@ -43,11 +43,11 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class CurrencyCreateBody {\n");
|
||||
sb.Append(" Name: ").Append(Name).Append('\n');
|
||||
sb.Append(" Symbol: ").Append(Symbol).Append('\n');
|
||||
sb.Append("}\n");
|
||||
StringBuilder sb = new();
|
||||
StringBuilder unused3 = sb.Append("class CurrencyCreateBody {\n");
|
||||
StringBuilder unused2 = sb.Append(" Name: ").Append(Name).Append('\n');
|
||||
StringBuilder unused1 = sb.Append(" Symbol: ").Append(Symbol).Append('\n');
|
||||
StringBuilder unused = sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@ -67,9 +67,7 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is null) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
return obj.GetType() == GetType() && Equals((CurrencyCreateBody)obj);
|
||||
return obj is not null && (ReferenceEquals(this, obj) || (obj.GetType() == GetType() && Equals((CurrencyCreateBody) obj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -79,20 +77,18 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(CurrencyCreateBody other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
return
|
||||
(
|
||||
return other is not null
|
||||
&& (ReferenceEquals(this, other)
|
||||
|| ((
|
||||
Name == other.Name ||
|
||||
Name != null &&
|
||||
Name.Equals(other.Name)
|
||||
(Name != null &&
|
||||
Name.Equals(other.Name))
|
||||
) &&
|
||||
(
|
||||
Symbol == other.Symbol ||
|
||||
Symbol != null &&
|
||||
Symbol.Equals(other.Symbol)
|
||||
);
|
||||
(Symbol != null &&
|
||||
Symbol.Equals(other.Symbol))
|
||||
)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -103,12 +99,12 @@ namespace IO.Swagger.Models.RequestDto
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
var hashCode = 41;
|
||||
int hashCode = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
if (Name != null)
|
||||
hashCode = hashCode * 59 + Name.GetHashCode();
|
||||
hashCode = (hashCode * 59) + Name.GetHashCode();
|
||||
if (Symbol != null)
|
||||
hashCode = hashCode * 59 + Symbol.GetHashCode();
|
||||
hashCode = (hashCode * 59) + Symbol.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
@ -116,15 +112,9 @@ namespace IO.Swagger.Models.RequestDto
|
||||
#region Operators
|
||||
#pragma warning disable 1591
|
||||
|
||||
public static bool operator ==(CurrencyCreateBody left, CurrencyCreateBody right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
public static bool operator ==(CurrencyCreateBody left, CurrencyCreateBody right) => Equals(left, right);
|
||||
|
||||
public static bool operator !=(CurrencyCreateBody left, CurrencyCreateBody right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
public static bool operator !=(CurrencyCreateBody left, CurrencyCreateBody right) => !Equals(left, right);
|
||||
|
||||
#pragma warning restore 1591
|
||||
#endregion Operators
|
||||
|
||||
@ -33,10 +33,10 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class CurrencyCreateCollectionBody {\n");
|
||||
sb.Append(" CollectionName: ").Append(CollectionName).Append("\n");
|
||||
sb.Append("}\n");
|
||||
StringBuilder sb = new();
|
||||
StringBuilder unused2 = sb.Append("class CurrencyCreateCollectionBody {\n");
|
||||
StringBuilder unused1 = sb.Append(" CollectionName: ").Append(CollectionName).Append('\n');
|
||||
StringBuilder unused = sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@ -56,9 +56,7 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
return obj.GetType() == GetType() && Equals((CurrencyCreateCollectionBody)obj);
|
||||
return obj is not null && (ReferenceEquals(this, obj) || (obj.GetType() == GetType() && Equals((CurrencyCreateCollectionBody) obj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -68,15 +66,11 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(CurrencyCreateCollectionBody other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
return
|
||||
|
||||
CollectionName == other.CollectionName ||
|
||||
CollectionName != null &&
|
||||
CollectionName.Equals(other.CollectionName)
|
||||
;
|
||||
return other is not null
|
||||
&& (ReferenceEquals(this, other)
|
||||
|| CollectionName == other.CollectionName ||
|
||||
(CollectionName != null &&
|
||||
CollectionName.Equals(other.CollectionName)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -87,10 +81,10 @@ namespace IO.Swagger.Models.RequestDto
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
var hashCode = 41;
|
||||
int hashCode = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
if (CollectionName != null)
|
||||
hashCode = hashCode * 59 + CollectionName.GetHashCode();
|
||||
hashCode = (hashCode * 59) + CollectionName.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
@ -98,15 +92,9 @@ namespace IO.Swagger.Models.RequestDto
|
||||
#region Operators
|
||||
#pragma warning disable 1591
|
||||
|
||||
public static bool operator ==(CurrencyCreateCollectionBody left, CurrencyCreateCollectionBody right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
public static bool operator ==(CurrencyCreateCollectionBody left, CurrencyCreateCollectionBody right) => Equals(left, right);
|
||||
|
||||
public static bool operator !=(CurrencyCreateCollectionBody left, CurrencyCreateCollectionBody right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
public static bool operator !=(CurrencyCreateCollectionBody left, CurrencyCreateCollectionBody right) => !Equals(left, right);
|
||||
|
||||
#pragma warning restore 1591
|
||||
#endregion Operators
|
||||
|
||||
@ -43,11 +43,11 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class CurrencyMintBody {\n");
|
||||
sb.Append(" CurrencyId: ").Append(CurrencyId).Append('\n');
|
||||
sb.Append(" Amount: ").Append(Amount).Append('\n');
|
||||
sb.Append("}\n");
|
||||
StringBuilder sb = new();
|
||||
StringBuilder unused3 = sb.Append("class CurrencyMintBody {\n");
|
||||
StringBuilder unused2 = sb.Append(" CurrencyId: ").Append(CurrencyId).Append('\n');
|
||||
StringBuilder unused1 = sb.Append(" Amount: ").Append(Amount).Append('\n');
|
||||
StringBuilder unused = sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@ -67,9 +67,7 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is null) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
return obj.GetType() == GetType() && Equals((CurrencyMintBody)obj);
|
||||
return obj is not null && (ReferenceEquals(this, obj) || (obj.GetType() == GetType() && Equals((CurrencyMintBody) obj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -79,18 +77,16 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(CurrencyMintBody other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
return
|
||||
(
|
||||
return other is not null
|
||||
&& (ReferenceEquals(this, other)
|
||||
|| ((
|
||||
CurrencyId == other.CurrencyId ||
|
||||
CurrencyId.Equals(other.CurrencyId)
|
||||
) &&
|
||||
(
|
||||
Amount == other.Amount ||
|
||||
Amount.Equals(other.Amount)
|
||||
);
|
||||
)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -105,15 +101,9 @@ namespace IO.Swagger.Models.RequestDto
|
||||
#region Operators
|
||||
#pragma warning disable 1591
|
||||
|
||||
public static bool operator ==(CurrencyMintBody left, CurrencyMintBody right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
public static bool operator ==(CurrencyMintBody left, CurrencyMintBody right) => Equals(left, right);
|
||||
|
||||
public static bool operator !=(CurrencyMintBody left, CurrencyMintBody right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
public static bool operator !=(CurrencyMintBody left, CurrencyMintBody right) => !Equals(left, right);
|
||||
|
||||
#pragma warning restore 1591
|
||||
#endregion Operators
|
||||
|
||||
@ -40,11 +40,11 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class WalletTransferDigitalBody {\n");
|
||||
sb.Append(" Email: ").Append(Email).Append("\n");
|
||||
sb.Append(" AssetId: ").Append(AssetId).Append("\n");
|
||||
sb.Append("}\n");
|
||||
StringBuilder sb = new();
|
||||
StringBuilder unused3 = sb.Append("class WalletTransferDigitalBody {\n");
|
||||
StringBuilder unused2 = sb.Append(" Email: ").Append(Email).Append('\n');
|
||||
StringBuilder unused1 = sb.Append(" AssetId: ").Append(AssetId).Append('\n');
|
||||
StringBuilder unused = sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@ -64,9 +64,7 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
return obj.GetType() == GetType() && Equals((WalletTransferDigitalBody)obj);
|
||||
return obj is not null && (ReferenceEquals(this, obj) || (obj.GetType() == GetType() && Equals((WalletTransferDigitalBody) obj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -76,20 +74,18 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(WalletTransferDigitalBody other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
return
|
||||
(
|
||||
return other is not null
|
||||
&& (ReferenceEquals(this, other)
|
||||
|| ((
|
||||
Email == other.Email ||
|
||||
Email != null &&
|
||||
Email.Equals(other.Email)
|
||||
(Email != null &&
|
||||
Email.Equals(other.Email))
|
||||
) &&
|
||||
(
|
||||
AssetId == other.AssetId ||
|
||||
AssetId != null &&
|
||||
AssetId.Equals(other.AssetId)
|
||||
);
|
||||
(AssetId != null &&
|
||||
AssetId.Equals(other.AssetId))
|
||||
)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -100,12 +96,12 @@ namespace IO.Swagger.Models.RequestDto
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
var hashCode = 41;
|
||||
int hashCode = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
if (Email != null)
|
||||
hashCode = hashCode * 59 + Email.GetHashCode();
|
||||
hashCode = (hashCode * 59) + Email.GetHashCode();
|
||||
if (AssetId != null)
|
||||
hashCode = hashCode * 59 + AssetId.GetHashCode();
|
||||
hashCode = (hashCode * 59) + AssetId.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
@ -113,15 +109,9 @@ namespace IO.Swagger.Models.RequestDto
|
||||
#region Operators
|
||||
#pragma warning disable 1591
|
||||
|
||||
public static bool operator ==(WalletTransferDigitalBody left, WalletTransferDigitalBody right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
public static bool operator ==(WalletTransferDigitalBody left, WalletTransferDigitalBody right) => Equals(left, right);
|
||||
|
||||
public static bool operator !=(WalletTransferDigitalBody left, WalletTransferDigitalBody right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
public static bool operator !=(WalletTransferDigitalBody left, WalletTransferDigitalBody right) => !Equals(left, right);
|
||||
|
||||
#pragma warning restore 1591
|
||||
#endregion Operators
|
||||
|
||||
@ -59,12 +59,12 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class WalletTransferPhysicalBody {\n");
|
||||
sb.Append(" DestUserEmail: ").Append(DestUserEmail).Append('\n');
|
||||
sb.Append(" Amount: ").Append(Amount).Append('\n');
|
||||
sb.Append(" CurrencyId: ").Append(CurrencyId).Append('\n');
|
||||
sb.Append("}\n");
|
||||
StringBuilder sb = new();
|
||||
StringBuilder unused4 = sb.Append("class WalletTransferPhysicalBody {\n");
|
||||
StringBuilder unused3 = sb.Append(" DestUserEmail: ").Append(DestUserEmail).Append('\n');
|
||||
StringBuilder unused2 = sb.Append(" Amount: ").Append(Amount).Append('\n');
|
||||
StringBuilder unused1 = sb.Append(" CurrencyId: ").Append(CurrencyId).Append('\n');
|
||||
StringBuilder unused = sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@ -84,9 +84,7 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is null) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
return obj.GetType() == GetType() && Equals((WalletTransferPhysicalBody)obj);
|
||||
return obj is not null && (ReferenceEquals(this, obj) || (obj.GetType() == GetType() && Equals((WalletTransferPhysicalBody) obj)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -96,14 +94,12 @@ namespace IO.Swagger.Models.RequestDto
|
||||
/// <returns>Boolean</returns>
|
||||
public bool Equals(WalletTransferPhysicalBody other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
return
|
||||
(
|
||||
return other is not null
|
||||
&& (ReferenceEquals(this, other)
|
||||
|| ((
|
||||
DestUserEmail == other.DestUserEmail ||
|
||||
DestUserEmail != null &&
|
||||
DestUserEmail.Equals(other.DestUserEmail)
|
||||
(DestUserEmail != null &&
|
||||
DestUserEmail.Equals(other.DestUserEmail))
|
||||
) &&
|
||||
(
|
||||
Amount == other.Amount ||
|
||||
@ -112,7 +108,7 @@ namespace IO.Swagger.Models.RequestDto
|
||||
(
|
||||
CurrencyId == other.CurrencyId ||
|
||||
CurrencyId.Equals(other.CurrencyId)
|
||||
);
|
||||
)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -123,12 +119,12 @@ namespace IO.Swagger.Models.RequestDto
|
||||
{
|
||||
unchecked // Overflow is fine, just wrap
|
||||
{
|
||||
var hashCode = 41;
|
||||
int hashCode = 41;
|
||||
// Suitable nullity checks etc, of course :)
|
||||
if (DestUserEmail != null)
|
||||
hashCode = hashCode * 59 + DestUserEmail.GetHashCode();
|
||||
hashCode = hashCode * 59 + Amount.GetHashCode();
|
||||
hashCode = hashCode * 59 + CurrencyId.GetHashCode();
|
||||
hashCode = (hashCode * 59) + DestUserEmail.GetHashCode();
|
||||
hashCode = (hashCode * 59) + Amount.GetHashCode();
|
||||
hashCode = (hashCode * 59) + CurrencyId.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
@ -136,15 +132,9 @@ namespace IO.Swagger.Models.RequestDto
|
||||
#region Operators
|
||||
#pragma warning disable 1591
|
||||
|
||||
public static bool operator ==(WalletTransferPhysicalBody left, WalletTransferPhysicalBody right)
|
||||
{
|
||||
return Equals(left, right);
|
||||
}
|
||||
public static bool operator ==(WalletTransferPhysicalBody left, WalletTransferPhysicalBody right) => Equals(left, right);
|
||||
|
||||
public static bool operator !=(WalletTransferPhysicalBody left, WalletTransferPhysicalBody right)
|
||||
{
|
||||
return !Equals(left, right);
|
||||
}
|
||||
public static bool operator !=(WalletTransferPhysicalBody left, WalletTransferPhysicalBody right) => !Equals(left, right);
|
||||
|
||||
#pragma warning restore 1591
|
||||
#endregion Operators
|
||||
|
||||
@ -74,5 +74,4 @@ namespace IO.Swagger.Models.db
|
||||
/// </value>
|
||||
public ICollection<Transaction> TransactionsTo { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,8 +22,10 @@ namespace IO.Swagger
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns>IWebHostBuilder</returns>
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
|
||||
{
|
||||
return WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ namespace IO.Swagger.Repositories
|
||||
if (await context.Currencies.AnyAsync(c => c.Symbol == request.Symbol || c.Name.ToLower() == request.Name.ToLower()))
|
||||
return false;
|
||||
|
||||
await context.Currencies.AddAsync(new Currency
|
||||
Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<Currency> unused = await context.Currencies.AddAsync(new Currency
|
||||
{
|
||||
Name = request.Name,
|
||||
Symbol = request.Symbol,
|
||||
@ -53,11 +53,11 @@ namespace IO.Swagger.Repositories
|
||||
/// <inheritdoc/>
|
||||
public async Task<bool> MintCurrency(CurrencyMintBody request, int userId)
|
||||
{
|
||||
var existsAndIsOwner = await context.Currencies.AnyAsync(c => c.CurrencyId == request.CurrencyId && c.UserId == userId);
|
||||
bool existsAndIsOwner = await context.Currencies.AnyAsync(c => c.CurrencyId == request.CurrencyId && c.UserId == userId);
|
||||
if (!existsAndIsOwner)
|
||||
return false;
|
||||
|
||||
await context.Transactions.AddAsync(new Transaction
|
||||
Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<Transaction> unused = await context.Transactions.AddAsync(new Transaction
|
||||
{
|
||||
Amount = request.Amount,
|
||||
CurrencyId = request.CurrencyId,
|
||||
|
||||
@ -26,28 +26,29 @@ namespace IO.Swagger.Repositories
|
||||
this.context = context ?? throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<List<Transaction>> GetTransactionsForUser(int userId)
|
||||
{
|
||||
var transactions = await context.Transactions.Where(t => t.ToUserId == userId || t.FromUserId == userId)
|
||||
List<Transaction> transactions = await context.Transactions.Where(t => t.ToUserId == userId || t.FromUserId == userId)
|
||||
.Include(t => t.Currency)
|
||||
.Include(t => t.FromUser)
|
||||
.Include(t => t.ToUser)
|
||||
.OrderByDescending(t => t.TransactionTime)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var t in transactions)
|
||||
foreach (Transaction t in transactions)
|
||||
{
|
||||
if (t.ToUserId != t.FromUserId && t.FromUserId == userId)
|
||||
t.Amount *= -1;
|
||||
}
|
||||
|
||||
return transactions;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<List<Tuple<Currency, float>>> GetBalancesForUser(int userId)
|
||||
{
|
||||
var transactions = await context.Transactions.Where(t => t.ToUserId == userId || t.FromUserId == userId)
|
||||
List<Tuple<Currency, float>> transactions = await context.Transactions.Where(t => t.ToUserId == userId || t.FromUserId == userId)
|
||||
.Include(t => t.Currency)
|
||||
.GroupBy(t => t.Currency)
|
||||
.Select(g => Tuple.Create(
|
||||
@ -63,22 +64,20 @@ namespace IO.Swagger.Repositories
|
||||
return transactions;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<TransactionReturnCode> TransferPhysical(WalletTransferPhysicalBody request, int fromUserId)
|
||||
{
|
||||
var trimmedDest = request.DestUserEmail.Trim().ToLower();
|
||||
var destUser = await context.Users.FirstOrDefaultAsync(u => u.Email == trimmedDest);
|
||||
string trimmedDest = request.DestUserEmail.Trim().ToLower();
|
||||
User destUser = await context.Users.FirstOrDefaultAsync(u => u.Email == trimmedDest);
|
||||
if (destUser == null)
|
||||
return TransactionReturnCode.UnknownDestinationUser;
|
||||
|
||||
var balances = await GetBalancesForUser(fromUserId);
|
||||
var balance = balances.FirstOrDefault(b => b.Item1.CurrencyId == request.CurrencyId);
|
||||
List<Tuple<Currency, float>> balances = await GetBalancesForUser(fromUserId);
|
||||
Tuple<Currency, float> balance = balances.FirstOrDefault(b => b.Item1.CurrencyId == request.CurrencyId);
|
||||
if (balance == null || balance.Item2 < request.Amount)
|
||||
return TransactionReturnCode.InsufficientFunds;
|
||||
|
||||
|
||||
await context.Transactions.AddAsync(new Transaction
|
||||
Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<Transaction> unused = await context.Transactions.AddAsync(new Transaction
|
||||
{
|
||||
Amount = request.Amount,
|
||||
CurrencyId = request.CurrencyId,
|
||||
@ -88,6 +87,5 @@ namespace IO.Swagger.Repositories
|
||||
});
|
||||
return await context.SaveChangesAsync() > 0 ? TransactionReturnCode.Success : TransactionReturnCode.DbError;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ namespace IO.Swagger.Repositories
|
||||
string hashedPassword = Convert.ToBase64String(hashedBytes);
|
||||
|
||||
// Create and insert the user
|
||||
var newUser = new User
|
||||
User newUser = new()
|
||||
{
|
||||
PasswordHash = hashedPassword,
|
||||
Salt = salt,
|
||||
@ -53,8 +53,8 @@ namespace IO.Swagger.Repositories
|
||||
LastName = request.LastName
|
||||
};
|
||||
|
||||
await bankDbContext.Users.AddAsync(newUser);
|
||||
await bankDbContext.SaveChangesAsync();
|
||||
Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<User> unused1 = await bankDbContext.Users.AddAsync(newUser);
|
||||
int unused = await bankDbContext.SaveChangesAsync();
|
||||
return newUser;
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ namespace IO.Swagger.Repositories
|
||||
public async Task<User> LoginUser(AuthLoginBody request)
|
||||
{
|
||||
request.Email = request.Email.ToLower();
|
||||
var user = await bankDbContext.Users.FirstOrDefaultAsync(u => u.Email.Equals(request.Email));
|
||||
User user = await bankDbContext.Users.FirstOrDefaultAsync(u => u.Email.Equals(request.Email));
|
||||
if (user == null)
|
||||
return null;
|
||||
|
||||
@ -72,9 +72,7 @@ namespace IO.Swagger.Repositories
|
||||
byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes(saltedPassword);
|
||||
byte[] hashedBytes = SHA256.HashData(passwordBytes);
|
||||
string hashedPassword = Convert.ToBase64String(hashedBytes);
|
||||
if (hashedPassword != user.PasswordHash)
|
||||
return null;
|
||||
return user;
|
||||
return hashedPassword != user.PasswordHash ? null : user;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@ -44,12 +44,13 @@ namespace IO.Swagger.Security
|
||||
{
|
||||
return AuthenticateResult.Fail("Missing Authorization Header");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]);
|
||||
AuthenticationHeaderValue authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]);
|
||||
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var validationParameters = new TokenValidationParameters
|
||||
JwtSecurityTokenHandler tokenHandler = new();
|
||||
TokenValidationParameters validationParameters = new()
|
||||
{
|
||||
ValidateIssuerSigningKey = true,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(secretBytes),
|
||||
@ -59,15 +60,15 @@ namespace IO.Swagger.Security
|
||||
|
||||
try
|
||||
{
|
||||
var claimsPrincipal = tokenHandler.ValidateToken(authHeader.Parameter, validationParameters, out _);
|
||||
var userIdClaim = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier);
|
||||
ClaimsPrincipal claimsPrincipal = tokenHandler.ValidateToken(authHeader.Parameter, validationParameters, out _);
|
||||
Claim userIdClaim = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier);
|
||||
|
||||
if (userIdClaim != null && int.TryParse(userIdClaim.Value, out int userId))
|
||||
{
|
||||
var claims = new[] { new Claim(ClaimTypes.NameIdentifier, userId.ToString()) };
|
||||
var identity = new ClaimsIdentity(claims, SchemeName);
|
||||
var principal = new ClaimsPrincipal(identity);
|
||||
var ticket = new AuthenticationTicket(principal, Scheme.Name);
|
||||
Claim[] claims = new[] { new Claim(ClaimTypes.NameIdentifier, userId.ToString()) };
|
||||
ClaimsIdentity identity = new(claims, SchemeName);
|
||||
ClaimsPrincipal principal = new(identity);
|
||||
AuthenticationTicket ticket = new(principal, Scheme.Name);
|
||||
|
||||
return AuthenticateResult.Success(ticket);
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ namespace IO.Swagger.Services
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
// currency -> user FK
|
||||
modelBuilder.Entity<User>()
|
||||
Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceCollectionBuilder<User, Currency> unused3 = modelBuilder.Entity<User>()
|
||||
.HasMany(u => u.Currencies)
|
||||
.WithOne(c => c.User)
|
||||
.HasForeignKey(c => c.UserId)
|
||||
@ -50,21 +50,21 @@ namespace IO.Swagger.Services
|
||||
.OnDelete(DeleteBehavior.NoAction);
|
||||
|
||||
// transaction -> from user
|
||||
modelBuilder.Entity<User>()
|
||||
Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceCollectionBuilder<User, Transaction> unused2 = modelBuilder.Entity<User>()
|
||||
.HasMany(u => u.TransactionsFrom)
|
||||
.WithOne(t => t.FromUser)
|
||||
.HasForeignKey(t => t.FromUserId)
|
||||
.HasPrincipalKey(u => u.Id)
|
||||
.OnDelete(DeleteBehavior.NoAction);
|
||||
// transaction -> to user
|
||||
modelBuilder.Entity<User>()
|
||||
Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceCollectionBuilder<User, Transaction> unused1 = modelBuilder.Entity<User>()
|
||||
.HasMany(u => u.TransactionsTo)
|
||||
.WithOne(t => t.ToUser)
|
||||
.HasForeignKey(t => t.ToUserId)
|
||||
.HasPrincipalKey(u => u.Id)
|
||||
.OnDelete(DeleteBehavior.NoAction);
|
||||
// transaction -> currency
|
||||
modelBuilder.Entity<Transaction>()
|
||||
Microsoft.EntityFrameworkCore.Metadata.Builders.ReferenceCollectionBuilder<Currency, Transaction> unused = modelBuilder.Entity<Transaction>()
|
||||
.HasOne(t => t.Currency)
|
||||
.WithMany(c => c.Transactions)
|
||||
.HasForeignKey(t => t.CurrencyId)
|
||||
|
||||
@ -30,20 +30,20 @@ namespace IO.Swagger.Services
|
||||
/// <returns>A JWT that will expire in 1hr from time of issue enconding the user id supplied</returns>
|
||||
public string GenerateJwt(int userId)
|
||||
{
|
||||
var claims = new[]
|
||||
Claim[] claims = new[]
|
||||
{
|
||||
new Claim(ClaimTypes.NameIdentifier, userId.ToString())
|
||||
};
|
||||
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var tokenDescriptor = new SecurityTokenDescriptor
|
||||
JwtSecurityTokenHandler tokenHandler = new();
|
||||
SecurityTokenDescriptor tokenDescriptor = new()
|
||||
{
|
||||
Subject = new ClaimsIdentity(claims),
|
||||
Expires = DateTime.UtcNow.AddHours(1), // Token expiration time
|
||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(secretBytes), SecurityAlgorithms.HmacSha256Signature)
|
||||
};
|
||||
|
||||
var token = tokenHandler.CreateToken(tokenDescriptor);
|
||||
SecurityToken token = tokenHandler.CreateToken(tokenDescriptor);
|
||||
return tokenHandler.WriteToken(token);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,11 +16,11 @@ namespace IO.Swagger.Services
|
||||
/// </summary>
|
||||
public MapperProfile()
|
||||
{
|
||||
CreateMap<User, UserDto>();
|
||||
CreateMap<Currency, CurrencyDto>();
|
||||
CreateMap<Transaction, TransactionDto>();
|
||||
IMappingExpression<User, UserDto> unused3 = CreateMap<User, UserDto>();
|
||||
IMappingExpression<Currency, CurrencyDto> unused2 = CreateMap<Currency, CurrencyDto>();
|
||||
IMappingExpression<Transaction, TransactionDto> unused1 = CreateMap<Transaction, TransactionDto>();
|
||||
|
||||
CreateMap<Currency, CurrencyInfoDto>().ForMember(ci => ci.AmountInCirculation,
|
||||
IMappingExpression<Currency, CurrencyInfoDto> unused = CreateMap<Currency, CurrencyInfoDto>().ForMember(ci => ci.AmountInCirculation,
|
||||
mapper => mapper.MapFrom(c => c.Transactions.Where(t => t.ToUserId == t.FromUserId).Sum(t => t.Amount)))
|
||||
.ForMember(ci => ci.CurrencyOwner,
|
||||
mapper => mapper.MapFrom(c => c.User));
|
||||
|
||||
@ -16,10 +16,8 @@ using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
@ -35,17 +33,13 @@ namespace IO.Swagger
|
||||
{
|
||||
private readonly IWebHostEnvironment _hostingEnv;
|
||||
|
||||
private IConfiguration Configuration { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="env"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public Startup(IWebHostEnvironment env, IConfiguration configuration)
|
||||
public Startup(IWebHostEnvironment env)
|
||||
{
|
||||
_hostingEnv = env;
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -55,7 +49,7 @@ namespace IO.Swagger
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Add framework services.
|
||||
services
|
||||
IMvcBuilder unused11 = services
|
||||
.AddMvc(options =>
|
||||
{
|
||||
options.InputFormatters.RemoveType<Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonInputFormatter>();
|
||||
@ -68,11 +62,10 @@ namespace IO.Swagger
|
||||
})
|
||||
.AddXmlSerializerFormatters();
|
||||
|
||||
services.AddAuthentication(BearerAuthenticationHandler.SchemeName)
|
||||
AuthenticationBuilder unused10 = services.AddAuthentication(BearerAuthenticationHandler.SchemeName)
|
||||
.AddScheme<AuthenticationSchemeOptions, BearerAuthenticationHandler>(BearerAuthenticationHandler.SchemeName, null);
|
||||
|
||||
|
||||
services
|
||||
IServiceCollection unused9 = services
|
||||
.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("1.0.0", new OpenApiInfo
|
||||
@ -122,23 +115,16 @@ namespace IO.Swagger
|
||||
});
|
||||
|
||||
// Auto Mapper Configurations
|
||||
var mapperConfig = new MapperConfiguration(mc =>
|
||||
{
|
||||
mc.AddProfile(new MapperProfile());
|
||||
});
|
||||
|
||||
MapperConfiguration mapperConfig = new(mc => mc.AddProfile(new MapperProfile()));
|
||||
|
||||
// CORS sucks
|
||||
services.AddCors(opt =>
|
||||
{
|
||||
opt.AddDefaultPolicy(po =>
|
||||
IServiceCollection unused8 = services.AddCors(opt => opt.AddDefaultPolicy(po =>
|
||||
{
|
||||
po.AllowAnyHeader()
|
||||
Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder unused7 = po.AllowAnyHeader()
|
||||
.WithMethods("GET", "POST")
|
||||
.SetIsOriginAllowedToAllowWildcardSubdomains();
|
||||
po.SetIsOriginAllowed((or) => or.Contains("localhost") || or.Contains("shrukanslab"));
|
||||
});
|
||||
});
|
||||
Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder unused6 = po.SetIsOriginAllowed((or) => or.Contains("localhost") || or.Contains("shrukanslab"));
|
||||
}));
|
||||
|
||||
//Datase connections
|
||||
string connectionString = Environment.GetEnvironmentVariable("DATABASE_CONNECTION_STRING");
|
||||
@ -149,13 +135,13 @@ namespace IO.Swagger
|
||||
}
|
||||
|
||||
// DI setup
|
||||
services.AddScoped<IUserRepository, UserRepository>();
|
||||
services.AddScoped<ICurrencyRepository, CurrencyRepository>();
|
||||
services.AddScoped<ITransactionRepository, TransactionRepository>();
|
||||
services.AddDbContext<BankDbContext>(x => x.UseSqlServer(connectionString: connectionString));
|
||||
services.AddSingleton<JwtService>();
|
||||
IServiceCollection unused5 = services.AddScoped<IUserRepository, UserRepository>();
|
||||
IServiceCollection unused4 = services.AddScoped<ICurrencyRepository, CurrencyRepository>();
|
||||
IServiceCollection unused3 = services.AddScoped<ITransactionRepository, TransactionRepository>();
|
||||
IServiceCollection unused2 = services.AddDbContext<BankDbContext>(x => x.UseSqlServer(connectionString: connectionString));
|
||||
IServiceCollection unused1 = services.AddSingleton<JwtService>();
|
||||
IMapper mapper = mapperConfig.CreateMapper();
|
||||
services.AddSingleton(mapper);
|
||||
IServiceCollection unused = services.AddSingleton(mapper);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -163,45 +149,36 @@ namespace IO.Swagger
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="env"></param>
|
||||
/// <param name="loggerFactory"></param>
|
||||
/// <param name="context"></param>
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, BankDbContext context)
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, BankDbContext context)
|
||||
{
|
||||
context.Database.Migrate();
|
||||
app.UseRouting();
|
||||
IApplicationBuilder unused8 = app.UseRouting();
|
||||
|
||||
app.UseCors();
|
||||
IApplicationBuilder unused7 = app.UseCors();
|
||||
|
||||
app.UseAuthorization();
|
||||
IApplicationBuilder unused6 = app.UseAuthorization();
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
IApplicationBuilder unused5 = app.UseSwagger();
|
||||
IApplicationBuilder unused4 = app.UseSwaggerUI(c =>
|
||||
//TODO: Either use the SwaggerGen generated Swagger contract (generated from C# classes)
|
||||
c.SwaggerEndpoint("/swagger/1.0.0/swagger.json", "T&J Central Bank API");
|
||||
|
||||
//TODO: Or alternatively use the original Swagger contract that's included in the static files
|
||||
// c.SwaggerEndpoint("/swagger-original.json", "T&J Central Bank API Original");
|
||||
});
|
||||
c.SwaggerEndpoint("/swagger/1.0.0/swagger.json", "T&J Central Bank API"));
|
||||
|
||||
//TODO: Use Https Redirection
|
||||
// app.UseHttpsRedirection();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
IApplicationBuilder unused3 = app.UseEndpoints(endpoints => endpoints.MapControllers());
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
IApplicationBuilder unused2 = app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO: Enable production exception handling (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/error-handling)
|
||||
app.UseExceptionHandler("/Error");
|
||||
IApplicationBuilder unused1 = app.UseExceptionHandler("/Error");
|
||||
|
||||
app.UseHsts();
|
||||
IApplicationBuilder unused = app.UseHsts();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user