This commit is contained in:
2023-07-23 20:27:23 +03:00
parent d0cdaa85b6
commit 96eca795ab
62 changed files with 2934 additions and 847 deletions
+57 -9
View File
@@ -1,5 +1,6 @@
namespace MyOffice.Services.Account
{
using AutoMapper;
using Core;
using Core.Extensions;
using Core.Helpers;
@@ -16,7 +17,9 @@
public class AccountService
{
private ILogger<AccountService> _logger;
private readonly IMapper _mapper;
private readonly IAccountCategoryRepository _accountCategoryRepository;
private readonly IAccountAccessRepository _accountAccessRepository;
private readonly IAccountRepository _accountRepository;
private readonly ICurrencyRepository _currencyRepository;
private readonly IAccountAccountCategoryRepository _accountAccountCategoryRepository;
@@ -27,7 +30,9 @@
public AccountService(
ILogger<AccountService> logger,
IMapper mapper,
IAccountCategoryRepository accountCategoryRepository,
IAccountAccessRepository accountAccessRepository,
IAccountRepository accountRepository,
ICurrencyRepository currencyRepository,
IAccountAccountCategoryRepository accountAccountCategoryRepository,
@@ -38,7 +43,9 @@
)
{
_logger = logger;
_mapper = mapper;
_accountCategoryRepository = accountCategoryRepository;
_accountAccessRepository = accountAccessRepository;
_accountRepository = accountRepository;
_currencyRepository = currencyRepository;
_accountAccountCategoryRepository = accountAccountCategoryRepository;
@@ -130,24 +137,24 @@
return result.Set(exists);
}
public List<Account> GetAllAccounts(Guid userId)
public List<AccountDto> GetAllAccounts(Guid userId)
{
return _accountRepository.GetAll(userId);
return _mapper.Map<List<AccountDto>>(_accountRepository.GetAll(userId));
}
public List<Account> GetByCategory(Guid userId, Guid categoryId)
public List<AccountDto> GetByCategory(Guid userId, Guid categoryId)
{
return _accountRepository.GetByCategory(userId, categoryId);
return _mapper.Map<List<AccountDto>>(_accountRepository.GetByCategory(userId, categoryId));
}
public List<AccountDetailed> GetByCategoryDetailed(Guid userId, Guid categoryId)
public List<AccountDetailedDto> GetByCategoryDetailed(Guid userId, Guid categoryId)
{
return _accountRepository.GetByCategoryDetailed(userId, categoryId);
return _mapper.Map<List<AccountDetailedDto>>(_accountRepository.GetByCategoryDetailed(userId, categoryId));
}
public Exec<AccountDetailed, GeneralExecStatus> GetByIdDetailed(Guid userId, Guid id)
public Exec<AccountDetailedDto, GeneralExecStatus> GetByIdDetailed(Guid userId, Guid id)
{
var result = new Exec<AccountDetailed, GeneralExecStatus>(GeneralExecStatus.success);
var result = new Exec<AccountDetailedDto, GeneralExecStatus>(GeneralExecStatus.success);
var account = _accountRepository.GetByIdDetailed(userId, id);
if (account == null)
@@ -155,7 +162,7 @@
return result.Set(GeneralExecStatus.not_found);
}
return result.Set(account);
return result.Set(_mapper.Map<AccountDetailedDto>(account));
}
public Exec<Account, AccountAddResult> AccountAdd(Guid userId, AccountAdd input)
@@ -208,9 +215,40 @@
return result.Set(AccountAddResult.failure);
}
var access = account.AccessRights!.FirstOrDefault(x => x.UserId == userId);
if (access != null && access.Type.ToString() != input.Type)
{
if (Enum.TryParse<AccountAccessTypeEnum>(input.Type, out var enumType))
{
access.Type = enumType;
_accountAccessRepository.Update(access);
}
}
return result.Set(account);
}
public Exec<Account, GeneralExecStatus> AccountDelete(Guid userId, string id)
{
var result = new Exec<Account, GeneralExecStatus>(GeneralExecStatus.success);
var account = _accountRepository.Get(userId, id.AsGuid());
if (account == null)
{
return result.Set(GeneralExecStatus.not_found);
}
if (account.Motions!.Any())
{
return result.Set(GeneralExecStatus.not_found);
}
_accountRepository.Delete(account);
result.Set(account);
return result;
}
public Exec<Account, AccountEditResult> AccountUpdate(Guid userId, Guid accountId, AccountEdit input)
{
if (input == null)
@@ -263,6 +301,16 @@
return result.Set(AccountEditResult.failure);
}
var access = account.AccessRights!.FirstOrDefault(x => x.UserId == userId);
if (access != null && access.Type.ToString() != input.Type)
{
if (Enum.TryParse<AccountAccessTypeEnum>(input.Type, out var enumType))
{
access.Type = enumType;
_accountAccessRepository.Update(access);
}
}
return result.Set(account);
}