#48 cleaned userService. We will use IdentityService only
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
using Hutopy.Application.Common.Models;
|
||||
using Hutopy.Domain.Models;
|
||||
|
||||
namespace Hutopy.Application.Common.Interfaces;
|
||||
|
||||
public interface IIdentityService
|
||||
{
|
||||
Task<string?> GetUserNameAsync(string userId);
|
||||
|
||||
Task CreateUserAsync(string email, string userName, string firstName, string lastName, string password);
|
||||
|
||||
Task<UserModel?> FindUserByIdAsync(string id);
|
||||
Task<UserModel?> GetCurrentUserAsync();
|
||||
Task<UserModel?> FindUserByEmailAsync(string id);
|
||||
|
||||
Task<bool> IsInRoleAsync(string userId, string role);
|
||||
|
||||
Task<bool> AuthorizeAsync(string userId, string policyName);
|
||||
|
||||
Task<(Result Result, string UserId)> CreateUserAsync(string userName, string password);
|
||||
|
||||
Task<Result> DeleteUserAsync(string userId);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System.Dynamic;
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Domain.Entities;
|
||||
using Hutopy.Domain.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
|
||||
namespace Hutopy.Application.Users.Commands;
|
||||
public record CreateUserCommand : IRequest<Guid>
|
||||
@@ -17,24 +13,20 @@ public record CreateUserCommand : IRequest<Guid>
|
||||
public class CreateUserCommandHandler : IRequestHandler<CreateUserCommand, Guid>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
private readonly IUserService _userService;
|
||||
private readonly IIdentityService _identityService;
|
||||
|
||||
public CreateUserCommandHandler(IApplicationDbContext context, IUserService userService)
|
||||
public CreateUserCommandHandler(IApplicationDbContext context, IIdentityService identityService)
|
||||
{
|
||||
_context = context;
|
||||
_userService = userService;
|
||||
_identityService = identityService;
|
||||
}
|
||||
|
||||
public async Task<Guid> Handle(CreateUserCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Dont really need the handler for the create. The get will work like this :
|
||||
var user = await _userService.FindUserByIdAsync("072ae7d5-8c4a-4a0f-b250-7d39941125cb");
|
||||
// var user2 = await _userService.FindUserByEmailAsync("test10@hotmail.com");
|
||||
|
||||
var tt = user?.FirstName;
|
||||
var user = await _identityService.FindUserByEmailAsync(request.EmailAddress);
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return Guid.NewGuid();
|
||||
return new Guid(user?.Id ?? string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Domain.Interfaces;
|
||||
|
||||
namespace Hutopy.Application.Users.Queries.GetCurrentUser;
|
||||
|
||||
@@ -8,13 +7,13 @@ public record GetCurrentUserQuery : IRequest<UserDto>;
|
||||
public class GetCurrentUserQueryHandler(
|
||||
IApplicationDbContext context,
|
||||
IMapper mapper,
|
||||
IUserService userService
|
||||
IIdentityService identityService
|
||||
)
|
||||
: IRequestHandler<GetCurrentUserQuery, UserDto>
|
||||
{
|
||||
public async Task<UserDto> Handle(GetCurrentUserQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var identityUser = await userService.GetCurrentUserAsync();
|
||||
var identityUser = await identityService.GetCurrentUserAsync();
|
||||
var currentUserId = new Guid(identityUser?.Id ?? "");
|
||||
|
||||
var transactions = await context.UserTransactions
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Hutopy.Domain.Interfaces;
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
|
||||
namespace Hutopy.Application.Users.Queries.GetMinimalUser;
|
||||
|
||||
@@ -8,15 +8,15 @@ public record GetMinimalUserQuery : IRequest<MinimalUserDto>
|
||||
};
|
||||
|
||||
public class GetMinimalUserQueryHandler(
|
||||
IUserService userService
|
||||
IIdentityService identityService
|
||||
)
|
||||
: IRequestHandler<GetMinimalUserQuery, MinimalUserDto>
|
||||
{
|
||||
public async Task<MinimalUserDto> Handle(GetMinimalUserQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var identityUser = await userService.FindUserByIdAsync(request.UserId);
|
||||
var identityUser = await identityService.FindUserByIdAsync(request.UserId);
|
||||
|
||||
var user = new MinimalUserDto()
|
||||
var user = new MinimalUserDto
|
||||
{
|
||||
FirstName = identityUser?.FirstName ?? "",
|
||||
LastName = identityUser?.LastName ?? "",
|
||||
|
||||
Reference in New Issue
Block a user