fix
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using AutoMapper;
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Data.Models.Accounts;
|
||||
@@ -15,14 +16,17 @@ using Services.Account.Domain;
|
||||
public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
private readonly ILogger<SettingsAccountController> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly AccountService _accountService;
|
||||
|
||||
public SettingsAccountController(
|
||||
ILogger<SettingsAccountController> logger,
|
||||
IMapper mapper,
|
||||
AccountService accountService
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
_mapper = mapper;
|
||||
_accountService = accountService;
|
||||
}
|
||||
|
||||
@@ -111,15 +115,13 @@ public class SettingsAccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/accounts")]
|
||||
public object AccountsGet(string? category)
|
||||
public List<AccountViewModel> AccountsGet(string? category)
|
||||
{
|
||||
var list = category.IsPresent()
|
||||
? _accountService.GetByCategory(UserId, category!.AsGuid())
|
||||
: _accountService.GetAllAccounts(UserId);
|
||||
|
||||
return list
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => x.ToModel());
|
||||
return _mapper.Map<List<AccountViewModel>>(list.OrderBy(x => x.Name));
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/accounts")]
|
||||
@@ -130,6 +132,7 @@ public class SettingsAccountController : BaseApiController
|
||||
Name = request.Name,
|
||||
CurrencyId = request.CurrencyId,
|
||||
CategoryId = request.CategoryId.AsGuid(),
|
||||
Type = request.Type,
|
||||
});
|
||||
|
||||
switch (exec.Status)
|
||||
@@ -158,6 +161,7 @@ public class SettingsAccountController : BaseApiController
|
||||
CurrencyId = request.CurrencyId,
|
||||
CategoryId = request.CategoryId?.AsGuidNull(),
|
||||
UserId = request.UserId?.AsGuidNull(),
|
||||
Type = request.Type,
|
||||
});
|
||||
|
||||
switch (exec.Status)
|
||||
@@ -177,7 +181,23 @@ public class SettingsAccountController : BaseApiController
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpDelete("~/api/settings/accounts/{id}")]
|
||||
public object AccountsDelete(string id)
|
||||
{
|
||||
var exec = _accountService.AccountDelete(UserId, id);
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/settings/accounts/{id}/category/{categoryId}")]
|
||||
public object AccountsCategoryRemove(string id, string categoryId)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user