Initial Commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using WyvernInventory.Core.Interfaces.Repos;
|
||||
using WyvernInventory.Core.Models;
|
||||
|
||||
namespace WyvernInventory.Infrastructure.Repos;
|
||||
|
||||
public class GenericInventoryItemRepo : IDbObjectRepo<GenericInventoryItem>
|
||||
{
|
||||
private List<GenericInventoryItem> _genericItemList = [];
|
||||
|
||||
public async Task<List<GenericInventoryItem>> GetAsync(Predicate<GenericInventoryItem>? filter = null)
|
||||
{
|
||||
List<GenericInventoryItem> result = [];
|
||||
|
||||
if (filter is null) return _genericItemList;
|
||||
|
||||
result.AddRange(_genericItemList.Where(item => filter(item)));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<(int created, int updated)> UpsertAsync(List<GenericInventoryItem> items)
|
||||
{
|
||||
int created = 0;
|
||||
int updated = 0;
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item.Id is not null && _genericItemList.Any(_ => _.Id == item.Id))
|
||||
{
|
||||
int index = _genericItemList.IndexOf(_genericItemList.Find(_ => _.Id == item.Id));
|
||||
_genericItemList[index] = item;
|
||||
|
||||
updated++;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Id = _genericItemList.Count;
|
||||
_genericItemList.Add(item);
|
||||
|
||||
created++;
|
||||
}
|
||||
}
|
||||
|
||||
return (created, updated);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(List<GenericInventoryItem> items)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
_genericItemList.Remove(_genericItemList.Find(_ => _.Id == item.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using WyvernInventory.Core.Interfaces.Repos;
|
||||
using WyvernInventory.Core.Interfaces.Services;
|
||||
using WyvernInventory.Core.Models;
|
||||
|
||||
namespace WyvernInventory.Infrastructure.Services;
|
||||
|
||||
public class GenericInventoryItemService(IDbObjectRepo<GenericInventoryItem> dbRepo)
|
||||
: IDataObjectService<GenericInventoryItem>
|
||||
{
|
||||
private readonly IDbObjectRepo<GenericInventoryItem> _dbRepo = dbRepo;
|
||||
|
||||
public async Task<List<GenericInventoryItem>> GetAsync(Predicate<GenericInventoryItem>? filter = null) => await _dbRepo.GetAsync(filter);
|
||||
|
||||
public async Task<(int created, int updated)> UpsertAsync(List<GenericInventoryItem> items) => await _dbRepo.UpsertAsync(items);
|
||||
|
||||
public async Task DeleteAsync(List<GenericInventoryItem> items) => await _dbRepo.DeleteAsync(items);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WyvernInventory.Core\WyvernInventory.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user