This commit is contained in:
2023-07-29 16:25:16 +03:00
parent 90f0386bfe
commit 4312a5c084
34 changed files with 1998 additions and 61 deletions
@@ -10,6 +10,7 @@ using Models.Account;
using Services.Account;
using Services.Account.Domain;
using MyOffice.Web.Infrastructure.Attributes;
using Services.Identity;
[Authorize]
[ApiController]
@@ -19,16 +20,19 @@ public class SettingsAccountController : BaseApiController
private readonly ILogger<SettingsAccountController> _logger;
private readonly IMapper _mapper;
private readonly AccountService _accountService;
private readonly IContextProvider _contextProvider;
public SettingsAccountController(
ILogger<SettingsAccountController> logger,
IMapper mapper,
AccountService accountService
AccountService accountService,
IContextProvider contextProvider
)
{
_logger = logger;
_mapper = mapper;
_accountService = accountService;
_contextProvider = contextProvider;
}
[HttpGet("~/api/settings/account-categories")]
@@ -251,8 +255,6 @@ public class SettingsAccountController : BaseApiController
return ProblemBadRequest("Account not found.");
case AccessInviteStatus.access_exists:
return ProblemBadRequest("Access allowed.");
case AccessInviteStatus.invite_exists:
case AccessInviteStatus.success:
return exec.Result!;
@@ -279,6 +281,53 @@ public class SettingsAccountController : BaseApiController
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpGet("~/api/settings/accounts/invites")]
public List<AccountAccessInviteViewModel> AccountInvites()
{
var invites = _accountService.InvitesGet(_contextProvider.User.Email);
return _mapper.Map<List<AccountAccessInviteViewModel>>(invites);
}
[HttpPost("~/api/settings/accounts/invites/{id}/accept")]
public object AccountInviteAccept([AsGuid]string id, AccountInviteAcceptRequest request)
{
var exec = _accountService.InviteAccept(UserId, id.AsGuid(), request.Name);
switch (exec.Status)
{
case InviteAcceptStatus.invite_not_found:
return ProblemBadRequest("Invite not found.");
case InviteAcceptStatus.account_not_found:
return ProblemBadRequest("Account not found.");
case InviteAcceptStatus.already_accepted:
case InviteAcceptStatus.success:
return _mapper.Map<AccountViewModel>(exec.Result!);
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpPost("~/api/settings/accounts/invites/{id}/reject")]
public object AccountInviteReject([AsGuid] string id)
{
var exec = _accountService.InviteReject(id.AsGuid());
switch (exec.Status)
{
case GeneralExecStatus.not_found:
case GeneralExecStatus.failure:
return ProblemBadRequest("Invite not found.");
case GeneralExecStatus.success:
return _mapper.Map<AccountAccessInviteViewModel>(exec.Result!);
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
}