Skip to content

Commit

Permalink
Merge pull request #11 from LibardiFelipe/teste
Browse files Browse the repository at this point in the history
Teste
  • Loading branch information
LibardiFelipe committed Jan 12, 2023
2 parents e768b33 + 8065572 commit cb4fabe
Show file tree
Hide file tree
Showing 81 changed files with 758 additions and 1,689 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# CS8618: O campo não anulável precisa conter um valor não nulo ao sair do construtor. Considere declará-lo como anulável.
dotnet_diagnostic.CS8618.severity = none
34 changes: 0 additions & 34 deletions TemplateBase.Application/Commands/Auth/AuthCommandHandler.cs

This file was deleted.

14 changes: 0 additions & 14 deletions TemplateBase.Application/Commands/Auth/UserLoginCommand.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

24 changes: 0 additions & 24 deletions TemplateBase.Application/Commands/Users/RegisterUserCommand.cs

This file was deleted.

21 changes: 21 additions & 0 deletions TemplateBase.Application/Commands/Users/SetupUserCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Security.Claims;
using TemplateBase.Application.Commands.Base;

namespace TemplateBase.Application.Commands.Users
{
public class SetupUserCommand : Command
{
public SetupUserCommand(IEnumerable<Claim> claims)
{
Claims = claims;
}

public IEnumerable<Claim> Claims { get; private set; }

public override void Validate()
{

}
}
}
38 changes: 11 additions & 27 deletions TemplateBase.Application/Commands/Users/UserCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,34 @@
using MediatR;
using System.Threading;
using System.Threading.Tasks;
using TemplateBase.Application.Commands.Auth;
using TemplateBase.Application.Commands.Base;
using TemplateBase.Application.Models;
using TemplateBase.Domain.Resources;
using TemplateBase.Domain.Services.Contracts;

namespace TemplateBase.Application.Commands.Persons
namespace TemplateBase.Application.Commands.Users
{
public class UserCommandHandler : CommandHandler,
IRequestHandler<RegisterUserCommand, Result>,
IRequestHandler<VerifyUserCommand, Result>
IRequestHandler<SetupUserCommand, Result>
{
private readonly IUserService _userService;
private readonly IUserService _userServices;

public UserCommandHandler(IUserService userService)
public UserCommandHandler(IUserService userServices)
{
_userService = userService;
_userServices = userServices;
}

public async Task<Result> Handle(RegisterUserCommand request, CancellationToken cancellationToken)
public async Task<Result> Handle(SetupUserCommand request, CancellationToken cancellationToken)
{
if (request.IsInvalid())
return new Result(DefaultMessages.Handler_ComandoInvalido, false, request.Notifications);
return new Result(Mensagens.Handler_ComandoInvalido, false, request.Notifications);

var entity = await _userService.RegisterUserAsync(request.Name, request.Email,
request.Password, request.BirthDate, request.ProfilePicture, cancellationToken);
var entity = await _userServices.SetupUserAsync(request.Claims, cancellationToken);

if (_userService.IsInvalid())
return new Result(DefaultMessages.Handler_FalhaAoExecutarComando, false, _userService.GetNotifications());
if (_userServices.IsInvalid())
return new Result(Mensagens.Handler_FalhaAoExecutarComando, false, _userServices.GetNotifications());

return new Result(DefaultMessages.Handler_ComandoExecutado, true, entity);
}

public async Task<Result> Handle(VerifyUserCommand request, CancellationToken cancellationToken)
{
if (request.IsInvalid())
return new Result(DefaultMessages.Handler_ComandoInvalido, false, request.Notifications);

var entity = await _userService.VerifyUserAsync(request.Hash, cancellationToken);

if (_userService.IsInvalid())
return new Result(DefaultMessages.Handler_FalhaAoExecutarComando, false, _userService.GetNotifications());

return new Result(DefaultMessages.Handler_ComandoExecutado, true, entity);
return new Result(Mensagens.Handler_ComandoExecutado, true, entity);
}
}
}
23 changes: 0 additions & 23 deletions TemplateBase.Application/Commands/Users/VerifyUserCommand.cs

This file was deleted.

4 changes: 2 additions & 2 deletions TemplateBase.Application/Models/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class Result
{
public Result(string message, bool success, object data = null)
public Result(string message, bool success, object? data = null)
{
Message = message;
Success = success;
Expand All @@ -11,6 +11,6 @@ public Result(string message, bool success, object data = null)

public string Message { get; private set; }
public bool Success { get; private set; }
public object Data { get; private set; }
public object? Data { get; private set; }
}
}
22 changes: 20 additions & 2 deletions TemplateBase.Application/Queries/Base/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,38 @@

namespace TemplateBase.Application.Queries.Base
{
public abstract class Query<TEntity> : Notifiable<Notification>, IRequest<Result> where TEntity : Entity
public abstract class Query<TQuery, TEntity> : Notifiable<Notification>, IRequest<Result> where TEntity : Entity where TQuery : Query<TQuery, TEntity>
{
protected Guid? _id = null;
protected DateTime? _createdAtStart = null;
protected DateTime? _createdAtEnd = null;
protected DateTime? _updatedAtStart = null;
protected DateTime? _updatedAtEnd = null;

public Query() { }

public Query(string id)
{
if (Guid.TryParse(id, out var guidId) is false)
AddNotification("", DefaultMessages.Entidade_IdentificadorInvalido);
AddNotification("", Mensagens.Entidade_IdentificadorInvalido);

_id = guidId;
}

public TQuery FilterByCreationRange(DateTime? startDate, DateTime? endDate)
{
_createdAtStart = startDate;
_createdAtEnd = endDate;
return (TQuery)this;
}

public TQuery FilterByUpdateRange(DateTime? startDate, DateTime? endDate)
{
_updatedAtStart = startDate;
_updatedAtEnd = endDate;
return (TQuery)this;
}

public abstract ISpecification<TEntity> ToSpecification();
public bool IsInvalid() => Notifications.Any();
public abstract void Validate();
Expand Down
Loading

0 comments on commit cb4fabe

Please sign in to comment.