fix
This commit is contained in:
@@ -58,7 +58,6 @@ public class AccountController : BaseApiController
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return _mapper.Map<AccountDetailedViewModel>(exec.Result);
|
||||
//return exec.Result!.ToModel();
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -92,11 +91,11 @@ public class AccountController : BaseApiController
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case MotionAddResult.account_not_found:
|
||||
case MotionAddStatus.account_not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
case MotionAddResult.failure:
|
||||
case MotionAddStatus.failure:
|
||||
return ProblemBadRequest("Adding motion failed.");
|
||||
case MotionAddResult.success:
|
||||
case MotionAddStatus.success:
|
||||
return _mapper.Map<MotionViewModel[]>(exec.Result!);
|
||||
|
||||
default:
|
||||
@@ -111,11 +110,11 @@ public class AccountController : BaseApiController
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case MotionUpdateResult.not_found:
|
||||
case MotionUpdateStatus.not_found:
|
||||
return ProblemBadRequest("Motion not found.");
|
||||
case MotionUpdateResult.failure:
|
||||
case MotionUpdateStatus.failure:
|
||||
return ProblemBadRequest("Updating motion failed.");
|
||||
case MotionUpdateResult.success:
|
||||
case MotionUpdateStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
|
||||
default:
|
||||
@@ -130,11 +129,11 @@ public class AccountController : BaseApiController
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case MotionDeleteResult.not_found:
|
||||
case MotionDeleteStatus.not_found:
|
||||
return ProblemBadRequest("Motion not found.");
|
||||
case MotionDeleteResult.failure:
|
||||
case MotionDeleteStatus.failure:
|
||||
return ProblemBadRequest("Deliting motion failed.");
|
||||
case MotionDeleteResult.success:
|
||||
case MotionDeleteStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
|
||||
default:
|
||||
|
||||
@@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Models.Account;
|
||||
using Services.Account;
|
||||
using Services.Account.Domain;
|
||||
using MyOffice.Web.Infrastructure.Attributes;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
@@ -35,11 +36,11 @@ public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
var list = _accountService.GetAllCategories(UserId);
|
||||
|
||||
return list.OrderBy(x => x.Name).Select(x => x.ToModel());
|
||||
return _mapper.Map<AccountCategoryViewModel[]>(list).OrderBy(x => x.Name);
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/account-categories/{id}")]
|
||||
public object AccountCategory(string id)
|
||||
public object AccountCategory([AsGuid] string id)
|
||||
{
|
||||
var exec = _accountService.GetCategory(UserId, id.AsGuid());
|
||||
|
||||
@@ -50,7 +51,7 @@ public class SettingsAccountController : BaseApiController
|
||||
return ProblemBadRequest("Account category not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return _mapper.Map<AccountCategoryViewModel>(exec.Result!);
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -76,7 +77,7 @@ public class SettingsAccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/account-categories/{id}")]
|
||||
public object AccountCategoriesEdit(string id, AccountCategoryViewModel request)
|
||||
public object AccountCategoriesEdit([AsGuid] string id, AccountCategoryViewModel request)
|
||||
{
|
||||
var exec = _accountService.CategoryUpdate(UserId, id.AsGuid(), new AccountCategory { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
@@ -94,7 +95,7 @@ public class SettingsAccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/settings/account-categories/{id}")]
|
||||
public object AccountCategoriesDelete(string id)
|
||||
public object AccountCategoriesDelete([AsGuid] string id)
|
||||
{
|
||||
var exec = _accountService.CategoryRemove(UserId, id.AsGuid());
|
||||
switch (exec.Status)
|
||||
@@ -115,7 +116,7 @@ public class SettingsAccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/accounts")]
|
||||
public List<AccountViewModel> AccountsGet(string? category)
|
||||
public List<AccountViewModel> AccountsGet([AsGuid(true)] string? category)
|
||||
{
|
||||
var list = category.IsPresent()
|
||||
? _accountService.GetByCategory(UserId, category!.AsGuid())
|
||||
@@ -137,13 +138,13 @@ public class SettingsAccountController : BaseApiController
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case AccountAddResult.category_not_found:
|
||||
case AccountAddStatus.category_not_found:
|
||||
return ProblemBadRequest("Category not found.");
|
||||
case AccountAddResult.currency_not_found:
|
||||
case AccountAddStatus.currency_not_found:
|
||||
return ProblemBadRequest("Currency not found.");
|
||||
case AccountAddResult.failure:
|
||||
case AccountAddStatus.failure:
|
||||
return ProblemBadRequest("Adding account failed.");
|
||||
case AccountAddResult.success:
|
||||
case AccountAddStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
default:
|
||||
@@ -153,7 +154,7 @@ public class SettingsAccountController : BaseApiController
|
||||
|
||||
|
||||
[HttpPut("~/api/settings/accounts/{id}")]
|
||||
public object AccountsAdd(string id, AccountEditRequestModel request)
|
||||
public object AccountsAdd([AsGuid] string id, AccountEditRequestModel request)
|
||||
{
|
||||
var exec = _accountService.AccountUpdate(UserId, id.AsGuid(), new AccountEdit
|
||||
{
|
||||
@@ -166,15 +167,15 @@ public class SettingsAccountController : BaseApiController
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case AccountEditResult.not_found:
|
||||
case AccountEditStatus.not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
case AccountEditResult.category_not_found:
|
||||
case AccountEditStatus.category_not_found:
|
||||
return ProblemBadRequest("Category not found.");
|
||||
case AccountEditResult.currency_not_found:
|
||||
case AccountEditStatus.currency_not_found:
|
||||
return ProblemBadRequest("Currency not found.");
|
||||
case AccountEditResult.failure:
|
||||
case AccountEditStatus.failure:
|
||||
return ProblemBadRequest("Adding account failed.");
|
||||
case AccountEditResult.success:
|
||||
case AccountEditStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
default:
|
||||
@@ -183,7 +184,7 @@ public class SettingsAccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/settings/accounts/{id}")]
|
||||
public object AccountsDelete(string id)
|
||||
public object AccountsDelete([AsGuid] string id)
|
||||
{
|
||||
var exec = _accountService.AccountDelete(UserId, id);
|
||||
switch (exec.Status)
|
||||
@@ -199,7 +200,7 @@ public class SettingsAccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/settings/accounts/{id}/category/{categoryId}")]
|
||||
public object AccountsCategoryRemove(string id, string categoryId)
|
||||
public object AccountsCategoryRemove([AsGuid] string id, [AsGuid] string categoryId)
|
||||
{
|
||||
var exec = _accountService.AccountCategoryRemove(UserId, id.AsGuid(), categoryId.AsGuid());
|
||||
|
||||
@@ -216,4 +217,68 @@ public class SettingsAccountController : BaseApiController
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/accounts/{id}/access")]
|
||||
public object AccountsAdd([AsGuid] string id, AccountAccessViewModel request)
|
||||
{
|
||||
var model = _mapper.Map<List<AccountAccessDto>>(request.Accesses);
|
||||
|
||||
var exec = _accountService.AccessUpdate(UserId, id.AsGuid(), model);
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
|
||||
if (!request.Email.IsPresent())
|
||||
{
|
||||
return exec.Result!;
|
||||
}
|
||||
|
||||
var inviteExec = _accountService.AccessInvite(UserId, id.AsGuid(), request.Email!, request.AllowWrite);
|
||||
|
||||
switch (inviteExec.Status)
|
||||
{
|
||||
case AccessInviteStatus.account_not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
|
||||
case AccessInviteStatus.access_exists:
|
||||
return ProblemBadRequest("Access allowed.");
|
||||
|
||||
case AccessInviteStatus.invite_exists:
|
||||
case AccessInviteStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/settings/accounts/{id}/access/{userId}")]
|
||||
public object AccountsAdd([AsGuid] string id, [AsGuid] string userId)
|
||||
{
|
||||
var exec = _accountService.AccessDelete(UserId, id.AsGuid(), userId.AsGuid());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user