Files
caliverse_server/BrokerApiCore/Repository/SqlConfig/PlanetExchangeOrderConfig.cs
2025-05-01 07:23:28 +09:00

164 lines
4.5 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace BrokerApiCore;
public class PlanetExchangeOrderConfig : IEntityTypeConfiguration<PlanetItemExchangeOrder>
{
public void Configure(EntityTypeBuilder<PlanetItemExchangeOrder> builder)
{
builder.ToTable("planet_item_exchange_order");
builder.HasIndex(o => o.CreatedAt);
builder.HasIndex(o => o.OrderStatus);
builder.HasIndex(o => o.PlanetId);
builder.HasIndex(o => o.SeasonId);
builder.HasIndex(o => o.AccountId);
builder.HasIndex(o => o.UserGuid);
// 기본 키 (Primary Key)
builder.HasKey(o => o.OrderId);
builder.Property(o => o.OrderId)
.HasColumnOrder(1)
.HasColumnName("order_id")
.HasMaxLength(50)
.IsRequired()
.HasComment("교환 주문 아이디 (GUID)");
// 주문 상태 (Enum)
builder.Property(o => o.OrderStatus)
.HasColumnOrder(2)
.HasColumnName("order_status")
.IsRequired()
.HasConversion<string>()
.HasMaxLength(50)
.HasComment("교환 주문 상태");
// 플래닛 ID (string)
builder.Property(o => o.PlanetId)
.HasColumnOrder(3)
.HasColumnName("planet_id")
.HasMaxLength(50)
.IsRequired()
.HasComment("플래닛 아이디");
// PlanetInfo와의 외래 키 관계 설정
builder.HasOne<PlanetInfo>()
.WithMany()
.HasForeignKey(o => o.PlanetId)
.OnDelete(DeleteBehavior.Restrict) // 삭제 동작 정책을 Restrict로 설정
.HasConstraintName("FK_PlanetExchangeOrder_PlanetInfo");
builder.Property(o => o.SeasonId)
.HasColumnOrder(4)
.HasColumnName("season_id")
.HasMaxLength(50)
.IsRequired()
.HasComment("시즌 아이디");
builder.Property(o => o.ExchangeMetaId)
.HasColumnOrder(5)
.HasColumnName("exchange_meta_id")
.HasMaxLength(50)
.IsRequired()
.HasComment("교환 메타 아이디");
builder.Property(o => o.ExchangeMetaAmount)
.HasColumnOrder(6)
.HasColumnName("exchange_meta_amount")
.HasColumnType("INT")
.IsRequired()
.HasComment("교환 메타 수량");
// 계정 ID (ulong)
builder.Property(o => o.AccountId)
.HasColumnOrder(7)
.HasColumnName("account_id")
.HasMaxLength(50)
.IsRequired()
.HasComment("SSO 아이디");
// 사용자 GUID (string)
builder.Property(o => o.UserGuid)
.HasColumnOrder(8)
.HasColumnName("user_guid")
.HasMaxLength(50)
.IsRequired()
.HasComment("유저 아이디 (GUID)");
// 사용자 닉네임 (string)
builder.Property(o => o.Nickname)
.HasColumnOrder(9)
.HasColumnName("nickname")
.HasMaxLength(50)
.IsRequired()
.HasComment("유저 닉네임");
// 칼리버스 아이템 타입 (Enum)
builder.Property(o => o.CaliverseItemType)
.HasColumnOrder(10)
.HasColumnName("caliverse_item_type")
.IsRequired()
.HasConversion<string>()
.HasMaxLength(50)
.HasComment("칼리버스 아이템 타입");
// 칼리버스 아이템 ID (string)
builder.Property(o => o.CaliverseItemId)
.HasColumnOrder(11)
.HasColumnName("caliverse_item_id")
.HasMaxLength(50)
.IsRequired()
.HasComment("칼리버스 아이템 아이디");
// 칼리버스 아이템 수량 (long)
builder.Property(o => o.CaliverseItemDeltaAmount)
.HasColumnOrder(12)
.HasColumnName("caliverse_item_quantity")
.HasColumnType("INT")
.IsRequired()
.HasComment("칼리버스 아이템 갯수");
// 플래닛 아이템 타입 (Enum)
builder.Property(o => o.PlanetItemType)
.HasColumnOrder(13)
.HasColumnName("planet_item_type")
.IsRequired()
.HasConversion<string>()
.HasMaxLength(50)
.HasComment("플래닛 아이템 타입");
// 플래닛 아이템 ID (string)
builder.Property(o => o.PlanetItemId)
.HasColumnOrder(14)
.HasColumnName("planet_item_id")
.HasMaxLength(50)
.IsRequired()
.HasComment("플래닛 아이템 아이디");
// 플래닛 아이템 수량 (long)
builder.Property(o => o.PlanetItemDeltaAmount)
.HasColumnOrder(15)
.HasColumnName("planet_item_quantity")
.HasColumnType("INT")
.IsRequired()
.HasComment("플래닛 아이템 갯수");
// 생성 시간 (TIMESTAMP)
builder.Property(o => o.CreatedAt)
.HasColumnOrder(16)
.HasColumnName("created_at")
.HasColumnType("TIMESTAMP")
.IsRequired()
.HasDefaultValueSql("CURRENT_TIMESTAMP")
.HasComment("교환 주문 시작 시간");
// 완료 시간 (TIMESTAMP?) - Nullable
builder.Property(o => o.CompletedAt)
.HasColumnOrder(17)
.HasColumnName("completed_at")
.HasColumnType("TIMESTAMP")
.IsRequired(false)
.HasComment("교환 주문 완료 시간");
}
}