Skip to content

Commit 4078c15

Browse files
committed
style: format code for consistency and readability across multiple files
1 parent 438d41f commit 4078c15

File tree

276 files changed

+7368
-7371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

276 files changed

+7368
-7371
lines changed

.husky/pre-commit

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
echo "Husky.NET Started"
66
echo "Running Pre-Commit Hook"
77

8-
dotnet format
8+
dotnet tool restore
9+
dotnet tool run dotnet-csharpier ./Source/Ecommerce.Application/ ./Source/Ecommerce.Domain/ ./Source/Ecommerce.Infrastructure/ ./Source/Ecommerce.Api/ ./Source/Ecommerce.Contracts/ ./Tests/UnitTests/
910

1011

1112
echo "Husky.NET Finished"

Source/Ecommerce.Api/ActionFilters/FluentResultsActionFilter.cs

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,69 @@ namespace Ecommerce.Api.ActionFilters;
1010

1111
public class FluentResultsActionFilter : IActionFilter
1212
{
13-
public void OnActionExecuted(ActionExecutedContext context)
14-
{
15-
var result = context.Result;
13+
public void OnActionExecuted(ActionExecutedContext context)
14+
{
15+
var result = context.Result;
1616

17-
if (result is ObjectResult objectResult)
17+
if (result is ObjectResult objectResult)
18+
{
19+
if (objectResult.Value is FluentResults.IResultBase fluentResult)
20+
{
21+
// Handle the failure
22+
var error = fluentResult.Errors.First();
23+
var errorName = error.GetType().Name;
24+
var problemDetails = new ProblemDetails
1825
{
19-
if (objectResult.Value is FluentResults.IResultBase fluentResult)
20-
{
21-
// Handle the failure
22-
var error = fluentResult.Errors.First();
23-
var errorName = error.GetType().Name;
24-
var problemDetails = new ProblemDetails
25-
{
26-
Title = ConversionUtility.PascalToSpacedPascal(errorName),
27-
Detail = error.Message,
28-
Status = StatusCodes.Status500InternalServerError,
29-
};
30-
31-
if (error is FluentErrorBase fluentError)
32-
{
33-
problemDetails.Detail = fluentError.Detail;
34-
problemDetails.Extensions.Add("path", fluentError.Path);
35-
problemDetails.Extensions.Add("message", fluentError.Message);
26+
Title = ConversionUtility.PascalToSpacedPascal(errorName),
27+
Detail = error.Message,
28+
Status = StatusCodes.Status500InternalServerError,
29+
};
3630

37-
int status = StatusCodes.Status500InternalServerError;
31+
if (error is FluentErrorBase fluentError)
32+
{
33+
problemDetails.Detail = fluentError.Detail;
34+
problemDetails.Extensions.Add("path", fluentError.Path);
35+
problemDetails.Extensions.Add("message", fluentError.Message);
3836

39-
switch (fluentError)
40-
{
41-
case AuthenticationError:
42-
status = StatusCodes.Status401Unauthorized;
43-
break;
44-
case ValidationError:
45-
case LengthError:
46-
case BelowZeroError:
47-
case InvalidCurrencyError:
48-
case InvalidDateRangeError:
49-
case PasswordMatchError:
50-
case IncorrectCurrentPasswordError:
51-
case ExpiryError:
52-
status = StatusCodes.Status400BadRequest;
53-
break;
54-
case AlreadyExistsError:
55-
status = StatusCodes.Status409Conflict;
56-
break;
57-
case NotFoundError:
58-
status = StatusCodes.Status404NotFound;
59-
break;
60-
default:
61-
status = StatusCodes.Status500InternalServerError;
62-
break;
63-
}
37+
int status = StatusCodes.Status500InternalServerError;
6438

65-
problemDetails.Status = status;
66-
}
39+
switch (fluentError)
40+
{
41+
case AuthenticationError:
42+
status = StatusCodes.Status401Unauthorized;
43+
break;
44+
case ValidationError:
45+
case LengthError:
46+
case BelowZeroError:
47+
case InvalidCurrencyError:
48+
case InvalidDateRangeError:
49+
case PasswordMatchError:
50+
case IncorrectCurrentPasswordError:
51+
case ExpiryError:
52+
status = StatusCodes.Status400BadRequest;
53+
break;
54+
case AlreadyExistsError:
55+
status = StatusCodes.Status409Conflict;
56+
break;
57+
case NotFoundError:
58+
status = StatusCodes.Status404NotFound;
59+
break;
60+
default:
61+
status = StatusCodes.Status500InternalServerError;
62+
break;
63+
}
6764

68-
context.Result = new ObjectResult(problemDetails) { StatusCode = problemDetails.Status };
69-
}
70-
else
71-
{
72-
Console.WriteLine("Result is not a failed Result object");
73-
}
65+
problemDetails.Status = status;
7466
}
67+
68+
context.Result = new ObjectResult(problemDetails) { StatusCode = problemDetails.Status };
69+
}
70+
else
71+
{
72+
Console.WriteLine("Result is not a failed Result object");
73+
}
7574
}
75+
}
7676

77-
public void OnActionExecuting(ActionExecutingContext context) { }
77+
public void OnActionExecuting(ActionExecutingContext context) { }
7878
}

Source/Ecommerce.Api/ActionFilters/ModelBindingErrorActionFilter.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@ namespace Ecommerce.Api.ActionFilters;
55

66
public class ModelBindingErrorActionFilter : IActionFilter
77
{
8-
public void OnActionExecuted(ActionExecutedContext context) { }
8+
public void OnActionExecuted(ActionExecutedContext context) { }
99

10-
public void OnActionExecuting(ActionExecutingContext context)
10+
public void OnActionExecuting(ActionExecutingContext context)
11+
{
12+
// Intercept the model state errors
13+
if (!context.ModelState.IsValid)
1114
{
12-
// Intercept the model state errors
13-
if (!context.ModelState.IsValid)
14-
{
15-
var errors = context
16-
.ModelState.Where(ms => ms.Value is not null && ms.Value.Errors.Any())
17-
.ToDictionary(
18-
kvp => kvp.Key.Replace("$.", ""),
19-
kvp => kvp.Value!.Errors.Select(e => e.ErrorMessage).ToArray()
20-
);
15+
var errors = context
16+
.ModelState.Where(ms => ms.Value is not null && ms.Value.Errors.Any())
17+
.ToDictionary(
18+
kvp => kvp.Key.Replace("$.", ""),
19+
kvp => kvp.Value!.Errors.Select(e => e.ErrorMessage).ToArray()
20+
);
2121

22-
var response = new ProblemDetails
23-
{
24-
Title = "One or more validation errors occurred.",
25-
Status = StatusCodes.Status400BadRequest,
26-
Detail = "The request contains invalid data, please correct the errors and try again.",
27-
Instance = context.HttpContext.Request.Path,
28-
Extensions = { ["errors"] = errors },
29-
};
22+
var response = new ProblemDetails
23+
{
24+
Title = "One or more validation errors occurred.",
25+
Status = StatusCodes.Status400BadRequest,
26+
Detail = "The request contains invalid data, please correct the errors and try again.",
27+
Instance = context.HttpContext.Request.Path,
28+
Extensions = { ["errors"] = errors },
29+
};
3030

31-
context.Result = new JsonResult(response) { StatusCode = StatusCodes.Status400BadRequest };
32-
}
31+
context.Result = new JsonResult(response) { StatusCode = StatusCodes.Status400BadRequest };
3332
}
33+
}
3434
}

Source/Ecommerce.Api/Controllers/AuthenticationController.cs

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,74 +14,74 @@ namespace Ecommerce.Api.Controllers;
1414
[Route("auth")]
1515
public class AuthenticationController : ControllerBase
1616
{
17-
private readonly ISender _mediator;
18-
private readonly IMapper _mapper;
19-
private readonly CookieSettings _cookieSettings;
20-
private readonly IWebHostEnvironment _webHostEnv;
21-
private readonly ILogger<AuthenticationController> _logger;
17+
private readonly ISender _mediator;
18+
private readonly IMapper _mapper;
19+
private readonly CookieSettings _cookieSettings;
20+
private readonly IWebHostEnvironment _webHostEnv;
21+
private readonly ILogger<AuthenticationController> _logger;
2222

23-
public AuthenticationController(
24-
ISender mediator,
25-
IMapper mapper,
26-
IOptions<CookieSettings> cookieSettings,
27-
IWebHostEnvironment webHostEnv,
28-
ILogger<AuthenticationController> logger
29-
)
30-
{
31-
_mediator = mediator;
32-
_mapper = mapper;
33-
_cookieSettings = cookieSettings.Value;
34-
_webHostEnv = webHostEnv;
35-
_logger = logger;
36-
}
23+
public AuthenticationController(
24+
ISender mediator,
25+
IMapper mapper,
26+
IOptions<CookieSettings> cookieSettings,
27+
IWebHostEnvironment webHostEnv,
28+
ILogger<AuthenticationController> logger
29+
)
30+
{
31+
_mediator = mediator;
32+
_mapper = mapper;
33+
_cookieSettings = cookieSettings.Value;
34+
_webHostEnv = webHostEnv;
35+
_logger = logger;
36+
}
3737

38-
[HttpPost("register")]
39-
public async Task<IActionResult> Register([FromBody] RegisterRequest registerRequest)
40-
{
41-
var command = _mapper.Map<RegisterUserCommand>(registerRequest);
38+
[HttpPost("register")]
39+
public async Task<IActionResult> Register([FromBody] RegisterRequest registerRequest)
40+
{
41+
var command = _mapper.Map<RegisterUserCommand>(registerRequest);
4242

43-
var result = await _mediator.Send(command);
43+
var result = await _mediator.Send(command);
4444

45-
return result.IsFailed
46-
? new ObjectResult(result)
47-
: Ok(_mapper.Map<AuthenticationResponse>(result.Value));
48-
}
45+
return result.IsFailed
46+
? new ObjectResult(result)
47+
: Ok(_mapper.Map<AuthenticationResponse>(result.Value));
48+
}
4949

50-
[HttpPost("login")]
51-
public async Task<IActionResult> Login([FromBody] LoginRequest loginRequest)
52-
{
53-
var loginQuery = _mapper.Map<LoginUserQuery>(loginRequest);
50+
[HttpPost("login")]
51+
public async Task<IActionResult> Login([FromBody] LoginRequest loginRequest)
52+
{
53+
var loginQuery = _mapper.Map<LoginUserQuery>(loginRequest);
5454

55-
var result = await _mediator.Send(loginQuery);
55+
var result = await _mediator.Send(loginQuery);
5656

57-
if (result.IsFailed)
58-
return new ObjectResult(result);
57+
if (result.IsFailed)
58+
return new ObjectResult(result);
5959

60-
var jwtToken = new JwtSecurityTokenHandler().ReadJwtToken(result.Value.Token);
61-
var expClaim = jwtToken.Claims.FirstOrDefault(c => c.Type == JwtRegisteredClaimNames.Exp);
60+
var jwtToken = new JwtSecurityTokenHandler().ReadJwtToken(result.Value.Token);
61+
var expClaim = jwtToken.Claims.FirstOrDefault(c => c.Type == JwtRegisteredClaimNames.Exp);
6262

63-
if (expClaim is null)
64-
{
65-
_logger.LogError(
66-
"Token does not contain an expiration claim. Token: {Token}",
67-
result.Value.Token
68-
);
69-
return StatusCode(500, "An error occured trying to log you in. Please contact support.");
70-
}
63+
if (expClaim is null)
64+
{
65+
_logger.LogError(
66+
"Token does not contain an expiration claim. Token: {Token}",
67+
result.Value.Token
68+
);
69+
return StatusCode(500, "An error occured trying to log you in. Please contact support.");
70+
}
7171

72-
// Set the http-only cookie
73-
HttpContext.Response.Cookies.Append(
74-
_cookieSettings.CookieKey,
75-
result.Value.Token,
76-
new CookieOptions
77-
{
78-
HttpOnly = _cookieSettings.HttpOnly,
79-
Secure = _cookieSettings.Secure,
80-
Expires = DateTimeOffset.FromUnixTimeSeconds(long.Parse(expClaim.Value)),
81-
SameSite = _cookieSettings.SameSite,
82-
}
83-
);
72+
// Set the http-only cookie
73+
HttpContext.Response.Cookies.Append(
74+
_cookieSettings.CookieKey,
75+
result.Value.Token,
76+
new CookieOptions
77+
{
78+
HttpOnly = _cookieSettings.HttpOnly,
79+
Secure = _cookieSettings.Secure,
80+
Expires = DateTimeOffset.FromUnixTimeSeconds(long.Parse(expClaim.Value)),
81+
SameSite = _cookieSettings.SameSite,
82+
}
83+
);
8484

85-
return Ok(_mapper.Map<AuthenticationResponse>(result.Value));
86-
}
85+
return Ok(_mapper.Map<AuthenticationResponse>(result.Value));
86+
}
8787
}

Source/Ecommerce.Api/Controllers/OrderController.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,38 @@ namespace Ecommerce.Api.Controllers;
99
[Route("orders")]
1010
public class OrderController(ISender sender) : ControllerBase
1111
{
12-
public async Task<IActionResult> CreateOrder([FromBody] CreateOrderRequest createOrderRequest)
13-
{
14-
var result = await sender.Send(
15-
new CreateOrderCommand
16-
{
17-
OrderProducts = createOrderRequest.Products.Select(p => new OrderProductCommand
18-
{
19-
ProductId = p.ProductId,
20-
Quantity = p.Quantity,
21-
}),
22-
PaymentInformation = new PaymentInformationCommand
23-
{
24-
CardHolderName = createOrderRequest.PaymentInformation.CardHolderName,
25-
CardNumber = createOrderRequest.PaymentInformation.CardNumber,
26-
CVV = createOrderRequest.PaymentInformation.CVV,
27-
ExpiryMonth = createOrderRequest.PaymentInformation.ExpiryMonth,
28-
ExpiryYear = createOrderRequest.PaymentInformation.ExpiryYear,
29-
},
30-
ShippingAddress = new ShippingAddressCommand
31-
{
32-
City = createOrderRequest.ShippingAddress.City,
33-
Country = createOrderRequest.ShippingAddress.Country,
34-
State = createOrderRequest.ShippingAddress.State,
35-
Street = createOrderRequest.ShippingAddress.Street,
36-
ZipCode = createOrderRequest.ShippingAddress.ZipCode,
37-
},
38-
}
39-
);
12+
public async Task<IActionResult> CreateOrder([FromBody] CreateOrderRequest createOrderRequest)
13+
{
14+
var result = await sender.Send(
15+
new CreateOrderCommand
16+
{
17+
OrderProducts = createOrderRequest.Products.Select(p => new OrderProductCommand
18+
{
19+
ProductId = p.ProductId,
20+
Quantity = p.Quantity,
21+
}),
22+
PaymentInformation = new PaymentInformationCommand
23+
{
24+
CardHolderName = createOrderRequest.PaymentInformation.CardHolderName,
25+
CardNumber = createOrderRequest.PaymentInformation.CardNumber,
26+
CVV = createOrderRequest.PaymentInformation.CVV,
27+
ExpiryMonth = createOrderRequest.PaymentInformation.ExpiryMonth,
28+
ExpiryYear = createOrderRequest.PaymentInformation.ExpiryYear,
29+
},
30+
ShippingAddress = new ShippingAddressCommand
31+
{
32+
City = createOrderRequest.ShippingAddress.City,
33+
Country = createOrderRequest.ShippingAddress.Country,
34+
State = createOrderRequest.ShippingAddress.State,
35+
Street = createOrderRequest.ShippingAddress.Street,
36+
ZipCode = createOrderRequest.ShippingAddress.ZipCode,
37+
},
38+
}
39+
);
4040

41-
if (result.IsFailed)
42-
return new ObjectResult(result);
41+
if (result.IsFailed)
42+
return new ObjectResult(result);
4343

44-
return Created();
45-
}
44+
return Created();
45+
}
4646
}

0 commit comments

Comments
 (0)