120 lines
3.6 KiB
C#
120 lines
3.6 KiB
C#
using AutobusApi.Domain.Entities;
|
|
using AutobusApi.Domain.Enums;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace AutobusApi.Infrastructure.Data.Configurations;
|
|
|
|
public class TicketGroupConfiguration : EntityBaseConfiguration<TicketGroup>
|
|
{
|
|
public override void Configure(EntityTypeBuilder<TicketGroup> builder)
|
|
{
|
|
base.Configure(builder);
|
|
|
|
builder
|
|
.ToTable("ticket_groups")
|
|
.HasKey(e => e.Id);
|
|
|
|
builder
|
|
.Property(tg => tg.BuyerFirstName)
|
|
.HasColumnName("buyer_first_name")
|
|
.HasColumnType("varchar(32)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(tg => tg.BuyerLastName)
|
|
.HasColumnName("buyer_last_name")
|
|
.HasColumnType("varchar(32)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(tg => tg.BuyerPhoneNumber)
|
|
.HasColumnName("buyer_phone_number")
|
|
.HasColumnType("varchar(16)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(tg => tg.BuyerEmailAddress)
|
|
.HasColumnName("buyer_email")
|
|
.HasColumnType("varchar(256)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(tg => tg.PassengerFirstName)
|
|
.HasColumnName("passenger_first_name")
|
|
.HasColumnType("varchar(32)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(tg => tg.PassengerLastName)
|
|
.HasColumnName("passenger_last_name")
|
|
.HasColumnType("varchar(32)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(tg => tg.PassengerPatronymic)
|
|
.HasColumnName("passenger_patronymic")
|
|
.HasColumnType("varchar(32)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(tg => tg.PassengerSex)
|
|
.HasColumnName("passenger_sex")
|
|
.HasColumnType("varchar(16)")
|
|
.HasConversion(
|
|
e => e.ToString(),
|
|
s => (Sex)Enum.Parse(typeof(Sex), s)
|
|
)
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(tg => tg.PassengerBirthDate)
|
|
.HasColumnName("passenger_birth_date")
|
|
.HasColumnType("date")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(tg => tg.PurchaseDateTimeUtc)
|
|
.HasColumnName("purchase_timestamp_utc")
|
|
.HasColumnType("timestamptz")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(tg => tg.IsReturned)
|
|
.HasColumnName("is_returned")
|
|
.HasColumnType("boolean")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(tg => tg.BuyerEmailAddress)
|
|
.HasColumnName("buyer_email")
|
|
.HasColumnType("varchar(256)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(tg => tg.UserId)
|
|
.HasColumnName("user_id")
|
|
.HasColumnType("int")
|
|
.IsRequired(false);
|
|
|
|
builder
|
|
.HasOne(tg => tg.User)
|
|
.WithMany(u => u.TicketGroups)
|
|
.HasForeignKey(tg => tg.UserId)
|
|
.HasConstraintName("fk_ticketGroups_users_userId")
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder
|
|
.HasMany(tg => tg.Tickets)
|
|
.WithOne(t => t.TicketGroup)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder
|
|
.HasOne(tg => tg.TicketDocument)
|
|
.WithOne(td => td.TicketGroup)
|
|
.HasForeignKey<TicketGroup>(tg => tg.TicketDocumentId)
|
|
.HasConstraintName("fk_ticketGroups_ticketDocuments_ticketDocumentId")
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|