Removed todos and added User endpoint combined with register. Id changed to guid

This commit is contained in:
Dominic Villemure
2024-04-03 23:57:01 -04:00
parent df8b42bdf1
commit 1f795c53bb
67 changed files with 1750 additions and 1895 deletions

View File

@@ -0,0 +1,39 @@
using Hutopy.Application.Common.Interfaces;
using Hutopy.Domain.Entities;
namespace Hutopy.Application.Users.Commands;
public record CreateUserCommand : IRequest<Guid>
{
public required string FirstName { get; init; }
public required string LastName { get; init; }
public required string EmailAddress { get; init; }
public required string UserName { get; init; }
public required string Password { get; init; }
}
public class CreateUserCommandHandler : IRequestHandler<CreateUserCommand, Guid>
{
private readonly IApplicationDbContext _context;
public CreateUserCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Guid> Handle(CreateUserCommand request, CancellationToken cancellationToken)
{
var entity = new User
{
FirstName = request.FirstName,
LastName = request.LastName,
EmailAddress = request.EmailAddress,
UserName = request.UserName,
};
_context.DomainUsers.Add(entity);
await _context.SaveChangesAsync(cancellationToken);
return entity.Id;
}
}