-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'revisions/dotnet6' into main
- Loading branch information
Showing
36 changed files
with
556 additions
and
568 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using YuckQi.Domain.Aspects.Abstract; | ||
using YuckQi.Domain.Entities.Abstract; | ||
using YuckQi.Domain.Services.Models; | ||
using YuckQi.Domain.Validation; | ||
using YuckQi.Domain.ValueObjects.Abstract; | ||
|
||
namespace YuckQi.Domain.Services.Abstract | ||
namespace YuckQi.Domain.Services.Abstract; | ||
|
||
public interface ITypeEntityService<TTypeEntity, in TIdentifier> where TTypeEntity : IEntity<TIdentifier>, IType where TIdentifier : IEquatable<TIdentifier> | ||
{ | ||
public interface ITypeEntityService<TTypeEntity, in TKey> where TTypeEntity : IEntity<TKey>, IType where TKey : struct | ||
{ | ||
Task<Result<TTypeEntity>> CreateAsync(TTypeEntity entity); | ||
Task<Result<TTypeEntity>> GetAsync(Guid identifier); | ||
Task<Result<TTypeEntity>> GetAsync(TKey key); | ||
Task<Result<TTypeEntity>> ModifyAsync(TTypeEntity entity); | ||
Task<Result<IPage<TTypeEntity>>> SearchAsync(TypeSearchCriteria criteria = null); | ||
} | ||
Task<Result<TTypeEntity>> Create(TTypeEntity entity, CancellationToken cancellationToken = default); | ||
Task<Result<TTypeEntity>> Get(TIdentifier identifier, CancellationToken cancellationToken = default); | ||
Task<Result<TTypeEntity>> Modify(TTypeEntity entity, CancellationToken cancellationToken = default); | ||
Task<Result<IPage<TTypeEntity>>> Search(TypeSearchCriteria? criteria = null, CancellationToken cancellationToken = default); | ||
} |
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,12 +1,11 @@ | ||
using System; | ||
using YuckQi.Domain.ValueObjects.Abstract; | ||
|
||
namespace YuckQi.Domain.Services.Models | ||
namespace YuckQi.Domain.Services.Models; | ||
|
||
public class TypeSearchCriteria : IPage | ||
{ | ||
public class TypeSearchCriteria : IPage | ||
{ | ||
public String Name { get; set; } | ||
public Int32 PageNumber { get; set; } | ||
public Int32 PageSize { get; set; } | ||
} | ||
public String Name { get; set; } | ||
public Int32 PageNumber { get; set; } | ||
public Int32 PageSize { get; set; } | ||
} |
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
48 changes: 0 additions & 48 deletions
48
src/YuckQi.Domain.Validation/Exceptions/DomainValidationException.cs
This file was deleted.
Oops, something went wrong.
60 changes: 33 additions & 27 deletions
60
src/YuckQi.Domain.Validation/Extensions/AbstractValidatorExtensions.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,44 +1,50 @@ | ||
using System; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentValidation; | ||
using FluentValidation.Results; | ||
|
||
namespace YuckQi.Domain.Validation.Extensions | ||
namespace YuckQi.Domain.Validation.Extensions; | ||
|
||
public static class AbstractValidatorExtensions | ||
{ | ||
public static class AbstractValidatorExtensions | ||
public static Result<T> GetResult<T>(this AbstractValidator<T> validator, T item) | ||
{ | ||
public static Result<T> GetResult<T>(this AbstractValidator<T> validator, T item, String failedValidationMessageId) | ||
{ | ||
var validationResult = validator.Validate(item); | ||
var result = BuildResult(validationResult, item, failedValidationMessageId); | ||
if (validator == null) | ||
throw new ArgumentNullException(nameof(validator)); | ||
|
||
return result; | ||
} | ||
var validationResult = validator.Validate(item); | ||
var result = BuildResult(validationResult, item); | ||
|
||
public static async Task<Result<T>> GetResultAsync<T>(this AbstractValidator<T> validator, T item, String failedValidationMessageId) | ||
{ | ||
var validationResult = await validator.ValidateAsync(item); | ||
var result = BuildResult(validationResult, item, failedValidationMessageId); | ||
return result; | ||
} | ||
|
||
return result; | ||
} | ||
public static async Task<Result<T>> GetResult<T>(this AbstractValidator<T> validator, T item, CancellationToken cancellationToken) | ||
{ | ||
if (validator == null) | ||
throw new ArgumentNullException(nameof(validator)); | ||
|
||
private static Result<T> BuildResult<T>(ValidationResult validationResult, T item, String failedValidationMessageId) | ||
{ | ||
if (validationResult == null) | ||
throw new ArgumentNullException(nameof(validationResult)); | ||
var validationResult = await validator.ValidateAsync(item, cancellationToken); | ||
var result = BuildResult(validationResult, item); | ||
|
||
if (validationResult.IsValid) | ||
return new Result<T>(item); | ||
return result; | ||
} | ||
|
||
return new Result<T>(default, GetResultDetail(validationResult, failedValidationMessageId)); | ||
} | ||
private static Result<T> BuildResult<T>(ValidationResult validationResult, T item) | ||
{ | ||
if (validationResult == null) | ||
throw new ArgumentNullException(nameof(validationResult)); | ||
|
||
private static IReadOnlyCollection<ResultDetail> GetResultDetail(ValidationResult result, String failedValidationMessageId) | ||
{ | ||
return result?.Errors.Select(t => new ResultDetail(ResultCode.InvalidRequestDetail, new ResultMessage(failedValidationMessageId, t.ErrorMessage), t.PropertyName)).ToList(); | ||
} | ||
if (validationResult.IsValid) | ||
return new Result<T>(item); | ||
|
||
return new Result<T>(default, GetResultDetail(validationResult)); | ||
} | ||
|
||
private static IReadOnlyCollection<ResultDetail> GetResultDetail(ValidationResult result) | ||
{ | ||
return result.Errors.Select(t => new ResultDetail(new ResultMessage(t.ErrorMessage), ResultCode.InvalidRequestDetail, t.PropertyName)).ToList(); | ||
} | ||
} |
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,50 +1,35 @@ | ||
using System; | ||
|
||
namespace YuckQi.Domain.Validation | ||
{ | ||
public readonly struct ResultCode | ||
{ | ||
#region Private Members | ||
|
||
private readonly String _code; | ||
|
||
#endregion | ||
|
||
namespace YuckQi.Domain.Validation; | ||
|
||
#region Implicit Operators | ||
|
||
public static implicit operator String(ResultCode resultCode) => resultCode._code; | ||
|
||
#endregion | ||
|
||
|
||
#region Constants | ||
public readonly struct ResultCode | ||
{ | ||
private readonly String _code; | ||
|
||
public static readonly ResultCode ConstraintViolation = new ResultCode(nameof(ConstraintViolation)); | ||
public static readonly ResultCode InvalidRequestDetail = new ResultCode(nameof(InvalidRequestDetail)); | ||
public static readonly ResultCode NotFound = new ResultCode(nameof(NotFound)); | ||
public static implicit operator String(ResultCode code) => code._code; | ||
|
||
#endregion | ||
public static readonly ResultCode ConstraintViolation = new(nameof(ConstraintViolation)); | ||
public static readonly ResultCode InvalidRequestDetail = new(nameof(InvalidRequestDetail)); | ||
public static readonly ResultCode NotFound = new(nameof(NotFound)); | ||
|
||
public ResultCode() : this(Guid.NewGuid().ToString()) { } | ||
|
||
#region Constructors | ||
public ResultCode(String code) | ||
{ | ||
_code = code; | ||
} | ||
|
||
public ResultCode(String code) | ||
public override Boolean Equals(Object? obj) | ||
{ | ||
return obj switch | ||
{ | ||
_code = code; | ||
} | ||
|
||
#endregion | ||
|
||
|
||
#region Public Methods | ||
|
||
public override Boolean Equals(Object obj) => obj != null && String.Equals(this, (ResultCode) obj); | ||
|
||
public override Int32 GetHashCode() => _code.GetHashCode(); | ||
ResultCode other => String.Equals(this, other), | ||
String other => String.Equals(this, other), | ||
_ => false | ||
}; | ||
} | ||
|
||
public override String ToString() => _code; | ||
public override Int32 GetHashCode() => _code.GetHashCode(); | ||
|
||
#endregion | ||
} | ||
public override String ToString() => _code; | ||
} |
Oops, something went wrong.