fix
This commit is contained in:
@@ -35,101 +35,17 @@ public class SettingsAccountController : BaseApiController
|
||||
_contextProvider = contextProvider;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/account-categories")]
|
||||
public object AccountCategories()
|
||||
{
|
||||
var list = _accountService.GetAllCategories(UserId);
|
||||
|
||||
return _mapper.Map<AccountCategoryViewModel[]>(list).OrderBy(x => x.Name);
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/account-categories/{id}")]
|
||||
public object AccountCategory([AsGuid] string id)
|
||||
{
|
||||
var exec = _accountService.GetCategory(UserId, id.AsGuid());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadResponse("Account category not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return _mapper.Map<AccountCategoryViewModel>(exec.Result!);
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/account-categories")]
|
||||
public object AccountCategoriesAdd(AccountCategoryViewModel request)
|
||||
{
|
||||
var exec = _accountService.CategoryAdd(UserId, new AccountCategoryDto { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadResponse("Adding account category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/account-categories/{id}")]
|
||||
public object AccountCategoriesEdit([AsGuid] string id, AccountCategoryViewModel request)
|
||||
{
|
||||
var exec = _accountService.CategoryUpdate(UserId, id.AsGuid(), new AccountCategoryDto { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadResponse("Update account category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/settings/account-categories/{id}")]
|
||||
public object AccountCategoriesDelete([AsGuid] string id)
|
||||
{
|
||||
var exec = _accountService.CategoryRemove(UserId, id.AsGuid());
|
||||
switch (exec.Status)
|
||||
{
|
||||
case AccountCategoryRemoveResult.success:
|
||||
return exec.Result!;
|
||||
|
||||
case AccountCategoryRemoveResult.failure:
|
||||
return ProblemBadResponse("Remove account category failed.");
|
||||
case AccountCategoryRemoveResult.not_found:
|
||||
return ProblemBadResponse("Account category not found.");
|
||||
case AccountCategoryRemoveResult.accounts_exists:
|
||||
return ProblemBadResponse("Account category have accounts.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/accounts")]
|
||||
public List<AccountViewModel> AccountsGet([AsGuid(true)] string? category)
|
||||
public ObjectResult AccountsGet([AsGuid(true)] string? category)
|
||||
{
|
||||
var list = category.IsPresent()
|
||||
? _accountService.GetByCategory(UserId, category!.AsGuid())
|
||||
: _accountService.GetAllAccounts(UserId);
|
||||
|
||||
return _mapper.Map<List<AccountViewModel>>(list.OrderBy(x => x.Name));
|
||||
return OkResponse(list.ToViewModel(_mapper));
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/accounts")]
|
||||
//[HttpPost("~/api/settings/accounts")]
|
||||
public object AccountsAdd(AccountViewModel request)
|
||||
{
|
||||
var exec = _accountService.AccountAdd(UserId, new AccountAdd
|
||||
@@ -149,7 +65,7 @@ public class SettingsAccountController : BaseApiController
|
||||
case AccountAddStatus.failure:
|
||||
return ProblemBadResponse("Adding account failed.");
|
||||
case AccountAddStatus.success:
|
||||
return exec.Result!;
|
||||
return _mapper.Map<AccountViewModel>(exec.Result!);
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -180,7 +96,7 @@ public class SettingsAccountController : BaseApiController
|
||||
case AccountEditStatus.failure:
|
||||
return ProblemBadResponse("Adding account failed.");
|
||||
case AccountEditStatus.success:
|
||||
return exec.Result!;
|
||||
return _mapper.Map<AccountViewModel>(exec.Result!);
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -196,7 +112,7 @@ public class SettingsAccountController : BaseApiController
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadResponse("Account not found.");
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!;
|
||||
return _mapper.Map<AccountViewModel>(exec.Result!);
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
|
||||
Reference in New Issue
Block a user