Сейчас у меня есть микросервис Account в котором реализованы два контроллера AccountsController и AuthenticationController. Сейчас они в месте так как в модели данных User есть данные и от авторизации и от персонализации. Как я понял микросервис должен выполнять только один функционал, по это хочу понять стоит ли класс User разбить на два класса скажем User и AuthData, чтобы у микросервиса Account была база с User, а у микросервиса Authentication с базой AuthData?
User
public class User
{
public int Id { get; set; }
public List<string> Roles { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string Username { get; set; }
public string PasswordHash { get; set; }
public string? RefreshToken { get; set; }
public DateTime RefreshTokenExpiryTime { get; set; }
}
AccountsController
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class AccountsController : ControllerBase
{
private readonly IMediator _mediator;
public AccountsController(IMediator mediator)
{
_mediator = mediator;
}
[HttpGet("Me/{id}")]
public async Task<IActionResult> Me(int id)
=> await _mediator.Send(new MeQuery(id));
[HttpPut("Update")]
public async Task<IActionResult> Update(UpdateCommand command)
=> await _mediator.Send(command);
[HttpGet]
[Authorize(Roles = "Admin")]
public async Task<IActionResult> GetAccounts([FromQuery] int from, [FromQuery] int count)
=> await _mediator.Send(new GetAccountsQuery(from, count));
[HttpPost]
[Authorize(Roles = "Admin")]
public async Task<IActionResult> CreateAccount(CreateAccountCommand command)
=> await _mediator.Send(command);
[HttpPut("{id}")]
[Authorize(Roles = "Admin")]
public async Task<IActionResult> UpdateAccount(int id, [FromBody] UpdateAccountCommand command)
=> await _mediator.Send(new UpdateAccountCommand(id,
command.Roles,
command.LastName,
command.FirstName,
command.Username,
command.Password));
[HttpDelete("{id}")]
[Authorize(Roles = "Admin")]
public async Task<IActionResult> DeleteAccount(int id)
=> await _mediator.Send(new DeleteAccountCommand(id));
}
AuthenticationController
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class AuthenticationController : ControllerBase
{
private readonly IMediator _mediator;
public AuthenticationController(IMediator mediator)
{
_mediator = mediator;
}
[HttpPost("SignUp")]
[AllowAnonymous]
public async Task<IActionResult> SignUp(SignUpCommand command)
=> await _mediator.Send(command);
[HttpPost("SignIn")]
[AllowAnonymous]
public async Task<IActionResult> SignIn(SignInCommand command)
=> await _mediator.Send(command);
[HttpPut("SignOut")]
public async Task<IActionResult> SignOut(SignOutCommand command)
=> await _mediator.Send(command);
[HttpGet("Validate")]
[AllowAnonymous]
public async Task<IActionResult> Validate(string accessToken)
=> await _mediator.Send(new ValidateQuery(accessToken));
[HttpPost("Refresh")]
[AllowAnonymous]
public async Task<IActionResult> Refresh(string refreshToken)
=> await _mediator.Send(new RefreshCommand(refreshToken));
}