ItemDB+API
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Server.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Database-backed crafting recipe for Void Scavengers
|
||||
/// </summary>
|
||||
public sealed class GameRecipe
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ResultItemId { get; set; }
|
||||
public bool IsEnabled { get; set; } = true;
|
||||
|
||||
// Resource costs
|
||||
public int ScrapCost { get; set; }
|
||||
public int EnergyCost { get; set; }
|
||||
public int RareCost { get; set; }
|
||||
|
||||
// Timestamps
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
// Navigation
|
||||
public GameItem? ResultItem { get; set; }
|
||||
}
|
||||
|
||||
public sealed class GameRecipeConfig : IEntityTypeConfiguration<GameRecipe>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<GameRecipe> e)
|
||||
{
|
||||
e.ToTable("game_recipes");
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedNever();
|
||||
|
||||
e.HasIndex(x => x.ResultItemId);
|
||||
e.HasIndex(x => x.IsEnabled);
|
||||
|
||||
e.HasOne(x => x.ResultItem)
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ResultItemId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
e.Property(x => x.IsEnabled).HasDefaultValue(true);
|
||||
e.Property(x => x.CreatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)");
|
||||
e.Property(x => x.UpdatedAt).HasDefaultValueSql("CURRENT_TIMESTAMP(6)")
|
||||
.ValueGeneratedOnAddOrUpdate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user