Added style guidance and performed enforcement

This commit is contained in:
2023-08-19 21:24:01 -04:00
parent 49de8aa8d7
commit 1a25e62fa4
29 changed files with 535 additions and 417 deletions

230
.editorconfig Normal file
View File

@ -0,0 +1,230 @@
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true
# C# files
[*.cs]
#### Core EditorConfig Options ####
# Indentation and spacing
indent_size = 4
indent_style = space
tab_width = 4
# New line preferences
end_of_line = crlf
insert_final_newline = false
#### .NET Coding Conventions ####
# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = false
file_header_template = unset
# this. and Me. preferences
dotnet_style_qualification_for_event = false:error
dotnet_style_qualification_for_field = false:error
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_property = false:error
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:error
dotnet_style_predefined_type_for_member_access = true:error
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:error
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:error
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:error
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:error
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members
# Expression-level preferences
dotnet_style_coalesce_expression = true:error
dotnet_style_collection_initializer = true:error
dotnet_style_explicit_tuple_names = true:error
dotnet_style_namespace_match_folder = true
dotnet_style_null_propagation = true:error
dotnet_style_object_initializer = true:error
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_prefer_auto_properties = true:error
dotnet_style_prefer_compound_assignment = true:error
dotnet_style_prefer_conditional_expression_over_assignment = true:error
dotnet_style_prefer_conditional_expression_over_return = true:error
dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed
dotnet_style_prefer_inferred_anonymous_type_member_names = true:error
dotnet_style_prefer_inferred_tuple_names = true:error
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:error
dotnet_style_prefer_simplified_boolean_expressions = true:error
dotnet_style_prefer_simplified_interpolation = true
# Field preferences
dotnet_style_readonly_field = true:error
# Parameter preferences
dotnet_code_quality_unused_parameters = all:error
# Suppression preferences
dotnet_remove_unnecessary_suppression_exclusions = none
# New line preferences
dotnet_style_allow_multiple_blank_lines_experimental = false:error
dotnet_style_allow_statement_immediately_after_block_experimental = false:error
#### C# Coding Conventions ####
# var preferences
csharp_style_var_elsewhere = false:suggestion
csharp_style_var_for_built_in_types = false:error
csharp_style_var_when_type_is_apparent = false:error
# Expression-bodied members
csharp_style_expression_bodied_accessors = true:error
csharp_style_expression_bodied_constructors = false:error
csharp_style_expression_bodied_indexers = true:error
csharp_style_expression_bodied_lambdas = true:error
csharp_style_expression_bodied_local_functions = true:error
csharp_style_expression_bodied_methods = false:error
csharp_style_expression_bodied_operators = when_on_single_line:error
csharp_style_expression_bodied_properties = true:error
# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true:error
csharp_style_pattern_matching_over_is_with_cast_check = true:error
csharp_style_prefer_extended_property_pattern = true
csharp_style_prefer_not_pattern = true:error
csharp_style_prefer_pattern_matching = false:error
csharp_style_prefer_switch_expression = true:error
# Null-checking preferences
csharp_style_conditional_delegate_call = true:error
# Modifier preferences
csharp_prefer_static_local_function = true:error
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async
csharp_style_prefer_readonly_struct = true:error
csharp_style_prefer_readonly_struct_member = true
# Code-block preferences
csharp_prefer_braces = when_multiline:error
csharp_prefer_simple_using_statement = true:error
csharp_style_namespace_declarations = block_scoped:error
csharp_style_prefer_method_group_conversion = true:error
csharp_style_prefer_primary_constructors = true
csharp_style_prefer_top_level_statements = false:error
# Expression-level preferences
csharp_prefer_simple_default_expression = true:error
csharp_style_deconstructed_variable_declaration = true:error
csharp_style_implicit_object_creation_when_type_is_apparent = true:error
csharp_style_inlined_variable_declaration = true:error
csharp_style_prefer_index_operator = false:error
csharp_style_prefer_local_over_anonymous_function = true:error
csharp_style_prefer_null_check_over_type_check = true:error
csharp_style_prefer_range_operator = true:error
csharp_style_prefer_tuple_swap = true
csharp_style_prefer_utf8_string_literals = true
csharp_style_throw_expression = true:error
csharp_style_unused_value_assignment_preference = unused_local_variable:error
csharp_style_unused_value_expression_statement_preference = unused_local_variable:error
# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:error
# New line preferences
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false:error
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false:error
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false:error
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:error
csharp_style_allow_embedded_statements_on_same_line_experimental = false:error
#### C# Formatting Rules ####
# New line preferences
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true
# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true
# Space preferences
csharp_space_after_cast = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
#### Naming styles ####
# Naming rules
dotnet_naming_rule.interface_should_be_begins_with_i.severity = error
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
dotnet_naming_rule.types_should_be_pascal_case.severity = error
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = error
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
# Symbol specifications
dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
# Naming styles
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

View File

@ -5,6 +5,11 @@ VisualStudioVersion = 17.7.34003.232
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{DE0790AC-036E-402C-BB2D-6FF54543B851}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CA855B91-1761-4B48-B830-D9431F7CA6DF}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU

View File

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

View File

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

View File

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

View File

@ -49,8 +49,6 @@ namespace IO.Swagger.Controllers
this.mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
}
/// <summary>
/// Get user&#x27;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,13 +138,13 @@ 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);
TransactionReturnCode transactionResult = await transactionRepository.TransferPhysical(body, userId);
return transactionResult == TransactionReturnCode.Success ? Ok() : StatusCode(409, (int) transactionResult);
}
}

View File

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

View File

@ -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)
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;
}
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;
}
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;
}
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;
if (swaggerParam is OpenApiParameter)
if (swaggerParam is not null)
{
swaggerParam.Schema.Minimum = rangeMin;
swaggerParam.Schema.Maximum = rangeMax;

View File

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

View File

@ -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)",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -74,5 +74,4 @@ namespace IO.Swagger.Models.db
/// </value>
public ICollection<Transaction> TransactionsTo { get; set; }
}
}

View File

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

View File

@ -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,

View File

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

View File

@ -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/>

View File

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

View File

@ -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)

View File

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

View File

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

View File

@ -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 =>
IServiceCollection unused8 = services.AddCors(opt => opt.AddDefaultPolicy(po =>
{
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();
}
}
}