Removed todos and added User endpoint combined with register. Id changed to guid
This commit is contained in:
39
src/Application/Users/Commands/CreateUser.cs
Normal file
39
src/Application/Users/Commands/CreateUser.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user