Добавил слой Infrastructure

This commit is contained in:
2026-04-28 15:52:19 +03:00
parent 25d617639c
commit df0e30a1ae
32 changed files with 4139 additions and 0 deletions
@@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using UniVerse.Domain.Entities;
namespace UniVerse.Infrastructure.Data.Configurations;
public class CoinTransactionConfiguration : IEntityTypeConfiguration<CoinTransaction>
{
public void Configure(EntityTypeBuilder<CoinTransaction> builder)
{
builder.ToTable("coin_transactions");
builder.HasKey(ct => ct.Id);
builder.Property(ct => ct.Id).HasColumnName("id");
builder.Property(ct => ct.UserId).HasColumnName("user_id");
builder.Property(ct => ct.Amount).HasColumnName("amount");
builder.Property(ct => ct.Type).HasColumnName("type");
builder.Property(ct => ct.ReviewId).HasColumnName("review_id");
builder.Property(ct => ct.AchievementId).HasColumnName("achievement_id");
builder.Property(ct => ct.Description).HasColumnName("description").HasMaxLength(500);
builder.Property(ct => ct.CreatedAt).HasColumnName("created_at").HasDefaultValueSql("NOW()");
builder.HasOne(ct => ct.User)
.WithMany(u => u.CoinTransactions)
.HasForeignKey(ct => ct.UserId)
.OnDelete(DeleteBehavior.Cascade);
builder.HasOne(ct => ct.Review)
.WithMany(r => r.CoinTransactions)
.HasForeignKey(ct => ct.ReviewId)
.OnDelete(DeleteBehavior.SetNull);
builder.HasOne(ct => ct.Achievement)
.WithMany()
.HasForeignKey(ct => ct.AchievementId)
.OnDelete(DeleteBehavior.SetNull);
builder.HasIndex(ct => ct.UserId);
}
}