Commit 852fc824 authored by Almouhannad's avatar Almouhannad

(B) Edit register response

parent 98a22859
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace Application.Users.Commands.RegisterDoctor; namespace Application.Users.Commands.RegisterDoctor;
public class RegisterDoctorCommand : ICommand<RegisterDoctorResponse> public class RegisterDoctorCommand : ICommand
{ {
public string UserName { get; set; } = null!; public string UserName { get; set; } = null!;
public string Password { get; set; } = null!; public string Password { get; set; } = null!;
......
...@@ -7,7 +7,7 @@ using Domain.UnitOfWork; ...@@ -7,7 +7,7 @@ using Domain.UnitOfWork;
namespace Application.Users.Commands.RegisterDoctor; namespace Application.Users.Commands.RegisterDoctor;
public class RegisterDoctorHandler : CommandHandlerBase<RegisterDoctorCommand, RegisterDoctorResponse> public class RegisterDoctorHandler : CommandHandlerBase<RegisterDoctorCommand>
{ {
#region CTOR DI #region CTOR DI
private readonly IUserRepository _userRepository; private readonly IUserRepository _userRepository;
...@@ -18,7 +18,7 @@ public class RegisterDoctorHandler : CommandHandlerBase<RegisterDoctorCommand, R ...@@ -18,7 +18,7 @@ public class RegisterDoctorHandler : CommandHandlerBase<RegisterDoctorCommand, R
#endregion #endregion
public override async Task<Result<RegisterDoctorResponse>> HandleHelper(RegisterDoctorCommand request, CancellationToken cancellationToken) public override async Task<Result> HandleHelper(RegisterDoctorCommand request, CancellationToken cancellationToken)
{ {
#region 1. Create doctor user #region 1. Create doctor user
Result<DoctorUser> doctorUserResult = DoctorUser.Create( Result<DoctorUser> doctorUserResult = DoctorUser.Create(
...@@ -28,23 +28,23 @@ public class RegisterDoctorHandler : CommandHandlerBase<RegisterDoctorCommand, R ...@@ -28,23 +28,23 @@ public class RegisterDoctorHandler : CommandHandlerBase<RegisterDoctorCommand, R
); );
if (doctorUserResult.IsFailure) if (doctorUserResult.IsFailure)
return Result.Failure<RegisterDoctorResponse>(doctorUserResult.Error); return Result.Failure(doctorUserResult.Error);
#endregion #endregion
#region 2. Verify unique username #region 2. Verify unique username
var uniqueUserNameResult = await _userRepository.IsUserNameAvailableAsunc(request.UserName); var uniqueUserNameResult = await _userRepository.IsUserNameAvailableAsunc(request.UserName);
if (uniqueUserNameResult.IsFailure) if (uniqueUserNameResult.IsFailure)
return Result.Failure<RegisterDoctorResponse>(uniqueUserNameResult.Error); return Result.Failure(uniqueUserNameResult.Error);
if (uniqueUserNameResult.Value == false) if (uniqueUserNameResult.Value == false)
return Result.Failure<RegisterDoctorResponse>(IdentityErrors.TakenUserName); return Result.Failure(IdentityErrors.TakenUserName);
#endregion #endregion
#region 3. Register (save to DB) #region 3. Register (save to DB)
var registerResult = await _userRepository.RegisterDoctorAsync(doctorUserResult.Value); var registerResult = await _userRepository.RegisterDoctorAsync(doctorUserResult.Value);
if (registerResult.IsFailure) if (registerResult.IsFailure)
return Result.Failure<RegisterDoctorResponse>(registerResult.Error); return Result.Failure(registerResult.Error);
#endregion #endregion
return RegisterDoctorResponse.GetResponse(registerResult.Value); return Result.Success();
} }
} }
using Domain.Entities.Identity.Users;
using Domain.Entities.People.Doctors;
using Domain.Errors;
using Domain.Shared;
namespace Application.Users.Commands.RegisterDoctor;
public class RegisterDoctorResponse
{
public int Id { get; set; }
public Doctor Doctor { get; set; } = null!;
public static Result<RegisterDoctorResponse> GetResponse(DoctorUser doctorUser)
{
if (doctorUser is null)
return Result.Failure<RegisterDoctorResponse>(IdentityErrors.NotFound);
return new RegisterDoctorResponse
{
Id = doctorUser.Id,
Doctor = doctorUser.Doctor
};
}
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace Application.Users.Commands.RegisterReceptionist; namespace Application.Users.Commands.RegisterReceptionist;
public class RegisterReceptionistCommand : ICommand<RegisterReceptionistResponse> public class RegisterReceptionistCommand : ICommand
{ {
public string UserName { get; set; } = null!; public string UserName { get; set; } = null!;
public string Password { get; set; } = null!; public string Password { get; set; } = null!;
......
...@@ -8,7 +8,7 @@ using Domain.UnitOfWork; ...@@ -8,7 +8,7 @@ using Domain.UnitOfWork;
namespace Application.Users.Commands.RegisterReceptionist; namespace Application.Users.Commands.RegisterReceptionist;
public class RegisterReceptionistCommandHandler : CommandHandlerBase<RegisterReceptionistCommand, RegisterReceptionistResponse> public class RegisterReceptionistCommandHandler : CommandHandlerBase<RegisterReceptionistCommand>
{ {
#region CTOR DI #region CTOR DI
private readonly IUserRepository _userRepository; private readonly IUserRepository _userRepository;
...@@ -19,7 +19,7 @@ public class RegisterReceptionistCommandHandler : CommandHandlerBase<RegisterRec ...@@ -19,7 +19,7 @@ public class RegisterReceptionistCommandHandler : CommandHandlerBase<RegisterRec
#endregion #endregion
public override async Task<Result<RegisterReceptionistResponse>> HandleHelper(RegisterReceptionistCommand request, CancellationToken cancellationToken) public override async Task<Result> HandleHelper(RegisterReceptionistCommand request, CancellationToken cancellationToken)
{ {
#region 1. Create receptionist user #region 1. Create receptionist user
Result<ReceptionistUser> receptionistUserResult = ReceptionistUser.Create( Result<ReceptionistUser> receptionistUserResult = ReceptionistUser.Create(
...@@ -29,26 +29,23 @@ public class RegisterReceptionistCommandHandler : CommandHandlerBase<RegisterRec ...@@ -29,26 +29,23 @@ public class RegisterReceptionistCommandHandler : CommandHandlerBase<RegisterRec
); );
if (receptionistUserResult.IsFailure) if (receptionistUserResult.IsFailure)
return Result.Failure<RegisterReceptionistResponse>(receptionistUserResult.Error); return Result.Failure(receptionistUserResult.Error);
#endregion #endregion
#region 2. Verify unique username #region 2. Verify unique username
var uniqueUserNameResult = await _userRepository.IsUserNameAvailableAsunc(request.UserName); var uniqueUserNameResult = await _userRepository.IsUserNameAvailableAsunc(request.UserName);
if (uniqueUserNameResult.IsFailure) if (uniqueUserNameResult.IsFailure)
return Result.Failure<RegisterReceptionistResponse>(uniqueUserNameResult.Error); return Result.Failure(uniqueUserNameResult.Error);
if (uniqueUserNameResult.Value == false) if (uniqueUserNameResult.Value == false)
return Result.Failure<RegisterReceptionistResponse>(IdentityErrors.TakenUserName); return Result.Failure(IdentityErrors.TakenUserName);
#endregion #endregion
#region 3. Register (save to DB) #region 3. Register (save to DB)
var registerResult = await _userRepository.RegisterReceptionistAsync(receptionistUserResult.Value); var registerResult = await _userRepository.RegisterReceptionistAsync(receptionistUserResult.Value);
if (registerResult.IsFailure) if (registerResult.IsFailure)
return Result.Failure<RegisterReceptionistResponse>(registerResult.Error); return Result.Failure(registerResult.Error);
#endregion #endregion
return RegisterReceptionistResponse.GetResponse(registerResult.Value); return Result.Success();
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
};
}
}
...@@ -45,7 +45,7 @@ public class UsersController : ApiController ...@@ -45,7 +45,7 @@ public class UsersController : ApiController
if (result.IsFailure) if (result.IsFailure)
return HandleFailure(result); return HandleFailure(result);
return Ok(result.Value); return Created();
} }
[Authorize(Roles = Roles.AdminName)] [Authorize(Roles = Roles.AdminName)]
...@@ -70,7 +70,7 @@ public class UsersController : ApiController ...@@ -70,7 +70,7 @@ public class UsersController : ApiController
if (result.IsFailure) if (result.IsFailure)
return HandleFailure(result); return HandleFailure(result);
return Ok(result.Value); return Created();
} }
[Authorize(Roles = Roles.AdminName)] [Authorize(Roles = Roles.AdminName)]
[HttpGet("Receptionists")] [HttpGet("Receptionists")]
......
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