-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update backend to dotnet 6 * Update readme with .NET 6 update info * Update backend CI to dotnet 6 * Fix failing unit tests
- Loading branch information
1 parent
65ab084
commit b72d78c
Showing
184 changed files
with
4,229 additions
and
3,818 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
::Usage: AddMigration <migrationName> | ||
@dotnet ef migrations add --project ../src/MyWarehouse.Infrastructure --startup-project ../src/MyWarehouse.Api %* | ||
@dotnet ef migrations add --project ../src/Infrastructure --startup-project ../src/WebApi %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
@dotnet ef dbcontext info --project ../src/MyWarehouse.Infrastructure --startup-project ../src/MyWarehouse.Api | ||
@dotnet ef dbcontext info --project ../src/Infrastructure --startup-project ../src/WebApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
@dotnet ef migrations remove --project ../src/MyWarehouse.Infrastructure --startup-project ../src/MyWarehouse.Api | ||
@dotnet ef migrations remove --project ../src/Infrastructure --startup-project ../src/WebApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
::Usage: UpdateDatebase <migrationName> (where <migrationName> is required only when reverting to an older migration) | ||
@dotnet ef database update --project ../src/MyWarehouse.Infrastructure --startup-project ../src/MyWarehouse.Api %* | ||
@dotnet ef database update --project ../src/Infrastructure --startup-project ../src/WebApi %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
using AutoMapper; | ||
using FluentValidation; | ||
using MediatR; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using MyWarehouse.Application.Common.Behaviors; | ||
using System.Reflection; | ||
|
||
namespace MyWarehouse.Application | ||
namespace MyWarehouse.Application; | ||
|
||
public static class ApplicationStartup | ||
{ | ||
public static class ApplicationStartup | ||
public static void AddMyApplicationDependencies(this IServiceCollection services) | ||
{ | ||
public static void AddMyApplicationDependencies(this IServiceCollection services) | ||
{ | ||
services.AddAutoMapper(Assembly.GetExecutingAssembly()); | ||
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly()); | ||
services.AddMediatR(Assembly.GetExecutingAssembly()); | ||
services.AddAutoMapper(Assembly.GetExecutingAssembly()); | ||
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly()); | ||
services.AddMediatR(Assembly.GetExecutingAssembly()); | ||
|
||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ExceptionLoggingBehavior<,>)); | ||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestValidationBehavior<,>)); | ||
} | ||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ExceptionLoggingBehavior<,>)); | ||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestValidationBehavior<,>)); | ||
} | ||
} |
52 changes: 24 additions & 28 deletions
52
src/Application/Common/Behaviors/ExceptionLoggingBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,35 @@ | ||
using MediatR; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging; | ||
using MyWarehouse.Application.Common.Exceptions; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace MyWarehouse.Application.Common.Behaviors | ||
namespace MyWarehouse.Application.Common.Behaviors; | ||
|
||
public class ExceptionLoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> | ||
where TRequest: IRequest<TResponse> | ||
{ | ||
public class ExceptionLoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> | ||
{ | ||
private readonly ILogger<TRequest> _logger; | ||
private readonly ILogger<TRequest> _logger; | ||
|
||
public ExceptionLoggingBehavior(ILogger<TRequest> logger) | ||
=> _logger = logger; | ||
public ExceptionLoggingBehavior(ILogger<TRequest> logger) | ||
=> _logger = logger; | ||
|
||
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next) | ||
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next) | ||
{ | ||
try | ||
{ | ||
try | ||
{ | ||
return await next(); | ||
} | ||
catch (InputValidationException ive) | ||
{ | ||
var requestName = typeof(TRequest).Name; | ||
_logger.LogError(ive, "Validation error occurred in request '{RequestName}'\r\n\tRequestPayload: {@RequestPayload}\r\n\tErrors: {@Errors}.", requestName, request, ive.Errors); | ||
return await next(); | ||
} | ||
catch (InputValidationException ive) | ||
{ | ||
var requestName = typeof(TRequest).Name; | ||
_logger.LogError(ive, "Validation error occurred in request '{RequestName}'\r\n\tRequestPayload: {@RequestPayload}\r\n\tErrors: {@Errors}.", requestName, request, ive.Errors); | ||
|
||
throw; | ||
} | ||
catch (Exception e) | ||
{ | ||
var requestName = typeof(TRequest).Name; | ||
_logger.LogError(e, "Exception occurred in request '{RequestName}'\r\n\tRequestPayload: {@RequestPayload}", requestName, request); | ||
throw; | ||
} | ||
catch (Exception e) | ||
{ | ||
var requestName = typeof(TRequest).Name; | ||
_logger.LogError(e, "Exception occurred in request '{RequestName}'\r\n\tRequestPayload: {@RequestPayload}", requestName, request); | ||
|
||
throw; | ||
} | ||
throw; | ||
} | ||
} | ||
} |
50 changes: 23 additions & 27 deletions
50
src/Application/Common/Behaviors/RequestValidationBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,38 @@ | ||
using FluentValidation; | ||
using MediatR; | ||
using MyWarehouse.Application.Common.Exceptions; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
namespace MyWarehouse.Application.Common.Behaviors; | ||
|
||
namespace MyWarehouse.Application.Common.Behaviors | ||
public class RequestValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> | ||
where TRequest : IRequest<TResponse> | ||
{ | ||
public class RequestValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> | ||
where TRequest : IRequest<TResponse> | ||
private readonly IEnumerable<IValidator<TRequest>> _validators; | ||
|
||
public RequestValidationBehavior(IEnumerable<IValidator<TRequest>> validators) | ||
{ | ||
private readonly IEnumerable<IValidator<TRequest>> _validators; | ||
_validators = validators; | ||
} | ||
|
||
public RequestValidationBehavior(IEnumerable<IValidator<TRequest>> validators) | ||
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next) | ||
{ | ||
if (_validators.Any()) | ||
{ | ||
_validators = validators; | ||
} | ||
var context = new ValidationContext<TRequest>(request); | ||
|
||
public Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next) | ||
{ | ||
if (_validators.Any()) | ||
{ | ||
var context = new ValidationContext<TRequest>(request); | ||
var results = await Task.WhenAll(_validators | ||
.Select(v => v.ValidateAsync(context))); | ||
|
||
var failures = _validators | ||
.Select(v => v.Validate(context)) | ||
.SelectMany(result => result.Errors) | ||
.Where(f => f != null) | ||
.ToList(); | ||
var failures = results | ||
.Where(r => !r.IsValid) | ||
.SelectMany(r => r.Errors) | ||
.ToList(); | ||
|
||
if (failures.Count != 0) | ||
{ | ||
throw new InputValidationException(failures); | ||
} | ||
if (failures.Any()) | ||
{ | ||
throw new InputValidationException(failures); | ||
} | ||
|
||
return next(); | ||
} | ||
|
||
return await next(); | ||
} | ||
} |
25 changes: 11 additions & 14 deletions
25
src/Application/Common/Dependencies/DataAccess/IUnitOfWork.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
using MyWarehouse.Application.Common.Dependencies.DataAccess.Repositories; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace MyWarehouse.Application.Common.Dependencies.DataAccess | ||
namespace MyWarehouse.Application.Common.Dependencies.DataAccess; | ||
|
||
public interface IUnitOfWork : IDisposable | ||
{ | ||
public interface IUnitOfWork : IDisposable | ||
{ | ||
public IPartnerRepository Partners { get; } | ||
public IProductRepository Products { get; } | ||
public ITransactionRepository Transactions { get; } | ||
bool HasActiveTransaction { get; } | ||
public IPartnerRepository Partners { get; } | ||
public IProductRepository Products { get; } | ||
public ITransactionRepository Transactions { get; } | ||
bool HasActiveTransaction { get; } | ||
|
||
Task BeginTransactionAsync(); | ||
Task CommitTransactionAsync(); | ||
Task RollbackTransactionAsync(); | ||
public Task SaveChanges(); | ||
} | ||
Task BeginTransactionAsync(); | ||
Task CommitTransactionAsync(); | ||
Task RollbackTransactionAsync(); | ||
public Task SaveChanges(); | ||
} |
Oops, something went wrong.