fix
This commit is contained in:
@@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using AutoMapper;
|
||||
using Domain;
|
||||
using MyOffice.Core;
|
||||
using MyOffice.Data.Models.Accounts;
|
||||
@@ -16,20 +17,23 @@ public class ItemService
|
||||
private readonly IItemCategoryRepository _itemCategoryRepository;
|
||||
private readonly IItemRepository _itemRepository;
|
||||
private readonly IItemGlobalRepository _itemGlobalRepository;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public ItemService(
|
||||
IItemCategoryRepository itemCategoryRepository,
|
||||
IItemRepository itemRepository,
|
||||
IItemGlobalRepository itemGlobalRepository
|
||||
IItemGlobalRepository itemGlobalRepository,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
_itemCategoryRepository = itemCategoryRepository;
|
||||
_itemRepository = itemRepository;
|
||||
_itemGlobalRepository = itemGlobalRepository;
|
||||
_mapper = mapper;
|
||||
|
||||
}
|
||||
|
||||
public List<ItemCategory> GetAllCategories(Guid userId)
|
||||
public List<ItemCategoryDto> GetAllCategories(Guid userId)
|
||||
{
|
||||
var result = _itemCategoryRepository.GetAll(userId);
|
||||
if (result.All(x => x.Id != userId))
|
||||
@@ -44,35 +48,38 @@ public class ItemService
|
||||
|
||||
result.Add(_itemCategoryRepository.Get(userId, userId)!);
|
||||
}
|
||||
return result;
|
||||
return _mapper.Map<List<ItemCategoryDto>>(result);
|
||||
}
|
||||
|
||||
public Exec<ItemCategory, GeneralExecStatus> CategoryAdd(Guid userId, ItemCategory category)
|
||||
public Exec<ItemCategoryDto, GeneralExecStatus> CategoryAdd(Guid userId, ItemCategoryDto input)
|
||||
{
|
||||
if (category == null)
|
||||
throw new ArgumentNullException(nameof(category));
|
||||
if (input == null)
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
|
||||
var result = new Exec<ItemCategory, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
var result = new Exec<ItemCategoryDto, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
category.Id = Guid.NewGuid();
|
||||
category.UserId = userId;
|
||||
category.IsInternal = category.IsInternal;
|
||||
category.Items = new List<Item>();
|
||||
var category = new ItemCategory
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = userId,
|
||||
Name = input.Name,
|
||||
IsInternal = input.IsInternal,
|
||||
};
|
||||
|
||||
if (!_itemCategoryRepository.Add(category))
|
||||
{
|
||||
return result.Set(GeneralExecStatus.failure);
|
||||
}
|
||||
|
||||
return result.Set(category);
|
||||
return result.Set(_mapper.Map<ItemCategoryDto>(category));
|
||||
}
|
||||
|
||||
public Exec<ItemCategory, GeneralExecStatus> CategoryUpdate(Guid userId, Guid id, ItemCategory category)
|
||||
public Exec<ItemCategoryDto, GeneralExecStatus> CategoryUpdate(Guid userId, Guid id, ItemCategoryDto category)
|
||||
{
|
||||
if (category == null)
|
||||
throw new ArgumentNullException(nameof(category));
|
||||
|
||||
var result = new Exec<ItemCategory, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
var result = new Exec<ItemCategoryDto, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
var exists = _itemCategoryRepository.Get(userId, id);
|
||||
if (exists == null)
|
||||
@@ -82,19 +89,18 @@ public class ItemService
|
||||
|
||||
exists.Name = category.Name;
|
||||
exists.IsInternal = category.IsInternal;
|
||||
exists.Items = new List<Item>();
|
||||
|
||||
if (!_itemCategoryRepository.Update(exists))
|
||||
{
|
||||
return result.Set(GeneralExecStatus.failure);
|
||||
}
|
||||
|
||||
return result.Set(exists);
|
||||
return result.Set(_mapper.Map<ItemCategoryDto>(exists));
|
||||
}
|
||||
|
||||
public Exec<ItemCategory, ItemCategoryRemoveResult> CategoryRemove(Guid userId, Guid id)
|
||||
public Exec<ItemCategoryDto, ItemCategoryRemoveResult> CategoryRemove(Guid userId, Guid id)
|
||||
{
|
||||
var result = new Exec<ItemCategory, ItemCategoryRemoveResult>(ItemCategoryRemoveResult.success);
|
||||
var result = new Exec<ItemCategoryDto, ItemCategoryRemoveResult>(ItemCategoryRemoveResult.success);
|
||||
|
||||
var exists = _itemCategoryRepository.Get(userId, id);
|
||||
if (exists == null)
|
||||
@@ -111,33 +117,33 @@ public class ItemService
|
||||
return result.Set(ItemCategoryRemoveResult.failure);
|
||||
}
|
||||
|
||||
return result.Set(exists);
|
||||
return result.Set(_mapper.Map<ItemCategoryDto>(exists));
|
||||
}
|
||||
|
||||
public List<Item> GetAll(Guid userId)
|
||||
public List<ItemDto> GetAll(Guid userId)
|
||||
{
|
||||
return _itemRepository.GetAll(userId);
|
||||
return _mapper.Map<List<ItemDto>>(_itemRepository.GetAll(userId));
|
||||
}
|
||||
|
||||
public List<Item> GetByCategory(Guid userId, Guid categoryId)
|
||||
public List<ItemDto> GetByCategory(Guid userId, Guid categoryId)
|
||||
{
|
||||
return _itemRepository.GetByCategory(userId, categoryId);
|
||||
return _mapper.Map<List<ItemDto>>(_itemRepository.GetByCategory(userId, categoryId));
|
||||
}
|
||||
|
||||
public Exec<Item, GeneralExecStatus> Update(Guid userId, Guid motionId, Guid categoryId)
|
||||
public Exec<ItemDto, GeneralExecStatus> Update(Guid userId, Guid motionId, Guid categoryId)
|
||||
{
|
||||
var result = new Exec<Item, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
var result = new Exec<ItemDto, GeneralExecStatus>(GeneralExecStatus.success);
|
||||
|
||||
var motion = _itemRepository.GetByGlobal(userId, motionId);
|
||||
if (motion == null)
|
||||
var item = _itemRepository.GetByGlobal(userId, motionId);
|
||||
if (item == null)
|
||||
{
|
||||
return result.Set(GeneralExecStatus.not_found);
|
||||
}
|
||||
|
||||
motion.Category!.Id = categoryId;
|
||||
_itemRepository.Update(motion);
|
||||
item.CategoryId = categoryId;
|
||||
_itemRepository.Update(item);
|
||||
|
||||
return result.Set(motion);
|
||||
return result.Set(_mapper.Map<ItemDto>(item));
|
||||
}
|
||||
|
||||
public Exec<Item, ItemGetOrAddResult> GetOrCreate(Guid userId, string name)
|
||||
@@ -191,11 +197,11 @@ public class ItemService
|
||||
return result.Set(item);
|
||||
}
|
||||
|
||||
public List<Item> FindItems(Guid userId, string term, int limit = 15)
|
||||
public List<ItemDto> FindItems(Guid userId, string term, int limit = 15)
|
||||
{
|
||||
if (term == null)
|
||||
throw new ArgumentNullException(nameof(term));
|
||||
|
||||
return _itemRepository.Find(userId, term, limit);
|
||||
return _mapper.Map<List<ItemDto>>(_itemRepository.Find(userId, term, limit));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user