fix
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using AutoMapper;
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -18,28 +19,29 @@ using Services.Item;
|
||||
public class AccountController : BaseApiController
|
||||
{
|
||||
private readonly ILogger<AccountController> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly AccountService _accountService;
|
||||
private readonly ItemService _itemService;
|
||||
|
||||
public AccountController(
|
||||
ILogger<AccountController> logger,
|
||||
IMapper mapper,
|
||||
AccountService accountService,
|
||||
ItemService itemService
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
_mapper = mapper;
|
||||
_accountService = accountService;
|
||||
_itemService = itemService;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts")]
|
||||
public object AccountsGet(string category)
|
||||
public List<AccountDetailedViewModel> AccountsGet(string category)
|
||||
{
|
||||
var list = _accountService.GetByCategoryDetailed(UserId, category!.AsGuid());
|
||||
|
||||
return list
|
||||
.OrderBy(x => x.Account.Name)
|
||||
.Select(x => x.ToModel());
|
||||
return _mapper.Map<List<AccountDetailedViewModel>>(list.OrderBy(x => x.Account.Name).ToList());
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts/{id}")]
|
||||
@@ -54,7 +56,8 @@ public class AccountController : BaseApiController
|
||||
return ProblemBadRequest("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return _mapper.Map<AccountDetailedViewModel>(exec.Result);
|
||||
//return exec.Result!.ToModel();
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@ using MyOffice.Core.Identity;
|
||||
using Core;
|
||||
using Services.Users;
|
||||
using Services.Users.Domain;
|
||||
using MyOffice.Data.Models.Currencies;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
@@ -40,7 +41,8 @@ public class UserController : BaseApiController
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserName = request.UserName,
|
||||
Email = request.UserName
|
||||
Email = request.UserName,
|
||||
CurrencyId = CurrencyGlobalIdEnum.USD.ToString(),
|
||||
};
|
||||
|
||||
var result = await _userManager.CreateAsync(user, request.Password);
|
||||
|
||||
Reference in New Issue
Block a user