Created API Controllers (#1)

Removed strongly typed inventory objects

Added EAV inventory types

Added EAV object handling philosophy

Added controllers

Added EF Core migration integration

Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
2026-05-02 19:24:06 -05:00
parent 4674529b91
commit 0b357e1e13
47 changed files with 1252 additions and 219 deletions
@@ -0,0 +1,45 @@
using Microsoft.EntityFrameworkCore;
using WyvernInventory.Core.Models;
namespace WyvernInventory.Infrastructure.Data;
public class DBContext : DbContext
{
public DBContext(DbContextOptions<DBContext> options) : base(options) {}
public DbSet<InventoryItem> InventoryItems => Set<InventoryItem>();
public DbSet<InventoryAttributeDefinition> InventoryAttributeDefinitions => Set<InventoryAttributeDefinition>();
public DbSet<InventoryAttributeValue> InventoryAttributeValues => Set<InventoryAttributeValue>();
public DbSet<InventoryType> InventoryTypes => Set<InventoryType>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<InventoryItem>()
.HasOne(_ => _.Type)
.WithMany()
.HasForeignKey(_ => _.TypeId);
modelBuilder.Entity<InventoryAttributeValue>()
.HasOne(_ => _.Item)
.WithMany(_ => _.AttributeValues)
.HasForeignKey(_ => _.ItemId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<InventoryAttributeValue>()
.HasOne(_ => _.AttributeDefinition)
.WithMany()
.HasForeignKey(_ => _.AttributeDefinitionId)
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<InventoryAttributeDefinition>()
.HasOne(_ => _.Type)
.WithMany(_ => _.AttributeDefinitions)
.HasForeignKey(_ => _.TypeId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<InventoryAttributeValue>()
.HasIndex(_ => new { _.ItemId, _.AttributeDefinitionId})
.IsUnique();
}
}
@@ -0,0 +1,182 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using WyvernInventory.Infrastructure.Data;
#nullable disable
namespace WyvernInventory.Infrastructure.Migrations
{
[DbContext(typeof(DBContext))]
[Migration("20260501023055_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryAttributeDefinition", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("DataType")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<int?>("TypeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TypeId");
b.ToTable("InventoryAttributeDefinitions");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryAttributeValue", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AttributeDefinitionId")
.HasColumnType("int");
b.Property<bool?>("BoolValue")
.HasColumnType("bit");
b.Property<DateTime?>("DateTimeValue")
.HasColumnType("datetime2");
b.Property<decimal?>("DecimalValue")
.HasColumnType("decimal(18,2)");
b.Property<int?>("IntValue")
.HasColumnType("int");
b.Property<int>("ItemId")
.HasColumnType("int");
b.Property<string>("StringValue")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("AttributeDefinitionId");
b.HasIndex("ItemId", "AttributeDefinitionId")
.IsUnique();
b.ToTable("InventoryAttributeValues");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("TypeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TypeId");
b.ToTable("InventoryItems");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryType", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("InventoryTypes");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryAttributeDefinition", b =>
{
b.HasOne("WyvernInventory.Core.Models.InventoryType", "Type")
.WithMany("AttributeDefinitions")
.HasForeignKey("TypeId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Type");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryAttributeValue", b =>
{
b.HasOne("WyvernInventory.Core.Models.InventoryAttributeDefinition", "AttributeDefinition")
.WithMany()
.HasForeignKey("AttributeDefinitionId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.HasOne("WyvernInventory.Core.Models.InventoryItem", "Item")
.WithMany("AttributeValues")
.HasForeignKey("ItemId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("AttributeDefinition");
b.Navigation("Item");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryItem", b =>
{
b.HasOne("WyvernInventory.Core.Models.InventoryType", "Type")
.WithMany()
.HasForeignKey("TypeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Type");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryItem", b =>
{
b.Navigation("AttributeValues");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryType", b =>
{
b.Navigation("AttributeDefinitions");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,136 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WyvernInventory.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "InventoryTypes",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_InventoryTypes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "InventoryAttributeDefinitions",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
TypeId = table.Column<int>(type: "int", nullable: true),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
DataType = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_InventoryAttributeDefinitions", x => x.Id);
table.ForeignKey(
name: "FK_InventoryAttributeDefinitions_InventoryTypes_TypeId",
column: x => x.TypeId,
principalTable: "InventoryTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "InventoryItems",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
TypeId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_InventoryItems", x => x.Id);
table.ForeignKey(
name: "FK_InventoryItems_InventoryTypes_TypeId",
column: x => x.TypeId,
principalTable: "InventoryTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "InventoryAttributeValues",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ItemId = table.Column<int>(type: "int", nullable: false),
AttributeDefinitionId = table.Column<int>(type: "int", nullable: false),
StringValue = table.Column<string>(type: "nvarchar(max)", nullable: true),
IntValue = table.Column<int>(type: "int", nullable: true),
DecimalValue = table.Column<decimal>(type: "decimal(18,2)", nullable: true),
BoolValue = table.Column<bool>(type: "bit", nullable: true),
DateTimeValue = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_InventoryAttributeValues", x => x.Id);
table.ForeignKey(
name: "FK_InventoryAttributeValues_InventoryAttributeDefinitions_AttributeDefinitionId",
column: x => x.AttributeDefinitionId,
principalTable: "InventoryAttributeDefinitions",
principalColumn: "Id");
table.ForeignKey(
name: "FK_InventoryAttributeValues_InventoryItems_ItemId",
column: x => x.ItemId,
principalTable: "InventoryItems",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_InventoryAttributeDefinitions_TypeId",
table: "InventoryAttributeDefinitions",
column: "TypeId");
migrationBuilder.CreateIndex(
name: "IX_InventoryAttributeValues_AttributeDefinitionId",
table: "InventoryAttributeValues",
column: "AttributeDefinitionId");
migrationBuilder.CreateIndex(
name: "IX_InventoryAttributeValues_ItemId_AttributeDefinitionId",
table: "InventoryAttributeValues",
columns: new[] { "ItemId", "AttributeDefinitionId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_InventoryItems_TypeId",
table: "InventoryItems",
column: "TypeId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "InventoryAttributeValues");
migrationBuilder.DropTable(
name: "InventoryAttributeDefinitions");
migrationBuilder.DropTable(
name: "InventoryItems");
migrationBuilder.DropTable(
name: "InventoryTypes");
}
}
}
@@ -0,0 +1,179 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using WyvernInventory.Infrastructure.Data;
#nullable disable
namespace WyvernInventory.Infrastructure.Migrations
{
[DbContext(typeof(DBContext))]
partial class DBContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.7")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryAttributeDefinition", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("DataType")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<int?>("TypeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TypeId");
b.ToTable("InventoryAttributeDefinitions");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryAttributeValue", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AttributeDefinitionId")
.HasColumnType("int");
b.Property<bool?>("BoolValue")
.HasColumnType("bit");
b.Property<DateTime?>("DateTimeValue")
.HasColumnType("datetime2");
b.Property<decimal?>("DecimalValue")
.HasColumnType("decimal(18,2)");
b.Property<int?>("IntValue")
.HasColumnType("int");
b.Property<int>("ItemId")
.HasColumnType("int");
b.Property<string>("StringValue")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("AttributeDefinitionId");
b.HasIndex("ItemId", "AttributeDefinitionId")
.IsUnique();
b.ToTable("InventoryAttributeValues");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("TypeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TypeId");
b.ToTable("InventoryItems");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryType", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("InventoryTypes");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryAttributeDefinition", b =>
{
b.HasOne("WyvernInventory.Core.Models.InventoryType", "Type")
.WithMany("AttributeDefinitions")
.HasForeignKey("TypeId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Type");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryAttributeValue", b =>
{
b.HasOne("WyvernInventory.Core.Models.InventoryAttributeDefinition", "AttributeDefinition")
.WithMany()
.HasForeignKey("AttributeDefinitionId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
b.HasOne("WyvernInventory.Core.Models.InventoryItem", "Item")
.WithMany("AttributeValues")
.HasForeignKey("ItemId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("AttributeDefinition");
b.Navigation("Item");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryItem", b =>
{
b.HasOne("WyvernInventory.Core.Models.InventoryType", "Type")
.WithMany()
.HasForeignKey("TypeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Type");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryItem", b =>
{
b.Navigation("AttributeValues");
});
modelBuilder.Entity("WyvernInventory.Core.Models.InventoryType", b =>
{
b.Navigation("AttributeDefinitions");
});
#pragma warning restore 612, 618
}
}
}
@@ -1,53 +0,0 @@
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,133 @@
using Microsoft.EntityFrameworkCore;
using WyvernInventory.Core.Interfaces.Repos;
using WyvernInventory.Core.Models;
using WyvernInventory.Infrastructure.Data;
namespace WyvernInventory.Infrastructure.Repos;
public class InventoryItemRepo(DBContext dbContext) : IInventoryItemRepo
{
private DBContext _dbContext = dbContext;
public async Task<List<InventoryItemDto>> GetAsync(List<InventoryItemRequest>? filterList = null)
{
return _dbContext.InventoryItems
.Include(_ => _.AttributeValues)
.Include(_ => _.Type)
.Select(_ => new InventoryItemDto
{
Id = (int)_.Id!,
Name = _.Name,
AttributeValues = _.AttributeValues.Select(x => new InventoryAttributeValueDto
{
Id = x.Id,
AttributeDefinitionId = (int)x.AttributeDefinitionId!,
AttributeDefinition = new InventoryAttributeDefinitionDto()
{
Id = x.AttributeDefinitionId,
Name = x.AttributeDefinition.Name,
DataType = x.AttributeDefinition.DataType
},
StringValue = x.StringValue,
IntValue = x.IntValue,
DecimalValue = x.DecimalValue,
BoolValue = x.BoolValue,
DateTimeValue = x.DateTimeValue
}).ToList(),
Type = new InventoryTypeDto()
{
Id = _.TypeId,
Name = _.Type.Name,
}
})
.ToList<InventoryItemDto>();
}
public async Task<(int created, int updated)> UpsertAsync(List<InventoryItemRequest> items)
{
var created = 0;
var updated = 0;
var itemsToCreate = items
.Where(_ => _.Id is null or 0)
.Select(_ => new InventoryItem
{
Name = _.Name,
AttributeValues = _.AttributeValues?.Select(x => new InventoryAttributeValue
{
Id = x.Id,
AttributeDefinitionId = x.AttributeDefinitionId,
BoolValue = x.BoolValue,
DateTimeValue = x.DateTimeValue,
DecimalValue = x.DecimalValue,
IntValue = x.IntValue,
StringValue = x.StringValue
}).ToList(),
TypeId = _.TypeId
})
.ToList();
var itemsToUpdate = items
.Where(_ => _.Id is not null and not 0)
.Select(_ => new InventoryItem
{
Id = _.Id,
Name = _.Name,
AttributeValues = _.AttributeValues?.Select(x => new InventoryAttributeValue
{
Id = x.Id,
AttributeDefinitionId = x.AttributeDefinitionId,
BoolValue = x.BoolValue,
DateTimeValue = x.DateTimeValue,
DecimalValue = x.DecimalValue,
IntValue = x.IntValue,
StringValue = x.StringValue
}).ToList(),
TypeId = _.TypeId
})
.ToList();
if (itemsToCreate.Count > 0)
{
_dbContext.InventoryItems.AddRange(itemsToCreate);
created = itemsToCreate.Count;
}
if (itemsToUpdate.Count > 0)
{
List<int> idList = itemsToUpdate.Select(_ =>
{
if (_.Id != null) return (int)_.Id;
throw new NullReferenceException();
}).ToList<int>();
var existingItems = _dbContext.InventoryItems.ToList()
.Where(_ => idList.Contains((int)_.Id!))
.ToDictionary(_ => (int)_.Id!);
foreach (var incoming in itemsToUpdate)
{
if (!existingItems.TryGetValue(incoming.Id!.Value, out var existing))
continue;
existing.Name = incoming.Name;
existing.AttributeValues = incoming.AttributeValues;
updated++;
}
}
await _dbContext.SaveChangesAsync();
return (created, updated);
}
public async Task<int> DeleteAsync(List<InventoryItemRequest> items)
{
var itemsToDelete = _dbContext.InventoryItems.Where(_ => items.Select(_ => _.Id).Contains(_.Id)).ToList();
_dbContext.InventoryItems.RemoveRange(itemsToDelete);
return await _dbContext.SaveChangesAsync();
}
}
@@ -0,0 +1,86 @@
using Microsoft.EntityFrameworkCore;
using WyvernInventory.Core.Interfaces.Repos;
using WyvernInventory.Core.Models;
using WyvernInventory.Infrastructure.Data;
namespace WyvernInventory.Infrastructure.Repos;
public class InventoryTypeRepo(DBContext dbContext) : IDbObjectRepo<InventoryType, InventoryTypeDto>
{
private readonly DBContext _dbContext = dbContext;
public async Task<List<InventoryTypeDto>> GetAsync(List<InventoryType>? filterList = null)
{
return _dbContext.InventoryTypes
.Include(_ => _.AttributeDefinitions)
.Select(_ => new InventoryTypeDto
{
Id = _.Id,
Name = _.Name,
AttributeDefinitions = _.AttributeDefinitions.Select(x => new InventoryAttributeDefinitionDto
{
Id = x.Id,
Name = x.Name,
DataType = x.DataType
}).ToList()
})
.ToList();
}
public async Task<(int created, int updated)> UpsertAsync(List<InventoryType> items)
{
var created = 0;
var updated = 0;
var itemsToCreate = items
.Where(_ => _.Id is null or 0)
.ToList();
var itemsToUpdate = items
.Where(_ => _.Id is not null and not 0)
.ToList();
if (itemsToCreate.Count > 0)
{
_dbContext.InventoryTypes.AddRange(itemsToCreate);
created = itemsToCreate.Count;
}
if (itemsToUpdate.Count > 0)
{
List<int> idList = itemsToUpdate.Select(_ =>
{
if (_.Id != null) return (int)_.Id;
throw new NullReferenceException();
}).ToList<int>();
var existingItems = _dbContext.InventoryTypes.ToList()
.Where(_ => idList.Contains((int)_.Id!))
.ToDictionary(_ => (int)_.Id!);
foreach (var incoming in itemsToUpdate)
{
if (!existingItems.TryGetValue(incoming.Id!.Value, out var existing))
continue;
existing.Name = incoming.Name;
existing.AttributeDefinitions = incoming.AttributeDefinitions;
updated++;
}
}
await _dbContext.SaveChangesAsync();
return (created, updated);
}
public async Task<int> DeleteAsync(List<InventoryType> items)
{
var itemsToDelete = _dbContext.InventoryTypes.Where(_ => items.Select(_ => _.Id).Contains(_.Id)).ToList();
_dbContext.InventoryTypes.RemoveRange(itemsToDelete);
return await _dbContext.SaveChangesAsync();
}
}
@@ -1,17 +0,0 @@
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,16 @@
using WyvernInventory.Core.Interfaces.Repos;
using WyvernInventory.Core.Interfaces.Services;
using WyvernInventory.Core.Models;
namespace WyvernInventory.Infrastructure.Services;
public class InventoryItemService(IInventoryItemRepo repo) : IInventoryItemService
{
private IInventoryItemRepo _repo = repo;
public async Task<List<InventoryItemDto>> GetAsync(List<InventoryItemRequest>? filter = null) => await _repo.GetAsync(filter);
public async Task<(int created, int updated)> UpsertAsync(List<InventoryItemRequest> items) => await _repo.UpsertAsync(items);
public async Task<int> DeleteAsync(List<InventoryItemRequest> items) => await _repo.DeleteAsync(items);
}
@@ -0,0 +1,16 @@
using WyvernInventory.Core.Interfaces.Repos;
using WyvernInventory.Core.Interfaces.Services;
using WyvernInventory.Core.Models;
namespace WyvernInventory.Infrastructure.Services;
public class InventoryTypeService(IDbObjectRepo<InventoryType, InventoryTypeDto> repo) : IDataObjectService<InventoryType, InventoryTypeDto>
{
private IDbObjectRepo<InventoryType, InventoryTypeDto> _repo = repo;
public async Task<List<InventoryTypeDto>> GetAsync(List<InventoryType>? filter = null) => await _repo.GetAsync(filter);
public async Task<(int created, int updated)> UpsertAsync(List<InventoryType> items) => await _repo.UpsertAsync(items);
public async Task<int> DeleteAsync(List<InventoryType> items) => await _repo.DeleteAsync(items);
}
@@ -0,0 +1,22 @@
using Microsoft.Extensions.Logging;
using Serilog.Core;
using WyvernInventory.Infrastructure.Data;
namespace WyvernInventory.Infrastructure.Utils;
public static class DbUtils
{
public static bool CanConnectToDatabase(DBContext db, ILogger<Logger> logger)
{
if (db.Database.CanConnect())
{
return true;
}
logger.LogCritical("Unable to connect to DB");
Environment.Exit(1);
return false;
}
}
@@ -10,4 +10,12 @@
<ProjectReference Include="..\WyvernInventory.Core\WyvernInventory.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>