-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vanderlan Gomes da Silva
committed
Oct 31, 2023
1 parent
c631e7a
commit ab24998
Showing
13 changed files
with
125 additions
and
35 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
20 changes: 20 additions & 0 deletions
20
src/Orion.Application.Core/Commands/UserDelete/UserDeleteRequestValidator.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using FluentValidation; | ||
using Microsoft.Extensions.Localization; | ||
using Orion.Croscutting.Resources; | ||
using static Orion.Croscutting.Resources.Messages.MessagesKeys; | ||
|
||
namespace Orion.Application.Core.Commands.UserDelete; | ||
|
||
public class UserDeleteRequestValidator : AbstractValidator<UserDeleteRequest> | ||
{ | ||
public UserDeleteRequestValidator(IStringLocalizer<OrionResources> stringLocalizer) | ||
{ | ||
RuleFor(c => c) | ||
.NotNull() | ||
.WithMessage(stringLocalizer[UserMessages.NullEntity]); | ||
|
||
RuleFor(c => c.PublicId) | ||
.NotEmpty().WithMessage(stringLocalizer[UserMessages.EmptyId]) | ||
.NotNull().WithMessage(stringLocalizer[UserMessages.EmptyId]); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Orion.Application.Core/Commands/UserUpdate/UserUpdateRequestValidator.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using FluentValidation; | ||
using Microsoft.Extensions.Localization; | ||
using Orion.Croscutting.Resources; | ||
using static Orion.Croscutting.Resources.Messages.MessagesKeys; | ||
|
||
namespace Orion.Application.Core.Commands.UserUpdate; | ||
|
||
public class UserUpdateRequestValidator : AbstractValidator<UserUpdateRequest> | ||
{ | ||
public UserUpdateRequestValidator(IStringLocalizer<OrionResources> stringLocalizer) | ||
{ | ||
RuleFor(c => c) | ||
.NotNull() | ||
.WithMessage(stringLocalizer[UserMessages.NullEntity]); | ||
|
||
RuleFor(c => c.Name) | ||
.NotEmpty().WithMessage(stringLocalizer[UserMessages.EmptyName]) | ||
.NotNull().WithMessage(stringLocalizer[UserMessages.EmptyName]); | ||
|
||
RuleFor(c => c.Email) | ||
.NotEmpty().WithMessage(stringLocalizer[UserMessages.EmptyEmail]) | ||
.NotNull().WithMessage(stringLocalizer[UserMessages.EmptyEmail]); | ||
|
||
RuleFor(c => c.PublicId) | ||
.NotEmpty().WithMessage(stringLocalizer[UserMessages.EmptyId]) | ||
.NotNull().WithMessage(stringLocalizer[UserMessages.EmptyId]); | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/Orion.Application.Core/Queries/UserGetById/UserGetByIdRequestValidator.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using FluentValidation; | ||
using Microsoft.Extensions.Localization; | ||
using Orion.Croscutting.Resources; | ||
using static Orion.Croscutting.Resources.Messages.MessagesKeys; | ||
|
||
namespace Orion.Application.Core.Queries.UserGetById; | ||
|
||
public class UserGetByIdRequestValidator : AbstractValidator<UserGetByIdRequest> | ||
{ | ||
public UserGetByIdRequestValidator(IStringLocalizer<OrionResources> stringLocalizer) | ||
{ | ||
RuleFor(c => c) | ||
.NotNull() | ||
.WithMessage(stringLocalizer[UserMessages.NullEntity]); | ||
|
||
RuleFor(c => c.PublicId) | ||
.NotEmpty().WithMessage(stringLocalizer[UserMessages.EmptyId]) | ||
.NotNull().WithMessage(stringLocalizer[UserMessages.EmptyId]); | ||
} | ||
} |
18 changes: 10 additions & 8 deletions
18
src/Orion.Application.Core/Queries/UserGetPaginated/UserGetByIdRequestHandler.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,22 +1,24 @@ | ||
using MediatR; | ||
using Orion.Application.Core.Queries.UserGetById; | ||
using Orion.Domain.Core.Entities; | ||
using Orion.Domain.Core.Services.Interfaces; | ||
using Orion.Domain.Core.ValueObjects.Pagination; | ||
|
||
namespace Orion.Application.Core.Queries.UserGetPaginated; | ||
|
||
public class UserGetPaginatedRequestHandler : IRequestHandler<UserGetPaginatedRequest, PagedList<User>> | ||
public class UserGetPaginatedRequestHandler : IRequestHandler<UserGetPaginatedRequest, PagedList<UserGetPaginatedResponse>> | ||
{ | ||
private readonly IUserService _customerService; | ||
private readonly IUserService _userService; | ||
|
||
public UserGetPaginatedRequestHandler(IUserService customerService) | ||
public UserGetPaginatedRequestHandler(IUserService userService) | ||
{ | ||
_customerService = customerService; | ||
_userService = userService; | ||
} | ||
|
||
public async Task<PagedList<User>> Handle(UserGetPaginatedRequest request, CancellationToken cancellationToken) | ||
public async Task<PagedList<UserGetPaginatedResponse>> Handle(UserGetPaginatedRequest request, CancellationToken cancellationToken) | ||
{ | ||
return await _customerService.ListPaginateAsync(request); | ||
var users = await _userService.ListPaginateAsync(request); | ||
|
||
var usersPaginated = users.Items.Select(user => (UserGetPaginatedResponse)user).ToList(); | ||
|
||
return new PagedList<UserGetPaginatedResponse>(usersPaginated); | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
src/Orion.Application.Core/Queries/UserGetPaginated/UserGetPaginatedRequest.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,11 +1,10 @@ | ||
using MediatR; | ||
using Orion.Domain.Core.Entities; | ||
using Orion.Domain.Core.Filters; | ||
using Orion.Domain.Core.ValueObjects.Pagination; | ||
|
||
namespace Orion.Application.Core.Queries.UserGetPaginated; | ||
|
||
public class UserGetPaginatedRequest : UserFilter, IRequest<PagedList<User>> | ||
public class UserGetPaginatedRequest : UserFilter, IRequest<PagedList<UserGetPaginatedResponse>> | ||
{ | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/Orion.Application.Core/Queries/UserGetPaginated/UserGetPaginatedResponse.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Orion.Domain.Core.Entities; | ||
using Orion.Domain.Core.Entities.Enuns; | ||
|
||
namespace Orion.Application.Core.Queries.UserGetPaginated; | ||
|
||
public class UserGetPaginatedResponse | ||
{ | ||
public string PublicId { get; set; } | ||
public string Name { get; set; } | ||
public string Email { get; set; } | ||
public UserProfile Profile { get; set; } | ||
public DateTime LastUpdated { get; set; } | ||
public DateTime CreatedAt { get; set; } | ||
|
||
public static implicit operator UserGetPaginatedResponse(User user) | ||
{ | ||
if (user is null) | ||
return default; | ||
|
||
return new UserGetPaginatedResponse | ||
{ | ||
PublicId = user.PublicId, | ||
Name = user.Name, | ||
Email = user.Email, | ||
Profile = user.Profile, | ||
LastUpdated = user.LastUpdated, | ||
CreatedAt = user.CreatedAt | ||
}; | ||
} | ||
} |
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