You need to sign in or sign up before continuing.
Commit 4e374cb3 authored by Almouhannad's avatar Almouhannad

(B) Add register receptionist

parent f228f27b
using Application.Abstractions.CQRS.Commands;
namespace Application.Users.Commands.RegisterReceptionist;
public class RegisterReceptionistCommand : ICommand<RegisterReceptionistResponse>
{
public string UserName { get; set; } = null!;
public string Password { get; set; } = null!;
public string FirstName { get; set; } = null!;
public string MiddleName { get; set; } = null!;
public string LastName { get; set; } = null!;
}
using Application.Abstractions.CQRS.Commands;
using Application.Users.Commands.RegisterDoctor;
using Domain.Entities.Identity.Users;
using Domain.Repositories;
using Domain.Shared;
using Domain.UnitOfWork;
namespace Application.Users.Commands.RegisterReceptionist;
public class RegisterReceptionistCommandHandler : CommandHandlerBase<RegisterReceptionistCommand, RegisterReceptionistResponse>
{
#region CTOR DI
private readonly IUserRepository _userRepository;
public RegisterReceptionistCommandHandler(IUnitOfWork unitOfWork, IUserRepository userRepository) : base(unitOfWork)
{
_userRepository = userRepository;
}
#endregion
public override async Task<Result<RegisterReceptionistResponse>> HandleHelper(RegisterReceptionistCommand request, CancellationToken cancellationToken)
{
#region 1. Create receptionist user
Result<ReceptionistUser> receptionistUserResult = ReceptionistUser.Create(
request.UserName, request.Password,
request.FirstName, request.MiddleName, request.LastName
);
if (receptionistUserResult.IsFailure)
return Result.Failure<RegisterReceptionistResponse>(receptionistUserResult.Error);
#endregion
#region 2. Register (save to DB)
var registerResult = await _userRepository.RegisterReceptionistAsync(receptionistUserResult.Value);
if (registerResult.IsFailure)
return Result.Failure<RegisterReceptionistResponse>(registerResult.Error);
#endregion
return RegisterReceptionistResponse.GetResponse(registerResult.Value);
throw new NotImplementedException();
}
}
using Application.Users.Commands.RegisterDoctor;
using Domain.Entities.Identity.Users;
using Domain.Entities.People.Doctors;
using Domain.Entities.People.Shared;
using Domain.Errors;
using Domain.Shared;
namespace Application.Users.Commands.RegisterReceptionist;
public class RegisterReceptionistResponse
{
public int Id { get; set; }
public PersonalInfo PersonalInfo { get; set; } = null!;
public static Result<RegisterReceptionistResponse> GetResponse(ReceptionistUser receptionistUser)
{
if (receptionistUser is null)
return Result.Failure<RegisterReceptionistResponse>(IdentityErrors.NotFound);
return new RegisterReceptionistResponse
{
Id = receptionistUser.Id,
PersonalInfo = receptionistUser.PersonalInfo
};
}
}
using Application.Users.Commands.Login; using Application.Users.Commands.Login;
using Application.Users.Commands.RegisterDoctor; using Application.Users.Commands.RegisterDoctor;
using Application.Users.Commands.RegisterReceptionist;
using Domain.Entities.Identity.UserRoles; using Domain.Entities.Identity.UserRoles;
using MediatR; using MediatR;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
...@@ -18,6 +19,7 @@ public class UsersController : ApiController ...@@ -18,6 +19,7 @@ public class UsersController : ApiController
} }
#endregion #endregion
#region Login
[HttpPost] [HttpPost]
public async Task<IActionResult> LoginUser([FromBody] LoginCommand command) public async Task<IActionResult> LoginUser([FromBody] LoginCommand command)
{ {
...@@ -29,7 +31,10 @@ public class UsersController : ApiController ...@@ -29,7 +31,10 @@ public class UsersController : ApiController
return Ok(result.Value); return Ok(result.Value);
} }
[Authorize(Roles =Roles.AdminName)] #endregion
#region Doctors
[Authorize(Roles = Roles.AdminName)]
[HttpPost("Doctors")] [HttpPost("Doctors")]
public async Task<IActionResult> RegisterDoctor([FromBody] RegisterDoctorCommand command) public async Task<IActionResult> RegisterDoctor([FromBody] RegisterDoctorCommand command)
{ {
...@@ -40,5 +45,21 @@ public class UsersController : ApiController ...@@ -40,5 +45,21 @@ public class UsersController : ApiController
return Ok(result.Value); return Ok(result.Value);
} }
#endregion
#region Receptionist
[Authorize(Roles = Roles.AdminName)]
[HttpPost("Receptionist")]
public async Task<IActionResult> RegisterReceptionist([FromBody] RegisterReceptionistCommand command)
{
var result = await _sender.Send(command);
if (result.IsFailure)
return HandleFailure(result);
return Ok(result.Value);
}
#endregion
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment